杀死入侵者在C++中不起作用

Ann*_*ody 9 c++ collision visual-c++

我知道为了在C++中杀死入侵者,我需要制造一个对撞机.但是,在那场比赛中没有任何东西会杀死入侵者.这是标题中的代码:

bool DoCollision(float Xbpos, float Ybpos, int BulWidth, int BulHeight, float Xipos, float Yipos, int InvWidth, int InvHeight);
Run Code Online (Sandbox Code Playgroud)

这是我正在初始化的功能:

bool Game::DoCollision(float Xbpos, float Ybpos, int BulWidth, int BulHeight, float Xipos, float Yipos, int InvWidth, int InvHeight) {
if (Xbpos+BulWidth < Xipos || Xbpos > Xipos+InvWidth) return false;
if (Ybpos+BulHeight < Yipos || Ybpos > Yipos+InvHeight) return false;

return true;
}
Run Code Online (Sandbox Code Playgroud)

如果有人按下空格键,就会发生这种情况:

if (code == 57) { //Space
    myKeyInvader.MeBullet.Active = true;
    myKeyInvader.MeBullet.Xpos = myKeyInvader.Xpos + 10;
    myKeyInvader.MeBullet.Ypos = myKeyInvader.Ypos - 10;
    myKeyInvader.MeBullet.yvuel = 0.2;
    myKeyInvader.MeBullet.BulletP->CopyTo(m_Screen,myKeyInvader.Xpos,myKeyInvader.Ypos);

    if (DoCollision(Invaders[counter].MyBullet.Xbpos,Invaders[counter].MyBullet.Ybpos,Invaders[counter].MyBullet.BulWidth,
    Invaders[counter].MyBullet.BulHeight,Invaders[counter].Xipos,Invaders[counter].Yipos,Invaders[counter].InvWidth,Invaders[counter].InvHeight)) {
        //myKeyInvader.Ypos = 100;
        Invaders[counter].Active = false;
        printf("Collide!\n");
    }
}
Run Code Online (Sandbox Code Playgroud)

有人知道出了什么问题吗?

小智 0

你说//Space,是这样还是应该是 32(如果是 ASCII)而不是 57?程序是否流入 if==57 块?