Jump to content
  • Advertisement
Sign in to follow this  

Updating every instance of class

This topic is 2180 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

I am finishing off my Space Invaders game in XNA. One stumbling block I am having is getting all the martians to change direction whenever the furthest right ones reach the end of the screen. Difficult to post code without posting large chunks, but what I have is

Ususal Game1 class
Player class (Drawable component)
Martian class with about 48 instances

What I am basically trying to do from the Game class is

If last column have reached the end of the screen
{
For Each instance of Martian
{
change Xspeed to -Xspeed
}
}

I have tried using foreach Game Component in Components but that hasn't worked. I could make a public struct Martian in the Game1 class but that seems to take away some object orientedness.

Share this post


Link to post
Share on other sites
Advertisement
Make sure you're clear about the way things fail. They don't change direction? Every object on the screen changes direction? They jitter back and forth?

You could store a collection of your Martians so it's easy to loop through. Or (as their velocity is always in lockstep) you could make it a static property.

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.

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

Sign me up!