User prompt
Now make the players stay in like the maze and like they can't move out of the maze otherwise that would just be bad
User prompt
it can the joystick be like pretty big and then when you move it around when you like touch it or move around and it moves in that direction and also make it stay in like the box like the maze so yeah
Code edit (1 edits merged)
Please save this source code
User prompt
Mine Shaft Escape
Initial prompt
the game the game will be about a guy who is stuck in a mine shaft and monsters one one monster the skeleton tries to change
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Exit = Container.expand(function () { var self = Container.call(this); var exitGraphics = self.attachAsset('exit', { anchorX: 0.5, anchorY: 0.5 }); // Pulsing effect self.pulseDirection = 1; self.update = function () { exitGraphics.alpha += self.pulseDirection * 0.02; if (exitGraphics.alpha >= 1) { self.pulseDirection = -1; } else if (exitGraphics.alpha <= 0.3) { self.pulseDirection = 1; } }; return self; }); var Floor = Container.expand(function () { var self = Container.call(this); var floorGraphics = self.attachAsset('floor', { anchorX: 0, anchorY: 0 }); return self; }); var Joystick = Container.expand(function () { var self = Container.call(this); var baseGraphics = self.attachAsset('joystick_base', { anchorX: 0.5, anchorY: 0.5 }); baseGraphics.alpha = 0.6; var knobGraphics = self.attachAsset('joystick_knob', { anchorX: 0.5, anchorY: 0.5 }); knobGraphics.alpha = 0.8; self.isDragging = false; self.maxDistance = 60; self.inputX = 0; self.inputY = 0; self.down = function (x, y, obj) { self.isDragging = true; }; self.up = function (x, y, obj) { self.isDragging = false; knobGraphics.x = 0; knobGraphics.y = 0; self.inputX = 0; self.inputY = 0; }; self.move = function (x, y, obj) { if (self.isDragging) { var localPos = self.toLocal(obj.parent.toGlobal(obj.position)); var distance = Math.sqrt(localPos.x * localPos.x + localPos.y * localPos.y); if (distance <= self.maxDistance) { knobGraphics.x = localPos.x; knobGraphics.y = localPos.y; } else { knobGraphics.x = localPos.x / distance * self.maxDistance; knobGraphics.y = localPos.y / distance * self.maxDistance; } self.inputX = knobGraphics.x / self.maxDistance; self.inputY = knobGraphics.y / self.maxDistance; } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); self.speed = 3; self.update = function () { if (joystick && (joystick.inputX !== 0 || joystick.inputY !== 0)) { var newX = self.x + joystick.inputX * self.speed; var newY = self.y + joystick.inputY * self.speed; // Calculate maze boundaries var mazeLeft = offsetX; var mazeRight = offsetX + mazeLayout[0].length * cellSize; var mazeTop = offsetY; var mazeBottom = offsetY + mazeLayout.length * cellSize; // Check boundaries and wall collisions for X movement if (newX >= mazeLeft && newX <= mazeRight && !checkWallCollision(newX, self.y)) { self.x = newX; } // Check boundaries and wall collisions for Y movement if (newY >= mazeTop && newY <= mazeBottom && !checkWallCollision(self.x, newY)) { self.y = newY; } // Play footstep sound occasionally while moving if (Math.random() < 0.05) { LK.getSound('footstep').play(); } } }; var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Skeleton = Container.expand(function () { var self = Container.call(this); self.update = function () { if (player) { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { var speed = 2.5; self.x += dx / distance * speed; self.y += dy / distance * speed; } // Random roar sound if (Math.random() < 0.002) { LK.getSound('skeleton_roar').play(); } } }; var skeletonGraphics = self.attachAsset('skeleton', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0, anchorY: 0 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ // Game variables var player; var skeleton; var walls = []; var floors = []; var exit; var joystick; var gameStarted = false; var lastPlayerX = 0; var lastPlayerY = 0; var lastSkeletonDistance = Infinity; // Create maze layout var mazeLayout = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]; var cellSize = 100; var offsetX = (2048 - mazeLayout[0].length * cellSize) / 2; var offsetY = 200; // Create maze for (var row = 0; row < mazeLayout.length; row++) { for (var col = 0; col < mazeLayout[row].length; col++) { var x = offsetX + col * cellSize; var y = offsetY + row * cellSize; if (mazeLayout[row][col] === 1) { var wall = new Wall(); wall.x = x; wall.y = y; walls.push(wall); game.addChild(wall); } else { var floor = new Floor(); floor.x = x; floor.y = y; floors.push(floor); game.addChild(floor); } } } // Create player at starting position player = new Player(); player.x = offsetX + 1.5 * cellSize; player.y = offsetY + 1.5 * cellSize; lastPlayerX = player.x; lastPlayerY = player.y; game.addChild(player); // Create skeleton at bottom of maze skeleton = new Skeleton(); skeleton.x = offsetX + 18.5 * cellSize; skeleton.y = offsetY + 13.5 * cellSize; game.addChild(skeleton); // Create exit at top right exit = new Exit(); exit.x = offsetX + 18.5 * cellSize; exit.y = offsetY + 1.5 * cellSize; game.addChild(exit); // Create joystick joystick = new Joystick(); joystick.x = 200; joystick.y = 2732 - 200; game.addChild(joystick); // UI elements var instructionText = new Text2('Use joystick to move. Escape the mine!', { size: 60, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); LK.gui.top.addChild(instructionText); instructionText.y = 100; var distanceText = new Text2('', { size: 50, fill: 0xFF4444 }); distanceText.anchor.set(0.5, 0); LK.gui.top.addChild(distanceText); distanceText.y = 180; function checkWallCollision(x, y) { var col = Math.floor((x - offsetX) / cellSize); var row = Math.floor((y - offsetY) / cellSize); if (row < 0 || row >= mazeLayout.length || col < 0 || col >= mazeLayout[0].length) { return true; } return mazeLayout[row][col] === 1; } game.update = function () { // Check if player reached exit if (player.intersects(exit)) { LK.getSound('escape').play(); LK.showYouWin(); return; } // Check if skeleton caught player var skeletonDistance = Math.sqrt(Math.pow(player.x - skeleton.x, 2) + Math.pow(player.y - skeleton.y, 2)); if (!lastSkeletonDistance) lastSkeletonDistance = skeletonDistance; if (lastSkeletonDistance > 80 && skeletonDistance <= 80) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } lastSkeletonDistance = skeletonDistance; // Update distance display var distanceToExit = Math.sqrt(Math.pow(player.x - exit.x, 2) + Math.pow(player.y - exit.y, 2)); distanceText.setText('Skeleton Distance: ' + Math.floor(skeletonDistance)); // Create tension effect when skeleton is close if (skeletonDistance < 200) { var intensity = (200 - skeletonDistance) / 200; game.setBackgroundColor(Math.floor(0x1a * (1 + intensity)) << 16 | Math.floor(0x1a * (1 - intensity * 0.5)) << 8 | Math.floor(0x1a * (1 - intensity * 0.5))); } else { game.setBackgroundColor(0x1a1a1a); } }; // Start ambient music LK.playMusic('horror_ambient');
===================================================================
--- original.js
+++ change.js
@@ -81,13 +81,19 @@
self.update = function () {
if (joystick && (joystick.inputX !== 0 || joystick.inputY !== 0)) {
var newX = self.x + joystick.inputX * self.speed;
var newY = self.y + joystick.inputY * self.speed;
- // Check if new position would collide with walls
- if (!checkWallCollision(newX, self.y)) {
+ // Calculate maze boundaries
+ var mazeLeft = offsetX;
+ var mazeRight = offsetX + mazeLayout[0].length * cellSize;
+ var mazeTop = offsetY;
+ var mazeBottom = offsetY + mazeLayout.length * cellSize;
+ // Check boundaries and wall collisions for X movement
+ if (newX >= mazeLeft && newX <= mazeRight && !checkWallCollision(newX, self.y)) {
self.x = newX;
}
- if (!checkWallCollision(self.x, newY)) {
+ // Check boundaries and wall collisions for Y movement
+ if (newY >= mazeTop && newY <= mazeBottom && !checkWallCollision(self.x, newY)) {
self.y = newY;
}
// Play footstep sound occasionally while moving
if (Math.random() < 0.05) {
A guy with a bag over his head with a cross on it. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
The player with a torch in his hand and the monster skeleton dead on the floor with a knife in his head and blood everywhere. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat