User prompt
add background feature
User prompt
added new rule. player win when all coin collected
User prompt
can double jump
User prompt
erase long jump
User prompt
long range jump into upper
User prompt
erase long jump controler
User prompt
fix long jump function
User prompt
duck can long jump reach a upper
User prompt
speed attack movement
Code edit (1 edits merged)
Please save this source code
User prompt
Duck Dash: Fox Hunt Adventure
Initial prompt
JavaScript 2D Platformer Game jumping attack duck. duck jump attack all fox. collect all coins. time race end 300 second. game over when duck got hit fox. touchscreen controler button for move left adn right. touch controler button for jump attack
/**** * 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 }); // Coin animation self.animateCoin = function () { tween(coinGraphics, { rotation: Math.PI * 2 }, { duration: 1500, easing: tween.linear, onFinish: function onFinish() { coinGraphics.rotation = 0; self.animateCoin(); } }); }; self.animateCoin(); return self; }); var ControlButton = Container.expand(function (type) { var self = Container.call(this); var buttonGraphics = self.attachAsset('controlButton', { anchorX: 0.5, anchorY: 0.5, alpha: 0.5 }); // Store the button type self.type = type; // Label for the button var label = new Text2(type, { size: 40, fill: 0xFFFFFF }); label.anchor.set(0.5, 0.5); self.addChild(label); // Button events self.down = function (x, y, obj) { buttonGraphics.alpha = 0.8; // Trigger the appropriate action based on button type switch (self.type) { case "←": duck.moveLeft(); break; case "→": duck.moveRight(); break; case "JUMP": duck.jump(); break; case "ATTACK": duck.attack(); break; case "LONG JUMP": duck.longRangeJump(); break; } }; self.up = function (x, y, obj) { buttonGraphics.alpha = 0.5; // Stop movement for direction buttons if (self.type === "←" || self.type === "→") { duck.stop(); } }; return self; }); var Duck = Container.expand(function () { var self = Container.call(this); var duckGraphics = self.attachAsset('duck', { anchorX: 0.5, anchorY: 0.5 }); // Duck properties self.vx = 0; self.vy = 0; self.speed = 8; self.jumpVelocity = -20; self.gravity = 1; self.isOnGround = false; self.isJumping = false; self.isAttacking = false; self.facingRight = true; self.jump = function () { if (self.isOnGround || !self.isOnGround && !self.isDoubleJumping) { self.vy = self.jumpVelocity; self.isJumping = true; if (!self.isOnGround) { self.isDoubleJumping = true; } self.isOnGround = false; LK.getSound('jump').play(); } }; self.attack = function () { if (!self.isAttacking) { self.isAttacking = true; // Increase speed temporarily for attack var originalSpeed = self.speed; self.speed *= 2; // Double the speed during attack // Visual feedback for attack tween(duckGraphics, { rotation: self.facingRight ? 0.5 : -0.5 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(duckGraphics, { rotation: 0 }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { self.isAttacking = false; // Restore original speed after attack self.speed = originalSpeed; } }); } }); LK.getSound('attack').play(); } }; self.moveLeft = function () { self.vx = -self.speed; if (self.facingRight) { self.facingRight = false; duckGraphics.scaleX = -1; } }; self.moveRight = function () { self.vx = self.speed; if (!self.facingRight) { self.facingRight = true; duckGraphics.scaleX = 1; } }; self.stop = function () { self.vx = 0; }; self.update = function () { // Apply gravity if (!self.isOnGround) { self.vy += self.gravity; } // Update position self.x += self.vx; self.y += self.vy; // Boundary checks if (self.x < 50) { self.x = 50; } if (self.x > 2048 - 50) { self.x = 2048 - 50; } // Check if duck hits the ground or platforms self.checkCollisions(); }; self.checkCollisions = function () { // This will be implemented in the game class }; return self; }); var Fox = Container.expand(function () { var self = Container.call(this); var foxGraphics = self.attachAsset('fox', { anchorX: 0.5, anchorY: 0.5 }); // Fox properties self.vx = -3; // Initially move left self.leftBoundary = 0; self.rightBoundary = 0; self.facingRight = false; self.update = function () { // Move fox self.x += self.vx; // Change direction if reaching boundaries if (self.x <= self.leftBoundary) { self.vx = Math.abs(self.vx); self.facingRight = true; foxGraphics.scaleX = 1; } else if (self.x >= self.rightBoundary) { self.vx = -Math.abs(self.vx); self.facingRight = false; foxGraphics.scaleX = -1; } }; self.setBoundaries = function (left, right) { self.leftBoundary = left; self.rightBoundary = right; }; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); // If needed, we can add more platform-specific properties and methods here return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue }); /**** * Game Code ****/ // Game variables var duck; var platforms = []; var foxes = []; var coins = []; var score = 0; var timeLeft = 300; // 300 seconds (5 minutes) var leftButton, rightButton, jumpButton, attackButton; var scoreTxt, timeTxt; var isGameOver = false; var levelComplete = false; // Initialize UI function setupUI() { // Score text scoreTxt = new Text2('COINS: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -300; // Offset from top right // Time text timeTxt = new Text2('TIME: 300', { size: 60, fill: 0xFFFFFF }); timeTxt.anchor.set(0, 0); LK.gui.top.addChild(timeTxt); // Control buttons leftButton = new ControlButton("←"); leftButton.x = 150; leftButton.y = 2732 - 150; game.addChild(leftButton); rightButton = new ControlButton("→"); rightButton.x = 350; rightButton.y = 2732 - 150; game.addChild(rightButton); jumpButton = new ControlButton("JUMP"); jumpButton.x = 2048 - 450; jumpButton.y = 2732 - 150; game.addChild(jumpButton); attackButton = new ControlButton("ATTACK"); attackButton.x = 2048 - 150; attackButton.y = 2732 - 150; game.addChild(attackButton); } // Create level elements function createLevel() { // Create ground var ground = LK.getAsset('ground', { anchorX: 0.5, anchorY: 0.5 }); ground.x = 2048 / 2; ground.y = 2732 - 40; game.addChild(ground); // Add ground to platforms array for collision detection var groundPlatform = new Platform(); groundPlatform.x = ground.x; groundPlatform.y = ground.y; groundPlatform.width = ground.width; groundPlatform.height = ground.height; platforms.push(groundPlatform); // Create platforms var platformPositions = [{ x: 300, y: 2400 }, { x: 700, y: 2200 }, { x: 1200, y: 2000 }, { x: 1700, y: 1800 }, { x: 1300, y: 1600 }, { x: 800, y: 1400 }, { x: 400, y: 1200 }, { x: 900, y: 1000 }, { x: 1400, y: 800 }, { x: 1800, y: 600 }]; for (var i = 0; i < platformPositions.length; i++) { var platform = new Platform(); platform.x = platformPositions[i].x; platform.y = platformPositions[i].y; game.addChild(platform); platforms.push(platform); } // Create coins for (var i = 0; i < platforms.length; i++) { // Add 1-3 coins above each platform var numCoins = Math.floor(Math.random() * 3) + 1; for (var j = 0; j < numCoins; j++) { var coin = new Coin(); coin.x = platforms[i].x + (j - 1) * 70; // Spread coins out horizontally coin.y = platforms[i].y - 100; // Position coins above platform game.addChild(coin); coins.push(coin); } } // Create foxes (enemies) var foxPositions = [{ x: 500, y: 2400 - 50, leftBound: 300, rightBound: 700 }, { x: 1400, y: 2000 - 50, leftBound: 1200, rightBound: 1600 }, { x: 1000, y: 1600 - 50, leftBound: 800, rightBound: 1300 }, { x: 600, y: 1200 - 50, leftBound: 400, rightBound: 800 }, { x: 1200, y: 800 - 50, leftBound: 900, rightBound: 1400 }]; for (var i = 0; i < foxPositions.length; i++) { var fox = new Fox(); fox.x = foxPositions[i].x; fox.y = foxPositions[i].y; fox.setBoundaries(foxPositions[i].leftBound, foxPositions[i].rightBound); game.addChild(fox); foxes.push(fox); } // Create duck (player character) duck = new Duck(); duck.x = 300; duck.y = 2600; game.addChild(duck); } // Check for collisions between duck and platforms function checkPlatformCollisions() { duck.isOnGround = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; // Simple platform collision detection if (duck.vy >= 0 && // Duck is moving downward duck.y - 55 <= platform.y - 20 && // Duck was above platform in previous frame duck.y + 55 >= platform.y - 20 && // Duck's bottom is below platform's top duck.x + 45 >= platform.x - platform.width / 2 && // Duck's right edge is beyond platform's left edge duck.x - 45 <= platform.x + platform.width / 2) { // Duck's left edge is before platform's right edge duck.isOnGround = true; duck.isDoubleJumping = false; // Reset double jump duck.y = platform.y - 75; // Position duck on platform duck.vy = 0; // Stop vertical movement break; } } } // Check for collisions between duck and coins function checkCoinCollisions() { for (var i = coins.length - 1; i >= 0; i--) { if (duck.intersects(coins[i])) { // Collect coin score++; scoreTxt.setText('COINS: ' + score); // Play sound LK.getSound('coin').play(); // Check if all coins are collected if (coins.length === 0 && !levelComplete) { levelComplete = true; LK.showYouWin(); } // Remove coin coins[i].destroy(); coins.splice(i, 1); // Flash effect LK.effects.flashObject(duck, 0xFFD700, 300); } } } // Check for collisions between duck and foxes function checkFoxCollisions() { for (var i = 0; i < foxes.length; i++) { if (duck.intersects(foxes[i])) { if (duck.isAttacking) { // Duck defeats fox during attack foxes[i].destroy(); foxes.splice(i, 1); i--; // Increment score score += 5; scoreTxt.setText('COINS: ' + score); // Visual feedback LK.effects.flashObject(duck, 0x00FF00, 300); } else { // Fox defeats duck if (!isGameOver) { isGameOver = true; LK.getSound('hit').play(); LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } } } } } // Check if level is complete (duck reached the top platform) function checkLevelComplete() { if (duck.y < 700 && !levelComplete) { levelComplete = true; LK.showYouWin(); } } // Update timer function updateTimer() { if (timeLeft > 0) { timeLeft--; timeTxt.setText('TIME: ' + timeLeft); } else if (!isGameOver) { isGameOver = true; LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } } // Initialize game function initGame() { // Add background image var background = LK.getAsset('backgroundImage', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2; game.addChild(background); createLevel(); setupUI(); // Start timer LK.setInterval(updateTimer, 1000); // Play background music LK.playMusic('gameMusic'); } // Initialize the game initGame(); // Game update function game.update = function () { if (!isGameOver && !levelComplete) { // Update duck duck.update(); // Check collisions checkPlatformCollisions(); checkCoinCollisions(); checkFoxCollisions(); checkLevelComplete(); // Update foxes for (var i = 0; i < foxes.length; i++) { foxes[i].update(); } } }; // Game touch handlers game.move = function (x, y, obj) { // No additional move handling needed for this game }; game.down = function (x, y, obj) { // No additional down handling needed for this game }; game.up = function (x, y, obj) { // No additional up handling needed for this game };
===================================================================
--- original.js
+++ change.js
@@ -469,8 +469,16 @@
}
}
// Initialize game
function initGame() {
+ // Add background image
+ var background = LK.getAsset('backgroundImage', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ background.x = 2048 / 2;
+ background.y = 2732 / 2;
+ game.addChild(background);
createLevel();
setupUI();
// Start timer
LK.setInterval(updateTimer, 1000);
cartoon fantasy yellow duck warrior slash long sword movement. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
chibi cartoon eagle pirate fly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
ghibli anime 2d style. meadow at lake. sky full of small with cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
cartoo brown straw lines. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
green meadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
white egg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows