Created
April 17, 2016 16:55
-
-
Save Willsr71/457f37c1a5c406bad705cd8d2f5fdcee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createEnemies() { | |
console.log(enemies.length); | |
if (enemies.length < 4 * player.corners && Math.round(Math.random() * 100) <= 10) { | |
var ycoord = game._height + 1; | |
while (ycoord > game._height) { | |
ycoord = Math.round(Math.random() * 10000); | |
} | |
var size = 1; | |
var enemy = game.add.sprite(game._width, ycoord, 'enemy' + size); | |
game.physics.enable(enemy, Phaser.Physics.ARCADE); | |
enemy.anchor.setTo(0.5, 0.5); | |
console.log("x", player.pos.x); | |
var angle = Math.atan2(game._width - player.pos.x, ycoord - player.pos.y) * (180 / Math.PI); | |
enemy.body.sprite.angle = angle; | |
enemy.body.velocity.x = Math.cos(angle * (Math.PI / 180)) * 200; | |
enemy.body.velocity.y = Math.sin(angle * (Math.PI / 180)) * 200; | |
enemies.add(enemy); | |
//enemies.push(new Enemy({x:game._width, y:height}, (Math.atan2(game._width - player.pos.x, height - player.pos.y) * (180 / Math.PI)) + 90, 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment