User prompt
Fix what's stopping level 3 from going to level 4!
User prompt
Add wall4 to level4 respawning from bottom to top and from left to right
User prompt
Play level 4 after level 3
User prompt
Add level 4 text
User prompt
If time reach 0 in level 3 move to level 4
User prompt
If walls start respawning start decreasing time in level 3
User prompt
Add level 4 5 and 6 to the game
User prompt
Don't stop the game in level 3 move to next levels
User prompt
If level 3 starts start decrease time numbers form 10 to 0 sec
User prompt
If time reach 0 in level 3 play level 4
User prompt
ADD level 4
User prompt
Add statu time 10 sec in level 3
User prompt
Make th time numbers reducing to 0
User prompt
Don't make level 3 the last level move to next level 4
User prompt
Remove text of time in level3 and make a new one similar as level 2
User prompt
Don't do game over if time 0 in level 2 just move to the next level by time statu of 10 sec
User prompt
If time reach 0 in level 3 go to next level
User prompt
Make the time the time for player to survive in each level and set it to 10 sec.
User prompt
Make same text of time in level 1 and 2 for level3 and each level
User prompt
Fix time not moving in level3!
User prompt
Decreas the number in time 10 to 0 if level 3 start
User prompt
Add statu time in time text
User prompt
Add time statu to level 3 and Decreas time from 10 to 0 in level 3 to go to level 4
User prompt
Decreas time text statu to 0 in level3
User prompt
Add level 4
/**** * Classes ****/ // Create a Player class var Player = Container.expand(function () { var self = Container.call(this); // Attach a shape asset to represent the player var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Set player speed self.speed = 50; // This is automatically called every game tick, if the player is attached! self.update = function () { // No continuous movement }; }); // Create a RandomShape class for shapes spawning from top and left var RandomShape = Container.expand(function () { var self = Container.call(this); // Attach a random shape asset to represent the shape var shapeGraphics = self.attachAsset('shape' + Math.floor(Math.random() * 10), { anchorX: 0.5, anchorY: 0.5, width: Math.random() * 200, // Random width between 0 and 200 height: Math.random() * 200 // Random height between 0 and 200 }); // Set shape speed self.speed = 2; // This is automatically called every game tick, if the shape is attached! self.update = function () { // Randomly decide the direction of the shape if (Math.random() < 0.5) { self.y += self.speed; } else { self.x += self.speed; } }; }); // Create a Wall2 class for wall2 spawning from top and moving vertically to the bottom var Wall2 = Container.expand(function () { var self = Container.call(this); // Attach a wall2 asset to represent the wall var wallGraphics = self.attachAsset('wall2', { anchorX: 0.5, anchorY: 0.5, height: 200 // Make the wall taller }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.y += self.speed; }; }); // Create a Wall3 class for walls spawning from bottom to top and right to left var Wall3 = Container.expand(function () { var self = Container.call(this); // Attach a wall3 asset to represent the wall var wallGraphics = self.attachAsset('wall3', { anchorX: 0.5, anchorY: 0.5, width: Math.random() * 200 + 100, // Random width height: Math.random() * 200 + 100 // Random height }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.y -= self.speed; // Move upwards }; }); // Create a Wall3Right class for walls spawning from right to left var Wall3Right = Container.expand(function () { var self = Container.call(this); // Attach a wall3 asset to represent the wall var wallGraphics = self.attachAsset('wall3', { anchorX: 0.5, anchorY: 0.5, width: Math.random() * 200 + 100, // Random width height: Math.random() * 200 + 100 // Random height }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.x -= self.speed; // Move leftwards }; }); // Create a WallHorizontal class for taller horizontal walls spawning from right var WallHorizontal = Container.expand(function () { var self = Container.call(this); // Attach a wall asset to represent the wall var wallGraphics = self.attachAsset('wall1', { anchorX: 0.5, anchorY: 0.5, width: Math.random() * 200 + 100 // Make the wall wider and random }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.x -= self.speed; }; }); // Create a WallVertical class for vertical walls spawning from top var WallVertical = Container.expand(function () { var self = Container.call(this); // Attach a wall asset to represent the wall var wallGraphics = self.attachAsset('wall1', { anchorX: 0.5, anchorY: 0.5, height: Math.random() * 200 + 100 // Make the wall taller and random }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.y += self.speed; }; }); // Create a WallVertical2 class for taller vertical walls spawning from top to bottom var WallVertical2 = Container.expand(function () { var self = Container.call(this); // Attach a wall asset to represent the wall var wallGraphics = self.attachAsset('wall1', { anchorX: 0.5, anchorY: 0.5, height: Math.random() * 200 + 100 // Make the wall taller and random }); // Set wall speed self.speed = 4; // This is automatically called every game tick, if the wall is attached! self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = null; function setBackgroundForLevel(level) { if (background) { background.destroy(); // Remove the current background } if (level === 1) { background = game.addChildAt(LK.getAsset('Background1', { anchorX: 0.0, anchorY: 0.0, x: (game.width - LK.getAsset('Background1', {}).width * game.width / LK.getAsset('Background1', {}).width) / 2, y: (game.height - LK.getAsset('Background1', {}).height * game.height / LK.getAsset('Background1', {}).height) / 2 }), 0); background.scale.set(game.width / background.width, game.height / background.height); } else if (level === 2) { background = game.addChildAt(LK.getAsset('Background2', { anchorX: 0.0, anchorY: 0.0, x: (game.width - LK.getAsset('Background2', {}).width * game.width / LK.getAsset('Background2', {}).width) / 2, y: (game.height - LK.getAsset('Background2', {}).height * game.height / LK.getAsset('Background2', {}).height) / 2 }), 0); background.scale.set(game.width / background.width, game.height / background.height); } else if (level === 3) { background = game.addChildAt(LK.getAsset('Background3', { anchorX: 0.0, anchorY: 0.0, x: (game.width - LK.getAsset('Background3', {}).width * game.width / LK.getAsset('Background3', {}).width) / 2, y: (game.height - LK.getAsset('Background3', {}).height * game.height / LK.getAsset('Background3', {}).height) / 2 }), 0); background.scale.set(game.width / background.width, game.height / background.height); timer = 10; // Set timer for level 3 timerText.setText('Time: ' + timer); // Update timer text for level 3 } else if (level === 4) { background = game.addChildAt(LK.getAsset('Background4', { anchorX: 0.0, anchorY: 0.0, x: (game.width - LK.getAsset('Background4', {}).width * game.width / LK.getAsset('Background4', {}).width) / 2, y: (game.height - LK.getAsset('Background4', {}).height * game.height / LK.getAsset('Background4', {}).height) / 2 }), 0); background.scale.set(game.width / background.width, game.height / background.height); } if (background) { background.scale.set(game.width / background.width, game.height / background.height); } } setBackgroundForLevel(level); var level = 1; // Initialize timer for each level var timers = Array(10).fill(10); // Set all levels to have a timer of 10 seconds var timer = timers[level - 1]; // Initialize background var background; if (level === 1) { background = game.addChildAt(LK.getAsset('Background1', { anchorX: 0.0, anchorY: 0.0, width: game.width, height: game.height, x: 0, y: 0 }), 0); } else if (level === 2) { background = game.addChildAt(LK.getAsset('Background2', { anchorX: 0.0, anchorY: 0.0, width: game.width, height: game.height, x: 0, y: 0 }), 0); } else if (level === 3) { background = game.addChildAt(LK.getAsset('Background3', { anchorX: 0.0, anchorY: 0.0, x: (game.width - LK.getAsset('Background3', {}).width * game.width / LK.getAsset('Background3', {}).width) / 2, y: (game.height - LK.getAsset('Background3', {}).height * game.height / LK.getAsset('Background3', {}).height) / 2 }), 0); background.scale.set(game.width / background.width, game.height / background.height); timer = 10; // Set timer for level 3 timerText.setText('Time: ' + timer); // Update timer text for level 3 } // Fit the background to the screen if it is defined if (background) { background.scale.set(game.width / background.width, game.height / background.height); background.width = game.width; background.height = game.height; } // Add level text on the top right corner var levelText = new Text2('Level 1', { size: 100, fill: 0x808080 // Grey color }); levelText.anchor.set(1, 0); // Sets anchor to the right of the top edge of the text. LK.gui.topRight.addChild(levelText); // Add timer on the top left corner var timerText = new Text2('Time: ' + timer + ' sec', { size: 100, fill: 0x808080 // Grey color }); timerText.anchor.set(0, 0); // Sets anchor to the left of the top edge of the text. LK.gui.topLeft.addChild(timerText); // Decrease timer every second and update timer text var timerInterval = LK.setInterval(function () { if (timer > 0) { timer--; timerText.setText('Time: ' + timer); } else { LK.clearInterval(timerInterval); level += 1; // Increase level levelText.setText('Level ' + level); // Update level text timer = timers[level - 1]; // Reset timer for each level timerText.setText('Time: ' + timer); // Change background for the new level setBackgroundForLevel(level); // Restart the timer for the next level timerInterval = LK.setInterval(function () { if (timer > 0) { timer--; timerText.setText('Time: ' + timer); } else { LK.clearInterval(timerInterval); level += 1; // Increase level levelText.setText('Level ' + level); // Update level text timer = timers[level - 1]; // Reset timer for each level timerText.setText('Time: ' + timer); setBackgroundForLevel(level); } }, 1000); } }, 1000); // Initialize 10 background assets for each level for (var i = 1; i <= 10; i++) {} // Initialize a player instance and attach it to the game var player = game.addChild(new Player()); // Position player at the center of the screen player.x = game.width / 2; player.y = game.height / 2; // Show player on the screen for level 2 if (level === 2) { player.visible = true; player.x = game.width / 2; player.y = 0; } // Initialize dragNode var dragNode = null; // Removed maze regeneration and player reinitialization // Removed player movement and click event listener related to the maze // Function to generate a random maze // Add event listener for player movement // Removed game.down event listener as it's not needed // Update game loop to move player towards target position var targetPosition = null; game.update = function () { if (targetPosition) { var dx = targetPosition.x - player.x; var dy = targetPosition.y - player.y; var angle = Math.atan2(dy, dx); player.x += Math.cos(angle) * player.speed; player.y += Math.sin(angle) * player.speed; } // Create random vertical and horizontal walls for wall1 in level 1 only if (level === 1 && LK.ticks % 60 == 0) { var newWall; if (Math.random() < 0.5) { newWall = new WallVertical(); newWall.x = Math.random() * (game.width - newWall.width) + newWall.width / 2; newWall.y = 0; } else { newWall = new WallHorizontal(); newWall.x = game.width; newWall.y = Math.random() * (game.height - newWall.height) + newWall.height / 2; } game.addChild(newWall); } // Hide walls from level 1 when level 2 starts if (level === 2) { for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof WallVertical || game.children[i] instanceof WallHorizontal) { game.children[i].visible = false; } } } // Hide walls from level 2 when level 3 starts if (level === 3) { for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Wall2) { game.children[i].visible = false; } } } // Add wall2 to level 2 as objects respawning randomly from top to bottom if (level === 2 && LK.ticks % 60 == 0) { var newWall2 = new Wall2(); newWall2.x = Math.random() * (game.width - newWall2.width) + newWall2.width / 2; newWall2.y = 0; game.addChild(newWall2); } // Add wall3 to level 3 as objects respawning from bottom to top and right to left if (level === 3 && LK.ticks % 60 == 0) { var newWall3; if (Math.random() < 0.5) { newWall3 = new Wall3(); newWall3.x = Math.random() * (game.width - newWall3.width) + newWall3.width / 2; newWall3.y = game.height; } else { newWall3 = new Wall3Right(); newWall3.x = game.width; newWall3.y = Math.random() * (game.height - newWall3.height) + newWall3.height / 2; } game.addChild(newWall3); } // Add wall4 to level 4 as objects respawning from top to bottom if (level === 4 && LK.ticks % 60 == 0) { var newWall4 = new WallVertical2(); newWall4.x = Math.random() * (game.width - newWall4.width) + newWall4.width / 2; newWall4.y = 0; game.addChild(newWall4); } for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof WallVertical || game.children[i] instanceof WallHorizontal || game.children[i] instanceof Wall2 || game.children[i] instanceof WallVertical2) { if (player.intersects(game.children[i]) && game.children[i].visible) { LK.showGameOver(); break; } } } }; // Add event listeners for player movement // Define handleMove function function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } game.down = function (x, y, obj) { dragNode = player; handleMove(x, y, obj); }; game.move = handleMove; // Removed game.move event listener as it's not needed // Removed player movement towards target position in game update game.up = function (x, y, obj) { dragNode = null; };
===================================================================
--- original.js
+++ change.js
@@ -178,9 +178,10 @@
x: (game.width - LK.getAsset('Background3', {}).width * game.width / LK.getAsset('Background3', {}).width) / 2,
y: (game.height - LK.getAsset('Background3', {}).height * game.height / LK.getAsset('Background3', {}).height) / 2
}), 0);
background.scale.set(game.width / background.width, game.height / background.height);
- timer = 0; // Decrease timer to 0 when level 3 starts
+ timer = 10; // Set timer for level 3
+ timerText.setText('Time: ' + timer); // Update timer text for level 3
} else if (level === 4) {
background = game.addChildAt(LK.getAsset('Background4', {
anchorX: 0.0,
anchorY: 0.0,