Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 6042 times)
0 Members and 1 Guest are viewing this topic.
Offline Graziano Mesina

Senior Newbie





« Posted 2005-08-04 11: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 13:17:14 »

Space Invaders 101

shmoove
Offline Graziano Mesina

Senior Newbie





« Reply #2 - Posted 2005-08-04 15: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!
Try the Free Demo of Droid Assault
Offline Delnizz

Junior Newbie





« Reply #3 - Posted 2005-10-28 06: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
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #4 - Posted 2005-10-28 10: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 17: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
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #6 - Posted 2005-10-28 17: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 20: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
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #8 - Posted 2005-10-29 09: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: 7
Projects: 3


Java tames rock!


« Reply #9 - Posted 2005-10-29 10: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!
Try the Free Demo of Revenge of the Titans
Offline Psalms23rd

JGO Visitor




« Reply #10 - Posted 2005-11-27 11: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: 1


pixels! :x


« Reply #11 - Posted 2005-11-27 11: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 23: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 01: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 14: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 14: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: 7
Projects: 3


Java tames rock!


« Reply #16 - Posted 2006-01-03 08: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 21: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (91 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (123 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (196 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.158 seconds with 21 queries.