Added win condition
authorMegaBrutal <code+git@megabrutal.com>
Tue, 16 May 2017 21:40:45 +0000 (23:40 +0200)
committerMegaBrutal <code+git@megabrutal.com>
Tue, 16 May 2017 21:40:45 +0000 (23:40 +0200)
This and possible future commits are post-compo updates.

modified:   ld38.js

ld38.js

diff --git a/ld38.js b/ld38.js
index f99fd63a12b60efe9298a767e7f5373d4ee39720..4179b4a1ad0e801dc2317c2623f6c6f9cddb2bfa 100644 (file)
--- a/ld38.js
+++ b/ld38.js
@@ -1,4 +1,5 @@
         var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
+        var helptext, wintext;
         var walls;
         var gems;
         var shrinklevel = 0;
@@ -7,6 +8,7 @@
         const WAIT_GEM          =   2000;
         const WALL_THICKNESS    =     32;
         const MAX_GEMS          =     16;
+        const WIN_CONDITION     =      4;
 
         var newWorldStartX;
         var newWorldEndX;
                 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');
             }
         }
 
-        function sign(n) {
-            if (n >= 0) { return 1 } else { return -1 };
-        }
-
         function preload () {
 
             game.load.image('wall', 'wall.png');
 
             var isAllActive = true;
             gems.children.forEach(function(gem) { if (!gem.isActivated) { isAllActive = false; }});
-            if (isAllActive) {
+            if (isAllActive && (gems.length > 0)) {
+                console.log(shrinklevel);
                 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();
+                }
             };
 
             if ((game.time.now - player.lastmovetime) > WAIT_KEY) player.body.velocity.x = player.body.velocity.y = 0;
         }
 
         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) {
             }
             gems.children.forEach(relocateGem);
 
+            shrinklevel++;
+
         }