User prompt
Exit ve prev_exit assetleri ne ses eklemek istiyorum
User prompt
The game starts from level 1 every time it is started.
User prompt
Oyuna arka plan müziği eklemek istiyorum
User prompt
Move counter continues to count even if level moves forward or backward
User prompt
In each section, there should be 3 exits to the next level and 3 exits to return to the previous level.
User prompt
Have a counter in the upper right corner that counts how many times the ball has moved.
User prompt
Bunu uygula
User prompt
The ball teleports to the place I click. What should happen is: I click on the ball and then i move it
User prompt
I can't move the ball. How will this game be played?
Code edit (1 edits merged)
Please save this source code
User prompt
Maze Ball Navigator
Initial prompt
There will be a maze on the screen. The hero who will play will be a ball. The player will touch the ball and move it around the maze. The maze should have an entrance and an exit. The ball will start at the entrance. There will be a portal at the exit. If the player reaches the portal, they will go to the next level. There will be no enemies or coins.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.gridX = 0; self.gridY = 0; self.targetX = 0; self.targetY = 0; self.isMoving = false; self.setGridPosition = function (gridX, gridY) { self.gridX = gridX; self.gridY = gridY; self.x = gridX * CELL_SIZE + CELL_SIZE / 2 + MAZE_OFFSET_X; self.y = gridY * CELL_SIZE + CELL_SIZE / 2 + MAZE_OFFSET_Y; self.targetX = self.x; self.targetY = self.y; }; self.moveToGrid = function (gridX, gridY) { if (self.isMoving) return; self.gridX = gridX; self.gridY = gridY; self.targetX = gridX * CELL_SIZE + CELL_SIZE / 2 + MAZE_OFFSET_X; self.targetY = gridY * CELL_SIZE + CELL_SIZE / 2 + MAZE_OFFSET_Y; self.isMoving = true; tween(self, { x: self.targetX, y: self.targetY }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.isMoving = false; } }); }; return self; }); var MazeCell = Container.expand(function () { var self = Container.call(this); self.cellType = 'wall'; self.gridX = 0; self.gridY = 0; self.cellGraphics = null; self.setCellType = function (type) { if (self.cellGraphics) { self.removeChild(self.cellGraphics); } self.cellType = type; var assetName = type; self.cellGraphics = self.attachAsset(assetName, { anchorX: 0, anchorY: 0 }); }; self.setGridPosition = function (gridX, gridY) { self.gridX = gridX; self.gridY = gridY; self.x = gridX * CELL_SIZE + MAZE_OFFSET_X; self.y = gridY * CELL_SIZE + MAZE_OFFSET_Y; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1A1A1A }); /**** * Game Code ****/ var MAZE_WIDTH = 13; var MAZE_HEIGHT = 17; var CELL_SIZE = 80; var MAZE_OFFSET_X = (2048 - MAZE_WIDTH * CELL_SIZE) / 2; var MAZE_OFFSET_Y = (2732 - MAZE_HEIGHT * CELL_SIZE) / 2; var currentLevel = storage.currentLevel || 1; var maze = []; var mazeCells = []; var ball = null; var entranceX = 1; var entranceY = 1; var exitX = MAZE_WIDTH - 2; var exitY = MAZE_HEIGHT - 2; var dragNode = null; var levelTxt = new Text2('Level: ' + currentLevel, { size: 80, fill: 0xFFFFFF }); levelTxt.anchor.set(0.5, 0); LK.gui.top.addChild(levelTxt); levelTxt.y = 100; function generateMaze() { maze = []; for (var y = 0; y < MAZE_HEIGHT; y++) { maze[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { maze[y][x] = 'wall'; } } var complexity = Math.min(currentLevel, 10); var pathCount = 3 + complexity; maze[entranceY][entranceX] = 'entrance'; maze[exitY][exitX] = 'exit'; var paths = [{ x: entranceX, y: entranceY }, { x: exitX, y: exitY }]; for (var i = 0; i < pathCount; i++) { var x = 1 + Math.floor(Math.random() * (MAZE_WIDTH - 2)); var y = 1 + Math.floor(Math.random() * (MAZE_HEIGHT - 2)); if (maze[y][x] === 'wall') { maze[y][x] = 'path'; paths.push({ x: x, y: y }); } } for (var p = 0; p < paths.length - 1; p++) { var start = paths[p]; var end = paths[p + 1]; createPath(start.x, start.y, end.x, end.y); } var extraConnections = Math.floor(complexity / 2); for (var e = 0; e < extraConnections; e++) { var start = paths[Math.floor(Math.random() * paths.length)]; var end = paths[Math.floor(Math.random() * paths.length)]; if (start !== end) { createPath(start.x, start.y, end.x, end.y); } } } function createPath(x1, y1, x2, y2) { var currentX = x1; var currentY = y1; while (currentX !== x2 || currentY !== y2) { if (maze[currentY] && maze[currentY][currentX] === 'wall') { maze[currentY][currentX] = 'path'; } if (currentX < x2) currentX++;else if (currentX > x2) currentX--;else if (currentY < y2) currentY++;else if (currentY > y2) currentY--; } if (maze[currentY] && maze[currentY][currentX] === 'wall') { maze[currentY][currentX] = 'path'; } } function createMazeVisuals() { for (var i = mazeCells.length - 1; i >= 0; i--) { mazeCells[i].destroy(); } mazeCells = []; for (var y = 0; y < MAZE_HEIGHT; y++) { for (var x = 0; x < MAZE_WIDTH; x++) { var cell = new MazeCell(); cell.setGridPosition(x, y); cell.setCellType(maze[y][x]); mazeCells.push(cell); game.addChild(cell); } } } function initializeLevel() { generateMaze(); createMazeVisuals(); if (ball) { ball.destroy(); } ball = new Ball(); ball.setGridPosition(entranceX, entranceY); game.addChild(ball); levelTxt.setText('Level: ' + currentLevel); } function isValidMove(gridX, gridY) { if (gridX < 0 || gridX >= MAZE_WIDTH || gridY < 0 || gridY >= MAZE_HEIGHT) { return false; } return maze[gridY][gridX] !== 'wall'; } function getGridFromPosition(x, y) { var gridX = Math.floor((x - MAZE_OFFSET_X) / CELL_SIZE); var gridY = Math.floor((y - MAZE_OFFSET_Y) / CELL_SIZE); return { x: gridX, y: gridY }; } function handleMove(x, y, obj) { if (dragNode && !ball.isMoving) { var grid = getGridFromPosition(x, y); if (isValidMove(grid.x, grid.y)) { ball.moveToGrid(grid.x, grid.y); if (maze[grid.y][grid.x] === 'exit') { LK.setTimeout(function () { currentLevel++; storage.currentLevel = currentLevel; LK.getSound('levelComplete').play(); initializeLevel(); }, 300); } } } } game.move = handleMove; game.down = function (x, y, obj) { // Check if the click is on the ball var ballBounds = { left: ball.x - 30, right: ball.x + 30, top: ball.y - 30, bottom: ball.y + 30 }; if (x >= ballBounds.left && x <= ballBounds.right && y >= ballBounds.top && y <= ballBounds.bottom) { dragNode = ball; } }; game.up = function (x, y, obj) { dragNode = null; }; initializeLevel();
===================================================================
--- original.js
+++ change.js
@@ -217,10 +217,18 @@
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
- dragNode = ball;
- handleMove(x, y, obj);
+ // Check if the click is on the ball
+ var ballBounds = {
+ left: ball.x - 30,
+ right: ball.x + 30,
+ top: ball.y - 30,
+ bottom: ball.y + 30
+ };
+ if (x >= ballBounds.left && x <= ballBounds.right && y >= ballBounds.top && y <= ballBounds.bottom) {
+ dragNode = ball;
+ }
};
game.up = function (x, y, obj) {
dragNode = null;
};