Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

bullets and tanks

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 almost have a tank sprite shooting a bullet sprite properly, I need just a little bit of help, here is some of the code I have been using, if (KEY_DOWN(VK_SPACE)) {//move the sprite bullet.x = tank.x + bullet.x; bullet.y = tank.y; if (bullet.x >= SCREEN_WIDTH) { bullet.x=tank.x; bullet.x=tank.y; } //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)); } this is in direct x and c++, if you need more code let me know,

Share this post


Link to post
Share on other sites
Advertisement
We can't help unless we know what the problem is. :)

EDIT: I found the problem.

bullet.x = tank.x + bullet.x;

that code sets the bullet to one pixel right of the tank. Its supposed to update every frame, not assume the position of the tank.

try:

bullet.x++;

That is, unless, you are updating the position of the bullet somewhere else. I wouldn't put the bullet.x++; in the space block though, because then the bullet would only move while you hold down space. You should probably make a variable for whether the bullet is being fired or not, then use that variable in the application's infinate while loop to update the position with bullet.x++;.

If that's not the problem, I'm sorry, but you didn't actually tell us what the problem is [smile]

Share this post


Link to post
Share on other sites
You set bullet.x two times in a row. This suggests to me that is the error.



if (KEY_DOWN(VK_SPACE))
{//move the sprite
bullet.x = tank.x + bullet.x;
bullet.y = tank.y;
if (bullet.x >= SCREEN_WIDTH)
{
bullet.x=tank.x;
bullet.x=tank.y;//Here
}
//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));
}




Change it to:



if (bullet.x >= SCREEN_WIDTH)
{
bullet.x=tank.x;
bullet.y=tank.y;
}


Share this post


Link to post
Share on other sites
This is in his Space block (shooting, so it would reset the position of the bullet), so setting it twice shouldn't cause a problem as long as it ends up in the right place, although it could cause some obscure problem. What he needs is a different piece of code that updates the bullet, if he doesn't already have one.

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!