User prompt
el juego se gana is ganas 5 rondas
User prompt
creame un background asset para ponerle fondo al juego
User prompt
y que tenga una musica jaz cantada por gatitos bebes
User prompt
cuando suena el miau caiga un pescado y el que llega a tener 10 pescados gana, separa mas a los jugadores y haz que sea mucho mas grande la mesa y generame asset de un back ground para hacer el fondo
Code edit (1 edits merged)
Please save this source code
User prompt
Miau Reflex - Cat Paw Slap Game
Initial prompt
crea un juego de 4 jugadores 3 son ia todos son patitas de gatos y hay un cronometro invisible y una voz que dice miau cuando hay que golpear una mesa el ultimo en golpearla pierde
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CatPaw = Container.expand(function (assetId, startX, startY, isPlayer, reactionSpeed) {
var self = Container.call(this);
self.isPlayer = isPlayer || false;
self.reactionSpeed = reactionSpeed || 300;
self.startX = startX;
self.startY = startY;
self.isEliminated = false;
self.hasReacted = false;
self.reactionTime = 0;
self.fishCount = 0;
var pawGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.resetPosition = function () {
self.x = self.startX;
self.y = self.startY;
self.hasReacted = false;
self.reactionTime = 0;
};
self.slapTable = function () {
if (self.isEliminated || self.hasReacted) return;
self.hasReacted = true;
self.reactionTime = Date.now() - gameStartTime;
// Animate paw moving to table
tween(self, {
x: 1024,
y: 1366
}, {
duration: 200,
easing: tween.easeOut
});
};
self.eliminate = function () {
self.isEliminated = true;
tween(pawGraphics, {
alpha: 0.3,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 500,
easing: tween.easeInOut
});
};
return self;
});
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.lastY = 0;
self.update = function () {
if (self.lastY === undefined) self.lastY = self.y;
self.y += self.speed;
if (self.lastY < 2732 && self.y >= 2732) {
self.destroy();
}
self.lastY = self.y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
// Add background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var table = game.addChild(LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create paws array with more separated positions
var paws = [];
var playerPaw = game.addChild(new CatPaw('playerPaw', 1024, 2200, true, 0));
var aiPaw1 = game.addChild(new CatPaw('aiPaw1', 200, 1366, false, 250 + Math.random() * 200));
var aiPaw2 = game.addChild(new CatPaw('aiPaw2', 1848, 1366, false, 300 + Math.random() * 250));
var aiPaw3 = game.addChild(new CatPaw('aiPaw3', 1024, 532, false, 200 + Math.random() * 300));
paws.push(playerPaw, aiPaw1, aiPaw2, aiPaw3);
// Fish array
var fishes = [];
// Game state variables
var gameState = 'waiting'; // 'waiting', 'countdown', 'listening', 'reacting', 'roundEnd'
var gameStartTime = 0;
var waitTimer = 0;
var roundNumber = 1;
var playerWins = storage.playerWins || 0;
var totalGames = storage.totalGames || 0;
// UI Elements
var instructionText = new Text2('Wait for the "MIAU" sound, then catch the fish!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
var fishCountText = new Text2('Your Fish: 0/10', {
size: 50,
fill: 0xFFFFFF
});
fishCountText.anchor.set(1, 0);
LK.gui.topRight.addChild(fishCountText);
var aiScoreText = new Text2('AI Fish: 0, 0, 0', {
size: 40,
fill: 0xFFFFFF
});
aiScoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(aiScoreText);
aiScoreText.x = 120;
function startNewRound() {
gameState = 'waiting';
waitTimer = LK.ticks + (180 + Math.random() * 300); // 3-8 seconds wait
// Reset all non-eliminated paws
for (var i = 0; i < paws.length; i++) {
if (!paws[i].isEliminated) {
paws[i].resetPosition();
}
}
instructionText.setText('Wait for the "MIAU" sound...');
roundText.setText('Round ' + roundNumber);
}
function playMiauSound() {
gameState = 'reacting';
gameStartTime = Date.now();
LK.getSound('miau').play();
instructionText.setText('CATCH THE FISH!');
// Spawn a fish
var fish = game.addChild(new Fish());
fish.x = 1024 + (Math.random() - 0.5) * 600;
fish.y = 200;
fishes.push(fish);
// AI reactions with their individual speeds
for (var i = 0; i < paws.length; i++) {
var paw = paws[i];
if (!paw.isPlayer && !paw.isEliminated) {
LK.setTimeout(function (p) {
return function () {
p.slapTable();
};
}(paw), paw.reactionSpeed + Math.random() * 100);
}
}
}
function checkFishCollection() {
var reactedPaws = [];
for (var i = 0; i < paws.length; i++) {
if (!paws[i].isEliminated && paws[i].hasReacted) {
reactedPaws.push(paws[i]);
}
}
if (reactedPaws.length > 0) {
// Find fastest paw
var fastestPaw = reactedPaws[0];
for (var i = 1; i < reactedPaws.length; i++) {
if (reactedPaws[i].reactionTime < fastestPaw.reactionTime) {
fastestPaw = reactedPaws[i];
}
}
// Give fish to fastest paw
fastestPaw.fishCount++;
// Update UI
updateFishCountDisplay();
// Check win condition
if (fastestPaw.fishCount >= 10) {
if (fastestPaw.isPlayer) {
instructionText.setText('You Won! 10 Fish Collected!');
playerWins++;
totalGames++;
storage.playerWins = playerWins;
storage.totalGames = totalGames;
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
} else {
instructionText.setText('AI Won! Game Over');
totalGames++;
storage.totalGames = totalGames;
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
} else {
LK.setTimeout(function () {
startNewRound();
}, 1500);
}
}
}
function updateFishCountDisplay() {
fishCountText.setText('Your Fish: ' + playerPaw.fishCount + '/10');
var aiCounts = [];
for (var i = 1; i < paws.length; i++) {
aiCounts.push(paws[i].fishCount);
}
aiScoreText.setText('AI Fish: ' + aiCounts.join(', '));
}
// Touch controls for player
game.down = function (x, y, obj) {
if (gameState === 'reacting' && !playerPaw.isEliminated) {
playerPaw.slapTable();
}
};
// Initialize first round
startNewRound();
game.update = function () {
if (gameState === 'waiting' && LK.ticks >= waitTimer) {
playMiauSound();
}
if (gameState === 'reacting') {
// Check fish collection
for (var i = fishes.length - 1; i >= 0; i--) {
var fish = fishes[i];
if (fish.y >= 2732) {
fish.destroy();
fishes.splice(i, 1);
continue;
}
// Check if any paw caught the fish
for (var j = 0; j < paws.length; j++) {
var paw = paws[j];
if (paw.hasReacted && fish.intersects(paw)) {
fish.destroy();
fishes.splice(i, 1);
break;
}
}
}
checkFishCollection();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -15,8 +15,9 @@
self.startY = startY;
self.isEliminated = false;
self.hasReacted = false;
self.reactionTime = 0;
+ self.fishCount = 0;
var pawGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
@@ -53,8 +54,26 @@
});
};
return self;
});
+var Fish = Container.expand(function () {
+ var self = Container.call(this);
+ var fishGraphics = self.attachAsset('fish', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.lastY = 0;
+ self.update = function () {
+ if (self.lastY === undefined) self.lastY = self.y;
+ self.y += self.speed;
+ if (self.lastY < 2732 && self.y >= 2732) {
+ self.destroy();
+ }
+ self.lastY = self.y;
+ };
+ return self;
+});
/****
* Initialize Game
****/
@@ -64,49 +83,57 @@
/****
* Game Code
****/
+// Add background
+var background = game.addChild(LK.getAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+}));
var table = game.addChild(LK.getAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
-// Create paws array
+// Create paws array with more separated positions
var paws = [];
-var playerPaw = game.addChild(new CatPaw('playerPaw', 1024, 1800, true, 0));
-var aiPaw1 = game.addChild(new CatPaw('aiPaw1', 400, 1366, false, 250 + Math.random() * 200));
-var aiPaw2 = game.addChild(new CatPaw('aiPaw2', 1648, 1366, false, 300 + Math.random() * 250));
-var aiPaw3 = game.addChild(new CatPaw('aiPaw3', 1024, 932, false, 200 + Math.random() * 300));
+var playerPaw = game.addChild(new CatPaw('playerPaw', 1024, 2200, true, 0));
+var aiPaw1 = game.addChild(new CatPaw('aiPaw1', 200, 1366, false, 250 + Math.random() * 200));
+var aiPaw2 = game.addChild(new CatPaw('aiPaw2', 1848, 1366, false, 300 + Math.random() * 250));
+var aiPaw3 = game.addChild(new CatPaw('aiPaw3', 1024, 532, false, 200 + Math.random() * 300));
paws.push(playerPaw, aiPaw1, aiPaw2, aiPaw3);
+// Fish array
+var fishes = [];
// Game state variables
var gameState = 'waiting'; // 'waiting', 'countdown', 'listening', 'reacting', 'roundEnd'
var gameStartTime = 0;
var waitTimer = 0;
var roundNumber = 1;
var playerWins = storage.playerWins || 0;
var totalGames = storage.totalGames || 0;
// UI Elements
-var instructionText = new Text2('Wait for the "MIAU" sound, then tap the table!', {
+var instructionText = new Text2('Wait for the "MIAU" sound, then catch the fish!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
-var scoreText = new Text2('Wins: ' + playerWins + '/' + totalGames, {
+var fishCountText = new Text2('Your Fish: 0/10', {
size: 50,
fill: 0xFFFFFF
});
-scoreText.anchor.set(1, 0);
-LK.gui.topRight.addChild(scoreText);
-var roundText = new Text2('Round ' + roundNumber, {
- size: 80,
- fill: 0xFFD700
+fishCountText.anchor.set(1, 0);
+LK.gui.topRight.addChild(fishCountText);
+var aiScoreText = new Text2('AI Fish: 0, 0, 0', {
+ size: 40,
+ fill: 0xFFFFFF
});
-roundText.anchor.set(0.5, 0.5);
-game.addChild(roundText);
-roundText.x = 1024;
-roundText.y = 600;
+aiScoreText.anchor.set(0, 0);
+LK.gui.topLeft.addChild(aiScoreText);
+aiScoreText.x = 120;
function startNewRound() {
gameState = 'waiting';
waitTimer = LK.ticks + (180 + Math.random() * 300); // 3-8 seconds wait
// Reset all non-eliminated paws
@@ -121,9 +148,14 @@
function playMiauSound() {
gameState = 'reacting';
gameStartTime = Date.now();
LK.getSound('miau').play();
- instructionText.setText('SLAP THE TABLE NOW!');
+ instructionText.setText('CATCH THE FISH!');
+ // Spawn a fish
+ var fish = game.addChild(new Fish());
+ fish.x = 1024 + (Math.random() - 0.5) * 600;
+ fish.y = 200;
+ fishes.push(fish);
// AI reactions with their individual speeds
for (var i = 0; i < paws.length; i++) {
var paw = paws[i];
if (!paw.isPlayer && !paw.isEliminated) {
@@ -134,63 +166,61 @@
}(paw), paw.reactionSpeed + Math.random() * 100);
}
}
}
-function checkRoundEnd() {
- var activePaws = [];
+function checkFishCollection() {
var reactedPaws = [];
for (var i = 0; i < paws.length; i++) {
- if (!paws[i].isEliminated) {
- activePaws.push(paws[i]);
- if (paws[i].hasReacted) {
- reactedPaws.push(paws[i]);
- }
+ if (!paws[i].isEliminated && paws[i].hasReacted) {
+ reactedPaws.push(paws[i]);
}
}
- if (reactedPaws.length === activePaws.length && activePaws.length > 1) {
- // Find slowest paw
- var slowestPaw = reactedPaws[0];
+ if (reactedPaws.length > 0) {
+ // Find fastest paw
+ var fastestPaw = reactedPaws[0];
for (var i = 1; i < reactedPaws.length; i++) {
- if (reactedPaws[i].reactionTime > slowestPaw.reactionTime) {
- slowestPaw = reactedPaws[i];
+ if (reactedPaws[i].reactionTime < fastestPaw.reactionTime) {
+ fastestPaw = reactedPaws[i];
}
}
- // Eliminate slowest paw
- slowestPaw.eliminate();
- if (slowestPaw.isPlayer) {
- instructionText.setText('You were eliminated! Game Over');
- totalGames++;
- storage.totalGames = totalGames;
- scoreText.setText('Wins: ' + playerWins + '/' + totalGames);
- LK.setTimeout(function () {
- LK.showGameOver();
- }, 2000);
- } else {
- activePaws = [];
- for (var j = 0; j < paws.length; j++) {
- if (!paws[j].isEliminated) {
- activePaws.push(paws[j]);
- }
- }
- if (activePaws.length === 1 && activePaws[0].isPlayer) {
- instructionText.setText('You Won! Well done!');
+ // Give fish to fastest paw
+ fastestPaw.fishCount++;
+ // Update UI
+ updateFishCountDisplay();
+ // Check win condition
+ if (fastestPaw.fishCount >= 10) {
+ if (fastestPaw.isPlayer) {
+ instructionText.setText('You Won! 10 Fish Collected!');
playerWins++;
totalGames++;
storage.playerWins = playerWins;
storage.totalGames = totalGames;
- scoreText.setText('Wins: ' + playerWins + '/' + totalGames);
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
} else {
- roundNumber++;
+ instructionText.setText('AI Won! Game Over');
+ totalGames++;
+ storage.totalGames = totalGames;
LK.setTimeout(function () {
- startNewRound();
- }, 1500);
+ LK.showGameOver();
+ }, 2000);
}
+ } else {
+ LK.setTimeout(function () {
+ startNewRound();
+ }, 1500);
}
}
}
+function updateFishCountDisplay() {
+ fishCountText.setText('Your Fish: ' + playerPaw.fishCount + '/10');
+ var aiCounts = [];
+ for (var i = 1; i < paws.length; i++) {
+ aiCounts.push(paws[i].fishCount);
+ }
+ aiScoreText.setText('AI Fish: ' + aiCounts.join(', '));
+}
// Touch controls for player
game.down = function (x, y, obj) {
if (gameState === 'reacting' && !playerPaw.isEliminated) {
playerPaw.slapTable();
@@ -202,7 +232,25 @@
if (gameState === 'waiting' && LK.ticks >= waitTimer) {
playMiauSound();
}
if (gameState === 'reacting') {
- checkRoundEnd();
+ // Check fish collection
+ for (var i = fishes.length - 1; i >= 0; i--) {
+ var fish = fishes[i];
+ if (fish.y >= 2732) {
+ fish.destroy();
+ fishes.splice(i, 1);
+ continue;
+ }
+ // Check if any paw caught the fish
+ for (var j = 0; j < paws.length; j++) {
+ var paw = paws[j];
+ if (paw.hasReacted && fish.intersects(paw)) {
+ fish.destroy();
+ fishes.splice(i, 1);
+ break;
+ }
+ }
+ }
+ checkFishCollection();
}
};
\ No newline at end of file