From 98e5b9470fdc102765a289078b3967e3d94fcae0 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Wed, 14 May 2014 12:18:39 +0200 Subject: Added pill to the world and set object anchors to their center re #4 --- game/prefabs/pill.js | 20 ++++++++++++++++++++ game/prefabs/player.js | 1 + game/prefabs/wall.js | 1 + game/states/play.js | 11 +++++++++++ game/states/preload.js | 1 + package.json | 1 - 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 game/prefabs/pill.js diff --git a/game/prefabs/pill.js b/game/prefabs/pill.js new file mode 100644 index 0000000..2df13f2 --- /dev/null +++ b/game/prefabs/pill.js @@ -0,0 +1,20 @@ +'use strict'; + +var Pill = function(game, x, y, frame) { + Phaser.Sprite.call(this, game, x, y, 'pill', frame); + this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; + // initialize your prefab here + +}; + +Pill.prototype = Object.create(Phaser.Sprite.prototype); +Pill.prototype.constructor = Pill; + +Pill.prototype.update = function() { + + // write your prefab's specific update code here + +}; + +module.exports = Pill; diff --git a/game/prefabs/player.js b/game/prefabs/player.js index a195f94..1336003 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -5,6 +5,7 @@ var Player = function(game, x, y, key, frame) { this.moving = false; this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; }; Player.prototype = Object.create(Phaser.Sprite.prototype); diff --git a/game/prefabs/wall.js b/game/prefabs/wall.js index 11ca511..c4eee79 100644 --- a/game/prefabs/wall.js +++ b/game/prefabs/wall.js @@ -3,6 +3,7 @@ var Wall = function(game, x, y, frame) { Phaser.Sprite.call(this, game, x, y, 'wall', frame); this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; }; Wall.prototype = Object.create(Phaser.Sprite.prototype); diff --git a/game/states/play.js b/game/states/play.js index c52b498..2d73701 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -2,6 +2,7 @@ var Wall = require('../prefabs/wall'); var Player = require('../prefabs/player'); +var Pill = require('../prefabs/pill'); function Play() {} @@ -32,7 +33,12 @@ Play.prototype = { }, create: function() { this.createWalls(); + this.createPills(); + this.world.scale = {x:100, y:100}; + this.world.bounds = {x: -50, y:-50, width: this.game.width, height: this.game.height}; + this.world.camera.setBoundsToWorld(); + this.playerA = new Player(this.game, 1, 2, 'player-a', 0); this.game.add.existing(this.playerA); this.addPlayerControls(); @@ -80,6 +86,11 @@ Play.prototype = { this.addToMap(wall.x, wall.y); }, this); }, + createPills: function() { + this.pills = this.game.add.group(); + + this.pills.add(new Pill(this.game, 1,1)); + }, addPlayerControls: function() { var controls = { up: Phaser.Keyboard.UP, diff --git a/game/states/preload.js b/game/states/preload.js index 7154c8f..906be3f 100644 --- a/game/states/preload.js +++ b/game/states/preload.js @@ -14,6 +14,7 @@ Preload.prototype = { this.load.setPreloadSprite(this.asset); this.load.image('wall', 'assets/images/wall.svg'); this.load.image('player-a', 'assets/images/player-a.svg'); + this.load.image('pill', 'assets/images/pill.svg'); }, create: function() { this.asset.cropEnabled = false; diff --git a/package.json b/package.json index b82d0e3..6ae9b8d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "private": true, "devDependencies": { "grunt": "~0.4.1", - "bower": "~0.9.2", "grunt-contrib-connect": "~0.2.0", "grunt-contrib-watch": "~0.4.3", "grunt-contrib-copy": "*", -- cgit v1.2.3