X-Git-Url: http://git.megabrutal.com/?p=shapeshift.git;a=blobdiff_plain;f=shapeshift.js;h=d960d62ad4066ca11756ea3b8a3bf251b63b65da;hp=ed05a37577947edb0c4405782e0e28c27e2f9077;hb=refs%2Fheads%2Fsvg;hpb=8365e5f779829456056345af2c145d35c4e14e30 diff --git a/shapeshift.js b/shapeshift.js index ed05a37..d960d62 100644 --- a/shapeshift.js +++ b/shapeshift.js @@ -1,6 +1,7 @@ window.onload = function() { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var ground; var platforms; var guards; var guard1, guard2; @@ -57,6 +58,13 @@ [ { actor: 'guard', text: "(By the way, this is the end of the game.\nYou really can't do anything more.\nThanks for playing!)" } ]; + window.addEventListener("keydown", function(e) { + // Prevent default browser action for arrows and spacebar + if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) { + e.preventDefault(); + } + }, false); + function sign(n) { if (n >= 0) { return 1 } else { return -1 }; } @@ -83,7 +91,7 @@ platforms.enableBody = true; - var ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground'); + ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground'); platforms.add(ground); ground.body.immovable = true; @@ -177,6 +185,11 @@ player.shape = SHAPE_GIRL; player.loadTexture('player_girl'); } + + player.body.setSize(player.texture.width, player.texture.height); + if ((ground.y - player.y) < player.body.halfHeight) + player.y = ground.y - player.body.halfHeight; + lastkeytime = game.time.now; } @@ -229,8 +242,8 @@ } - function putText(entity, text, color = '#000000') { - var textObject = game.add.text(entity.x, entity.y - (entity.height / 2) - 30, text, { align: 'center', fill: color, fontSize: 14 }); + 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'; textObject.anchor.setTo(.5,.5); return textObject;