Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-4 committed Dec 12, 2016
2 parents 6dbf6e1 + 0ede8e7 commit bff5438
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 224 deletions.
203 changes: 100 additions & 103 deletions RAW/ludMap37.tmx

Large diffs are not rendered by default.

Binary file removed bin/imgs/character128.png
Binary file not shown.
32 changes: 23 additions & 9 deletions bin/imgs/ludMap37.json

Large diffs are not rendered by default.

Binary file removed bin/imgs/spr_background.png
Binary file not shown.
4 changes: 2 additions & 2 deletions pageStyle.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
:root {
/*
--windowWidth: 640px;
--windowHeight: 360px;
*/

/*
--windowWidth: 1280px;
--windowHeight: 720px;
*/
}

body {
Expand Down
9 changes: 9 additions & 0 deletions src/objects/food.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Food {
constructor() {

}

update() {

}
}
66 changes: 66 additions & 0 deletions src/objects/player.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
class Player {
constructor() {
// Projectile
this.spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

// Movement
this.rotateLKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
this.rotateRKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
this.upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
this.downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);

this.speed = 30;
this.dir = 1;
this.rotationSpeed = 90;
this.fireRate = 300;
this.nextFire = 0;

this.spr = game.add.sprite(145, 656, 'bot');
this.spr.anchor.setTo(0.5, 0.5);
this.spr.animations.add('run');
this.spr.animations.play('run', 16, true);
game.physics.enable(this.spr, Phaser.Physics.ARCADE);
this.spr.f = new Phaser.Point(1,0);
game.camera.follow(this.spr);
this.spr.body.collideWorldBounds = true;

// Set collision
this.spr.body.setSize(32,32,16,16);

this.bullets = game.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.ARCADE;

this.bullets.createMultiple(50, 'bullet');
this.bullets.setAll('checkWorldBounds', true);
this.bullets.setAll('outOfBoundsKill', true);
}

update() {
var deltaTime = (game.time.elapsed/1000.0);

if (this.rotateLKey.isDown) {
this.spr.angle -= this.rotationSpeed * deltaTime + (0.01*(this.spr.body.speed));
}
else if (this.rotateRKey.isDown) {
this.spr.angle += this.rotationSpeed * deltaTime + (0.01*(this.spr.body.speed));
}

// Push
if (this.upKey.isDown) { move(this.spr, 1); }
else if (this.downKey.isDown) { move(this.spr, -1); }
else { this.spr.f = new Phaser.Point(0,0); }

// Projectile
if (this.spaceKey.isDown) { this.fire(); }

this.spr.body.velocity.x += this.spr.f.x * this.speed;
this.spr.body.velocity.y += this.spr.f.y * this.speed;
this.spr.body.velocity = this.spr.body.velocity.multiply(0.9,0.9);
}

fire() {
if (game.time.now > this.nextFire && this.bullets.countDead() > 0) {
this.nextFire = game.time.now + this.fireRate;
var bullet = this.bullets.getFirstDead();
bullet.reset(this.spr.x - 8, this.spr.y - 8);

//bullet.body.velocity.y = 300;
game.physics.arcade.moveToPointer(bullet, 600);
}
}

}
113 changes: 15 additions & 98 deletions src/states/game.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
class Game {
constructor() {
this.name = "game_state";
this.speed = 40;
this.dir = 1;
this.rotationSpeed = 90;

this.fireRate = 300;
this.nextFire = 0;
}

preload () {
game.load.image('houseimage', 'bin/imgs/character64.png');
// game.load.image('backdrop', 'bin/imgs/bg_map2.png');
game.load.atlasJSONHash('bot', 'bin/imgs/mainChar.png', 'bin/imgs/mainChar.json');

game.load.tilemap('ludmap', 'bin/imgs/ludMap37.json', null, Phaser.Tilemap.TILED_JSON);
Expand All @@ -23,8 +16,7 @@ class Game {
create () {
game.physics.startSystem(Phaser.Physics.ARCADE);
this.graphics = game.add.graphics(0,0);

game.stage.backgroundColor = '#787878';
game.stage.backgroundColor = '#000';

// Background Map
this.map = game.add.tilemap('ludmap');
Expand All @@ -33,112 +25,37 @@ class Game {
this.object_layer = this.map.createLayer('Objects');

//collision on blockedLayer

this.ground_layer.scale.setTo(2,2);
this.object_layer.scale.setTo(2,2);
this.map.setCollisionBetween(1, 20000, true, 'Objects');

this.ground_layer.resizeWorld();
this.object_layer.resizeWorld();
this.map.setCollisionBetween(1, 20000, true, 'Objects');

game.world.setBounds(0, 0, 4096, 2048);

this.house = game.add.sprite(0, 0, 'bot');
this.house.anchor.setTo(0.5, 0.5);
this.house.scale.setTo(2, 2);
this.house.animations.add('run');
this.house.animations.play('run', 16, true);
game.physics.enable(this.house, Phaser.Physics.ARCADE);
this.house.f = new Phaser.Point(1,0);
this.newDirection = new Phaser.Point(0,0);
game.camera.follow(this.house);

this.sprite2 = game.add.sprite(700, 220, 'houseimage');
this.sprite2.name = 'houseimage'
game.physics.enable(this.sprite2, Phaser.Physics.ARCADE);
game.world.setBounds(0, 0, 4096, 1024);

this.house = new Player();

// Set collision
// this.house.body.width = 32; this.house.body.height = 32
this.house.body.setSize(32,32,16,16);

// Projectile
this.spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

this.bullets = game.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.ARCADE;

this.bullets.createMultiple(50, 'bullet');
this.bullets.setAll('checkWorldBounds', true);
this.bullets.setAll('outOfBoundsKill', true);
this.mockSprite = game.add.sprite(700, 220, 'houseimage');
this.mockSprite.name = 'houseimage'
game.physics.enable(this.mockSprite, Phaser.Physics.ARCADE);
}

update () {
game.physics.arcade.collide(this.house, this.sprite2, collisionHandler, null, this);
game.physics.arcade.collide(this.house, this.object_layer, collisionHandler);

var deltaTime = (game.time.elapsed/1000.0);

if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
this.house.angle -= this.rotationSpeed * deltaTime + (0.01*(this.house.body.speed));
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
this.house.angle += this.rotationSpeed * deltaTime + (0.01*(this.house.body.speed));
}
game.physics.arcade.collide(this.house.spr, this.mockSprite, collisionHandler, null, this);
game.physics.arcade.collide(this.house.spr, this.object_layer, collisionHandler);

// Push away
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
move(this.house, 1);
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
move(this.house, -1);
} else {
this.house.f = new Phaser.Point(0,0);
}

this.house.body.velocity.x += this.house.f.x * this.speed;
this.house.body.velocity.y += this.house.f.y * this.speed;
this.house.body.velocity = this.house.body.velocity.multiply(0.9,0.9);
//
// var vTwo = new Phaser.Point(this.house.x, this.house.y);
// var vOne = new Phaser.Point(10 ,20);
// this.house.position = Phaser.Point.add(this.newDirection, this.house.position);
// this.newDirection = Phaser.Point.add(vOne, vTwo.multiply(-1,-1)).normalize().setMagnitude(vDist/10);
// this.newAngle = this.house.angle*(180.0/Math.PI)+90.0;

// Projectile

if (this.spaceKey.isDown)
{
this.fire();
}
this.house.update();
}

render () {
game.debug.text();
game.debug.start(20, 20, 'white');
game.debug.text(this.house.position, 32, 76);
game.debug.text(this.house.spr.position, 32, 76);
game.debug.stop();
game.debug.body(this.house);
game.debug.body(this.sprite2);

game.debug.text('Active Bullets: ' + this.bullets.countLiving() + ' / ' + this.bullets.total, 32, 32);

}
game.debug.body(this.house.spr);
game.debug.body(this.mockSprite);

fire() {
if (game.time.now > this.nextFire && this.bullets.countDead() > 0) {
this.nextFire = game.time.now + this.fireRate;
var bullet = this.bullets.getFirstDead();
bullet.reset(this.house.x - 8, this.house.y - 8);
game.debug.text('Active Bullets: ' + this.house.bullets.countLiving() + ' / ' + this.house.bullets.total, 32, 32);

//bullet.body.velocity.y = 300;
game.physics.arcade.moveToPointer(bullet, 600);
}
}
}

Expand Down
13 changes: 1 addition & 12 deletions src/states/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,7 @@ class Menu {
}

// Nearly all display objects in Phaser render automatically, you don't need to tell them to render. However the render method is called AFTER the game renderer and plugins have rendered,
render () {
this.graphics.clear();

this.graphics.endFill();
this.graphics.beginFill(0xe74c3c); // Red
this.graphics.drawRect(256,0,50,50);

// Circle
this.graphics.beginFill(0xff0000);
this.graphics.drawCircle(GAME_WIDTH/2, GAME_HEIGHT/2, 25);
this.graphics.endFill();

render () {

}

Expand Down

0 comments on commit bff5438

Please sign in to comment.