[java] Creating new objects
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
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.
"That's a very nice hat."-Korben Dallas
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement