| Author |
How can I use a class such as this one to improve game structure and code reuse ?
|
Steven Bishop
Greenhorn
Joined: Dec 07, 2012
Posts: 1
|
|
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
Joined: Oct 02, 2003
Posts: 9943
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Phil Freihofner
Ranch Hand
Joined: Sep 01, 2010
Posts: 107
|
|
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.
|
 |
 |
|
|
subject: How can I use a class such as this one to improve game structure and code reuse ?
|
|
|