Hello.
For my first Java game, I''m making a WORM-like game. I''m using rectangles as the Worm and its food. My problem is that I can''t get the program to respond to keyboard input. this input would be used to control the directionn of the worm. Any suggestions would be great on how I could improve this design and implement keyboard input. Heres what I have so far:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
public class TrivialApplet extends Applet {
int posX = 10;
int posY = 20;
boolean run = true;
public void init() {
setBackground( Color.white );
resize(420,420);
}
public void paint( Graphics g ) {
while( run == true ) {
g.setColor( Color.white );
g.fillRect(posX,posY, 10,3);
posX = posX + 1;
g.setColor( Color.black );
g.fillRect(posX,posY, 10,3);
try {
Thread.sleep(10);
}
catch ( Exception e ) {
break;
}
}
[java] Help with my first game
Started by jojor512, May 20 2000 12:50 PM
2 replies to this topic
Sponsor:
#2 Members - Reputation: 122
Posted 20 May 2000 - 08:07 PM
Since this is your first game I would really recommend getting one of the books available on Java game programming. I keep a list of the ones I know about on the FAQ:
http://games.cpbinc.com/faq/
In particular I would recommend ''Java Game Programming for Dummies''. It covers a lot of the basics in a step-by-step format and has pretty good source code included.
http://games.cpbinc.com/faq/
In particular I would recommend ''Java Game Programming for Dummies''. It covers a lot of the basics in a step-by-step format and has pretty good source code included.
#3 Members - Reputation: 122
Posted 21 May 2000 - 05:16 AM
http://java.sun.com/docs/books/tutorial/uiswing/events/intro.html
I was gonna tell you myself, but sun just does such good a job of it. I couldn''t find event listeners in the faq.
I was gonna tell you myself, but sun just does such good a job of it. I couldn''t find event listeners in the faq.






