Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

greensam

[java] Creating new objects

This topic is 6243 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''m taking my first steps towards game design. I''m trying to make a lame Space Invaders clone as my first project. I recently got some graphics moving in a window which was way cool! Now my question concerns creating more sprites for example the aliens shots in the game. I would probably have something like a method that checks if the alien wants to shoot and in the case of it then wanting to shoot call a some kind of shoot() method that would create a bullet sprite located underneath the alien and moving down the screen. Now I guess you could do this with an array of sprites but then you''d have to put a maximum amount of bullets that you''ll be able to display so that if one alien would be one pixel away from you he''d be helpless ''cause his friends have peppered the screen with bullets therefore filling up the bullet array. Am I going about this the wrong way or what? Sam

Share this post


Link to post
Share on other sites
Advertisement
There are a lot of ways you could handle something like that. One straightforward way would be to just dynamically create a "Bullet" object whenever an alien wants to shoot. You could keep a linked list of bullets. Another option would be to have each alien object contain a bullet or two, initially marked as invisible or located off the screen, and then when it wants to shoot, you just make it visible and give it a velocity. When ii hits something or goes off the screen, it becomes invisible and the alien can shoot again. That way the aliens can only have one or two (or however many) shots firing at one time.

Share this post


Link to post
Share on other sites

  • 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!