• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I use a class such as this one to improve game structure and code reuse ?

 
Steven Bishop
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

How do I use a class such as this one, for each entity of a game?
I have the standard game loop and Player class and so forth but the overal game infrastructure is of poor quality. Can you please help me understand how to do so. THankyou


 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking, you are doing this backwards.

You don't write a program by saying "How do I use this technology to make my program better/work". That's like saying "how do I use a socket wrench to improve my car?"

A socket wrench MAY help you improve your car...but if your biggest problem with your car is that the tires are flat, the socket wrench is NOT going to help you.

 
Phil Freihofner
Ranch Hand
Posts: 120
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I would do:

I would make an "Animatable" interface, and have two methods, update() and draw(Graphics2D g2). Make each of your basic objects implement this interface. Then your game loop can have a single array of ALL your animatable objects, and call their update methods and then their draw methods as part of the game loop cycle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic