Пример #1
0
  spawnEnemies() {
    let index = util.getRandomInt(0, spawnPoints.length-1)
    let point = spawnPoints[index];

    if(!point)
      return

    this.createEnemy(point.worldX, point.worldY)
  }
Пример #2
0
  createEnemy(x, y) {
    let eClass = enemyClass[util.getRandomInt(0,2)]

    let enemy = enemyNormalGroup.create(x, y, eClass);
    enemy.eClass = eClass;

    //enemy.anchor.setTo(0.5, 0.5);
    enemy.body.collideWorldBounds = true;
    enemy.body.bounce.y = 0.8;
    enemy.body.gravity.y = 500;
    enemy.anchor.setTo(0.5, 0.5);

    let direction = -1
    if(Math.random() > 0.5)
      direction = 1

    enemy.defaultX = direction * 150
    enemy.body.velocity.x = enemy.defaultX
  }
Пример #3
0
    enemies.forEach(function(enemy) {
      let pChange = Math.random()

      let tile = state.map.getTileWorldXY(enemy.x, enemy.y, tileWidth, tileHeight, "hotspots", true);
      if(tile && tile.properties["teleport"]) {
        let index = util.getRandomInt(0, spawnPoints.length-1)
        let point = spawnPoints[index];
        enemy.reset(point.worldX, point.worldY)
      }

      if(enemyRandomShift && pChange < enemyDirectionShiftProbability) {
        enemy.body.velocity.x = enemy.defaultX *= -1
      }

      if(enemy.body.blocked.left || enemy.body.blocked.right) {
        enemy.body.velocity.x = enemy.defaultX *= -1
      }

      if(enemy.body.velocity.x < 0)
        enemy.rotation -= 0.5
      else
        enemy.rotation += 0.5
    });