User prompt
Oyundakı bomblar doglar mouselar 15saniyə ərzində toxunulmasa səhnədən silinsin
User prompt
Bomb da gəlsin amma Catval bomba toxunsa game over olsun
User prompt
Mahnını əlavə et
Code edit (1 edits merged)
Please save this source code
User prompt
Catval's Mouse Chase
Initial prompt
İn this game,Catval is a cat who collects points by collecting mice.İf she collects dog that come across her by surprise,she loses 5 points.İf her total points fall below 1, the game iş över
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Bomb (hazard, instant game over) class var Bomb = Container.expand(function () { var self = Container.call(this); var bomb = self.attachAsset('Bomb', { anchorX: 0.5, anchorY: 0.5 }); // Randomize spawn position self.x = 200 + Math.random() * (2048 - 400); self.y = 300 + Math.random() * (2732 - 600); return self; }); // Catval (player) class var Catval = Container.expand(function () { var self = Container.call(this); var cat = self.attachAsset('catval', { anchorX: 0.5, anchorY: 0.5 }); // For possible future animation return self; }); // Dog (hazard) class var Dog = Container.expand(function () { var self = Container.call(this); var dog = self.attachAsset('dog', { anchorX: 0.5, anchorY: 0.5 }); // Randomize spawn position self.x = 200 + Math.random() * (2048 - 400); self.y = 300 + Math.random() * (2732 - 600); // For possible future animation return self; }); // Mouse (collectible) class var Mouse = Container.expand(function () { var self = Container.call(this); var mouse = self.attachAsset('mouse', { anchorX: 0.5, anchorY: 0.5 }); // Randomize spawn position self.x = 200 + Math.random() * (2048 - 400); self.y = 300 + Math.random() * (2732 - 600); // For possible future animation return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222244 }); /**** * Game Code ****/ // Score // Catval (the player cat) // Mouse (collectible, gives points) // Dog (hazard, costs points) var score = 0; // Score display var scoreTxt = new Text2('0', { size: 150, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Catval (player) var catval = new Catval(); game.addChild(catval); // Start at center catval.x = 2048 / 2; catval.y = 2732 / 2; // Arrays for collectibles/hazards var mice = []; var dogs = []; var bombs = []; // Bombs array // Dragging logic var dragNode = null; // Helper: spawn a mouse function spawnMouse() { var mouse = new Mouse(); mice.push(mouse); game.addChild(mouse); } // Helper: spawn a dog function spawnDog() { var dog = new Dog(); dogs.push(dog); game.addChild(dog); } // Helper: spawn a bomb function spawnBomb() { var bomb = new Bomb(); bombs.push(bomb); game.addChild(bomb); } // Initial spawn spawnMouse(); // Timers for spawning var mouseTimer = LK.setInterval(function () { // Only spawn if less than 3 mice if (mice.length < 3) { spawnMouse(); } }, 1200); var dogTimer = LK.setInterval(function () { // Dogs are rare, max 2 at a time if (dogs.length < 2 && Math.random() < 0.5) { spawnDog(); } }, 2200); // Bombs are rare, max 1 at a time var bombTimer = LK.setInterval(function () { if (bombs.length < 1 && Math.random() < 0.33) { spawnBomb(); } }, 3500); // Move handler (drag Catval) function handleMove(x, y, obj) { if (dragNode) { // Clamp to screen var halfW = catval.width / 2; var halfH = catval.height / 2; var nx = Math.max(halfW, Math.min(2048 - halfW, x)); var ny = Math.max(halfH, Math.min(2732 - halfH, y)); dragNode.x = nx; dragNode.y = ny; } } game.move = handleMove; game.down = function (x, y, obj) { // Start dragging Catval dragNode = catval; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; // Main update loop game.update = function () { // Check for Catval-mouse collisions for (var i = mice.length - 1; i >= 0; i--) { var mouse = mice[i]; if (catval.intersects(mouse)) { // Collect mouse score += 1; LK.setScore(score); scoreTxt.setText(score); // Animate mouse fade out tween(mouse, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { mouse.destroy(); } }); mice.splice(i, 1); // Flash Catval green LK.effects.flashObject(catval, 0x00ff00, 300); } } // Check for Catval-dog collisions for (var j = dogs.length - 1; j >= 0; j--) { var dog = dogs[j]; if (catval.intersects(dog)) { // Hit dog: lose 5 points score -= 5; LK.setScore(score); scoreTxt.setText(score); // Animate dog fade out tween(dog, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { dog.destroy(); } }); dogs.splice(j, 1); // Flash Catval red LK.effects.flashObject(catval, 0xff0000, 400); // Game over if score < 1 if (score < 1) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } } // Check for Catval-bomb collisions for (var b = bombs.length - 1; b >= 0; b--) { var bomb = bombs[b]; if (catval.intersects(bomb)) { // Bomb hit: instant game over tween(bomb, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { bomb.destroy(); } }); bombs.splice(b, 1); LK.effects.flashObject(catval, 0xffff00, 400); LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Remove offscreen mice/dogs (shouldn't happen, but safety) for (var k = mice.length - 1; k >= 0; k--) { var m = mice[k]; if (m.x < -200 || m.x > 2248 || m.y < -200 || m.y > 2932) { m.destroy(); mice.splice(k, 1); } } for (var l = dogs.length - 1; l >= 0; l--) { var d = dogs[l]; if (d.x < -200 || d.x > 2248 || d.y < -200 || d.y > 2932) { d.destroy(); dogs.splice(l, 1); } } // Remove offscreen bombs for (var n = bombs.length - 1; n >= 0; n--) { var bomb = bombs[n]; if (bomb.x < -200 || bomb.x > 2248 || bomb.y < -200 || bomb.y > 2932) { bomb.destroy(); bombs.splice(n, 1); } } }; // Reset score on game start LK.setScore(0); score = 0; scoreTxt.setText(score); // Play background music LK.playMusic('Music');
===================================================================
--- original.js
+++ change.js
@@ -5,8 +5,20 @@
/****
* Classes
****/
+// Bomb (hazard, instant game over) class
+var Bomb = Container.expand(function () {
+ var self = Container.call(this);
+ var bomb = self.attachAsset('Bomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Randomize spawn position
+ self.x = 200 + Math.random() * (2048 - 400);
+ self.y = 300 + Math.random() * (2732 - 600);
+ return self;
+});
// Catval (player) class
var Catval = Container.expand(function () {
var self = Container.call(this);
var cat = self.attachAsset('catval', {
@@ -73,8 +85,9 @@
catval.y = 2732 / 2;
// Arrays for collectibles/hazards
var mice = [];
var dogs = [];
+var bombs = []; // Bombs array
// Dragging logic
var dragNode = null;
// Helper: spawn a mouse
function spawnMouse() {
@@ -87,8 +100,14 @@
var dog = new Dog();
dogs.push(dog);
game.addChild(dog);
}
+// Helper: spawn a bomb
+function spawnBomb() {
+ var bomb = new Bomb();
+ bombs.push(bomb);
+ game.addChild(bomb);
+}
// Initial spawn
spawnMouse();
// Timers for spawning
var mouseTimer = LK.setInterval(function () {
@@ -102,8 +121,14 @@
if (dogs.length < 2 && Math.random() < 0.5) {
spawnDog();
}
}, 2200);
+// Bombs are rare, max 1 at a time
+var bombTimer = LK.setInterval(function () {
+ if (bombs.length < 1 && Math.random() < 0.33) {
+ spawnBomb();
+ }
+}, 3500);
// Move handler (drag Catval)
function handleMove(x, y, obj) {
if (dragNode) {
// Clamp to screen
@@ -175,8 +200,28 @@
return;
}
}
}
+ // Check for Catval-bomb collisions
+ for (var b = bombs.length - 1; b >= 0; b--) {
+ var bomb = bombs[b];
+ if (catval.intersects(bomb)) {
+ // Bomb hit: instant game over
+ tween(bomb, {
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ bomb.destroy();
+ }
+ });
+ bombs.splice(b, 1);
+ LK.effects.flashObject(catval, 0xffff00, 400);
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
// Remove offscreen mice/dogs (shouldn't happen, but safety)
for (var k = mice.length - 1; k >= 0; k--) {
var m = mice[k];
if (m.x < -200 || m.x > 2248 || m.y < -200 || m.y > 2932) {
@@ -190,8 +235,16 @@
d.destroy();
dogs.splice(l, 1);
}
}
+ // Remove offscreen bombs
+ for (var n = bombs.length - 1; n >= 0; n--) {
+ var bomb = bombs[n];
+ if (bomb.x < -200 || bomb.x > 2248 || bomb.y < -200 || bomb.y > 2932) {
+ bomb.destroy();
+ bombs.splice(n, 1);
+ }
+ }
};
// Reset score on game start
LK.setScore(0);
score = 0;