User prompt
po zmianie poziomu wydra znika, wydra zawsze powinna być na wierzchu - nad tłami
User prompt
Dodałem różne tła, od backgrund1 do background15 - losuj je w kolejnych poziomach, bez powtarzania w ramach jednej rozgrywki
User prompt
Po kliknięciu play again lvl powinien się resetować, zdobyte tokeny też ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Play again powinno restartować level do 1
User prompt
tło background1 chociaż jest w dobrej jakości, to wygląda na strasznie rozmazane i niewyraźne, popraw proszę sposób w jaki renderujesz tło
User prompt
Use Background1 as game background
User prompt
Eggs should fly toward the otter from various directions at different angles—but always from above—and if an egg hits the otter, the otter dies. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'active')' in or related to this line: 'if (!egg.active) {' Line Number: 236
Code edit (1 edits merged)
Please save this source code
User prompt
Otter Smash
Initial prompt
Otter Smash is a vibrant mobile game where you play as a playful otter hurling golden “ORO” coins at mysterious eggs—each successful hit cracks the shell and brings you closer to a prize. Collect the shattered eggs, advance through new levels, and win up to 15 Baby Otter tokens to unlock extra skins and special power-ups!
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.active = true;
self.update = function () {
if (!self.active) return;
self.x += self.speedX;
self.y += self.speedY;
// Remove coin if it goes off screen
if (self.y < -50 || self.y > 2732 + 50 || self.x < -50 || self.x > 2048 + 50) {
self.active = false;
}
};
return self;
});
var Egg = Container.expand(function () {
var self = Container.call(this);
var eggGraphics = self.attachAsset('egg', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 2;
self.speedY = 0;
self.hits = 0;
self.maxHits = 2;
self.active = true;
self.cracked = false;
var crackGraphics = null;
self.hit = function () {
self.hits++;
LK.getSound('crack').play();
if (self.hits >= self.maxHits && !self.cracked) {
self.cracked = true;
if (!crackGraphics) {
crackGraphics = self.attachAsset('crack', {
anchorX: 0.5,
anchorY: 0.5
});
}
LK.effects.flashObject(self, 0xFFFFFF, 300);
}
};
self.update = function () {
if (!self.active) return;
self.x += self.speedX;
self.y += self.speedY;
// Remove if goes off screen
if (self.y > 2732 + 100 || self.x < -100 || self.x > 2148) {
self.active = false;
}
};
return self;
});
var Otter = Container.expand(function () {
var self = Container.call(this);
var otterGraphics = self.attachAsset('otter', {
anchorX: 0.5,
anchorY: 0.5
});
self.canThrow = true;
self.throwCooldown = 0;
self.throwCoin = function (targetX, targetY) {
if (!self.canThrow) return null;
var coin = new Coin();
coin.x = self.x;
coin.y = self.y - 50;
// Calculate throw direction
var dx = targetX - coin.x;
var dy = targetY - coin.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 12;
coin.speedX = dx / distance * speed;
coin.speedY = dy / distance * speed;
self.canThrow = false;
self.throwCooldown = 20; // 20 ticks cooldown
LK.getSound('throw').play();
// Small throw animation
tween(otterGraphics, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 100
});
tween(otterGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
return coin;
};
self.update = function () {
if (self.throwCooldown > 0) {
self.throwCooldown--;
if (self.throwCooldown <= 0) {
self.canThrow = true;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var otter;
var coins = [];
var eggs = [];
var level = 1;
var babyOtterTokens = 0;
var eggsCollected = 0;
var eggsNeeded = 5;
var spawnTimer = 0;
var spawnInterval = 120; // 2 seconds at 60fps
var usedBackgrounds = [];
var availableBackgrounds = ['Background1', 'Background2', 'Background3', 'Background4', 'Background5', 'Background6', 'Background7', 'Background8', 'Background9', 'Background10', 'Background11', 'Background12', 'Background13', 'Background14', 'Background15'];
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
var levelText = new Text2('Level: ' + level, {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
var tokensText = new Text2('Tokens: ' + babyOtterTokens, {
size: 40,
fill: 0xFFD700
});
tokensText.anchor.set(1, 0);
tokensText.x = -20;
tokensText.y = 50;
LK.gui.topRight.addChild(tokensText);
var progressText = new Text2('Eggs: 0/' + eggsNeeded, {
size: 45,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 0);
progressText.y = 80;
LK.gui.top.addChild(progressText);
// Add background
var background = game.addChild(LK.getAsset('Background1', {
anchorX: 0,
anchorY: 0,
width: 2048,
height: 2732
}));
background.x = 0;
background.y = 0;
// Create otter
otter = game.addChild(new Otter());
otter.x = 1024;
otter.y = 2400;
// Touch handling
game.down = function (x, y, obj) {
if (otter.canThrow) {
var coin = otter.throwCoin(x, y);
if (coin) {
coins.push(coin);
game.addChild(coin);
}
}
};
// Background selection function
function getRandomBackground() {
// If all backgrounds have been used, reset the used array
if (usedBackgrounds.length >= availableBackgrounds.length) {
usedBackgrounds = [];
}
// Get available backgrounds not yet used
var remainingBackgrounds = [];
for (var i = 0; i < availableBackgrounds.length; i++) {
var bg = availableBackgrounds[i];
var isUsed = false;
for (var j = 0; j < usedBackgrounds.length; j++) {
if (usedBackgrounds[j] === bg) {
isUsed = true;
break;
}
}
if (!isUsed) {
remainingBackgrounds.push(bg);
}
}
// Select random background from remaining
var selectedBackground = remainingBackgrounds[Math.floor(Math.random() * remainingBackgrounds.length)];
usedBackgrounds.push(selectedBackground);
return selectedBackground;
}
// Spawn eggs
function spawnEgg() {
var egg = new Egg();
// Spawn from above at random X position
egg.x = Math.random() * 2048;
egg.y = -100;
// Calculate direction toward otter
var dx = otter.x - egg.x;
var dy = otter.y - egg.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 3 + level * 0.3;
egg.speedX = dx / distance * speed;
egg.speedY = dy / distance * speed;
eggs.push(egg);
game.addChild(egg);
}
// Check collisions
function checkCollisions() {
// Check egg-otter collisions (otter dies)
for (var e = eggs.length - 1; e >= 0; e--) {
var egg = eggs[e];
if (!egg || !egg.active) continue;
if (egg.intersects(otter)) {
// Flash otter red and show game over
LK.effects.flashObject(otter, 0xFF0000, 500);
LK.showGameOver();
return;
}
}
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.active) {
coin.destroy();
coins.splice(i, 1);
continue;
}
for (var j = eggs.length - 1; j >= 0; j--) {
var egg = eggs[j];
if (!egg || !egg.active) continue;
if (coin.intersects(egg)) {
egg.hit();
coin.active = false;
coin.destroy();
coins.splice(i, 1);
break;
}
}
}
// Check for cracked eggs to collect
for (var k = eggs.length - 1; k >= 0; k--) {
var egg = eggs[k];
if (!egg || !egg.active) {
if (egg) egg.destroy();
eggs.splice(k, 1);
continue;
}
if (egg.cracked) {
LK.setScore(LK.getScore() + 100);
LK.getSound('collect').play();
eggsCollected++;
// Flash effect
LK.effects.flashObject(egg, 0x00FF00, 500);
egg.destroy();
eggs.splice(k, 1);
// Update UI
scoreText.setText('Score: ' + LK.getScore());
progressText.setText('Eggs: ' + eggsCollected + '/' + eggsNeeded);
// Check level completion
if (eggsCollected >= eggsNeeded) {
levelComplete();
}
}
}
}
function levelComplete() {
level++;
babyOtterTokens++;
eggsCollected = 0;
eggsNeeded = Math.min(5 + level, 10);
spawnInterval = Math.max(60, 120 - level * 5);
// Change background for next level
var newBackgroundId = getRandomBackground();
background.destroy();
background = game.addChild(LK.getAsset(newBackgroundId, {
anchorX: 0,
anchorY: 0,
width: 2048,
height: 2732
}));
background.x = 0;
background.y = 0;
// Move otter to front to ensure it stays on top of new background
game.removeChild(otter);
game.addChild(otter);
// Update UI
levelText.setText('Level: ' + level);
tokensText.setText('Tokens: ' + babyOtterTokens);
progressText.setText('Eggs: 0/' + eggsNeeded);
// Clear screen
for (var i = eggs.length - 1; i >= 0; i--) {
eggs[i].destroy();
eggs.splice(i, 1);
}
for (var j = coins.length - 1; j >= 0; j--) {
coins[j].destroy();
coins.splice(j, 1);
}
// Flash celebration
LK.effects.flashScreen(0x00FF00, 1000);
// Check win condition
if (babyOtterTokens >= 15) {
LK.showYouWin();
}
}
// Main game loop
game.update = function () {
// Spawn eggs
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnEgg();
spawnTimer = 0;
}
// Check collisions
checkCollisions();
// Game over condition - if too many eggs escape
var activeEggs = 0;
for (var i = 0; i < eggs.length; i++) {
if (eggs[i].active) activeEggs++;
}
if (activeEggs > 8) {
LK.showGameOver();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -305,8 +305,11 @@
height: 2732
}));
background.x = 0;
background.y = 0;
+ // Move otter to front to ensure it stays on top of new background
+ game.removeChild(otter);
+ game.addChild(otter);
// Update UI
levelText.setText('Level: ' + level);
tokensText.setText('Tokens: ' + babyOtterTokens);
progressText.setText('Eggs: 0/' + eggsNeeded);
High-resolution digital illustration of a single gold coin lying flat, embossed in the center with the word ‘ORO’ in bold, elegant capital letters. The coin features a finely detailed rim pattern (e.g. laurel wreath or rope motif), a polished metallic surface with realistic reflections and highlights, and a slight bevel on the edges. Dramatic side lighting casts soft shadows, set against a dark gradient background for contrast. Rendered in a semi-realistic 3D style. In-Game asset. 2d. High contrast. No shadows
A high-resolution digital illustration of a rotten egg cracked open on one side, oozing a viscous, yellowish-green yolk and albumen. The shell is mottled with dark brown and green mold spots, with wisps of faint greenish gas rising. Textured detail on the shell’s rough, pitted surface, with subtle drips and splatters. Moody, low-key side lighting casts dramatic shadows and highlights the glossy, decaying textures. Semi-realistic style. In-Game asset. 2d. High contrast. No shadows
Create a hyper-detailed digital illustration of a sleek, golden-furred otter standing confidently in a neon-lit cyberpunk city at night. The otter wears high-tech armor with glowing blue and magenta circuitry patterns, a visor with holo-display reflections, and a utility belt of futuristic gadgets. Rain slicks the wet street beneath its feet, and towering skyscrapers with animated billboards loom behind. Moody atmosphere, vibrant neon color palette, cinematic lighting, 4K resolution, game-ready character portrait.. In-Game asset. 2d. High contrast. No shadows
Generate a high-resolution digital scene of a rain-soaked cyberpunk arena for a mobile game. The environment features slick neon-lit platforms suspended over glowing canals, holographic billboards prominently displaying ‘Otterverse Marketplace,’ and floating egg pods encased in translucent glass. Puddles on the metal grating reflect pulsating magenta and cyan lights, while distant skyscrapers tower through misty rain. Add animated sparks, drifting data streams in the sky, and a moody, atmospheric vibe—perfect for a 4K game backdrop without any character or currency visuals.. In-Game asset. 2d. High contrast. No shadows
Create a dynamic 4K digital background for a cyberpunk mobile game interface. The scene shows a sleek, rain-drenched urban plaza with neon-lit walkways and towering digital screens. One large holographic banner reads ‘Claim tokens every day in Otter Hub’ in bold, glowing lettering. Surround it with animated light trails, drifting data particles, and subtle reflections in wet pavement. In the distance, angular skyscrapers pulse with magenta and cyan accents against a misty night sky. This image should serve as an eye-catching game menu backdrop—no characters or coins visible.. High contrast. No shadows
Generate a 4K cyberpunk street market scene at dusk: crowded neon stalls, glowing signage in kanji and Latin scripts, and slick pavement reflecting holographic ads. A towering LED banner proclaims ‘World Chain Otterverse’ in bold angular typography. Add drifting smoke from street food vendors, flickering drone traffic overhead, and a moody violet-cyan color palette—no characters or coins visible.. In-Game asset. 2d. High contrast. No shadows
Create a rain-drenched neon alleyway with steam vents, flickering holoboards, and damp metal grates. One giant animated billboard reads ‘Otterverse ecosystem’ in glowing script. Include scattered cables, occasional sparks, and puddles that mirror the vibrant magenta and teal lights—character-free and coin-free.. In-Game asset. 2d. High contrast. No shadows
Design a nighttime rooftop vista overlooking a cyberpunk cityscape. Array of antennae and digital transmitters punctuate the skyline, while a floating holo-banner flashes ‘Play Maze Game daily.’ Add subtle lens flares, hovering data orbs, and background neon glow—perfect as a level 3 menu backdrop without any characters or coins.. In-Game asset. 2d. High contrast. No shadows
Render a subterranean transit hub lit by neon tubes and pulsating floor panels. The massive central screen displays ‘Visit otterverse.io’ in sleek futuristic font. Incorporate moving walkways, holographic route maps, and vapor clouds rising from vents—no character or coin elements.. In-Game asset. 2d. High contrast. No shadows
Produce a cyber-market plaza at dawn under diffuse magenta light. Glass kiosks line the area, each casting neon reflections on wet stone tiles. A floating banner above reads ‘Visit otter.trading’ in bold luminous text. Include subtle drifting circuit-patterned mist—coin- and character-free.. In-Game asset. 2d. High contrast. No shadows
Generate an elevated monorail station at night, with neon rails and transparent glass platforms. Holographic signage over the tracks proclaims ‘World Chain Otterverse.’ Add animated train arrival indicators, rain streaks on glass, and distant skyscrapers—no characters or coins present.. In-Game asset. 2d. High contrast. No shadows
Create a cyber-bazaar corridor lined with glowing vendor pods and digital price tags flickering in neon. A large holoscreen banner reads ‘Otterverse Marketplace - digital ownership’ Include floating ad drones, steam jets from vents, and reflective floor panels—no visible characters or coins.. In-Game asset. 2d. High contrast. No shadows
“Render a futuristic skyline view from a glass-walled sky-bridge at twilight. Huge digital billboard outside declares ‘Visit otterverse.io’ in crisp neon lettering. Include passing hover-cars, floating particle effects, and a wet floor inside reflecting the lights—no characters or coins.”. In-Game asset. 2d. High contrast. No shadows
“Design an abandoned data vault with pulsing core reactors and neon warning stripes. A central holo-banner flashes ‘Play Maze Game daily’ in glitchy, stylized lettering. Add drifting sparks, cable conduits, and a damp metal floor reflecting ambient light—empty of characters and coins.”. In-Game asset. 2d. High contrast. No shadows
“Design an abandoned data vault with pulsing core reactors and neon warning stripes. A central holo-banner flashes ‘Play Maze Game daily’ in glitchy, stylized lettering. Add drifting sparks, cable conduits, and a damp metal floor reflecting ambient light—empty of characters and coins.”. In-Game asset. 2d. High contrast. No shadows
Render a futuristic skyline view from a glass-walled sky-bridge at twilight. Huge digital billboard outside declares ‘Visit otterverse.io’ in crisp neon lettering. Include passing hover-cars, floating particle effects, and a wet floor inside reflecting the lights—no characters or coins.. In-Game asset. 2d. High contrast. No shadows
“Render a futuristic plaza interior with holographic directories, neon columns, and reflective glass panels. A massive overhead display reads ‘Play Maze Game daily’ in bold animated text. Include drifting digital confetti effects, subtle rain droplets on glass, and ambient neon glow—no characters or coins.”. In-Game asset. 2d. High contrast. No shadows
“Design a narrow cyber-alley between skyscrapers, with vibrant neon pipes crisscrossing overhead. One large digital holo-banner proclaims ‘Otterverse ecosystem.’ Add steam vents, flickering side-street lights, and wet cobblestones reflecting color—no characters or coins.”. In-Game asset. 2d. High contrast. No shadows