#### Archived

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

# Multiple Sprite on 1 surface in DX7

This topic is 6303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

(I am using ddraw7) I am making a small space shooter like the arcades in the early 90''s. I want to make it so every time the user presses the space button it shoots a bullet out that will go across the screen. How can I have multiple bullets on 1 surface. When I press the space bar and the bullet is flying across the screen, if I press it while the bullet is flying the bullet resets itself, so I need to have a lot of them that I can blt 1 to the surface each time the space bar is pressed. So somehow have them in some type of array and each time a bullet is let go it needs to be set to active and each time the space bar is pressed I need to check the bullets to see which ones are active, and then choose an inactive one to shoot. I really don''t know how to do it so if someone can help me out, post here, ICQ me, or lead me to a tutorial that will show me something similar. Thanks a lot

##### Share on other sites
Having multiple bullets on a DirectDraw surface is not really the issue here. You only need one bullet on an offscreen surface in order to draw it multiple times in each frame. The problem you''re having isn''t really with DirectX at all, it''s with how you''re representing bullets in memory. You should just have a bullet class or structure, create or activate a new one every time the player fires, and keep them all in an array or linked list. Then, every frame, walk through the list, or check the array for all active bullets, and draw them all from the same copy. A very simple bullet structure for a linked list implementation might be:

  typedef struct _BULLET{ int xSpeed, ySpeed; RECT rcLocation; _BULLET *lpbulNext;} BULLET;

Of course if you have bullets from multiple types of weapons that all look different, or you want bullets to accelerate as they move, or move on curved paths, or keep track of who fired them, etc. you''ll require a more complicated structure, but this is about the simplest example you can get. If you do it with an array it''s even easier; you can just replace the pointer to the next one with a flag that says whether or not the bullet is active.

-Ironblayde
Aeon Software

Down with Tiberia!
"All your women are belong to me." - Nekrophidius

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631362
• Total Posts
2999563
×