2014-04-27 5 views
1

저는 현재 직접 X로 C++로 게임을 작성하고 있으며, 현재 모든 스프라이트를 저장하는 벡터를 저장하고 있습니다. 벡터에서 총알이 작동하지 않습니다. 총알 촬영 만 한벡터로 촬영하려고합니다.

//this vector also contains all other sprites i have like my player and my score and other sprites 
///Draw is a class 

vector<Draw*> chap; 
vector<Draw*>::iterator it; 
Draw *bullet = NULL; 

///initialization of stuff 
for (int i = 0; i < gt; i++) 
{ 
    bullet = new Draw[gt]; 
    //this sets the x position and y position and other properties 
    bullet[i].setDraw(blet,0,0,.1,.1,0,64,64,1,0,1,color,0,0,90,0,0,false); 
    chap.push_back(&bullet[i]); 
} 
//end initialization 

///game loop 
for (int i = 0; i < bell; i++) 
{ 
    for (it = chap.begin(); it != chap.end(); it++) 
    { 
     (*it)->testShoot(&bullet[i], ME); 
     ME->playerMove(); 
     monster1->move(); 
    } 
} 
///end loop there is other stuff in loop but doesn't effect anything 

/// what i'm using 
void Draw::testShoot(Draw *sprite, Draw *sprite1) 
{ 
    if ((int)timeGetTime() < timer + 100)return; 
    timer = timeGetTime(); 

    for (int i = 0; i < 50; i++) 
    { 
     if (Key_Down(DIK_SPACE)) 
     { 
      if (!sprite[i].alive) 
      { 
       sprite[i].x = sprite1->x + sprite1->width/4; 
       sprite[i].y = sprite1->y + sprite1->height/4; 
       sprite[i].velx = 1; 
       sprite[i].vely = 0; 
       sprite[i].alive = true; 
       break; 
      } 
     } 
    } 
} 

답변

2

bullet = new Draw[gt]; (50)이 아닌 그 안에는 for 루프 전에 가야가 있어야 할 때 나온다. 지금 당장 루프를 반복 할 때마다 새로운 배열을 만들고 있습니다. 채워진 요소가 하나뿐이므로 매번 bullet의 값을 덮어 쓸 때 이전에 잃어버린 요소를 잃어 버리게됩니다. 즉

,이 :

for (int i = 0; i < gt; i++) 
{ 
    bullet = new Draw[gt]; 
    bullet[i].setDraw(... 

이 있어야한다 : 여기서 루프가 시작되고 어디 종료 내가 잊었

bullet = new Draw[gt]; 
for (int i = 0; i < gt; i++) 
{ 
    bullet[i].setDraw(... 
+0

을 넣어, 다 잘립니다, 오류 아무것도 나누기도 없다 , – deepfriedboot

+0

전혀 알지도 못했는데, 문제를 해결하기 위해 잘못된 곳을 찾고있었습니다. – deepfriedboot

+0

고맙습니다. – deepfriedboot