aspose file tools*
The moose likes Game Development and the fly likes How can I use a class such as this one to improve game structure and code reuse ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "How can I use a class such as this one to improve game structure and code reuse ?" Watch "How can I use a class such as this one to improve game structure and code reuse ?" New topic
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: 11412
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How can I use a class such as this one to improve game structure and code reuse ?