Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shooting game source code  (Read 9007 times)
0 Members and 1 Guest are viewing this topic.
Offline Graziano Mesina

Senior Newbie





« Posted 2005-08-04 09:30:03 »

Hi, I would write my first java game (a shooter), but i've some problem to start with it.
I think that a good idea is to look some simple source code.

Can anyone help me?

-Montanelli-: Ma lei evadeva quasi sempre, no? <br /><br />-Mesina-: Sì, ho la fortuna di avere i polsi più grossi delle mani...
Offline shmoove

Junior Member




Doh!


« Reply #1 - Posted 2005-08-04 11:17:14 »

Space Invaders 101

shmoove
Offline Graziano Mesina

Senior Newbie





« Reply #2 - Posted 2005-08-04 13:46:53 »

thnx very much, it's a good start point.

-Montanelli-: Ma lei evadeva quasi sempre, no? <br /><br />-Mesina-: Sì, ho la fortuna di avere i polsi più grossi delle mani...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Delnizz

Junior Newbie





« Reply #3 - Posted 2005-10-28 04:34:12 »

Hello all,

I am new to game programming, but not to java.  I have been trying to follow a couple of Space Invaders tutorials like the one listed above, but I am having trouble getting the code to compile.  I believe this is because I am using Java1.5 instead of 1.4.
Can anyone help me out with this?

How the heck do you mark text as Code?  the "Insert Code" button in here doesn't seem to do anything???

Code:----------------------------------------------------------------------------
// create a frame to contain our game
JFrame container = new JFrame("Space Invaders 101");
      
// get hold the content of the frame and set up the
// resolution of the game
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(800,600));
panel.setLayout(null);
      
// setup our canvas size and put it into the content of the frame
setBounds(0,0,800,600);
panel.add(this);
End Code-------------------------------------------------------------------------

The compiler gripes about the line saying:
panel.add(this);
It doesn't seem to be able to find the object that "this" points to.

Also, I don't understand the line:
JPanel panel = (JPanel) container.getContentPane();
What does this do?

I am used to something more like:
JPanel panel = new JPanel();
container.getContentPane();

Does anyone know of any gaming tutorials out there for the 1.5 Java?

Delnizz
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2005-10-28 08:36:56 »

You can use  [ code ]  [ /code ] tags round blocks to make them show up as code.

You'd need to post the exact the compiler failure message and the full code to be able to determine the problem here.

Kev

Offline Delnizz

Junior Newbie





« Reply #5 - Posted 2005-10-28 15:26:49 »

In the Space invaders101 program the error is:
org.newdawn.spaceinvaders.game does not exist

In the spanish space invaders page it is the same error pretty much:
version03.invaders does not exist

I am 100% positive the problem is that I am using java1.5.  This is just the first few errors.  Any use of the "this" pointer is resulting in an error similar to this.  Also some of the method calls for the Image class are not recognized.  They have probably been changed.

I really need to find something that was written for java 1.5.

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2005-10-28 15:35:14 »

Just means you either haven't got package at the top of the file where you should have, or the directory structure is off (i.e. it doesn't contain the directories org/newdawn/spaceinvaders/game)

Kev

Offline Delnizz

Junior Newbie





« Reply #7 - Posted 2005-10-28 18:39:16 »

Yes, that is exactly right.

But that doesn't solve the problem as I do have the package there and the directory structure is right.  I have also tried just compiling the source code for each of these tutorials as the author wrote it.  It won't compile.  Obviously, this isn't something where the syntax is wrong.
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2005-10-29 07:59:13 »

Given that plenty of people have infact done both those tutorials (in both 1.4 and 1.5) can we make the assumption for now that its infact that you're doing something wrong (or at least theres an assumption that the other people took that you haven't) rather than there is something intrinsicly wrong with the tutorials for 1.5.

Maybe you could cut and paste the errors you're getting?

Could you possibly explain the exact situation in which you're compiling - are you doing it from the command line, from an ide? Which directory are you in when you compiling if you are doing it from the command line?

Could you maybe tell us how much experience you have with compiling Java - if you've compiled lots of complicated things before we could all assume all the silly problems arn't the case here?

More information will definitely help us help you.

Kev

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #9 - Posted 2005-10-29 08:26:41 »

In the Space invaders101 program the error is:
org.newdawn.spaceinvaders.game does not exist

This usually happens when the source root directory (from which all the package paths are derived) is incorrectly specified.
When you mounted the directory for the project, it should be the one above the 'org' directory.

The file structure (assuming you are using an IDE) should be:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
- org
-- newdawn
--- spaceinvaders
---- AlienEntity
---- Entity
---- Game
---- ShipEntity
---- ShotEntity
---- Sprite
---- SpriteStore
- sprites
-- alien
-- ship
-- shot


I just D/L'd compiled & ran the tutorial (admittedly compiled with 1.4.2) with no problems.  Those aliens look as good as ever Smiley

/Edit:  And here is how to compile & run from the command line:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Alan Waddington>cd \User\Java\spaceinvaders101\spaceinvaders

C:\User\Java\spaceinvaders101\spaceinvaders>C:\j2sdk1.4.2_08\bin\javac org/newdawn/spaceinvaders/*.java

C:\User\Java\spaceinvaders101\spaceinvaders>C:\j2sdk1.4.2_08\bin\java org/newdawn/spaceinvaders/Game

C:\User\Java\spaceinvaders101\spaceinvaders>


1. Set current directory to the directory above the 'org' directory
2. Run the javac compiler (you may need to specify the full path to the compiler, which will differ from mine)
3. Run the java interpreter.
4. Kill pesky aliens.

/Edit2 I Installed Java 1.5 SDK just to check that works - It does - but there are some warnings.

1  
2  
3  
4  
5  
6  
7  
C:\User\Java\spaceinvaders101\spaceinvaders>"C:\Program Files\Java\jdk1.5.0_05\bin\javac" org\newdawn\spaceinvaders\*.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

C:\User\Java\spaceinvaders101\spaceinvaders>"C:\Program Files\Java\jdk1.5.0_05\bin\java" org.newdawn.spaceinvaders.Game

C:\User\Java\spaceinvaders101\spaceinvaders>


Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Psalms23rd

Innocent Bystander





« Reply #10 - Posted 2005-11-27 10:36:29 »

Will one of you guys send me the whole code for the space invaders game. For some odd reason the file willn't unzip. Thank you!
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #11 - Posted 2005-11-27 10:51:35 »

Try to redownload it. The file got most likely corrupted during download. (The filesize is 13,100 Bytes.)

弾幕 ☆ @mahonnaiseblog
Offline richardGoulter

Senior Newbie




Java - n. 2nd only to Chocolate


« Reply #12 - Posted 2005-12-31 22:48:05 »

Somewhere else to look for starting game programming is Java Cooperation

don't have the link, too lazy, just search it on google.

Sorry if i tick anyone off saying that, but that's where i learned game programming from

it also gives a different variety of game programming styles (if that makes sense)


Note: it does use AWT, a downside (Swing is better, no need to double buffer the screen output).

What do i put here, i wonder... 218, 211, 207...
Offline richardGoulter

Senior Newbie




Java - n. 2nd only to Chocolate


« Reply #13 - Posted 2006-01-01 00:38:03 »

btw:

when giving examples of your compiling you used the full path name to javac
why not just add it to the classpath environment variable? saves tonnes of typing,
it took me ages to figure out how to do this, originally, but i figured it out.
i'm a windows xp person, so i can only give you that way, but the readme the with the jdk, sdk thing
says how to do it on each platform and each flavor of windows

for windows xp it's in the "My Computer"->properties->advanced->environment variables
you then change classpath (separate it with a ' ; ' from the other stuff).
make sure that the '.' directory is still in the classpath too, otherwise java code won't compile

What do i put here, i wonder... 218, 211, 207...
Offline Mr_Light

Senior Member




shiny.


« Reply #14 - Posted 2006-01-02 13:16:54 »

can any one explain me why 1.4 source wouldn't compile under 5, sure there might be a few warnings.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Anon666

Junior Member




aka Abuse/AbU5e/TehJumpingJawa


« Reply #15 - Posted 2006-01-02 13:31:19 »

can any one explain me why 1.4 source wouldn't compile under 5, sure there might be a few warnings.

As of 1.5 "enum" has been made a keyword as so canno tbe used for variables, this for example is now illegal :-

1  
java.util.Enumeration enum;
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #16 - Posted 2006-01-03 07:32:09 »

when giving examples of your compiling you used the full path name to javac
why not just add it to the classpath environment variable? saves tonnes of typing,

Yep, although most of the time I'm using the IDE rather than the command line.  The command line just was more minimalistic for the examples. Smiley

The reason for the full path is that I have several different compilers installed and just find it easier, so as to be sure I'm using the right one.  It also made the example more stand alone, as it didn't require any previous environment variable tweaking.

Alan

Time flies like a bird. Fruit flies like a banana.
Offline Mr_Light

Senior Member




shiny.


« Reply #17 - Posted 2006-01-03 20:06:30 »

As of 1.5 "enum" has been made a keyword as so canno tbe used for variables, this for example is now illegal :-

1  
java.util.Enumeration enum;


ah yes, how dense of me. adding keywords can also cause issues not just taking them out.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (30 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!