Code edit (1 edits merged)
Please save this source code
User prompt
Make the player on the bottom right corner inside the 2 walls
User prompt
change the position of player and exit to be where i placed them now
User prompt
Make collision between player and walls to not pass it
User prompt
Same for exit
User prompt
Hold object to move it anywhere on the screen
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.target.name === 'player') {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target.name === 'player') {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.target.name === 'player') {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target.name === 'player') {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target.id === 'player') {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target === player) {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'currentTarget')' in or related to this line: 'if (obj.event.currentTarget === player) {' Line Number: 73
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target === player) {' Line Number: 73
User prompt
make them touched by cursor
User prompt
Click on player to move it anywher on the screen
User prompt
click player to move it same for exit
User prompt
Hold to drag player. hold to drag exit
User prompt
Remove drag of objects
User prompt
Make the game smooth and the images clearer
User prompt
Add wall2 too small walls in middle of the 4 walls
User prompt
more thick
User prompt
Make the walls thick little bit
User prompt
Remove the maze and its system and CenterAsset and all walls in the screen or outside it
User prompt
Remove left side line of wall from the maze
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * 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 }; }); /**** * Initialize Game ****/ // Function to generate a random maze var game = new LK.Game({ backgroundColor: 0x000000, width: 800, height: 800 }); /**** * 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); var player = new Player(); player.x = game.width / 2; player.y = game.height / 2; game.addChild(player); // 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; exit.y = game.height / 2; game.addChild(exit); // Handle player movement var dragNode = null; game.down = function (x, y, obj) { dragNode = centerAsset; mazePosition.x = x - centerAsset.x; // Update the maze's x position mazePosition.y = y - centerAsset.y; // Update the maze's y position storage.mazePosition = mazePosition; // Persist the maze's position }; game.move = function (x, y, obj) { if (dragNode) { centerAsset.x = x; centerAsset.y = y; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; // 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 removed } game.update = function () { checkCollisions(); checkExit(); // Collision prevention logic removed };
===================================================================
--- original.js
+++ change.js
@@ -5,32 +5,16 @@
/****
* Classes
****/
-// Class for the center asset
-var CenterAsset = Container.expand(function () {
- var self = Container.call(this);
- var centerAssetGraphics = self.attachAsset('centerAsset', {
- anchorX: 0.5,
- anchorY: 0.5
- });
-});
// 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 () {
@@ -43,30 +27,8 @@
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 = centerAsset;
- mazePosition.x = x - centerAsset.x; // Update the maze's x position
- mazePosition.y = y - centerAsset.y; // Update the maze's y position
- handleMove(x, y, obj);
- };
- self.move = function (x, y, obj) {
- if (dragNode === centerAsset) {
- handleMove(x, y, obj);
- }
- };
- self.up = function (x, y, obj) {
- dragNode = null;
- };
-});
/****
* Initialize Game
****/
@@ -88,119 +50,21 @@
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 CenterAsset) {
- dragNode.x = game.width / 2; // Center the centerAsset
- dragNode.y = game.height / 2; // Center the centerAsset
- // Update the position of all maze blocks and walls
- 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 = centerAsset.x - mazeData.maze[0].length * mazeData.blockSize.width / 2 + j * mazeData.blockSize.width; // Center the maze blocks around the centerAsset
- block.y = centerAsset.y - mazeData.maze.length * mazeData.blockSize.height / 2 + i * mazeData.blockSize.height; // Center the maze blocks around the centerAsset
- }
- }
- }
- }
- // Update the position of the player and the exit
- player.x = centerAsset.x - mazePosition.x + mazeData.blockSize.width; // Move the player to the centerAsset position
- player.y = centerAsset.y - mazePosition.y;
- exit.x = centerAsset.x - mazePosition.x + 2 * mazeData.blockSize.width; // Move the exit to the centerAsset position
- exit.y = centerAsset.y - mazePosition.y;
- }
-}
-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: game.width / mazeSize.width,
- height: game.height / mazeSize.height
- };
- for (var i = 0; i < mazeSize.height; i++) {
- maze[i] = [];
- for (var j = 0; j < mazeSize.width; j++) {
- // Add maze blocks
- // Create open paths by not adding a block
- maze[i][j] = null;
- }
- }
- return {
- maze: maze,
- blockSize: blockSize
- };
-}
-var mazeData = generateMaze();
-var mazePosition = storage.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;
+player.x = game.width / 2;
+player.y = game.height / 2;
game.addChild(player);
-var centerAsset = new CenterAsset();
-centerAsset.x = game.width / 2;
-centerAsset.y = game.height / 2;
-game.addChildAt(centerAsset, game.children.length);
-// Remove existing walls and generate new maze walls covering the entire screen
-function generateFullScreenMaze() {
- var maze = [];
- var mazeSize = {
- width: Math.floor(game.width / 100),
- height: Math.floor(game.height / 100)
- };
- var blockSize = {
- width: game.width / mazeSize.width,
- height: game.height / mazeSize.height
- };
- for (var i = 0; i < mazeSize.height; i++) {
- maze[i] = [];
- for (var j = 0; j < mazeSize.width; j++) {
- // Add a condition to create spaces inside the maze
- if (i === mazeSize.height - 1 || j === mazeSize.width - 1 || Math.random() < 0.2) {
- maze[i][j] = new MazeBlock();
- maze[i][j].width = blockSize.width;
- maze[i][j].height = blockSize.height;
- maze[i][j].x = j * blockSize.width;
- maze[i][j].y = i * blockSize.height;
- game.addChild(maze[i][j]);
- } else {
- maze[i][j] = null;
- }
- }
- }
- return {
- maze: maze,
- blockSize: blockSize
- };
-}
-mazeData = generateFullScreenMaze();
// 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;
+exit.x = game.width / 2;
+exit.y = game.height / 2;
game.addChild(exit);
// Handle player movement
var dragNode = null;
game.down = function (x, y, obj) {