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?
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?
thnx very much, it’s a good start point.
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
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
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.
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
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.
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
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:
- 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
/Edit: And here is how to compile & run from the command line:
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>
/Edit2 I Installed Java 1.5 SDK just to check that works - It does - but there are some warnings.
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>
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!
Try to redownload it. The file got most likely corrupted during download. (The filesize is 13,100 Bytes.)
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).
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
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 :-
java.util.Enumeration enum;
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.
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
ah yes, how dense of me. adding keywords can also cause issues not just taking them out.