User prompt
add explotion asset
User prompt
add background asset
User prompt
add background
User prompt
Player and enemy are not on the same platform
User prompt
infinite repeated swipe attack
User prompt
long range swipe
User prompt
player and enemy different platform
User prompt
player spawn different another platform
Code edit (1 edits merged)
Please save this source code
User prompt
Maze Dasher: Swipe Attack
Initial prompt
1. JavaScript 2D maze push attack game. 2. player swipe dash attack game. 3 enemy move left and right. 4. random platform. 5. game end when all enemies died. 6. game over when player died. 7. enemy not same platform with playe
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var DashTrail = Container.expand(function () { var self = Container.call(this); var trailGraphics = self.attachAsset('dashTrail', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); self.init = function (x, y) { self.x = x; self.y = y; self.alpha = 0.7; // Fade out and shrink tween(self, { alpha: 0, scaleX: 0.3, scaleY: 0.3 }, { duration: 400, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.width = enemyGraphics.width; self.height = enemyGraphics.height; self.vx = 3; self.platform = null; self.isDead = false; self.init = function (platform) { self.platform = platform; self.x = platform.x; self.y = platform.y - platform.height / 2 - self.height / 2; }; self.update = function () { if (self.isDead) { return; } // Move back and forth on platform self.x += self.vx; // Check platform boundaries if (self.x + self.width / 2 > self.platform.x + self.platform.width / 2 - 10) { self.x = self.platform.x + self.platform.width / 2 - self.width / 2 - 10; self.vx = -Math.abs(self.vx); } else if (self.x - self.width / 2 < self.platform.x - self.platform.width / 2 + 10) { self.x = self.platform.x - self.platform.width / 2 + self.width / 2 + 10; self.vx = Math.abs(self.vx); } // Check collision with player if (player.isDashing) { if (self.intersects(player)) { self.kill(); } } else if (self.intersects(player)) { // Player dies if touches enemy while not dashing LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }; self.kill = function () { if (self.isDead) { return; } self.isDead = true; LK.getSound('enemyDead').play(); // Visual effect for enemy death LK.effects.flashObject(self, 0xffffff, 300); tween(self, { alpha: 0, scaleX: 0.2, scaleY: 0.2 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); // Check if all enemies are defeated var allDefeated = true; for (var i = 0; i < enemies.length; i++) { if (!enemies[i].isDead) { allDefeated = false; break; } } if (allDefeated) { LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); LK.showYouWin(); } } }); }; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.width = platformGraphics.width; self.height = platformGraphics.height; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.width = playerGraphics.width; self.height = playerGraphics.height; self.vx = 0; self.vy = 0; self.gravity = 0.5; self.jumpPower = -15; self.speed = 7; self.isJumping = false; self.isDashing = false; self.dashCooldown = 0; self.dashDuration = 0; self.dashDirection = { x: 0, y: 0 }; self.dashSpeed = 25; self.currentPlatform = null; self.update = function () { if (self.isDashing) { // Handle dash movement self.x += self.dashDirection.x * self.dashSpeed; self.y += self.dashDirection.y * self.dashSpeed; self.dashDuration--; // Create trail effect if (self.dashDuration % 3 === 0) { var trail = new DashTrail(); game.addChild(trail); trail.init(self.x, self.y); } if (self.dashDuration <= 0) { self.isDashing = false; self.dashCooldown = 0; // No cooldown for continuous dashing } return; } // Apply gravity self.vy += self.gravity; // Apply movement self.x += self.vx; self.y += self.vy; // Check platform collisions self.isJumping = true; self.currentPlatform = null; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; // Simple platform collision if (self.vy > 0 && self.y + self.height / 2 >= platform.y - platform.height / 2 && self.y + self.height / 2 <= platform.y && self.x + self.width / 2 > platform.x - platform.width / 2 && self.x - self.width / 2 < platform.x + platform.width / 2) { self.y = platform.y - platform.height / 2 - self.height / 2; self.vy = 0; self.isJumping = false; self.currentPlatform = platform; } } // Check world boundaries if (self.x < self.width / 2) { self.x = self.width / 2; } else if (self.x > 2048 - self.width / 2) { self.x = 2048 - self.width / 2; } // Check if fell off the bottom if (self.y > 2732 + 100) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Slow down horizontal movement self.vx *= 0.9; }; self.jump = function () { if (!self.isJumping) { self.vy = self.jumpPower; self.isJumping = true; } }; self.moveLeft = function () { self.vx = -self.speed; }; self.moveRight = function () { self.vx = self.speed; }; self.dash = function (dirX, dirY) { if (self.isDashing) { return; } self.dashCooldown = 0; // Reset cooldown for infinite dashing self.dashDuration = 30; // Reset dash duration // Normalize direction var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length === 0) { return; } self.dashDirection.x = dirX / length; self.dashDirection.y = dirY / length; self.isDashing = true; self.dashDuration = 30; LK.getSound('dash').play(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game variables var player; var platforms = []; var enemies = []; var startX, startY, endX, endY; var isDragging = false; // Create score text var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.setText("Score: " + LK.getScore()); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize platforms function createPlatforms() { // Clear existing platforms for (var i = platforms.length - 1; i >= 0; i--) { platforms[i].destroy(); } platforms = []; // Create platforms in a maze-like pattern var numPlatforms = 7; var platformHeight = 350; // Vertical spacing between platforms for (var i = 0; i < numPlatforms; i++) { var platform = new Platform(); // Randomize platform position var minX = platform.width / 2 + 50; var maxX = 2048 - platform.width / 2 - 50; var x = Math.floor(Math.random() * (maxX - minX)) + minX; var y = 600 + i * platformHeight; platform.x = x; platform.y = y; platforms.push(platform); game.addChild(platform); } } // Initialize player function createPlayer() { if (player) { player.destroy(); } player = new Player(); // Ensure player spawns on a different platform than enemies var availablePlatformsForPlayer = platforms.slice(); if (availablePlatformsForPlayer.length > 0) { availablePlatformsForPlayer.shift(); // Remove the first platform to ensure a safe start } var playerPlatformIndex = Math.floor(Math.random() * availablePlatformsForPlayer.length); var playerPlatform = availablePlatformsForPlayer[playerPlatformIndex]; player.x = playerPlatform.x; player.y = playerPlatform.y - playerPlatform.height / 2 - player.height / 2; player.currentPlatform = playerPlatform; // Assign the player's current platform game.addChild(player); } // Initialize enemies function createEnemies() { // Clear existing enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); } enemies = []; // Create three enemies on different platforms var availablePlatforms = platforms.slice(); if (availablePlatforms.length > 0) { availablePlatforms = availablePlatforms.filter(function (platform) { return platform !== player.currentPlatform; }); } // Create 3 enemies or as many as we have platforms for var numEnemiesToCreate = Math.min(3, availablePlatforms.length); for (var i = 0; i < numEnemiesToCreate; i++) { // Select a random platform var platformIndex = Math.floor(Math.random() * availablePlatforms.length); var platform = availablePlatforms[platformIndex]; // Remove this platform from available ones availablePlatforms.splice(platformIndex, 1); // Create enemy var enemy = new Enemy(); enemy.init(platform); enemies.push(enemy); game.addChild(enemy); } } // Instructions text function showInstructions() { var instructions = new Text2("Swipe to dash and defeat enemies.\nOne hit and it's game over!", { size: 80, fill: 0xFFFFFF }); instructions.anchor.set(0.5, 0.5); instructions.x = 2048 / 2; instructions.y = 300; game.addChild(instructions); // Fade out after 3 seconds LK.setTimeout(function () { tween(instructions, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { instructions.destroy(); } }); }, 3000); } // Initialize game function initGame() { var bg = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(bg); createPlatforms(); createPlayer(); createEnemies(); showInstructions(); // Play background music LK.playMusic('bgMusic'); } // Start the game initGame(); // Handle touch/mouse input for player controls game.down = function (x, y, obj) { startX = x; startY = y; isDragging = true; // Calculate if the player needs to move left or right based on tap position if (x < player.x) { player.moveLeft(); } else if (x > player.x) { player.moveRight(); } // Jump when tapping player.jump(); }; game.move = function (x, y, obj) { if (isDragging) { endX = x; endY = y; } }; game.up = function (x, y, obj) { if (isDragging) { endX = x; endY = y; isDragging = false; // Calculate swipe distance and direction var dx = endX - startX; var dy = endY - startY; var distance = Math.sqrt(dx * dx + dy * dy); // Only dash if the swipe is long enough if (distance > 100) { player.dash(dx, dy); } } }; // Update game state game.update = function () { // Update player if (player) { player.update(); } // Update enemies for (var i = 0; i < enemies.length; i++) { if (enemies[i]) { enemies[i].update(); } } };
===================================================================
--- original.js
+++ change.js
@@ -341,8 +341,15 @@
}, 3000);
}
// Initialize game
function initGame() {
+ var bg = LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 / 2,
+ y: 2732 / 2
+ });
+ game.addChild(bg);
createPlatforms();
createPlayer();
createEnemies();
showInstructions();
2d image. ancient meiji castle japan at night on full moon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 2d image. full moon night. ancient temple meiji castle. surround of japanese forest
purple ninja with two blade jump style act for battle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
ancient japan oni red monster stand scary rage