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 ****/ // 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 ****/ // Dog (hazard, costs points) // Mouse (collectible, gives points) // Catval (the player cat) // Score 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 = []; // 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); } // 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); // 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; } } } // 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); } } }; // Reset score on game start LK.setScore(0); score = 0; scoreTxt.setText(score);
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,198 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x222244
+});
+
+/****
+* Game Code
+****/
+// Dog (hazard, costs points)
+// Mouse (collectible, gives points)
+// Catval (the player cat)
+// Score
+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 = [];
+// 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);
+}
+// 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);
+// 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;
+ }
+ }
+ }
+ // 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);
+ }
+ }
+};
+// Reset score on game start
+LK.setScore(0);
+score = 0;
+scoreTxt.setText(score);
\ No newline at end of file