User prompt
Make the obstacle walls can be touched
User prompt
random the shapes of walls for the maze inside all the space
User prompt
Fill the maze by abstacles
User prompt
Make it inside maze corner not screen corner
User prompt
Hold position player on the left bottom walls of maze corner
User prompt
Don't let player pass the maze walls
User prompt
1-Fill the inside space of maze walls with obstacles. 2-Make exit and player inside corner of walls
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
/**** * 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])) { LK.showGameOver(); } } }; }); //<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 static 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 generateMaze() { 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 || Math.random() < 0.2) { 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 = blockSize * 1.5; player.y = game.height - blockSize * 1.5; // Create an exit in the maze var exit = game.addChild(new Exit()); exit.width = blockSize; exit.height = blockSize; exit.x = game.width - blockSize * 2.5; exit.y = blockSize * 2.5; // 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 oldX = dragNode.x; var oldY = dragNode.y; dragNode.x = x - dragNode.width / 2; dragNode.y = y - dragNode.height / 2; for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof Wall && dragNode.intersects(game.children[i])) { dragNode.x = oldX; dragNode.y = oldY; break; } } if (player.intersects(exit)) { LK.showGameOver(); } } }; game.up = function (x, y, obj) { dragNode = null; };
===================================================================
--- original.js
+++ change.js
@@ -108,10 +108,19 @@
dragNode = player;
};
game.move = function (x, y, obj) {
if (dragNode) {
+ var oldX = dragNode.x;
+ var oldY = dragNode.y;
dragNode.x = x - dragNode.width / 2;
dragNode.y = y - dragNode.height / 2;
+ for (var i = 0; i < game.children.length; i++) {
+ if (game.children[i] instanceof Wall && dragNode.intersects(game.children[i])) {
+ dragNode.x = oldX;
+ dragNode.y = oldY;
+ break;
+ }
+ }
if (player.intersects(exit)) {
LK.showGameOver();
}
}