Javascript游戏 - 对象在本地副本上生成,而不是一次上传

时间:2013-07-18 20:25:30

标签: javascript jquery html5 gamequery

我正在使用GameQuery在Javascript中使用基本的“避免掉落物体”游戏。敌人经常产卵,并定期加电。加电生成函数是敌人生成函数的副本(如下所示),变量名称已更改,并且生成率/精灵不同。这在本地工作正常,但一旦上传到我的网站只有敌人产卵。可能是什么导致了这个? EnemyA =加强力量。

View the game here

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);

1 个答案:

答案 0 :(得分:0)

刚试过你的游戏,发现了一个闪闪发光的东西。抓住它,我没有死,这是一个加强吗?如果是这样,它看起来像我的工作正常。