我知道为了在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; …Run Code Online (Sandbox Code Playgroud)