User prompt
Create boxes at half the probability as are created now
User prompt
Lanterns (bubbles) should be spawned at a 10% from the bottom of the screen
User prompt
Box1 is causing many issues - it's rendering some times loooots of harpoons. That can't never happen, if a box1 gets active destroy the harpoons created by the currently active box1
User prompt
Boxes that destroy bubbles will prevent those bubbles from creating boxes
User prompt
Mark harpoons generated with boxes - those harpoons will never create boxes by triggering a bubble.
User prompt
Make sure that the popped ballons with the boxes power (the bomb - destruction, the multi harpoon, etc) - they don't produce any box. Boxes can only be produced if I manually pop the balloons with my harpoon.
User prompt
There is an issue: the effects of the boxes seem accumulative? Every time I pick a box it has the effect of the previous boxes otr something like that? Please fix it: one box one effect.
User prompt
When the player collisions / intersects any of the reward boxes (box, box1, box2, box3) they should be picked up and applied.
User prompt
Make the harpoon has less speed. Don't change antyhing else.
Code edit (4 edits merged)
Please save this source code
User prompt
Make the harpoon have a bigger vertical reach
Code edit (3 edits merged)
Please save this source code
User prompt
The death effect, now tints to red. Please make it so that it tints sequentially using rainbow colors
Code edit (1 edits merged)
Please save this source code
User prompt
When the player ends, be creative and create something during 2-3 seconds to let knwo the playe rhas died. And then the game over, as usual.
Code edit (1 edits merged)
Please save this source code
User prompt
The bubbles / lamps don't get destroyed by colliding with the player.
User prompt
Make the harpoon and trail go much quicker up ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please don't hurt / harm / remove life from the player with collisions between bubbles and the player. Remove that. The player only looses life when the lamps go out of the screen from the top of the screen.
User prompt
Ok. Now the lanterns can NOT really harm / hit the player. Instead, they will hit the player if they have not been destroyed when they go out of the screen from the top
User prompt
My bubbles - they go from top to bottom, as they fall. But they are really lanterns, so they should fly from the bottom to the top, the other way around. PLease make the fix
Code edit (1 edits merged)
Please save this source code
Initial prompt
Lantern Splash
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Box class var Box = Container.expand(function () { var self = Container.call(this); var boxGraphics = self.attachAsset('box', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, // Increase the scale to enlarge the bounding box scaleY: 1.2 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Box1 class var Box1 = Container.expand(function () { var self = Container.call(this); var boxGraphics = self.attachAsset('box1', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, // Increase the scale to enlarge the bounding box scaleY: 1.2 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Box2 class var Box2 = Container.expand(function () { var self = Container.call(this); var boxGraphics = self.attachAsset('box2', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, // Increase the scale to enlarge the bounding box scaleY: 1.2 }); self.speed = 7; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Box3 class var Box3 = Container.expand(function () { var self = Container.call(this); var boxGraphics = self.attachAsset('box3', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, // Increase the scale to enlarge the bounding box scaleY: 1.2 }); self.speed = 9; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // The assets will be automatically created and loaded by the LK engine. // Bubble class var Bubble = Container.expand(function () { var self = Container.call(this); var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Start transparent }); // Make the bubble opaque after 1 second tween(bubbleGraphics, { alpha: 1 }, { duration: 1000 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 1532) { // Start tinting when 500 pixels from the bottom tween(self, { tint: 0xFF0000 }, { duration: 500, easing: tween.linear }); } if (self.y > 2732 || self.intersects(player)) { self.destroy(); lives -= 1; // Remove a heart icon when a life is lost if (hearts.length > lives) { var heartToRemove = hearts.pop(); if (heartToRemove) { tween(heartToRemove.scale, { x: 0, y: 0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { heartToRemove.destroy(); } }); } } if (lives < 0) { LK.showGameOver(); } } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); tween(explosionGraphics, { scaleX: explosionGraphics.scaleX + 1, scaleY: explosionGraphics.scaleY + 1 }, { duration: 1000, easing: tween.bounceOut, onFinish: function onFinish() { self.destroy(); } }); self.update = function () { // The explosion will disappear after a while if (self.alpha > 0) { self.alpha -= 0.02; } else { self.destroy(); } }; }); // Harpoon class var Harpoon = Container.expand(function () { var self = Container.call(this); var harpoonGraphics = self.attachAsset('harpoon', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -20; self.trail = game.addChild(new Trail()); self.update = function () { self.y += self.speed; self.trail.height = 2732 - self.y; self.trail.y = self.y + self.trail.height / 2; if (self.y < 0 || self.y < 2732 * (1 / 3)) { self.destroy(); self.trail.destroy(); } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { if (self.direction && self.direction === 'left') { self.x -= self.speed; } else if (self.direction === 'right') { self.x += self.speed; } }; self.shoot = function () { var harpoon = new Harpoon(); harpoon.x = player.x; harpoon.y = player.y - 200; harpoon.trail.x = player.x; harpoon.trail.y = player.y - 200; game.addChild(harpoon); LK.getSound('crossbow').play(); }; }); // PowerUpText class var PowerUpText = Container.expand(function () { var self = Container.call(this); var textGraphics = self.attachAsset('PowerUpText', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y -= 2; if (self.y < 0) { self.destroy(); } }; }); // Trail class var Trail = Container.expand(function () { var self = Container.call(this); var trailGraphics = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5, width: 18 }); self.update = function () { self.y += 10; if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFFFF // Init game with black background }); /**** * Game Code ****/ var background = game.attachAsset('Landscape', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.setChildIndex(background, 0); var player = new Player(); player.x = 2048 / 2; player.y = 2732 - 100; game.addChild(player); // Add player after trail to ensure correct rendering order game.move = function (x, y, obj) { player.x = x; if (x < 2048 / 2 && player.scaleX > 0 || x >= 2048 / 2 && player.scaleX < 0) { player.scaleX *= -1; // Mirror the player image } }; var score = 0; var lives = 3; var scoreBackground = new Container(); var scoreBgGraphics = scoreBackground.attachAsset('scoreBg', { anchorX: 0.5, anchorY: 0.1, scaleX: 5, scaleY: 5, alpha: 1 }); scoreBackground.addChild(scoreBgGraphics); scoreBackground.x = 0; scoreBackground.y = 0; LK.gui.top.addChild(scoreBackground); var scoreTxt = new Text2('Balloons popped: 0', { size: 30, fill: 0xFFC0CB, font: "'Comic Sans MS', cursive, sans-serif" }); scoreTxt.anchor.set(0.5, -0.1); scoreBackground.addChild(scoreTxt); var hearts = []; for (var i = 0; i < lives; i++) { var heart = LK.getAsset('heart', { anchorX: 0.5, anchorY: 0.5, x: -1 * (i + 1) * 50, // Position hearts with some spacing y: 50 }); LK.gui.topRight.addChild(heart); hearts.push(heart); } var lastShot = -999; game.down = function (x, y, obj) { if (LK.ticks - lastShot > 30) { player.shoot(); lastShot = LK.ticks; } }; // Start the music 'chinese' upon starting the game LK.playMusic('chinese'); game.update = function () { if (LK.ticks % 50 == 0) { var newBubble = new Bubble(); newBubble.x = Math.random() * 2048; newBubble.y = 0; game.addChild(newBubble); var randomTween = { delta: Math.random() * (300 - 100) + 100, // Random delta between 100 and 300 duration: Math.random() * (1500 - 800) + 800, // Random duration between 800 and 1500 easing: [tween.easeIn, tween.easeOut, tween.elasticIn, tween.elasticOut, tween.bounceIn, tween.bounceOut, tween.easeInOut, tween.bounceInOut, tween.elasticInOut][Math.floor(Math.random() * 9)] // Random easing }; tween(newBubble, { x: Math.max(0, Math.min(2048, newBubble.x + randomTween.delta)) }, { duration: randomTween.duration, easing: randomTween.easing, onFinish: function onFinish() { tween(newBubble, { x: Math.max(0, Math.min(2048, newBubble.x - randomTween.delta)) }, { duration: randomTween.duration, easing: randomTween.easing }); } }); } var bubbles = game.children.filter(function (child) { return child instanceof Bubble; }); var harpoons = game.children.filter(function (child) { return child instanceof Harpoon; }); for (var i = 0; i < bubbles.length; i++) { var bubble = bubbles[i]; if (bubble.intersects(player)) { bubble.destroy(); lives -= 1; // Remove a heart icon when a life is lost if (hearts.length > lives) { var heartToRemove = hearts.pop(); if (heartToRemove) { tween(heartToRemove.scale, { x: 0, y: 0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { heartToRemove.destroy(); } }); } } if (lives < 0) { LK.showGameOver(); } } for (var j = 0; j < harpoons.length; j++) { var harpoon = harpoons[j]; if (bubble.intersects(harpoon)) { bubble.destroy(); LK.getSound('explosion').play(); harpoon.trail.destroy(); // Destroy the harpoon trail harpoon.destroy(); bubbles.splice(i, 1); // Remove bubble from the array score += 1; scoreTxt.setText("Balloons popped: " + score.toString()); tween(scoreTxt.scale, { x: 2, y: 2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(scoreTxt.scale, { x: 1, y: 1 }, { duration: 500, easing: tween.easeInOut }); } }); harpoons.splice(j, 1); // Remove harpoon from the array // Create an explosion at the intersection point var explosion = new Explosion(); explosion.x = bubble.x; explosion.y = bubble.y; game.addChild(explosion); // Create a box at the intersection point with a 10% probability if (!game.children.some(function (child) { return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3; })) { if (Math.random() < 1) { var boxType = Math.floor(Math.random() * 4); var box; switch (boxType) { case 0: box = new Box(); break; case 1: box = new Box1(); break; case 2: box = new Box2(); break; case 3: box = new Box3(); break; } box.x = bubble.x; box.y = bubble.y; game.addChild(box); } } } } var boxes = game.children.filter(function (child) { return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3; }); for (var k = 0; k < boxes.length; k++) { var box = boxes[k]; for (var l = 0; l < harpoons.length; l++) { var harpoon = harpoons[l]; if (box.intersects(harpoon)) { box.destroy(); LK.getSound('powerup').play(); harpoon.trail.destroy(); harpoon.destroy(); // Display toast text based on the type of box destroyed var toastText = new Text2('', { size: 250, fill: 0xFFC0CB, font: "'Comic Sans MS', cursive, sans-serif" }); var toastTextBg = new Text2('', { size: 255, fill: 0xFF00AA, font: "'Comic Sans MS', cursive, sans-serif" }); toastText.anchor.set(0.5, 0.5); toastText.x = 2048 / 2; toastText.y = 2732 / 2; toastTextBg.anchor.set(0.5, 0.5); toastTextBg.x = 2048 / 2; toastTextBg.y = 2732 / 2; game.addChild(toastText); game.addChild(toastTextBg); if (box instanceof Box1) { toastText.setText("Smash!"); toastTextBg.setText("Smash!"); } else if (box instanceof Box2) { toastText.setText("Destruction!"); toastTextBg.setText("Destruction!"); } else if (box instanceof Box) { toastText.setText("Less madness!"); toastTextBg.setText("Less madness!"); } else if (box instanceof Box3) { toastText.setText("Life up!"); toastTextBg.setText("Life up!"); } // Tween the toast text to fade out and destroy after 2 seconds tween(toastText, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { toastText.destroy(); } }); tween(toastTextBg, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { toastTextBg.destroy(); } }); boxes.splice(k, 1); harpoons.splice(l, 1); // Check if the destroyed box is an instance of Box1 if (box instanceof Box1) { // Create six additional harpoons and trails for (var i = 1; i <= 3; i++) { var leftHarpoon = new Harpoon(); leftHarpoon.x = player.x - i * 150; leftHarpoon.y = player.y; leftHarpoon.trail.x = player.x - i * 150; leftHarpoon.trail.y = player.y; game.addChild(leftHarpoon); var rightHarpoon = new Harpoon(); rightHarpoon.x = player.x + i * 150; rightHarpoon.y = player.y; rightHarpoon.trail.x = player.x + i * 150; rightHarpoon.trail.y = player.y; game.addChild(rightHarpoon); // Set a timeout to remove the additional harpoons after 5 seconds LK.setTimeout(function (lh, rh) { lh.destroy(); lh.trail.destroy(); rh.destroy(); rh.trail.destroy(); }.bind(null, leftHarpoon, rightHarpoon), 5000); } } // Check if the destroyed box is an instance of Box and reduce bubble speed if (box instanceof Box) { var bubbles = game.children.filter(function (child) { return child instanceof Bubble; }); bubbles.forEach(function (bubble) { bubble.speed /= 2; }); LK.setTimeout(function () { bubbles.forEach(function (bubble) { bubble.speed *= 2; }); }, 5000); } // Check if the destroyed box is an instance of Box3 and lives are less than 3 if (box instanceof Box3 && lives < 3) { lives += 1; var heart = LK.getAsset('heart', { anchorX: 0.5, anchorY: 0.5, x: -1 * lives * 50, y: 50 }); LK.gui.topRight.addChild(heart); hearts.push(heart); } // Check if the destroyed box is an instance of Box2 if (box instanceof Box2) { var bubbles = game.children.filter(function (child) { return child instanceof Bubble; }); var bubblesDestroyed = bubbles.length; bubbles.forEach(function (bubble) { bubble.destroy(); }); score += bubblesDestroyed; scoreTxt.setText("Balloons popped: " + score.toString()); tween(scoreTxt.scale, { x: 2, y: 2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(scoreTxt.scale, { x: 1, y: 1 }, { duration: 500, easing: tween.easeInOut }); } }); } break; } } } } };
===================================================================
--- original.js
+++ change.js
@@ -1,121 +1,568 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
-****/
-// Class for Enemies
-var Enemy = Container.expand(function () {
- var self = Container.call(this);
- var enemyGraphics = self.attachAsset('enemy', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732 + enemyGraphics.height) {
- self.destroy();
- }
- };
+****/
+// Box class
+var Box = Container.expand(function () {
+ var self = Container.call(this);
+ var boxGraphics = self.attachAsset('box', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ // Increase the scale to enlarge the bounding box
+ scaleY: 1.2
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
-//<Assets used in the game will automatically appear here>
-//<Write imports for supported plugins here>
-// Class for the Hero character
-var Hero = Container.expand(function () {
- var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- // Update logic for hero
- };
- self.shoot = function () {
- var bullet = new HeroBullet();
- bullet.x = self.x;
- bullet.y = self.y - heroGraphics.height / 2;
- game.addChild(bullet);
- heroBullets.push(bullet);
- };
+// Box1 class
+var Box1 = Container.expand(function () {
+ var self = Container.call(this);
+ var boxGraphics = self.attachAsset('box1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ // Increase the scale to enlarge the bounding box
+ scaleY: 1.2
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
-// Class for Hero's bullets
-var HeroBullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.attachAsset('heroBullet', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -15;
- self.update = function () {
- self.y += self.speed;
- if (self.y < -bulletGraphics.height) {
- self.destroy();
- }
- };
+// Box2 class
+var Box2 = Container.expand(function () {
+ var self = Container.call(this);
+ var boxGraphics = self.attachAsset('box2', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ // Increase the scale to enlarge the bounding box
+ scaleY: 1.2
+ });
+ self.speed = 7;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
+// Box3 class
+var Box3 = Container.expand(function () {
+ var self = Container.call(this);
+ var boxGraphics = self.attachAsset('box3', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.2,
+ // Increase the scale to enlarge the bounding box
+ scaleY: 1.2
+ });
+ self.speed = 9;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
+// The assets will be automatically created and loaded by the LK engine.
+// Bubble class
+var Bubble = Container.expand(function () {
+ var self = Container.call(this);
+ var bubbleGraphics = self.attachAsset('bubble', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0 // Start transparent
+ });
+ // Make the bubble opaque after 1 second
+ tween(bubbleGraphics, {
+ alpha: 1
+ }, {
+ duration: 1000
+ });
+ self.speed = 10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 1532) {
+ // Start tinting when 500 pixels from the bottom
+ tween(self, {
+ tint: 0xFF0000
+ }, {
+ duration: 500,
+ easing: tween.linear
+ });
+ }
+ if (self.y > 2732 || self.intersects(player)) {
+ self.destroy();
+ lives -= 1;
+ // Remove a heart icon when a life is lost
+ if (hearts.length > lives) {
+ var heartToRemove = hearts.pop();
+ if (heartToRemove) {
+ tween(heartToRemove.scale, {
+ x: 0,
+ y: 0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ heartToRemove.destroy();
+ }
+ });
+ }
+ }
+ if (lives < 0) {
+ LK.showGameOver();
+ }
+ }
+ };
+});
+// Explosion class
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var explosionGraphics = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ tween(explosionGraphics, {
+ scaleX: explosionGraphics.scaleX + 1,
+ scaleY: explosionGraphics.scaleY + 1
+ }, {
+ duration: 1000,
+ easing: tween.bounceOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ self.update = function () {
+ // The explosion will disappear after a while
+ if (self.alpha > 0) {
+ self.alpha -= 0.02;
+ } else {
+ self.destroy();
+ }
+ };
+});
+// Harpoon class
+var Harpoon = Container.expand(function () {
+ var self = Container.call(this);
+ var harpoonGraphics = self.attachAsset('harpoon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -20;
+ self.trail = game.addChild(new Trail());
+ self.update = function () {
+ self.y += self.speed;
+ self.trail.height = 2732 - self.y;
+ self.trail.y = self.y + self.trail.height / 2;
+ if (self.y < 0 || self.y < 2732 * (1 / 3)) {
+ self.destroy();
+ self.trail.destroy();
+ }
+ };
+});
+// Player class
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ if (self.direction && self.direction === 'left') {
+ self.x -= self.speed;
+ } else if (self.direction === 'right') {
+ self.x += self.speed;
+ }
+ };
+ self.shoot = function () {
+ var harpoon = new Harpoon();
+ harpoon.x = player.x;
+ harpoon.y = player.y - 200;
+ harpoon.trail.x = player.x;
+ harpoon.trail.y = player.y - 200;
+ game.addChild(harpoon);
+ LK.getSound('crossbow').play();
+ };
+});
+// PowerUpText class
+var PowerUpText = Container.expand(function () {
+ var self = Container.call(this);
+ var textGraphics = self.attachAsset('PowerUpText', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ self.y -= 2;
+ if (self.y < 0) {
+ self.destroy();
+ }
+ };
+});
+// Trail class
+var Trail = Container.expand(function () {
+ var self = Container.call(this);
+ var trailGraphics = self.attachAsset('line', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: 18
+ });
+ self.update = function () {
+ self.y += 10;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0xFFFFFFFF // Init game with black background
});
-/****
+/****
* Game Code
-****/
-// Initialize variables
-var hero;
-var heroBullets = [];
-var enemies = [];
+****/
+var background = game.attachAsset('Landscape', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+});
+game.setChildIndex(background, 0);
+var player = new Player();
+player.x = 2048 / 2;
+player.y = 2732 - 100;
+game.addChild(player); // Add player after trail to ensure correct rendering order
+game.move = function (x, y, obj) {
+ player.x = x;
+ if (x < 2048 / 2 && player.scaleX > 0 || x >= 2048 / 2 && player.scaleX < 0) {
+ player.scaleX *= -1; // Mirror the player image
+ }
+};
var score = 0;
-// Create hero and add to game
-hero = new Hero();
-hero.x = 2048 / 2;
-hero.y = 2732 - 150;
-game.addChild(hero);
-// Function to spawn enemies
-function spawnEnemy() {
- var enemy = new Enemy();
- enemy.x = Math.random() * 2048;
- enemy.y = -50;
- game.addChild(enemy);
- enemies.push(enemy);
+var lives = 3;
+var scoreBackground = new Container();
+var scoreBgGraphics = scoreBackground.attachAsset('scoreBg', {
+ anchorX: 0.5,
+ anchorY: 0.1,
+ scaleX: 5,
+ scaleY: 5,
+ alpha: 1
+});
+scoreBackground.addChild(scoreBgGraphics);
+scoreBackground.x = 0;
+scoreBackground.y = 0;
+LK.gui.top.addChild(scoreBackground);
+var scoreTxt = new Text2('Balloons popped: 0', {
+ size: 30,
+ fill: 0xFFC0CB,
+ font: "'Comic Sans MS', cursive, sans-serif"
+});
+scoreTxt.anchor.set(0.5, -0.1);
+scoreBackground.addChild(scoreTxt);
+var hearts = [];
+for (var i = 0; i < lives; i++) {
+ var heart = LK.getAsset('heart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -1 * (i + 1) * 50,
+ // Position hearts with some spacing
+ y: 50
+ });
+ LK.gui.topRight.addChild(heart);
+ hearts.push(heart);
}
-// Handle game updates
-game.update = function () {
- // Update hero bullets
- for (var i = heroBullets.length - 1; i >= 0; i--) {
- heroBullets[i].update();
- if (heroBullets[i].y < -50) {
- heroBullets[i].destroy();
- heroBullets.splice(i, 1);
- }
- }
- // Update enemies
- for (var j = enemies.length - 1; j >= 0; j--) {
- enemies[j].update();
- if (enemies[j].y > 2732 + 50) {
- enemies[j].destroy();
- enemies.splice(j, 1);
- }
- }
- // Check for collisions between hero bullets and enemies
- for (var k = heroBullets.length - 1; k >= 0; k--) {
- for (var l = enemies.length - 1; l >= 0; l--) {
- if (heroBullets[k].intersects(enemies[l])) {
- heroBullets[k].destroy();
- enemies[l].destroy();
- heroBullets.splice(k, 1);
- enemies.splice(l, 1);
- score += 10;
- break;
- }
- }
- }
-};
-// Set interval to spawn enemies
-LK.setInterval(spawnEnemy, 2000);
-// Handle touch events for shooting
+var lastShot = -999;
game.down = function (x, y, obj) {
- hero.shoot();
+ if (LK.ticks - lastShot > 30) {
+ player.shoot();
+ lastShot = LK.ticks;
+ }
+};
+// Start the music 'chinese' upon starting the game
+LK.playMusic('chinese');
+game.update = function () {
+ if (LK.ticks % 50 == 0) {
+ var newBubble = new Bubble();
+ newBubble.x = Math.random() * 2048;
+ newBubble.y = 0;
+ game.addChild(newBubble);
+ var randomTween = {
+ delta: Math.random() * (300 - 100) + 100,
+ // Random delta between 100 and 300
+ duration: Math.random() * (1500 - 800) + 800,
+ // Random duration between 800 and 1500
+ easing: [tween.easeIn, tween.easeOut, tween.elasticIn, tween.elasticOut, tween.bounceIn, tween.bounceOut, tween.easeInOut, tween.bounceInOut, tween.elasticInOut][Math.floor(Math.random() * 9)] // Random easing
+ };
+ tween(newBubble, {
+ x: Math.max(0, Math.min(2048, newBubble.x + randomTween.delta))
+ }, {
+ duration: randomTween.duration,
+ easing: randomTween.easing,
+ onFinish: function onFinish() {
+ tween(newBubble, {
+ x: Math.max(0, Math.min(2048, newBubble.x - randomTween.delta))
+ }, {
+ duration: randomTween.duration,
+ easing: randomTween.easing
+ });
+ }
+ });
+ }
+ var bubbles = game.children.filter(function (child) {
+ return child instanceof Bubble;
+ });
+ var harpoons = game.children.filter(function (child) {
+ return child instanceof Harpoon;
+ });
+ for (var i = 0; i < bubbles.length; i++) {
+ var bubble = bubbles[i];
+ if (bubble.intersects(player)) {
+ bubble.destroy();
+ lives -= 1;
+ // Remove a heart icon when a life is lost
+ if (hearts.length > lives) {
+ var heartToRemove = hearts.pop();
+ if (heartToRemove) {
+ tween(heartToRemove.scale, {
+ x: 0,
+ y: 0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ heartToRemove.destroy();
+ }
+ });
+ }
+ }
+ if (lives < 0) {
+ LK.showGameOver();
+ }
+ }
+ for (var j = 0; j < harpoons.length; j++) {
+ var harpoon = harpoons[j];
+ if (bubble.intersects(harpoon)) {
+ bubble.destroy();
+ LK.getSound('explosion').play();
+ harpoon.trail.destroy(); // Destroy the harpoon trail
+ harpoon.destroy();
+ bubbles.splice(i, 1); // Remove bubble from the array
+ score += 1;
+ scoreTxt.setText("Balloons popped: " + score.toString());
+ tween(scoreTxt.scale, {
+ x: 2,
+ y: 2
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(scoreTxt.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ harpoons.splice(j, 1); // Remove harpoon from the array
+ // Create an explosion at the intersection point
+ var explosion = new Explosion();
+ explosion.x = bubble.x;
+ explosion.y = bubble.y;
+ game.addChild(explosion);
+ // Create a box at the intersection point with a 10% probability
+ if (!game.children.some(function (child) {
+ return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
+ })) {
+ if (Math.random() < 1) {
+ var boxType = Math.floor(Math.random() * 4);
+ var box;
+ switch (boxType) {
+ case 0:
+ box = new Box();
+ break;
+ case 1:
+ box = new Box1();
+ break;
+ case 2:
+ box = new Box2();
+ break;
+ case 3:
+ box = new Box3();
+ break;
+ }
+ box.x = bubble.x;
+ box.y = bubble.y;
+ game.addChild(box);
+ }
+ }
+ }
+ }
+ var boxes = game.children.filter(function (child) {
+ return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
+ });
+ for (var k = 0; k < boxes.length; k++) {
+ var box = boxes[k];
+ for (var l = 0; l < harpoons.length; l++) {
+ var harpoon = harpoons[l];
+ if (box.intersects(harpoon)) {
+ box.destroy();
+ LK.getSound('powerup').play();
+ harpoon.trail.destroy();
+ harpoon.destroy();
+ // Display toast text based on the type of box destroyed
+ var toastText = new Text2('', {
+ size: 250,
+ fill: 0xFFC0CB,
+ font: "'Comic Sans MS', cursive, sans-serif"
+ });
+ var toastTextBg = new Text2('', {
+ size: 255,
+ fill: 0xFF00AA,
+ font: "'Comic Sans MS', cursive, sans-serif"
+ });
+ toastText.anchor.set(0.5, 0.5);
+ toastText.x = 2048 / 2;
+ toastText.y = 2732 / 2;
+ toastTextBg.anchor.set(0.5, 0.5);
+ toastTextBg.x = 2048 / 2;
+ toastTextBg.y = 2732 / 2;
+ game.addChild(toastText);
+ game.addChild(toastTextBg);
+ if (box instanceof Box1) {
+ toastText.setText("Smash!");
+ toastTextBg.setText("Smash!");
+ } else if (box instanceof Box2) {
+ toastText.setText("Destruction!");
+ toastTextBg.setText("Destruction!");
+ } else if (box instanceof Box) {
+ toastText.setText("Less madness!");
+ toastTextBg.setText("Less madness!");
+ } else if (box instanceof Box3) {
+ toastText.setText("Life up!");
+ toastTextBg.setText("Life up!");
+ }
+ // Tween the toast text to fade out and destroy after 2 seconds
+ tween(toastText, {
+ alpha: 0
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ toastText.destroy();
+ }
+ });
+ tween(toastTextBg, {
+ alpha: 0
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ toastTextBg.destroy();
+ }
+ });
+ boxes.splice(k, 1);
+ harpoons.splice(l, 1);
+ // Check if the destroyed box is an instance of Box1
+ if (box instanceof Box1) {
+ // Create six additional harpoons and trails
+ for (var i = 1; i <= 3; i++) {
+ var leftHarpoon = new Harpoon();
+ leftHarpoon.x = player.x - i * 150;
+ leftHarpoon.y = player.y;
+ leftHarpoon.trail.x = player.x - i * 150;
+ leftHarpoon.trail.y = player.y;
+ game.addChild(leftHarpoon);
+ var rightHarpoon = new Harpoon();
+ rightHarpoon.x = player.x + i * 150;
+ rightHarpoon.y = player.y;
+ rightHarpoon.trail.x = player.x + i * 150;
+ rightHarpoon.trail.y = player.y;
+ game.addChild(rightHarpoon);
+ // Set a timeout to remove the additional harpoons after 5 seconds
+ LK.setTimeout(function (lh, rh) {
+ lh.destroy();
+ lh.trail.destroy();
+ rh.destroy();
+ rh.trail.destroy();
+ }.bind(null, leftHarpoon, rightHarpoon), 5000);
+ }
+ }
+ // Check if the destroyed box is an instance of Box and reduce bubble speed
+ if (box instanceof Box) {
+ var bubbles = game.children.filter(function (child) {
+ return child instanceof Bubble;
+ });
+ bubbles.forEach(function (bubble) {
+ bubble.speed /= 2;
+ });
+ LK.setTimeout(function () {
+ bubbles.forEach(function (bubble) {
+ bubble.speed *= 2;
+ });
+ }, 5000);
+ }
+ // Check if the destroyed box is an instance of Box3 and lives are less than 3
+ if (box instanceof Box3 && lives < 3) {
+ lives += 1;
+ var heart = LK.getAsset('heart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -1 * lives * 50,
+ y: 50
+ });
+ LK.gui.topRight.addChild(heart);
+ hearts.push(heart);
+ }
+ // Check if the destroyed box is an instance of Box2
+ if (box instanceof Box2) {
+ var bubbles = game.children.filter(function (child) {
+ return child instanceof Bubble;
+ });
+ var bubblesDestroyed = bubbles.length;
+ bubbles.forEach(function (bubble) {
+ bubble.destroy();
+ });
+ score += bubblesDestroyed;
+ scoreTxt.setText("Balloons popped: " + score.toString());
+ tween(scoreTxt.scale, {
+ x: 2,
+ y: 2
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(scoreTxt.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ }
+ break;
+ }
+ }
+ }
+ }
};
\ No newline at end of file
a green cross, icon, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a sand clock pixel style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bomb, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a pixel harpoon, vertical and looking up, retro like in pang games.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A banner to show a message, pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
two harpoons looking up, retro, pixel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A chinese flying paper lantern, retro pixel style. In-Game asset. 2d. High contrast. No shadows
fireworks, retro pixel style, colorful. In-Game asset. 2d. High contrast. No shadows
A chinese pixel background of an arcade game, sunset, retro style,. In-Game asset. 2d. High contrast. No shadows