User prompt
Add ears to the rabbit
User prompt
Make the confetti 2 (Confetti_2) come out along with the normal confetti ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the rabbit and its eyes disappear when it explodes
User prompt
Make it so that when you lose, colored squares appear first (they're actually confetti) and then after the explosion the game over text appears ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Button Masher Rabbit
Initial prompt
You are a rabbit; every so often buttons will appear that you have to press. If you fail, the buttons disappear and you lose a life. If you lose all three lives, you explode.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GameButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.isPressed = false;
self.lifetime = 0;
self.maxLifetime = 2000;
self.colorIndex = Math.floor(Math.random() * 6);
var colors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
buttonGraphics.tint = colors[self.colorIndex];
self.update = function () {
self.lifetime += 16;
var progress = self.lifetime / self.maxLifetime;
var scale = 1 - progress * 0.3;
buttonGraphics.scale.x = scale;
buttonGraphics.scale.y = scale;
buttonGraphics.alpha = 1 - progress * 0.5;
};
self.press = function () {
self.isPressed = true;
};
return self;
});
var Rabbit = Container.expand(function () {
var self = Container.call(this);
var rabbitBody = self.attachAsset('rabbit', {
anchorX: 0.5,
anchorY: 0.5
});
var leftEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
var rightEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(leftEye);
self.addChild(rightEye);
leftEye.x = -25;
leftEye.y = -30;
rightEye.x = 25;
rightEye.y = -30;
self.lives = 3;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var rabbit = game.addChild(new Rabbit());
rabbit.x = 2048 / 2;
rabbit.y = 2200;
var buttons = [];
var score = 0;
var lives = 3;
var gameActive = true;
var buttonSpawnTimer = 0;
var buttonSpawnInterval = 800;
var difficultyMultiplier = 1;
var frameCount = 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 100,
fill: 0xFF6B6B
});
livesTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(livesTxt);
function spawnButton() {
var newButton = new GameButton();
newButton.x = Math.random() * 1800 + 124;
newButton.y = Math.random() * 1500 + 200;
newButton.maxLifetime = 2000 - difficultyMultiplier * 200;
if (newButton.maxLifetime < 600) newButton.maxLifetime = 600;
buttons.push(newButton);
game.addChild(newButton);
}
function updateDifficulty() {
difficultyMultiplier = 1 + score / 20 * 0.5;
if (difficultyMultiplier > 3) difficultyMultiplier = 3;
buttonSpawnInterval = 800 - difficultyMultiplier * 150;
if (buttonSpawnInterval < 300) buttonSpawnInterval = 300;
}
game.down = function (x, y, obj) {
if (!gameActive) return;
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.intersects(obj) || x > button.x - 60 && x < button.x + 60 && y > button.y - 60 && y < button.y + 60) {
if (!button.isPressed) {
button.press();
score++;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
updateDifficulty();
LK.getSound('buttonTap').play();
tween(button, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
button.destroy();
buttons.splice(a, 1);
}
});
}
return;
}
}
};
game.update = function () {
frameCount++;
if (!gameActive) return;
buttonSpawnTimer += 16;
if (buttonSpawnTimer >= buttonSpawnInterval) {
spawnButton();
buttonSpawnTimer = 0;
}
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.lifetime >= button.maxLifetime && !button.isPressed) {
LK.getSound('missButton').play();
lives--;
livesTxt.setText('Lives: ' + lives);
tween(button, {
tint: 0xff0000
}, {
duration: 100
});
button.destroy();
buttons.splice(a, 1);
if (lives <= 0) {
gameActive = false;
LK.getSound('explosion').play();
LK.effects.flashScreen(0xff6b6b, 500);
var explosionTint = {
tint: 0xffffff
};
tween(rabbit, {
tint: 0xff6b6b
}, {
duration: 300
});
LK.setTimeout(function () {
LK.showGameOver();
}, 800);
}
}
}
};
LK.playMusic('gameMusic'); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,172 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var GameButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isPressed = false;
+ self.lifetime = 0;
+ self.maxLifetime = 2000;
+ self.colorIndex = Math.floor(Math.random() * 6);
+ var colors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
+ buttonGraphics.tint = colors[self.colorIndex];
+ self.update = function () {
+ self.lifetime += 16;
+ var progress = self.lifetime / self.maxLifetime;
+ var scale = 1 - progress * 0.3;
+ buttonGraphics.scale.x = scale;
+ buttonGraphics.scale.y = scale;
+ buttonGraphics.alpha = 1 - progress * 0.5;
+ };
+ self.press = function () {
+ self.isPressed = true;
+ };
+ return self;
+});
+var Rabbit = Container.expand(function () {
+ var self = Container.call(this);
+ var rabbitBody = self.attachAsset('rabbit', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var leftEye = LK.getAsset('rabbitEye', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var rightEye = LK.getAsset('rabbitEye', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(leftEye);
+ self.addChild(rightEye);
+ leftEye.x = -25;
+ leftEye.y = -30;
+ rightEye.x = 25;
+ rightEye.y = -30;
+ self.lives = 3;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+var rabbit = game.addChild(new Rabbit());
+rabbit.x = 2048 / 2;
+rabbit.y = 2200;
+var buttons = [];
+var score = 0;
+var lives = 3;
+var gameActive = true;
+var buttonSpawnTimer = 0;
+var buttonSpawnInterval = 800;
+var difficultyMultiplier = 1;
+var frameCount = 0;
+var scoreTxt = new Text2('Score: 0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var livesTxt = new Text2('Lives: 3', {
+ size: 100,
+ fill: 0xFF6B6B
+});
+livesTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(livesTxt);
+function spawnButton() {
+ var newButton = new GameButton();
+ newButton.x = Math.random() * 1800 + 124;
+ newButton.y = Math.random() * 1500 + 200;
+ newButton.maxLifetime = 2000 - difficultyMultiplier * 200;
+ if (newButton.maxLifetime < 600) newButton.maxLifetime = 600;
+ buttons.push(newButton);
+ game.addChild(newButton);
+}
+function updateDifficulty() {
+ difficultyMultiplier = 1 + score / 20 * 0.5;
+ if (difficultyMultiplier > 3) difficultyMultiplier = 3;
+ buttonSpawnInterval = 800 - difficultyMultiplier * 150;
+ if (buttonSpawnInterval < 300) buttonSpawnInterval = 300;
+}
+game.down = function (x, y, obj) {
+ if (!gameActive) return;
+ for (var a = buttons.length - 1; a >= 0; a--) {
+ var button = buttons[a];
+ if (button.intersects(obj) || x > button.x - 60 && x < button.x + 60 && y > button.y - 60 && y < button.y + 60) {
+ if (!button.isPressed) {
+ button.press();
+ score++;
+ LK.setScore(score);
+ scoreTxt.setText('Score: ' + score);
+ updateDifficulty();
+ LK.getSound('buttonTap').play();
+ tween(button, {
+ alpha: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ button.destroy();
+ buttons.splice(a, 1);
+ }
+ });
+ }
+ return;
+ }
+ }
+};
+game.update = function () {
+ frameCount++;
+ if (!gameActive) return;
+ buttonSpawnTimer += 16;
+ if (buttonSpawnTimer >= buttonSpawnInterval) {
+ spawnButton();
+ buttonSpawnTimer = 0;
+ }
+ for (var a = buttons.length - 1; a >= 0; a--) {
+ var button = buttons[a];
+ if (button.lifetime >= button.maxLifetime && !button.isPressed) {
+ LK.getSound('missButton').play();
+ lives--;
+ livesTxt.setText('Lives: ' + lives);
+ tween(button, {
+ tint: 0xff0000
+ }, {
+ duration: 100
+ });
+ button.destroy();
+ buttons.splice(a, 1);
+ if (lives <= 0) {
+ gameActive = false;
+ LK.getSound('explosion').play();
+ LK.effects.flashScreen(0xff6b6b, 500);
+ var explosionTint = {
+ tint: 0xffffff
+ };
+ tween(rabbit, {
+ tint: 0xff6b6b
+ }, {
+ duration: 300
+ });
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 800);
+ }
+ }
+ }
+};
+LK.playMusic('gameMusic');
\ No newline at end of file