Programming non-applet games 2D

Hey guys, Im trying to program an offline platform shooter, iv scoured the net for a few hours and cant find any tutorials or resources for game programming without the applet.

Iv tried to work it out myself by embedding the applet in a JFrame, but that didnt help because you need to repaint the whole lot or else you end up with trailing, plus im pretty sure its not the best way to program it.

Can anyone point me to tutorials or resources that deals with this subject? thanks, Dave

Can anyone point me to tutorials or resources that deals with this subject?

Sure.

http://www.cokeandcode.com/tutorials

suuweeet! thanks a lot man 8)

Hmm…this is odd, this tutorial wont compile because Game makes referance to AlienShip, and AlienShip makes a referance to game…

X:\foo\spaceinvaders.zip\spaceinvaders>javac org/newdawn/spaceinvaders/Game.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

X:\foo\spaceinvaders.zip\spaceinvaders>java org.newdawn.spaceinvaders.Game

Works just fine here.

if i compile “game.java” in jcreator it says “cannot symbol class AlienEntity”

Javac is not recognised by my command line, grrr, this is what happens when i switch from linux to windows, im not good at configuring this.

nope, just got javac working properly and same problem.

Your classpath or source file path is not properly configured.

Did you use the -sourcepath arg to javac?

Java uses a multipass compiler so there is no problem with circular references like Game->Ship and Ship->Game.

no…i just used

javac Game.java

Sorry, i must be frustrating you guys by now, we always compiled from IDE’s so im not used to the command line args.

No problem, seems to be a common one, its probably to do with the package that Game is in. You see in onyx’s example he did this:

because you need to compile from the base of the package structure and because Game is in the package “org.newdawn.spaceinvaders”.

Kev

:’(

I have just tried that in cmd.exe, its still giving me 24 errors in the first game and 40 in spaceinvaders104.

Incase it is effecting it heres some details

package path : C:/JAVA/spaceinvaders/ (then /org and /sprites)

current path == C:/JAVA/spaceinvaders/
command im using : >javac org/newdawn/spaceinvaders/Game.java

I was using javac at the base of the package, i was also using jcreator.

By the way, thanks for your help!
Also, nice site, its the only one iv been sent to thats not entirely applet based

Added
i got it to compile with this :
in the director of game.java
javac *.java
but now i cant get it to run , i try java game.class but it says undefined class game()

Well, its “Game” and not “game”.

Eventually your java installation is broken. My bro’s install was b0rked once and it behaved very weird. So, maybe its a good idea to uninstall java and install it again. Set up the path stuff (+ -> advanced (or something) -> environment variables… add the jdk’s bin path to path… eg it could look like this: C:\Programme\GTK2-Runtime\lib;D:\java\jdk1.5.0_05\bin) and then try it again.

Erh. Why not install an editor like eclipse? I haven’t manually compiled a java program in years! And I shudder at what I had to go through back in those days… The difference is night and day.

Its pretty good to get compilation to work at the command line as a start - always nice to begin with the basics and build up.

Kev

This command line stuff is also the easiest way to reproduce.

X:\foo\spaceinvaders.zip\spaceinvaders>dir/b
org
sprites

X:\foo\spaceinvaders.zip\spaceinvaders>javac org/newdawn/spaceinvaders/Game.java
Note: org/newdawn/spaceinvaders/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

X:\foo\spaceinvaders.zip\spaceinvaders>java org.newdawn.spaceinvaders.Game

C’mon… its easy.

Im doing exactly as you said man…seriously.

My Path : > dir
C:\JAVA\spaceinvaders

dir/b
org
sprites

javac org/newdawn/spaceinvaders/Game.java

24 compile errors

I just reinstalled java SDK with the newest update and its making no difference.
Is it something iv screwed up or is my system actually screwed?

Could you list the errors, it might help.

Kev

All the errors are

cannot find symbol
Class : Entity/ShotEntity/AlienEntity
Location : org.newdawn.spaceinvaders.Game

Heres the exact dump from the console :
C:\JAVA\spaceinvaders>dir/b
org
sprites

C:\JAVA\spaceinvaders>javac org/newdawn/spaceinvaders/Game.java
org/newdawn/spaceinvaders/Game.java:42: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
private Entity ship;
^
org/newdawn/spaceinvaders/Game.java:170: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
public void removeEntity(Entity entity) {
^
org/newdawn/spaceinvaders/Game.java:141: cannot find symbol
symbol : class ShipEntity
location: class org.newdawn.spaceinvaders.Game
ship = new ShipEntity(this,“sprites/ship.gif”,370,550);
^
org/newdawn/spaceinvaders/Game.java:148: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity alien = new AlienEntity(this,“sprites/ali
en.gif”,100+(x50),(50)+row30);
^
org/newdawn/spaceinvaders/Game.java:148: cannot find symbol
symbol : class AlienEntity
location: class org.newdawn.spaceinvaders.Game
Entity alien = new AlienEntity(this,“sprites/ali
en.gif”,100+(x50),(50)+row30);
^
org/newdawn/spaceinvaders/Game.java:205: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i);
^
org/newdawn/spaceinvaders/Game.java:205: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i);
^
org/newdawn/spaceinvaders/Game.java:207: cannot find symbol
symbol : class AlienEntity
location: class org.newdawn.spaceinvaders.Game
if (entity instanceof AlienEntity) {
^
org/newdawn/spaceinvaders/Game.java:227: cannot find symbol
symbol : class ShotEntity
location: class org.newdawn.spaceinvaders.Game
ShotEntity shot = new ShotEntity(this,“sprites/shot.gif”,ship.ge
tX()+10,ship.getY()-30);
^
org/newdawn/spaceinvaders/Game.java:227: cannot find symbol
symbol : class ShotEntity
location: class org.newdawn.spaceinvaders.Game
ShotEntity shot = new ShotEntity(this,“sprites/shot.gif”,ship.ge
tX()+10,ship.getY()-30);
^
org/newdawn/spaceinvaders/Game.java:227: operator + cannot be applied to Entity.
getX,int
ShotEntity shot = new ShotEntity(this,“sprites/shot.gif”,ship.ge
tX()+10,ship.getY()-30);

^
org/newdawn/spaceinvaders/Game.java:262: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i)
;
^
org/newdawn/spaceinvaders/Game.java:262: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i)
;
^
org/newdawn/spaceinvaders/Game.java:270: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i);
^
org/newdawn/spaceinvaders/Game.java:270: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i);
^
org/newdawn/spaceinvaders/Game.java:280: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity me = (Entity) entities.get§;
^
org/newdawn/spaceinvaders/Game.java:280: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity me = (Entity) entities.get§;
^
org/newdawn/spaceinvaders/Game.java:281: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity him = (Entity) entities.get(s);
^
org/newdawn/spaceinvaders/Game.java:281: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity him = (Entity) entities.get(s);
^
org/newdawn/spaceinvaders/Game.java:299: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i)
;
^
org/newdawn/spaceinvaders/Game.java:299: cannot find symbol
symbol : class Entity
location: class org.newdawn.spaceinvaders.Game
Entity entity = (Entity) entities.get(i)
;
^
Note: org/newdawn/spaceinvaders/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
21 errors

Well, your java installation is broken, because the current directory isnt in the classpath (its in the classpath by default since 1.3 iirc).

Try “javac -cp . org/newdawn/spaceinvaders/Game.java” instead.

ok…that worked…

i try to java the Game class file and i get

C:\JAVA\spaceinvaders>java org/newdawn/spaceinvaders/Game.class
Exception in thread “main” java.lang.NoClassDefFoundError: org/newdawn/spaceinva
ders/Game/class

How do i go about fixing my java installation?