I have pretty much taught myself everything I know about programming, so while I know how to teach myself (books, internet and reading API's), I'm finding that there hasn't been a whole lot in the way of good programming.

I am finishing up learning the basics of XNA and I want to create a space simulator to test my knowledge. This isn't a full scale simulator, but just something that covers everything I learned. It's also going to be modular so I can build on it, after I get the basics down. One of the early features I want to implement is AI. And I want to take this into account as I'm designing my classes so I can minimize rewriting code.

So my question: How should I design ship classes so that both the player and AI can use them?

The only idea I have so far is:

Create a ship class that contains stats, models, textures, collision data etc. The player and AI would then have the data for position, rotation, health, etc and would base their status off of the ship stats.

  • \$\begingroup\$ You seem to have it all figured out. Are you asking if you did it right? Have you tried if it works? The best way to learn to program is to program. \$\endgroup\$ – Anko Dec 8 '12 at 12:15
  • \$\begingroup\$ This is how I've done it - using component based approach, but there are many ways, and you're seems ok too. depositfiles.com/files/fbvti6id9 \$\endgroup\$ – Kikaimaru Dec 8 '12 at 17:31

As mentioned in you comments you're already on the right track, It's becoming increasingly common to break game entities down into 'components', if you wanted a really clear explanation of component based game development this article is commonly referenced and considered a good solid guide still: http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

But re-structuring like that is not necessary for your needs and don't worry if you want to keep it simple.

I did a very similar thing in a very simple 2 player snake game with optional AI, when i created a new Snake, I passed it a Controller in the constructor, I had two children of the Controller parent class, a PlayerController that could handle keyboard input and an AIController that had a timer that allowed it to fire certain behavior every X seconds to change its direction and such. It meant that at run time I could decide what sort of controller to make and give to a snake based on player input/setting. This had other benefits too, reusing the same entities but dynamically changing their behavior is obviously favorable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.