User prompt
make simple maze and reduce gold
User prompt
hadirkan musuh dalam maze
User prompt
buat aturan dinding tidak bisa ditembus
User prompt
player bisa menembak dengan swipe
User prompt
hapus batas waktu
User prompt
buat 10 background
User prompt
perkecil ukuran maze dan letakkan di bawah layar
User prompt
tap control untuk player
Code edit (1 edits merged)
Please save this source code
User prompt
Maze Hunter: Golden Ball Chase
Initial prompt
create a maze in the middle with random entrance. hunting a golden balls
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.speed = 8; self.update = function () { // Store previous position for wall collision detection var prevX = self.x; var prevY = self.y; self.x += self.speedX; self.y += self.speedY; // Check if bullet hit a wall var mazeX = Math.floor((self.x - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((self.y - MAZE_START_Y) / CELL_SIZE); // If bullet is inside maze bounds and hits a wall, destroy it if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) { if (maze[mazeY][mazeX] === 1) { self.destroy(); return; } } // Remove bullet if it goes off screen if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; self.setDirection = function (dirX, dirY) { var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { self.speedX = dirX / length * self.speed; self.speedY = dirY / length * self.speed; } }; return self; }); var GoldenBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('goldenBall', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.update = function () { if (!self.collected) { ballGraphics.rotation += 0.05; ballGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.1; ballGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.1; } }; self.collect = function () { if (!self.collected) { self.collected = true; tween(ballGraphics, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.visible = false; } }); } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.targetX = 0; self.targetY = 0; self.update = function () { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 2) { // Calculate next position var nextX = self.x + dx / distance * self.speed; var nextY = self.y + dy / distance * self.speed; // Check if next position is valid (not a wall) var mazeX = Math.floor((nextX - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((nextY - MAZE_START_Y) / CELL_SIZE); // Only move if the next position is valid if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) { if (maze[mazeY][mazeX] === 0) { self.x = nextX; self.y = nextY; } } else { // If outside maze bounds, allow movement (for entrance/exit areas) self.x = nextX; self.y = nextY; } } }; self.setTarget = function (x, y) { self.targetX = x; self.targetY = y; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var CELL_SIZE = 48; var MAZE_WIDTH = 20; var MAZE_HEIGHT = 25; var MAZE_START_X = (2048 - MAZE_WIDTH * CELL_SIZE) / 2; var MAZE_START_Y = 2732 - MAZE_HEIGHT * CELL_SIZE - 100; var maze = []; var walls = []; var floors = []; var player; var goldenBalls = []; var totalBalls = 0; var collectedBalls = 0; var bullets = []; var swipeStart = { x: 0, y: 0 }; var isSwipping = false; // Tap controls - no drag node needed // Score display var scoreText = new Text2('Balls: 0/0', { size: 50, fill: 0xFFD700 }); scoreText.anchor.set(1, 0); LK.gui.topRight.addChild(scoreText); scoreText.x = -20; scoreText.y = 80; function generateMaze() { // Initialize maze with walls for (var y = 0; y < MAZE_HEIGHT; y++) { maze[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { maze[y][x] = 1; // 1 = wall, 0 = path } } // Simple maze generation using recursive backtracking var stack = []; var startX = 1; var startY = 1; maze[startY][startX] = 0; stack.push({ x: startX, y: startY }); var directions = [{ x: 0, y: -2 }, // up { x: 2, y: 0 }, // right { x: 0, y: 2 }, // down { x: -2, y: 0 } // left ]; while (stack.length > 0) { var current = stack[stack.length - 1]; var neighbors = []; for (var i = 0; i < directions.length; i++) { var nx = current.x + directions[i].x; var ny = current.y + directions[i].y; if (nx > 0 && nx < MAZE_WIDTH - 1 && ny > 0 && ny < MAZE_HEIGHT - 1 && maze[ny][nx] === 1) { neighbors.push({ x: nx, y: ny, dir: directions[i] }); } } if (neighbors.length > 0) { var next = neighbors[Math.floor(Math.random() * neighbors.length)]; maze[next.y][next.x] = 0; maze[current.y + next.dir.y / 2][current.x + next.dir.x / 2] = 0; stack.push({ x: next.x, y: next.y }); } else { stack.pop(); } } // Create entrance var entranceX = Math.floor(Math.random() * (MAZE_WIDTH - 2)) + 1; maze[0][entranceX] = 0; return { x: entranceX, y: 0 }; } function createMazeVisuals() { for (var y = 0; y < MAZE_HEIGHT; y++) { for (var x = 0; x < MAZE_WIDTH; x++) { var cellX = MAZE_START_X + x * CELL_SIZE; var cellY = MAZE_START_Y + y * CELL_SIZE; if (maze[y][x] === 1) { var wall = game.addChild(LK.getAsset('wall', { x: cellX, y: cellY })); walls.push(wall); } else { var floor = game.addChild(LK.getAsset('floor', { x: cellX, y: cellY })); floors.push(floor); } } } } function placeholdenBalls() { var ballCount = Math.floor(MAZE_WIDTH * MAZE_HEIGHT * 0.1); // 10% of maze cells var placedBalls = 0; while (placedBalls < ballCount) { var x = Math.floor(Math.random() * MAZE_WIDTH); var y = Math.floor(Math.random() * MAZE_HEIGHT); if (maze[y][x] === 0) { var cellX = MAZE_START_X + x * CELL_SIZE + CELL_SIZE / 2; var cellY = MAZE_START_Y + y * CELL_SIZE + CELL_SIZE / 2; var ball = game.addChild(new GoldenBall()); ball.x = cellX; ball.y = cellY; ball.mazeX = x; ball.mazeY = y; goldenBalls.push(ball); placedBalls++; } } totalBalls = goldenBalls.length; updateScoreText(); } function updateScoreText() { scoreText.setText('Balls: ' + collectedBalls + '/' + totalBalls); } function isValidPosition(x, y) { var mazeX = Math.floor((x - MAZE_START_X) / CELL_SIZE); var mazeY = Math.floor((y - MAZE_START_Y) / CELL_SIZE); if (mazeX < 0 || mazeX >= MAZE_WIDTH || mazeY < 0 || mazeY >= MAZE_HEIGHT) { return false; } return maze[mazeY][mazeX] === 0; } function getValidTargetPosition(targetX, targetY) { var currentMazeX = Math.floor((player.x - MAZE_START_X) / CELL_SIZE); var currentMazeY = Math.floor((player.y - MAZE_START_Y) / CELL_SIZE); var targetMazeX = Math.floor((targetX - MAZE_START_X) / CELL_SIZE); var targetMazeY = Math.floor((targetY - MAZE_START_Y) / CELL_SIZE); if (targetMazeX < 0 || targetMazeX >= MAZE_WIDTH || targetMazeY < 0 || targetMazeY >= MAZE_HEIGHT) { return { x: player.x, y: player.y }; } if (maze[targetMazeY][targetMazeX] === 1) { return { x: player.x, y: player.y }; } var cellCenterX = MAZE_START_X + targetMazeX * CELL_SIZE + CELL_SIZE / 2; var cellCenterY = MAZE_START_Y + targetMazeY * CELL_SIZE + CELL_SIZE / 2; return { x: cellCenterX, y: cellCenterY }; } // Initialize maze var entrance = generateMaze(); createMazeVisuals(); // Create player player = game.addChild(new Player()); player.x = MAZE_START_X + entrance.x * CELL_SIZE + CELL_SIZE / 2; player.y = MAZE_START_Y + entrance.y * CELL_SIZE + CELL_SIZE / 2; player.setTarget(player.x, player.y); // Place golden balls placeholdenBalls(); // Touch controls - swipe to shoot, tap to move game.down = function (x, y, obj) { swipeStart.x = x; swipeStart.y = y; isSwipping = true; }; game.move = function (x, y, obj) { // Track swipe movement but don't move player during swipe }; game.up = function (x, y, obj) { if (isSwipping) { var swipeEndX = x; var swipeEndY = y; var swipeDistanceX = swipeEndX - swipeStart.x; var swipeDistanceY = swipeEndY - swipeStart.y; var swipeDistance = Math.sqrt(swipeDistanceX * swipeDistanceX + swipeDistanceY * swipeDistanceY); if (swipeDistance > 30) { // Minimum swipe distance // Create bullet and shoot in swipe direction var bullet = game.addChild(new Bullet()); bullet.x = player.x; bullet.y = player.y; bullet.setDirection(swipeDistanceX, swipeDistanceY); bullets.push(bullet); LK.getSound('shoot').play(); } else { // Short tap - move player var validPos = getValidTargetPosition(x, y); player.setTarget(validPos.x, validPos.y); } isSwipping = false; } }; // Game update loop game.update = function () { // Clean up destroyed bullets for (var b = bullets.length - 1; b >= 0; b--) { var bullet = bullets[b]; if (!bullet.parent) { // Bullet has been destroyed bullets.splice(b, 1); } } // Check ball collection for (var i = 0; i < goldenBalls.length; i++) { var ball = goldenBalls[i]; if (!ball.collected && player.intersects(ball)) { ball.collect(); collectedBalls++; LK.setScore(collectedBalls); updateScoreText(); LK.getSound('collect').play(); // Check win condition if (collectedBalls >= totalBalls) { LK.getSound('complete').play(); LK.setTimeout(function () { LK.showYouWin(); }, 500); } } } };
===================================================================
--- original.js
+++ change.js
@@ -15,10 +15,23 @@
self.speedX = 0;
self.speedY = 0;
self.speed = 8;
self.update = function () {
+ // Store previous position for wall collision detection
+ var prevX = self.x;
+ var prevY = self.y;
self.x += self.speedX;
self.y += self.speedY;
+ // Check if bullet hit a wall
+ var mazeX = Math.floor((self.x - MAZE_START_X) / CELL_SIZE);
+ var mazeY = Math.floor((self.y - MAZE_START_Y) / CELL_SIZE);
+ // If bullet is inside maze bounds and hits a wall, destroy it
+ if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) {
+ if (maze[mazeY][mazeX] === 1) {
+ self.destroy();
+ return;
+ }
+ }
// Remove bullet if it goes off screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
@@ -77,10 +90,25 @@
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 2) {
- self.x += dx / distance * self.speed;
- self.y += dy / distance * self.speed;
+ // Calculate next position
+ var nextX = self.x + dx / distance * self.speed;
+ var nextY = self.y + dy / distance * self.speed;
+ // Check if next position is valid (not a wall)
+ var mazeX = Math.floor((nextX - MAZE_START_X) / CELL_SIZE);
+ var mazeY = Math.floor((nextY - MAZE_START_Y) / CELL_SIZE);
+ // Only move if the next position is valid
+ if (mazeX >= 0 && mazeX < MAZE_WIDTH && mazeY >= 0 && mazeY < MAZE_HEIGHT) {
+ if (maze[mazeY][mazeX] === 0) {
+ self.x = nextX;
+ self.y = nextY;
+ }
+ } else {
+ // If outside maze bounds, allow movement (for entrance/exit areas)
+ self.x = nextX;
+ self.y = nextY;
+ }
}
};
self.setTarget = function (x, y) {
self.targetX = x;
2d side scroller bee. In-Game asset. 2d. High contrast. No shadows
big evil wasp. In-Game asset. 2d. High contrast. No shadows
2d side scroller rose fresh rose flower. In-Game asset. 2d. High contrast. No shadows
image 2d classic full warna tentang hamparan bunga bunga liar disuatu lembah. In-Game asset. 2d. High contrast. No shadows