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


Multiple Sprite on 1 surface in DX7

Recommended Posts

ZodiacKilla    122
(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 this post

Link to post
Share on other sites
Ironblayde    130
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;

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.

 Aeon Software

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

Share this post

Link to post
Share on other sites