• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beginning Games

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Saloon Keeper
Posts: 15529
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15529
364
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan's answer is right.
 
reply
    Bookmark Topic Watch Topic
  • New Topic