Jump to content
  • Advertisement
Sign in to follow this  
imontheverge

Java Algorithms for simulation

This topic is 401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to create a simple " give order to Sprite, make Sprite do thing" game much like rimworld or oxygen not included.

So far I have two controllers type objects, on for the player and one for each Sprite. When a Sprite is selected, the player controller takes a reference of the Sprite and sets a Boolean variable hasMoveOrder to true when the player clicks on a spot.

My code right now is filled with if/else statements in order to get this to work. Once I add more work orders like digging, building, etc, a thousand if statements starts to get sloppy. The question is what kind of data structure or algorithms can I use to make this more efficient? Would an enumeration of the Sprite states be fine and just switch through them when the Sprite gets a new work order? Or would something more complex like a state machine make sense?

Share this post


Link to post
Share on other sites
Advertisement

This is basically what we call "AI", and as such there are many different approaches you can take. At a minimum you'll want some sort of object to represent the current action or behaviour, such as moving, digging, building, etc. You might choose to do this with a state machine for each order, so that "dig at x,y" starts off in the "move to x,y" state and then, once close enough, transitions to the "dig here" state. That is probably the simplest representation and is good for getting started.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!