Jump to content
  • Advertisement
Sign in to follow this  
imontheverge

Java Algorithms for simulation

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!