I'm working on a basic, "avoid the falling objects" game in Javascript with GameQuery. Enemies Spawn often, and power ups periodically. The the power up spawn function is a copy of the enemy spawn function (shown below) with the variable names changed, and a different spawn rate/sprite. This works fine locally, however once uploaded to my site only the enemies spawn. What could be causing this? EnemyA = power ups.
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);
Just tried your game and found a sparkling looking thing. Grabbed it and I didn't die, is that a powerup? If so it looks like it's working fine from my end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.