• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginning Games

 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how would i make a basic game like this: a 100x100 pixel square with a black dot in the center, that can be moved left/right/up/down with the arrow keys? I think I know one way to do it but I would like to get your guys's feedback! Thanks!
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Please take a look at your private messages for an important administrative issue.

Why don't you tell us about the one way that you already know?
 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I know a very limited amount about making a class that extends JComponent, and then inserting a paint method and painting individual shapes to the JComponent, and then adding the JComponent to a JFrame, and just adding keylisteners to get user input, but I would really like to see a simple example, because I just feel like my way is more tedious than it should be. And I think the other issue is all cleared up now, thanks
 
Stephan van Hulst
Bartender
Posts: 5334
48
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tedious as it may seem, that's the way it's done. There may be some libraries out there that make this process more smooth, but I can't think of any from the top of my head.

Here's an outline that may give you some ideas. Please keep in mind that I haven't tested this code, and I haven't added performance tricks (like selective repainting and making the panel opaque).

 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. Thank you so much for taking the time to write all this code. I will go try it and let you know how it works.
 
Jj Hill
Ranch Hand
Posts: 41
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan's answer is right.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic