X-Git-Url: http://git.megabrutal.com/?p=ld38.git;a=blobdiff_plain;f=ld38.js;h=d1a761a2baec4a4b26a97be22ca8dd575224aedf;hp=6e882beea09d7aed86d2556f0567443c6f07a917;hb=HEAD;hpb=9bc05df28e7738352d7e73d03e545cc46282814d diff --git a/ld38.js b/ld38.js index 6e882be..d1a761a 100644 --- a/ld38.js +++ b/ld38.js @@ -1,4 +1,6 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var player; + var helptext, wintext; var walls; var gems; var shrinklevel = 0; @@ -7,6 +9,7 @@ const WAIT_GEM = 2000; const WALL_THICKNESS = 32; const MAX_GEMS = 16; + const WIN_CONDITION = 4; var newWorldStartX; var newWorldEndX; @@ -48,6 +51,12 @@ this.isActivated = false; } + enablePhysics() { + super.enablePhysics(); + this.body.bounce.y = 0.75; + this.body.bounce.x = 0.75; + } + activate() { this.isActivated = true; this.loadTexture('gem_active'); @@ -59,10 +68,6 @@ } } - function sign(n) { - if (n >= 0) { return 1 } else { return -1 }; - } - function preload () { game.load.image('wall', 'wall.png'); @@ -89,7 +94,7 @@ walls.children.forEach(function(wall) { wall.body.immovable = true; }); gems = game.add.group(); - for (var i = 0; i <= MAX_GEMS; i++) + for (var i = 0; i < MAX_GEMS; i++) gems.add(new Gem((Math.random() * (game.world.width - (WALL_THICKNESS * 4))) + (WALL_THICKNESS * 2), (Math.random() * (game.world.height - (WALL_THICKNESS * 4))) + (WALL_THICKNESS * 2))); gems.children.forEach(function(gem) { gem.enablePhysics(); }); @@ -118,8 +123,67 @@ var isAllActive = true; gems.children.forEach(function(gem) { if (!gem.isActivated) { isAllActive = false; }}); - if (isAllActive) { + if (isAllActive && (gems.length > 0)) { world_shrink(); + helptext.kill(); + if (shrinklevel == WIN_CONDITION) { + wintext = game.add.text(0, 0, "YOU WON!\nFinally you are free...", { align: 'center', fill: '#ff00ff', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + wintext.x = (game.world.width - wintext.width) / 2; + wintext.y = (game.world.height - wintext.height) / 2; + walls.children.forEach(function(wall) { wall.body.immovable = false; }); + var i = 0; + gems.children.forEach(function(gem) { + switch(i % 4) { + case 0: gem.body.gravity.y = 100; break; + case 1: gem.body.gravity.x = 100; break; + case 2: gem.body.gravity.y = -100; break; + case 3: gem.body.gravity.x = -100; break; + } + i++ + }); + } + else if (shrinklevel > WIN_CONDITION) { + // Kill everything. + walls.removeAll(true); + gems.removeAll(true); + wintext.kill(); + game.world.setBounds(0, 0, 800 * 3, 600 * 3); + player.x = (800 * 3) / 2; + player.y = (600 * 3) / 2; + + var endtext; + endtext = game.add.text(0, 0, "What are you looking for?", { align: 'center', fill: '#ff00ff', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 - endtext.width) / 2; + endtext.y = (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "YOU DESTROYED\nTHE WORLD!", { align: 'center', fill: '#ff0000', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = 800 + (800 - endtext.width) / 2; + endtext.y = (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "This is cool if you\nthink about it...", { align: 'center', fill: '#00ffff', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 * 2) + (800 - endtext.width) / 2; + endtext.y = (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "You just needed\n\n\n\nsome space.", { align: 'center', fill: '#ff69b4', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 - endtext.width) / 2; + endtext.y = 600 + (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "Bonanza Banzai", { align: 'center', fill: '#00ff00', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 * 2) + (800 - endtext.width) / 2; + endtext.y = 600 + (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "But nobody came.", { align: 'center', fill: '#ff0000', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 - endtext.width) / 2; + endtext.y = (600 * 2) + (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "What do you expect?\nPretty stars?\nOr planets?", { align: 'center', fill: '#00ffff', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = 800 + (800 - endtext.width) / 2; + endtext.y = (600 * 2) + (600 - endtext.height) / 2; + + endtext = game.add.text(0, 0, "I think you should abandon this game.\nThere's nothing here.", { align: 'center', fill: '#ff00ff', font: 'Ubuntu Mono', fontSize: 18, fontWeight: 'bold' }); + endtext.x = (800 * 2) + (800 - endtext.width) / 2; + endtext.y = (600 * 2) + (600 - endtext.height) / 2; + } }; if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0; @@ -157,7 +221,7 @@ } function gem_isInteractable(player, gem) { - return (game.time.now - gem.lastInteraction) > WAIT_GEM; + return ((game.time.now - gem.lastInteraction) > WAIT_GEM) && (shrinklevel <= WIN_CONDITION); } function gem_overlap(player, gem) { @@ -195,4 +259,6 @@ } gems.children.forEach(relocateGem); + shrinklevel++; + }