/**** * Classes ****/ // Class for the exit point var Exit = Container.expand(function () { var self = Container.call(this); var exitGraphics = self.attachAsset('exit', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player update logic }; }); // Class for maze walls var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ // Function to generate a random maze var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Function to generate a random maze // Initialize player function generateMaze() { var maze = []; var mazeSize = 20; var blockSize = Math.min(2048 / mazeSize, 2732 / mazeSize); for (var i = 0; i < mazeSize; i++) { maze[i] = []; for (var j = 0; j < mazeSize; j++) { if (Math.random() > 0.7) { maze[i][j] = 1; } else { maze[i][j] = 0; } } } return { maze: maze, blockSize: blockSize }; } var mazeData = generateMaze(); var player = new Player(); player.x = mazeData.blockSize; player.y = mazeData.blockSize; player.width = mazeData.blockSize; player.height = mazeData.blockSize; game.addChild(player); // Initialize maze walls var walls = []; function createWall(x, y) { var wall = new Wall(); wall.x = x; wall.y = y; walls.push(wall); game.addChild(wall); } // Create a random maze var maze = mazeData.maze; for (var i = 0; i < maze.length; i++) { for (var j = 0; j < maze[i].length; j++) { if (maze[i][j] === 1) { createWall(i * mazeData.blockSize, j * mazeData.blockSize); } } } var exit = new Exit(); exit.x = 2048 - mazeData.blockSize; exit.y = 2732 - mazeData.blockSize; exit.width = mazeData.blockSize; exit.height = mazeData.blockSize; wall.width = mazeData.blockSize; wall.height = mazeData.blockSize; game.addChild(exit); // Create a simple maze // Handle player movement game.down = function (x, y, obj) { var targetX = x; var targetY = y; var dx = targetX - player.x; var dy = targetY - player.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { player.x += dx / distance * player.speed; player.y += dy / distance * player.speed; } }; // Check for collisions with walls function checkCollisions() { for (var i = 0; i < walls.length; i++) { if (player.intersects(walls[i])) { // Handle collision player.x -= (player.x - walls[i].x) * 0.1; player.y -= (player.y - walls[i].y) * 0.1; } } } // Check if player reaches the exit function checkExit() { if (player.intersects(exit)) { // Player reached the exit LK.showGameOver(); } } // Game update loop game.update = function () { checkCollisions(); checkExit(); };
===================================================================
--- original.js
+++ change.js
@@ -93,8 +93,10 @@
exit.x = 2048 - mazeData.blockSize;
exit.y = 2732 - mazeData.blockSize;
exit.width = mazeData.blockSize;
exit.height = mazeData.blockSize;
+wall.width = mazeData.blockSize;
+wall.height = mazeData.blockSize;
game.addChild(exit);
// Create a simple maze
// Handle player movement
game.down = function (x, y, obj) {