小编Ann*_*ody的帖子

杀死入侵者在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; …
Run Code Online (Sandbox Code Playgroud)

c++ collision visual-c++

9
推荐指数
1
解决办法
404
查看次数

标签 统计

c++ ×1

collision ×1

visual-c++ ×1