Tinto

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. Hi, I don't know how to assign the life variable individually to each zombie, avoiding that when one is hit, life is taken away from everyone. Same thing for the infectStatus which affects all zombies and not the individual. Thanks a lot! var zombies; var zombieLife = 3 this.create = () => { zombies = game.add.group(); zombies.enableBody = true; zombies.physicsBodyType = Phaser.Physics.ARCADE; var zombie0 = game.add.sprite(500, 1400, 'zombie'); var zombie1 = game.add.sprite(600, 1400, 'zombie'); zombies.add(zombie0); zombies.add(zombie1); zombies.setAll('anchor.x', 0.5); zombies.setAll('anchor.y', 0.5); zombies.setAll('body.gravity.y', 2000); zombies.setAll('body.velocity.x', 100); zombies.setAll('body.collideWorldBounds', true); } this.update = () => { game.physics.arcade.overlap(player, zombies, touchZombie); } function touchZombie(w, p) { if (player.body.touching.right && p.body.touching.left && !infectStatus) { if (!atkStatus) { infectStatus = true; life = life - 30; game.time.events.add(2000, function() { infectStatus = false; }) } else if (atkStatus) { return zombieKill(p, w) } } else if (player.body.touching.left && p.body.touching.right && !infectStatus) { if (!atkStatus) { infectStatus = true; life = life - 30; game.time.events.add(2000, function() { infectStatus = false; }) } else if (atkStatus) { return zombieKill(p, w) } } else if (player.body.touching && p.body.touching && infectStatus) { if (!atkStatus) { player.tint = 0xFF0000; game.time.events.add(2000, function() { player.tint = 0xffffff; }) } else if (atkStatus) { return zombieKill(p, w) } } } function zombieKill(w, b) { var zombieLife = 3 if (zombieLife > 0 && !hitZombie) { zombieLife-- hitZombie = true w.tint = 0xFF0000; game.time.events.add(500, function() { hitZombie = false; w.tint = 0xffffff; }) } else if (zombieLife <= 0) { w.body.velocity.x = 0; w.animations.play('killed'); game.time.events.add(500, function() { game.add.tween(w).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true, 1400, 0, false); game.time.events.add(2400, function() { w.kill(); }) }) } }