• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Help with my first game

This topic is 6457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; } }

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement