diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..0d6879c --- /dev/null +++ b/README.txt @@ -0,0 +1,6 @@ +README + + +Added player, enemy, and rock class. +Made player kill when hitting enemy. +Made rock kill when hitting ship. \ No newline at end of file diff --git a/enemy.js b/enemy.js new file mode 100644 index 0000000..d0898a1 --- /dev/null +++ b/enemy.js @@ -0,0 +1,12 @@ +function createEnemy(group) { + var randomX = game.rnd.integerInRange(0, boundsX); + var randomY = game.rnd.integerInRange(0, boundsY); + var enemy = enemies.create(randomX, randomY, 'enemy'); + + enemy.scale.setTo(.1, .1); + game.physics.enable(enemy, Phaser.Physics.ARCADE); + + enemy.body.velocity.setTo(50, 50); + enemy.body.collideWorldBounds = true; + enemy.body.bounce.set(1); +} \ No newline at end of file diff --git a/game.js b/game.js index 9b16a26..ab215b7 100644 --- a/game.js +++ b/game.js @@ -3,16 +3,25 @@ var boundsX = 800, boundsY = 600; var game = new Phaser.Game(boundsX, boundsY, Phaser.AUTO, "game", {preload:preload, update:update, create:create}); var ship; +var enemies; +var rock; var wasd; function preload () { game.load.image('ship', 'ship.png'); game.load.image('enemy', 'evil.png'); + game.load.image('rock', 'rock.png'); } function create() { + game.physics.startSystem(Phaser.Physics.ARCADE); ship = game.add.sprite(50, 50, 'ship'); - - ship.anchor.setTo(0.5, 0.5); + game.physics.enable(ship, Phaser.Physics.ARCADE); + ship.anchor.setTo(0.5, 0.5); + rock = game.add.sprite(300, 300, 'rock'); + game.physics.enable(rock, Phaser.Physics.ARCADE); + rock.scale.setTo(.1, .1); + enemies = game.add.group(); + createEnemy(enemies); this.cursors = game.input.keyboard.createCursorKeys(); wasd = { @@ -26,7 +35,7 @@ function create() { function update() { var mX = game.input.mousePointer.x; var mY = game.input.mousePointer.y; - /* look at the mouse */ + ship.angle = Math.atan2(ship.position.x - mX, ship.position.y - mY) * -57.2957795; if (wasd.up.isDown) { @@ -41,7 +50,7 @@ function update() { if (wasd.right.isDown) { ship.x += 3; } + game.physics.arcade.overlap(ship, enemies, kill, null, this); + game.physics.arcade.overlap(rock, ship, kill, null, this); -} - - +} \ No newline at end of file diff --git a/index.html b/index.html index 8ff39fb..94d71b5 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,9 @@
+ + + diff --git a/player.js b/player.js new file mode 100644 index 0000000..337c9e1 --- /dev/null +++ b/player.js @@ -0,0 +1,3 @@ +function kill(ship) { + ship.kill(); +} \ No newline at end of file diff --git a/rock.js b/rock.js new file mode 100644 index 0000000..76cc521 --- /dev/null +++ b/rock.js @@ -0,0 +1,3 @@ +function kill() { + rock.kill(); +} \ No newline at end of file diff --git a/rock.png b/rock.png new file mode 100644 index 0000000..b4e3735 Binary files /dev/null and b/rock.png differ