User prompt
Make many obstacles
User prompt
Make a static maze with different obstacles if player touch any obstacles do game over. Make the player in left bottom corner of the maze and exit on the top right of it
User prompt
Don't change th maze shape each time randoly let only one maze
User prompt
Make the player follow cursor exact same time not far from it
User prompt
If player touch exit asset in the maze do game over
User prompt
Don't teleport player to cursor and let it follow it only if hold on it
User prompt
Make collision between wall asset and player and can't pass through it if moving on the screen. can only move in the spaces.
User prompt
Resize the player and choose random location on the maze
User prompt
Make the exit in the middle of the screen
User prompt
resize it
User prompt
Make exit assets the exit in the maze
User prompt
Make the player position the right bottom side inside the maze not inside walls or outside it corner.
Code edit (1 edits merged)
Please save this source code
User prompt
Regenerate player and exit for the maze to be played
User prompt
Make the exit on the right top corner befor walls
User prompt
Add the exit asset to the maze make it shown in the screen, with same size of small wall asset
User prompt
Make the player position the left bottom corner inside maze
User prompt
Make the player have same size of the small walls without changing anything of the maze or its shape
User prompt
Add exit to the maze
User prompt
Change the exit position to be right upper corner before maze walls
User prompt
Add the exit asset to the game
User prompt
Analyse the game!
User prompt
Change playre position to the right corner
User prompt
repear game player is bigger then spaces in the maze
User prompt
fix it
/**** * Classes ****/ // Create an Exit class var Exit = Container.expand(function () { var self = Container.call(this); var exitGraphics = self.attachAsset('Exit', { anchorX: 1, anchorY: 1, width: blockSize * 2, height: blockSize * 2 }); }); // Create a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5, width: blockSize, height: blockSize }); self.speed = 5; self.update = function () { if (self.x < 0) { self.x = 0; } if (self.y < 0) { self.y = 0; } if (self.x > game.width) { self.x = game.width; } if (self.y > game.height) { self.y = game.height; } for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof Wall && self.intersects(game.children[i])) { self.x -= self.speed * Math.sign(self.x - game.children[i].x); self.y -= self.speed * Math.sign(self.y - game.children[i].y); } } }; }); //<Assets used in the game will automatically appear here> // Create a Wall class 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 }); /**** * Game Code ****/ // Function to generate a random maze var blockSize = 50; var background = LK.getAsset('Background1', { anchorX: 0.5, anchorY: 0.5 }); background.width = game.width; background.height = game.height; background.x = game.width / 2; background.y = game.height / 2; game.addChildAt(background, 0); // Function to generate a random maze function generateMaze() { blockSize = Math.floor(Math.random() * 30) + 20; // Random block size between 20 and 50 var mazeWidth = Math.floor(game.width / blockSize); var mazeHeight = Math.floor(game.height / blockSize); for (var i = 0; i < mazeWidth; i++) { for (var j = 0; j < mazeHeight; j++) { if (i === 0 || i === mazeWidth - 1 || j === 0 || j === mazeHeight - 1) { var wall = LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); wall.width = blockSize; wall.height = blockSize; wall.x = i * blockSize + blockSize / 2; wall.y = j * blockSize + blockSize / 2; game.addChild(wall); } else if (Math.random() > 0.7 && !(i % 2 === 0 && j % 2 === 0)) { // Adjusted randomness for different maze pattern // Clear paths in the maze by not creating a wall at every second column and every second row var wall = LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); wall.width = blockSize; wall.height = blockSize; wall.x = i * blockSize + blockSize / 2; wall.y = j * blockSize + blockSize / 2; game.addChild(wall); } } } } generateMaze(); var player = game.addChild(new Player()); player.x = Math.floor(Math.random() * (game.width - blockSize)) + blockSize / 2; player.y = Math.floor(Math.random() * (game.height - blockSize)) + blockSize / 2; // Create an exit in the maze var exit = game.addChild(new Exit()); exit.width = blockSize; exit.height = blockSize; exit.x = game.width / 2; exit.y = game.height / 2; // Add mouse down event to make player follow the cursor only when clicked and dragged var dragNode = null; game.down = function (x, y, obj) { dragNode = player; }; game.move = function (x, y, obj) { if (dragNode) { var dx = x - dragNode.x; var dy = y - dragNode.y; var angle = Math.atan2(dy, dx); dragNode.x += Math.cos(angle) * dragNode.speed; dragNode.y += Math.sin(angle) * dragNode.speed; } }; game.up = function (x, y, obj) { dragNode = null; };
===================================================================
--- original.js
+++ change.js
@@ -123,10 +123,13 @@
dragNode = player;
};
game.move = function (x, y, obj) {
if (dragNode) {
- dragNode.x = x;
- dragNode.y = y;
+ var dx = x - dragNode.x;
+ var dy = y - dragNode.y;
+ var angle = Math.atan2(dy, dx);
+ dragNode.x += Math.cos(angle) * dragNode.speed;
+ dragNode.y += Math.sin(angle) * dragNode.speed;
}
};
game.up = function (x, y, obj) {
dragNode = null;