Ice backfire效果不适用于我的JavaScript游戏

时间:2018-02-02 01:01:11

标签: javascript html5

我正试图在我的游戏中制作一个简单的反垃圾邮件策略,以便尝试与Cyborg Ninja两次执行“Freeze Ball”将导致另一名战士解冻并实际冻结Cyborg Ninja。

代码是:

if (myObstacle.crashWith(myGamePiece2)) {
ballCount += 1;
freezeTime = 0;
frozen = 1;
myObstacle.x = freezeX;     
myObstacle.y = freezeY;     
freeze = 0;
}

if (freeze == 1) {
myObstacle.update();
myObstacle.x += 5;
}

if (frozen == 1) {
myEffect = new component(80, 80, "https://vignette.wikia.nocookie.net/battlefordreamisland/images/4/4e/Old_Icy_Remake.png/revision/latest?cb=20180102221338", myGamePiece2.x, myGamePiece2.y, "image");  
myEffect.newPos();
myEffect.update();
freezeTime += 1;
}

if (freezeTime == 201) {
freezeTime = 0;
frozen = 0;
}

if (myObstacle2.x < -5) {
myObstacle2.x = freezeX2;     
myObstacle2.y = freezeY2;     
freeze2 = 0;
}

if (myObstacle2.crashWith(myGamePiece)) {
ballCount2 += 1;
freezeTime2 = 0;
frozen2 = 1;
myObstacle2.x = freezeX2;     
myObstacle2.y = freezeY2;     
freeze2 = 0;
}

if (freeze2 == 1) {
myObstacle2.update();
myObstacle2.x -= 5;
}

if (frozen2 == 1) {
myEffect2 = new component(80, 80, "https://vignette.wikia.nocookie.net/battlefordreamisland/images/4/4e/Old_Icy_Remake.png/revision/latest?cb=20180102221338", myGamePiece.x, myGamePiece.y+5, "image");  
myEffect2.newPos();
myEffect2.update();
freezeTime2 += 1;
}

if (freezeTime2 == 201) {
freezeTime2 = 0;
frozen2 = 0;
}

if (freeze == 1 && freeze2 == 1 && myObstacle.crashWith(myObstacle2)) {
freeze = 0;
freeze2 = 0;
myObstacle.x = freezeX;     
myObstacle.y = freezeY;     
myObstacle2.x = freezeX2;     
myObstacle2.y = freezeY2;     
}

//P1 Double Ice Backfire
if (doubleIce2 == 1 && ballCount > 1) {
freezeTime = 0;
frozen = 1;
freezeTime2 = 0;
frozen2 = 0;
myObstacle.x = freezeX;     
myObstacle.y = freezeY;     
freeze = 0;
doubleIce2 = 1;
doubleIce = 0;
doubleIceTime = 0;
}
//P2 Double Ice Backfire
if (doubleIce2 == 1 && ballCount2 > 1) {
freezeTime2 = 0;
frozen2 = 1;
freezeTime = 0;
frozen = 0;
myObstacle2.x = freezeX2;     
myObstacle2.y = freezeY2;     
freeze2 = 0;
doubleIce = 1;
doubleIce2 = 0;
doubleIceTime2 = 0;
}

当我尝试尝试此操作时,代码将失败并导致CPU无休止地冻结。

有人可以帮助我如何正确地为我的游戏做这个机制吗?感谢...

1 个答案:

答案 0 :(得分:0)

没关系,我设法找到了解决这个问题的方法。