我正在使用 GameQuery 在 Javascript 中开发一个基本的“避免坠落物体”游戏。敌人经常产生,并定期加电。加电生成函数是敌人生成函数(如下所示)的副本,变量名称已更改,生成速率/精灵也不同。这在本地工作得很好,但是一旦上传到我的网站,只会产生敌人。这可能是什么原因造成的?EnemyA = 加电。
var enemyHeight = 48;
var enemyWidth = 48;
var enemySpawnRate = 700;
var enemyAHeight = 48;
var enemyAWidth = 48;
var enemyASpawnRate = 7000;
function Enemy(node, value){
this.value = value;
this.speed = 4 + passCount;
this.node = node;
this.update = function(){
this.node.y(this.speed, true);
};
};
function EnemyA(node, value){
this.value = value;
this.speed = 9;
this.node = node;
this.update = function(){
this.node.y(this.speed, true);
};
};
$(".enemy").each(function(){
this.enemy.update();
if(($(this).y()+ enemyHeight) > 640){
passCount = passCount + 0.1;
totalScore = totalScore + 50;
$(this).remove();
} else {
var collided = $(this).collision("#playerBody,."+$.gQ.groupCssClass);
if(collided.length > 0){
$("#player")[0].player.value -= $(this)[0].enemy.value;
$(this).remove();
if($("#player")[0].player.value <= 0){
$('.enemy').remove();
$('.enemyA').remove();
$("#playground").fadeOut(800);
$("#gameover").delay(800).fadeIn(800);
Enemy.speed = 0;
$.playground().pauseGame();
}
}
}
});
$(".enemyA").each(function(){
this.enemyA.update();
if(($(this).y()+ enemyWidth) > 640){
$(this).remove();
} else {
var collided = $(this).collision("#playerBody,."+$.gQ.groupCssClass);
if(collided.length > 0){
totalScore = totalScore + 250;
playerSpeed = playerSpeed + 0.5;
$(this).remove();
}
}
});
$.playground().registerCallback(function(){
var enemyValue = 3;
var name = "enemy_"+(new Date) .getTime();
$("#enemies").addSprite(name, {animation: enemySprite[Math.floor(Math.random() * enemySprite.length)], posy: 0, posx: Math.random()*PLAYGROUND_WIDTH*0.9, width: enemyWidth, height: enemyHeight});
var enemyElement = $("#"+name);
enemyElement.addClass("enemy");
enemyElement[0].enemy = new Enemy(enemyElement, enemyValue);
}, enemySpawnRate);
$.playground().registerCallback(function(){
var enemyAValue = 100000;
var name = "enemyA_"+(new Date) .getTime();
$("#enemiesA").addSprite(name, {animation: enemyASprite, posy: 0, posx: Math.random()*PLAYGROUND_WIDTH*0.9, width: enemyAWidth, height: enemyAHeight});
var enemyAElement = $("#"+name);
enemyAElement.addClass("enemyA");
enemyAElement[0].enemyA = new EnemyA(enemyAElement, enemyAValue);
}, enemyASpawnRate);