User prompt
Make the Centerasset movable by mouse cursor
User prompt
Adjust the screen to fit the maze in it
User prompt
Maker the centrasset on the front of the screen and can be touched by cursor to move it and move maze with it.
User prompt
Create new asset in the center of the maze. If i drag it drage the maze with it.
User prompt
Hold on maze to move it anywhere on the screen
User prompt
Make the maze on the front side of the screen
User prompt
Make the maze follow the arrow of mouse if moved in the screen.
User prompt
Move maze to the right side
User prompt
Hold maze corner to drag it anywhere in the screen
User prompt
Move maze by one of its walls
User prompt
Center the maze
User prompt
Lower the maze little bit
User prompt
Move the maze to the right side little bit
User prompt
Remove many walls inside the 4 walls of the maze to create spaces for the player
User prompt
Reduce the number of walls inside maze
User prompt
Generate maze with walls inside the 4 sides of maze
User prompt
move maze to the bottom right side of the scren
User prompt
Make function that all walls can be removed from the maze axcept the surrounding lines
User prompt
Fit maze to screen
User prompt
make the maze in the center
User prompt
Reduce the number of the walls
User prompt
Remove all the walls then add anther walls with same size on all of the screen and generate a new maze
User prompt
move the taller walls of the all 4 sides to fit to the screen
User prompt
Return the 4 walls of the sides to its first position
User prompt
if drage any wall from the maze move the maze with it.
/**** * 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 }); }); // Class for maze blocks var MazeBlock = Container.expand(function () { var self = Container.call(this); var blockGraphics = self.attachAsset('wall', { 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 }); self.down = function (x, y, obj) { dragNode = self; mazePosition.x = x - self.x; // Update the maze's x position mazePosition.y = y - self.y; // Update the maze's y position handleMove(x, y, obj); }; self.move = function (x, y, obj) { if (dragNode === self) { handleMove(x, y, obj); } }; self.up = function (x, y, obj) { dragNode = null; }; }); /**** * Initialize Game ****/ // Function to generate a random maze var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ 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); // Define the handleMove function function handleMove(x, y, obj) { if (dragNode && dragNode instanceof Wall) { dragNode.x = x; dragNode.y = y; // Update the position of all maze blocks for (var i = 0; i < mazeData.maze.length; i++) { if (mazeData.maze[i] !== undefined) { // Check if mazeData.maze[i] is defined for (var j = 0; j < mazeData.maze[i].length; j++) { var block = mazeData.maze[i][j]; if (block !== null && block !== undefined) { block.x = x - mazePosition.x + j * mazeData.blockSize.width; block.y = y - mazePosition.y + i * mazeData.blockSize.height; // Update the position of all maze blocks } } } } // Update the position of the player and the exit player.x = x - mazePosition.x + mazeData.blockSize.width; player.y = y - mazePosition.y + mazeData.blockSize.height; exit.x = x - mazePosition.x + 2 * mazeData.blockSize.width; exit.y = y - mazePosition.y + 2 * mazeData.blockSize.height; } } game.move = handleMove; game.up = function (x, y, obj) { dragNode = null; }; function generateMaze() { var maze = []; var mazeSize = { width: Math.floor(game.width / 100), height: Math.floor(game.height / 100) }; // Set a dynamic maze size based on the game screen size var blockSize = { width: 2048 / mazeSize.width, height: 2732 / mazeSize.height }; for (var i = 0; i < mazeSize.height; i++) { maze[i] = []; for (var j = 0; j < mazeSize.width; j++) { // Add maze blocks if (Math.random() > 0.5 && j > 2 && j < mazeSize.width - 1 && i > 2 && i < mazeSize.height - 2) { // 50% chance to not create a block, creating a path // Avoid creating blocks in the first 3 and last 3 columns to reduce walls from the sides // Avoid creating blocks in the first 2 rows to remove the two upper lines of walls // Avoid creating blocks in the last row to remove the lower line of walls maze[i][j] = new MazeBlock(); maze[i][j].width = blockSize.width; maze[i][j].height = blockSize.height; maze[i][j].x = j * blockSize.width + (game.width - mazeSize.width * blockSize.width) / 2; maze[i][j].y = i * blockSize.height + (game.height - mazeSize.height * blockSize.height) / 2; game.addChild(maze[i][j]); } else { // Create open paths by not adding a block maze[i][j] = null; } } } return { maze: maze, blockSize: blockSize }; } var mazeData = generateMaze(); var mazePosition = { x: 0, y: 0 }; // Keep track of the maze's position var player = new Player(); player.x = game.width / 2 - mazeData.blockSize; player.y = game.height / 2 - mazeData.blockSize; player.width = mazeData.blockSize / 3; player.height = mazeData.blockSize / 3; game.addChild(player); // Create 4 walls for up, down, left and right sides var wallThickness = mazeData.blockSize / 4; // Adjust this value to change the thickness of the walls var wallUp = new Wall(); wallUp.width = game.width; wallUp.height = wallThickness; wallUp.x = game.width / 2; wallUp.y = wallUp.height / 2; game.addChild(wallUp); var wallDown = new Wall(); wallDown.width = game.width; wallDown.height = wallThickness; wallDown.x = game.width / 2; wallDown.y = game.height - wallDown.height / 2; game.addChild(wallDown); var wallLeft = new Wall(); wallLeft.width = wallThickness; wallLeft.height = game.height; wallLeft.x = wallLeft.width / 2; wallLeft.y = game.height / 2; game.addChild(wallLeft); var wallRight = new Wall(); wallRight.width = wallThickness; wallRight.height = game.height; wallRight.x = game.width - wallRight.width / 2; wallRight.y = game.height / 2; game.addChild(wallRight); // Set level 01 and background1 for level 1 game.level = 1; game.background = LK.getAsset('Background1', { anchorX: 0.5, anchorY: 0.5 }); var exit = new Exit(); exit.x = game.width / 2 + mazeData.blockSize; exit.y = game.height / 2 + mazeData.blockSize; exit.width = mazeData.blockSize / 3; exit.height = mazeData.blockSize / 3; game.addChild(exit); // Handle player movement var dragNode = null; game.down = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; // Update the position of the player and the exit player.x = x - mazePosition.x + mazeData.blockSize.width; player.y = y - mazePosition.y + mazeData.blockSize.height; exit.x = x - mazePosition.x + 2 * mazeData.blockSize.width; exit.y = y - mazePosition.y + 2 * mazeData.blockSize.height; } }; // Create a Text2 object to display the level number var levelText = new Text2('Level: 1', { size: 50, fill: 0xFFFF00 }); // Position the level text at the bottom left of the screen levelText.anchor.set(0, 1); levelText.x = 0; levelText.y = 2732; // Add the level text to the GUI overlay LK.gui.bottomLeft.addChild(levelText); // Check if player reaches the exit function checkExit() { if (player.intersects(exit)) { // Player reached the exit LK.showGameOver(); } } // Game update loop // Define the checkCollisions function function checkCollisions() { // Collision detection logic } game.update = function () { checkCollisions(); checkExit(); // Check if walls are out of screen bounds and prevent them from moving out for (var i = 0; i < mazeData.maze.length; i++) { for (var j = 0; j < mazeData.maze[i].length; j++) { var wall = mazeData.maze[i][j]; if (wall) { if (wall.x < 0) { wall.x = 0; } if (wall.y < 0) { wall.y = 0; } if (wall.x + wall.width > game.width) { wall.x = game.width - wall.width; } if (wall.y + wall.height > game.height) { wall.y = game.height - wall.height; } } } } };
/****
* 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
});
});
// Class for maze blocks
var MazeBlock = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('wall', {
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
});
self.down = function (x, y, obj) {
dragNode = self;
mazePosition.x = x - self.x; // Update the maze's x position
mazePosition.y = y - self.y; // Update the maze's y position
handleMove(x, y, obj);
};
self.move = function (x, y, obj) {
if (dragNode === self) {
handleMove(x, y, obj);
}
};
self.up = function (x, y, obj) {
dragNode = null;
};
});
/****
* Initialize Game
****/
// Function to generate a random maze
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
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);
// Define the handleMove function
function handleMove(x, y, obj) {
if (dragNode && dragNode instanceof Wall) {
dragNode.x = x;
dragNode.y = y;
// Update the position of all maze blocks
for (var i = 0; i < mazeData.maze.length; i++) {
if (mazeData.maze[i] !== undefined) {
// Check if mazeData.maze[i] is defined
for (var j = 0; j < mazeData.maze[i].length; j++) {
var block = mazeData.maze[i][j];
if (block !== null && block !== undefined) {
block.x = x - mazePosition.x + j * mazeData.blockSize.width;
block.y = y - mazePosition.y + i * mazeData.blockSize.height;
// Update the position of all maze blocks
}
}
}
}
// Update the position of the player and the exit
player.x = x - mazePosition.x + mazeData.blockSize.width;
player.y = y - mazePosition.y + mazeData.blockSize.height;
exit.x = x - mazePosition.x + 2 * mazeData.blockSize.width;
exit.y = y - mazePosition.y + 2 * mazeData.blockSize.height;
}
}
game.move = handleMove;
game.up = function (x, y, obj) {
dragNode = null;
};
function generateMaze() {
var maze = [];
var mazeSize = {
width: Math.floor(game.width / 100),
height: Math.floor(game.height / 100)
}; // Set a dynamic maze size based on the game screen size
var blockSize = {
width: 2048 / mazeSize.width,
height: 2732 / mazeSize.height
};
for (var i = 0; i < mazeSize.height; i++) {
maze[i] = [];
for (var j = 0; j < mazeSize.width; j++) {
// Add maze blocks
if (Math.random() > 0.5 && j > 2 && j < mazeSize.width - 1 && i > 2 && i < mazeSize.height - 2) {
// 50% chance to not create a block, creating a path
// Avoid creating blocks in the first 3 and last 3 columns to reduce walls from the sides
// Avoid creating blocks in the first 2 rows to remove the two upper lines of walls
// Avoid creating blocks in the last row to remove the lower line of walls
maze[i][j] = new MazeBlock();
maze[i][j].width = blockSize.width;
maze[i][j].height = blockSize.height;
maze[i][j].x = j * blockSize.width + (game.width - mazeSize.width * blockSize.width) / 2;
maze[i][j].y = i * blockSize.height + (game.height - mazeSize.height * blockSize.height) / 2;
game.addChild(maze[i][j]);
} else {
// Create open paths by not adding a block
maze[i][j] = null;
}
}
}
return {
maze: maze,
blockSize: blockSize
};
}
var mazeData = generateMaze();
var mazePosition = {
x: 0,
y: 0
}; // Keep track of the maze's position
var player = new Player();
player.x = game.width / 2 - mazeData.blockSize;
player.y = game.height / 2 - mazeData.blockSize;
player.width = mazeData.blockSize / 3;
player.height = mazeData.blockSize / 3;
game.addChild(player);
// Create 4 walls for up, down, left and right sides
var wallThickness = mazeData.blockSize / 4; // Adjust this value to change the thickness of the walls
var wallUp = new Wall();
wallUp.width = game.width;
wallUp.height = wallThickness;
wallUp.x = game.width / 2;
wallUp.y = wallUp.height / 2;
game.addChild(wallUp);
var wallDown = new Wall();
wallDown.width = game.width;
wallDown.height = wallThickness;
wallDown.x = game.width / 2;
wallDown.y = game.height - wallDown.height / 2;
game.addChild(wallDown);
var wallLeft = new Wall();
wallLeft.width = wallThickness;
wallLeft.height = game.height;
wallLeft.x = wallLeft.width / 2;
wallLeft.y = game.height / 2;
game.addChild(wallLeft);
var wallRight = new Wall();
wallRight.width = wallThickness;
wallRight.height = game.height;
wallRight.x = game.width - wallRight.width / 2;
wallRight.y = game.height / 2;
game.addChild(wallRight);
// Set level 01 and background1 for level 1
game.level = 1;
game.background = LK.getAsset('Background1', {
anchorX: 0.5,
anchorY: 0.5
});
var exit = new Exit();
exit.x = game.width / 2 + mazeData.blockSize;
exit.y = game.height / 2 + mazeData.blockSize;
exit.width = mazeData.blockSize / 3;
exit.height = mazeData.blockSize / 3;
game.addChild(exit);
// Handle player movement
var dragNode = null;
game.down = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
// Update the position of the player and the exit
player.x = x - mazePosition.x + mazeData.blockSize.width;
player.y = y - mazePosition.y + mazeData.blockSize.height;
exit.x = x - mazePosition.x + 2 * mazeData.blockSize.width;
exit.y = y - mazePosition.y + 2 * mazeData.blockSize.height;
}
};
// Create a Text2 object to display the level number
var levelText = new Text2('Level: 1', {
size: 50,
fill: 0xFFFF00
});
// Position the level text at the bottom left of the screen
levelText.anchor.set(0, 1);
levelText.x = 0;
levelText.y = 2732;
// Add the level text to the GUI overlay
LK.gui.bottomLeft.addChild(levelText);
// Check if player reaches the exit
function checkExit() {
if (player.intersects(exit)) {
// Player reached the exit
LK.showGameOver();
}
}
// Game update loop
// Define the checkCollisions function
function checkCollisions() {
// Collision detection logic
}
game.update = function () {
checkCollisions();
checkExit();
// Check if walls are out of screen bounds and prevent them from moving out
for (var i = 0; i < mazeData.maze.length; i++) {
for (var j = 0; j < mazeData.maze[i].length; j++) {
var wall = mazeData.maze[i][j];
if (wall) {
if (wall.x < 0) {
wall.x = 0;
}
if (wall.y < 0) {
wall.y = 0;
}
if (wall.x + wall.width > game.width) {
wall.x = game.width - wall.width;
}
if (wall.y + wall.height > game.height) {
wall.y = game.height - wall.height;
}
}
}
}
};