Sign in to follow this  
phil67rpg

sprites

Recommended Posts

phil67rpg    443
well I am able to rotate a tank sprite but I want it to shoot bullets (other sprites), here is some of the code

if (KEY_DOWN(VK_SPACE))
{//move the sprite
bullet.x = bullet.x + 5;
bullet.y = bullet.y + 0;
//set up the filename
sprintf(t,"bullet.bmp");
//load texture with "pink" as the transparent color
bullet_image[0] = LoadTexture(t, D3DCOLOR_XRGB(255,0,255));
}

Share this post


Link to post
Share on other sites
mdwheele    140
Well first things first, you need to embody what a bullet is, which you seem to have done already. Lets say bullets have the following attributes:

Position
Heading (angle)
Speed (magnitude)

So after setting this up all you need to do is when you press space:

1) create a new bullet
2) set its position to an offset of the tank (where the turret is)
3) set its heading to the current heading of the tank
4) set a speed constant
5) add the bullet to a running pool of "live" bullets
6) make updates to that pool

When you update the bullet list, calculate your new x,y coordinates with a bit of simple trig:

x += cos(heading)*speed
y -= sin(heading)*speed

Based on your api of choice, you may need to handle rounding errors with sin and cos. Since you seem to be using DX, you should be able to handle the floats just fine.

If you have any more questions, feel free. I hope I answered sufficiently.

-mdwheele

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this