help with c++ looop

Started by
18 comments, last by SirSmokey 19 years, 4 months ago
can some one fix this or tell me what I ma doing wrong
if (wParam==VK_SPACE)             {                                  bullettest =1;                                for (int Loop = 1; Loop<(rate);Loop++)              {// Bullet[Loop].Screenx = Bullet[Loop].Screenx + 50;                  Bullet[Loop].Screenx= x;                  Bullet[Loop].Screeny = y;                // Loop = rate;                  }//////inlize for ( int Loop = 1; Loop< 10;Loop++)   {             Bullet[Loop].top = 0;       Bullet[Loop].bottom =64;       Bullet[Loop].right =64;       Bullet[Loop].left =0;       Bullet[Loop].Screenx= x;       Bullet[Loop].Screeny= y;    }  //loopint test(){   for (int Loop = 1; Loop < rate; Loop++){         Bullet[Loop].Screenx += xspeed;   Bullet[Loop].Screeny += yspeed;           //if(Bullet[Loop].Screenx< 0 || Bullet[Loop].Screenx> mapX ) xspeed *= -1;   //if(Bullet[Loop].Screeny < 0 || Bullet[Loop].Screeny > mapY ) yspeed *= -1;  bltsprite(Bullet[Loop]);   }            }    //blt imagevoid bltsprite(TSprite Sprite){ r.left = Sprite.left;r.right = Sprite.right;r.top = Sprite.top;r.bottom = Sprite.bottom;lpBackBuffer->BltFast(Sprite.Screenx,Sprite.Screeny,g_pddbullet, &r,                       DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);                  }  
Advertisement
you're missing an end brace '}' somewhere. not sure what the code is doing, though, so I can't tell you where.
Quote:Original post by kingpinzs
can some one fix this or tell me what I ma doing wrong
*** Source Snippet Removed ***

The first thing that you're doing wrong is not explaining the expected and actual results.

Anyway, the loop index should start at 0:
for (int Loop =0; Loop< 10; Loop++)

I'm not sure what else if anything is wrong.

If a plant cannot live according to its nature, it dies; so a man.
Quote:Original post by KindFred
you're missing an end brace '}' somewhere. not sure what the code is doing, though, so I can't tell you where.
It seems that he selectively copy and paste'd from the source.
If a plant cannot live according to its nature, it dies; so a man.
oh crap. my bad. I thought he copied the entire event.
every time I hit the sapcebar it is suppose to shoot a bullet then when I hit the space bar agin it is suppose to make another one with oust deleting the first one. but all it does is make one and then just put it back were it started from and if it draws a new one I dont know becaues it is in the same spot.
IT'S HARD TO READ YOUR INTENT FOR TWO REASON:
1) YOU'RE NOT SPECIFIC OR EXPLAINING PROPERLY.
2) YOU'RE GRAMMAR IS REALLY BAD AND MAKES IT MORE AMBIGOUS.

RELAX....
Every time I push the spacebar it is suppose to draw a bullet at x and y then just move it across the screen. When I press the spacebar again it is suppose to draw bullet b at x and y then move it across the screen and bullet A is suppose to stay on the screen and keep moving around the screen.

But what it does is make bullet A and move it across the screen and then I hit the spacebar and it draws bullet a back at x and y as far as I can tell. Or it might be deleting it and drawing a new one I just can’t tell.


P.S I had people proof read it before posting it
can any one selse help? Or know what I should do to get it to work?
Ok I know lots of people have explained what you need to do but here's my shot at it.

Heres what you need to do in a simple example:

vector<Bullet> Bullets; // Create a vector list of bulletsBullet Temp // Just a temp of a bullet object to create more bulletsif(Key = SpaceBar){  Bullets.push_back(Temp);//Add another bullet to the list}for(int i = 0; i < Bullets.size(); i++) //Loop through your bullets{  Bullets.x++; //Move all the exsisting bullets  Blit(Bullets); //Blit all the exsiting bullets}


Ok so your first miskate is having an array of bullets. You should use a vector list so you can add bullets as they are created and remove them when need be (if you don't know what a vector is there are tons of tutorials and resources online you can easily find) this way you can have more then 10 bullets at a time and it will be easier to manage them in the long run. Also using a vector list makes 100% more sense for what your doing. If the space bar is pressed, create a bullet (add a new one to the vector list) then you loop through the list and increment their x values (all the exsiting bullets will move right) and then blit all of them (that probably shouldn't be in the same loop but for simplicity reasons i put it there). Easy eh!

So:
1. Use a vector list
2. Create new bullets as you need them
3. Loop through the list of bullets and update thier position
4. Loop through the list and blit them all

I hope that helps and if there are any errors or better suggestions anybody has please say so! (i'm kinda new as well)

This topic is closed to new replies.

Advertisement