X-Git-Url: http://git.megabrutal.com/?p=shapeshift.git;a=blobdiff_plain;f=shapeshift.js;h=14b4fda470cdcb3ee4ed6b72c01fde2a890ac306;hp=4fb57d165692400dfa9ef594b57484e89f5dca20;hb=HEAD;hpb=06bcb7c01a38183ae7b32459bda2dcfafe39e597 diff --git a/shapeshift.js b/shapeshift.js index 4fb57d1..14b4fda 100644 --- a/shapeshift.js +++ b/shapeshift.js @@ -1,5 +1,3 @@ - window.onload = function() { - var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); var ground; var platforms; @@ -65,6 +63,42 @@ } }, false); + class Entity extends Phaser.Sprite { + constructor(x, y, sprite) { + super(game, x, y, sprite); + this.anchor.setTo(.5,.5); + this.scale.x = 0.5; + this.scale.y = this.scale.x; + } + + enablePhysics() { + game.physics.arcade.enable(this); + this.body.bounce.y = 0.2; + this.body.bounce.x = 0.2; + this.body.gravity.y = 300; + this.body.collideWorldBounds = true; + } + } + + class Player extends Entity { + constructor(x, y, sprite) { + super(x, y, sprite); + this.anchor.setTo(.4,.5); + this.pushed = 0; + this.shape = SHAPE_GIRL; + this.learnedBird = false; + } + } + + class Guard extends Entity { + constructor(x, y, sprite, dialogues) { + //var guard = game.add.sprite(x, y, sprite); + super(x, y, sprite); + this.dialogues = dialogues; + guards.add(this); + } + } + function sign(n) { if (n >= 0) { return 1 } else { return -1 }; } @@ -96,31 +130,24 @@ ground.body.immovable = true; - player = game.add.sprite(64, game.world.height - 200, 'player_girl'); - player.anchor.setTo(.4,.5); - player.scale.x = 0.5; - player.scale.y = player.scale.x; - game.physics.arcade.enable(player); - player.body.bounce.y = 0.2; - player.body.bounce.x = 0.2; - player.body.gravity.y = 300; - player.body.collideWorldBounds = true; - player.pushed = 0; - player.shape = SHAPE_GIRL; - player.learnedBird = false; + //player = game.add.sprite(64, game.world.height - 200, 'player_girl'); + player = new Player(64, game.world.height - 200, 'player_girl'); + player.enablePhysics(); + game.add.existing(player); game.camera.follow(player); guards = game.add.group(); - guard1 = createGuard(600, game.world.height - 200, 'guard', + guard1 = new Guard(600, game.world.height - 200, 'guard', { girl: dialogue_guard1_girl, goat: dialogue_guard1_goat }); - guard2 = createGuard(1000, game.world.height - 200, 'player_girl', + guard2 = new Guard(1000, game.world.height - 200, 'player_girl', { girl: dialogue_guard2_girl, goat: dialogue_guard2_goat }); guard2.scale.x = -guard2.scale.x; - guard3 = createGuard(1400, game.world.height - 200, 'guard', + guard3 = new Guard(1400, game.world.height - 200, 'guard', { girl: dialogue_guard3_girl, goat: dialogue_guard3_goat, bird: dialogue_guard3_bird }); - guard4 = createGuard(2400, game.world.height - 200, 'player_goat', + guard4 = new Guard(2400, game.world.height - 200, 'player_goat', { girl: dialogue_guard4_girl, goat: dialogue_guard4_goat, bird: dialogue_guard4_girl }); guard4.scale.x = -guard4.scale.x; + guards.children.forEach(function(guard) { guard.enablePhysics(); }); birdcage = game.add.sprite(1100, game.world.height - 300, 'birdcage'); birdcage.scale.x = 0.5; @@ -225,23 +252,6 @@ } - function createGuard(x, y, sprite, dialogues) { - - var guard = game.add.sprite(x, y, sprite); - guard.anchor.setTo(.5,.5); - guard.scale.x = 0.5; - guard.scale.y = guard.scale.x; - game.physics.arcade.enable(guard); - guard.body.bounce.y = 0.2; - guard.body.bounce.x = 0.2; - guard.body.gravity.y = 300; - guard.body.collideWorldBounds = true; - guard.dialogues = dialogues; - guards.add(guard); - return guard; - - } - function putText(entity, text) { var textObject = game.add.text(entity.x, entity.y - (entity.height / 2) - 30, text, { align: 'center', fontSize: 14 }); textObject.font = 'Ubuntu Mono'; @@ -320,5 +330,3 @@ interaction_handler = interaction; } - - };