Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 1 pull request #32

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
README


Added player, enemy, and rock class.
Made player kill when hitting enemy.
Made rock kill when hitting ship.
12 changes: 12 additions & 0 deletions enemy.js
Original file line number Diff line number Diff line change
@@ -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);
}
21 changes: 15 additions & 6 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -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);

}


}
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.3/custom/phaser-arcade-physics.js"></script>
<script src="rock.js"></script>
<script src="player.js"></script>
<script src="enemy.js"></script>
<script src="game.js"></script>
</head>
<body>
Expand Down
3 changes: 3 additions & 0 deletions player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function kill(ship) {
ship.kill();
}
3 changes: 3 additions & 0 deletions rock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function kill() {
rock.kill();
}
Binary file added rock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.