diff --git a/.game.js.swp b/.game.js.swp new file mode 100644 index 0000000..b6bf356 Binary files /dev/null and b/.game.js.swp differ diff --git a/.index.html.swp b/.index.html.swp new file mode 100644 index 0000000..c6db054 Binary files /dev/null and b/.index.html.swp differ diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..d1f59dd --- /dev/null +++ b/README.txt @@ -0,0 +1,5 @@ +Changes: +1. Moved the player to an individual file. Player barely interacts with game.js anymore; the only thing the game does is create the player and let it run by itself +2. Created an enemy group and gave it an individual file. +3. Managed collision handling in the update function of the main game +4. Created rocks, which appear randomly on the screen and apparently don't do anything very interesting. Since the player destroys them if they're hit, the player can completely ignore them. \ No newline at end of file diff --git a/enemy.js b/enemy.js new file mode 100644 index 0000000..f855eb5 --- /dev/null +++ b/enemy.js @@ -0,0 +1,24 @@ +Enemy.prototype = Object.create(Phaser.Sprite.prototype); + +Enemy.prototype.constructor = Enemy; + +Enemy.prototype.force = {x:0.0, y:0.0}; + +function Enemy(game, x, y) { + Phaser.Sprite.call(this, game, x, y, 'evil'); + enemy.position.x = x; + enemy.position.y = y; + enemy.scale.setTo(0.05, 0.05); + enemy.anchor.setTo(0.5, 0.5); + game.physics.enable(enemy, Phaser.Physics.ARCADE); +} + +Enemy.prototype.update = function() { + var mX = game.input.mousePointer.x; + var mY = game.input.mousePointer.y; + + this.angle = Math.atan2(this.position.x - mX, this.position.y - mY) * -57.2957795; + enemies.forEach(function(enemy){ + enemy.angle++; + }); +} \ No newline at end of file diff --git a/evil.png b/evil.png new file mode 100644 index 0000000..d8f6879 Binary files /dev/null and b/evil.png differ diff --git a/game.js b/game.js new file mode 100644 index 0000000..e64f492 --- /dev/null +++ b/game.js @@ -0,0 +1,40 @@ + +var boundsX = 800, boundsY = 600; +var game = new Phaser.Game(boundsX, boundsY, Phaser.AUTO, "game", {preload:preload, update:update, create:create}); + +var ship; + +function preload () { + game.load.image('ship', 'ship.png'); + game.load.image('enemy', 'evil.png'); + game.load.image('rock', 'rock.png'); +} + +function create() { + ship = new Ship(game, game.world.centerX, game.world.centerY); + enemies = game.add.group(); + rocks = game.add.group(); + enemies.enableBody = true; + rocks.enableBody = true; + for (var i = 0;i<4;i++){ + var enemy = Enemy(enemies, 200 + i*50, 300); + var rock = rocks.create(100 + 40*Math.Random(), 200 + 50*Math.Random(), 'rock'); + } +} + +function update() { + game.physics.arcade.collide(ship, enemies); + game.physics.arcade.collide(ship, rocks); + game.physics.arcade.overlap(ship, enemies, shipDeath, null, this); + game.physics.arcade.overlap(ship, rocks, destroyRock, null, this); + +} + +function shipDeath(ship, enemy) { + ship.kill(); + game.shutdown(); +} + +function destroyRock(ship, rock) { + rock.kill(); +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..8ff39fb --- /dev/null +++ b/index.html @@ -0,0 +1,11 @@ + + + + + + + +
+ + + diff --git a/rock.png b/rock.png new file mode 100644 index 0000000..0b0b452 Binary files /dev/null and b/rock.png differ diff --git a/ship.js b/ship.js new file mode 100644 index 0000000..2dccd89 --- /dev/null +++ b/ship.js @@ -0,0 +1,35 @@ +Ship.prototype = Object.create(Phaser.Sprite.prototype); + +Ship.prototype.constructor = Ship; + +Ship.prototype.force = {x:0.0, y:0.0}; + +var wasd; + +function Ship(game, x, y) { + Phaser.Sprite.call(this, game, x, y, 'ship'); + this.anchor.setTo(0.5, 0.5); + game.physics.enable(ship, Phaser.Physics.ARCADE); + wasd = { + up: game.input.keyboard.addKey(Phaser.Keyboard.W), + down: game.input.keyboard.addKey(Phaser.Keyboard.S), + left: game.input.keyboard.addKey(Phaser.Keyboard.A), + right: game.input.keyboard.addKey(Phaser.Keyboard.D), + }; + game.add.existing(this); +} + +Ship.prototype.update = function() { + if (wasd.up.isDown) { + ship.y -= 3; + } + if (wasd.down.isDown) { + ship.y += 3; + } + if (wasd.left.isDown) { + ship.x -= 3; + } + if (wasd.right.isDown) { + ship.x += 3; + } +} \ No newline at end of file diff --git a/ship.png b/ship.png new file mode 100644 index 0000000..454faec Binary files /dev/null and b/ship.png differ diff --git a/view.png b/view.png new file mode 100644 index 0000000..bba76a4 Binary files /dev/null and b/view.png differ