Jump to content
  • Advertisement
Sign in to follow this  


This topic is 3613 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

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

{//move the sprite
bullet.x = bullet.x + 5;
bullet.y = bullet.y + 0;
//set up the filename
//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
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:

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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

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