/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Bubble class representing the target bubbles var Bubble = Container.expand(function () { var self = Container.call(this); var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -bubbleGraphics.height; self.x = Math.random() * 2048; } }; }); // Bullet class representing the player's bullets var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -20; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var bubbles = []; var bullets = []; var score = 0; // Create and position bubbles for (var i = 0; i < 10; i++) { var bubble = new Bubble(); bubble.x = Math.random() * 2048; bubble.y = Math.random() * 2732; bubbles.push(bubble); game.addChild(bubble); } // Create score display var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle shooting game.down = function (x, y, obj) { var bullet = new Bullet(); bullet.x = x; bullet.y = y; bullets.push(bullet); game.addChild(bullet); }; // Update game state game.update = function () { // Update bubbles for (var i = 0; i < bubbles.length; i++) { bubbles[i].update(); } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); if (bullets[j].y < -50) { bullets[j].destroy(); bullets.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { for (var l = bubbles.length - 1; l >= 0; l--) { if (bullets[k].intersects(bubbles[l])) { bullets[k].destroy(); bullets.splice(k, 1); bubbles[l].destroy(); bubbles.splice(l, 1); score += 20; scoreTxt.setText('Score: ' + score); // Winning condition: If the player score is bigger than 5,000,000,00 if (score >= 5000000000) { // Show "you win". The game will be automatically paused while you win is showing. LK.showYouWin(); // Calling this will set a win for the player, destroy the 'Game' and reset entire game state. } break; } } } };
===================================================================
--- original.js
+++ change.js
@@ -92,8 +92,13 @@
bubbles[l].destroy();
bubbles.splice(l, 1);
score += 20;
scoreTxt.setText('Score: ' + score);
+ // Winning condition: If the player score is bigger than 5,000,000,00
+ if (score >= 5000000000) {
+ // Show "you win". The game will be automatically paused while you win is showing.
+ LK.showYouWin(); // Calling this will set a win for the player, destroy the 'Game' and reset entire game state.
+ }
break;
}
}
}