User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'split')' in or related to this line: 'phaseText.setText(phaseText.text.split('(')[0] + '(' + secondsLeft + 's)');' Line Number: 3141
User prompt
el impostor pot sabotear electricitat,oxigen,portes de la nau,reactor i conexions que fa que te oculti la barra de task i apaga las cameras
User prompt
fes les portes que el impostor pot tancar
User prompt
fes un boto per obrir las camaras
User prompt
fes las camaras i la sala de camaras
User prompt
fes la task de els cables
User prompt
fes un boto per fer las tasks
User prompt
fes els pasadisos de la nau del among us
User prompt
fes que el spawn no pugui apareixer en un mur
User prompt
fes las tasks de among us
User prompt
crea un boto per reportar
User prompt
fes que es pugui skip la votacio de emergencia
User prompt
crea el boto de sabotages per el impostor
User prompt
fes que el impostor mati a tripulants si nosaltres no ho som
User prompt
Please fix the bug: 'TypeError: taskGraphics.removeFromParent is not a function' in or related to this line: 'taskGraphics.removeFromParent();' Line Number: 182
User prompt
fes que els tripulants facin les tasques
User prompt
fes que els murs no es puguin atravesar
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'tween.to(killButton, {' Line Number: 814 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
fes que el impostor pugui matar a els tripulants
User prompt
fes que la camara segueixi al jugador
User prompt
fes la nau de el among us
User prompt
pots triar en ser el impostor o un tripulant
User prompt
fes varias tasques per las misions
User prompt
posa una barra de progres de las tasques
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Player = Container.expand(function (isImpostor, color, id) { var self = Container.call(this); self.isImpostor = isImpostor || false; self.playerColor = color || 0x00ff00; self.playerId = id || 0; self.isAlive = true; self.speed = 3; self.targetX = 0; self.targetY = 0; self.tasksCompleted = 0; self.maxTasks = 5; self.canVote = true; self.lastKillTime = 0; self.killCooldown = 30000; // 30 seconds self.currentTask = null; // Track current task being worked on self.taskCompletionTimer = 0; // Timer for task completion var playerGraphics = self.attachAsset(self.isImpostor ? 'impostor' : 'crewmate', { anchorX: 0.5, anchorY: 0.5 }); if (!self.isImpostor) { playerGraphics.tint = self.playerColor; } self.moveTo = function (x, y) { var playerSize = 80; // Player width/height // Only set target if destination is not inside a wall if (!checkWallCollision(x, y, playerSize, playerSize)) { self.targetX = x; self.targetY = y; } else { // Keep current position as target if new position would collide self.targetX = self.x; self.targetY = self.y; } }; self.eliminate = function () { if (self.isAlive) { self.isAlive = false; self.alpha = 0.3; LK.getSound('eliminate').play(); } }; self.completeTask = function () { if (!self.isImpostor && self.isAlive) { self.tasksCompleted++; LK.getSound('taskComplete').play(); return true; } return false; }; self.canKill = function () { return self.isImpostor && self.isAlive && LK.ticks - self.lastKillTime > self.killCooldown; }; self.kill = function (target) { if (self.canKill() && target.isAlive && !target.isImpostor) { target.eliminate(); self.lastKillTime = LK.ticks; return true; } return false; }; self.update = function () { if (!self.isAlive) return; // Move towards target var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { var newX = self.x + dx / distance * self.speed; var newY = self.y + dy / distance * self.speed; var playerSize = 80; // Player width/height // Check collision before moving if (!checkWallCollision(newX, newY, playerSize, playerSize)) { self.x = newX; self.y = newY; } else { // Try moving only on X axis if (!checkWallCollision(newX, self.y, playerSize, playerSize)) { self.x = newX; } else if (!checkWallCollision(self.x, newY, playerSize, playerSize)) { // Try moving only on Y axis self.y = newY; } } } }; return self; }); var Task = Container.expand(function (x, y, id, taskType) { var self = Container.call(this); self.taskId = id || 0; self.isCompleted = false; self.x = x; self.y = y; self.taskType = taskType || 'basic'; self.completionProgress = 0; self.requiredClicks = 1; self.completionTime = 0; self.isBeingCompleted = false; // Set task properties based on type switch (self.taskType) { case 'electrical': self.requiredClicks = 3; self.assetName = 'electricalTask'; self.taskName = 'Fix Wiring'; break; case 'engine': self.requiredClicks = 5; self.assetName = 'engineTask'; self.taskName = 'Fuel Engines'; break; case 'reactor': self.requiredClicks = 7; self.assetName = 'reactorTask'; self.taskName = 'Stabilize Reactor'; break; case 'navigation': self.requiredClicks = 4; self.assetName = 'navigationTask'; self.taskName = 'Chart Course'; break; case 'medical': self.requiredClicks = 6; self.assetName = 'medicalTask'; self.taskName = 'Submit Scan'; break; default: self.requiredClicks = 1; self.assetName = 'task'; self.taskName = 'Basic Task'; break; } var taskGraphics = self.attachAsset(self.assetName, { anchorX: 0.5, anchorY: 0.5 }); // Add task name text var taskNameText = new Text2(self.taskName, { size: 24, fill: 0xFFFFFF }); taskNameText.anchor.set(0.5, 0); taskNameText.y = -50; self.addChild(taskNameText); self.complete = function () { if (!self.isCompleted) { self.isCompleted = true; taskGraphics.removeFromParent(); taskNameText.removeFromParent(); var completedGraphics = self.attachAsset('taskCompleted', { anchorX: 0.5, anchorY: 0.5 }); var completedText = new Text2('Complete', { size: 20, fill: 0x00FF00 }); completedText.anchor.set(0.5, 0); completedText.y = -40; self.addChild(completedText); return true; } return false; }; self.down = function (x, y, obj) { if (currentPlayer && currentPlayer.isAlive && !currentPlayer.isImpostor) { var distance = Math.sqrt(Math.pow(currentPlayer.x - self.x, 2) + Math.pow(currentPlayer.y - self.y, 2)); if (distance < 100 && !self.isCompleted) { self.completionProgress++; // Visual feedback for multi-click tasks if (self.requiredClicks > 1) { var progressText = new Text2(self.completionProgress + '/' + self.requiredClicks, { size: 32, fill: 0xFFFF00 }); progressText.anchor.set(0.5, 0); progressText.y = 50; self.addChild(progressText); // Remove old progress text if (self.lastProgressText) { self.lastProgressText.removeFromParent(); } self.lastProgressText = progressText; // Flash effect for progress tween(taskGraphics, { alpha: 0.5 }, { duration: 100, onFinish: function onFinish() { tween(taskGraphics, { alpha: 1.0 }, { duration: 100 }); } }); } if (self.completionProgress >= self.requiredClicks) { self.complete(); currentPlayer.completeTask(); completedTasks++; updateTaskProgress(); } } } }; return self; }); var VoteButton = Container.expand(function (playerId, x, y) { var self = Container.call(this); self.playerId = playerId; self.x = x; self.y = y; self.votes = 0; var buttonGraphics = self.attachAsset('voteButton', { anchorX: 0.5, anchorY: 0.5 }); var voteText = new Text2('Vote Player ' + playerId, { size: 40, fill: 0xFFFFFF }); voteText.anchor.set(0.5, 0.5); self.addChild(voteText); self.down = function (x, y, obj) { if (votingPhase && currentPlayer && currentPlayer.canVote) { self.votes++; currentPlayer.canVote = false; LK.getSound('vote').play(); voteText.setText('Votes: ' + self.votes); // Check if voting is complete var alivePlayers = players.filter(function (p) { return p.isAlive; }); var totalVotes = voteButtons.reduce(function (sum, button) { return sum + button.votes; }, 0); if (totalVotes >= alivePlayers.length) { endVoting(); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var players = []; var tasks = []; var currentPlayer = null; var totalTasks = 15; var completedTasks = 0; var impostorCount = 2; var votingPhase = false; var voteButtons = []; var gamePhase = 'roleSelection'; // 'roleSelection', 'playing', 'voting', 'gameOver' var meetingCooldown = 0; var meetingCooldownTime = 15000; // 15 seconds var roleSelectionComplete = false; var killButton = null; var killTarget = null; // UI Elements var taskProgressText = new Text2('Tasks: 0/' + totalTasks, { size: 60, fill: 0xFFFFFF }); taskProgressText.anchor.set(0.5, 0); LK.gui.top.addChild(taskProgressText); // Progress Bar Elements var progressBarBackground = LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 8, scaleY: 0.5, x: 0, y: 80 }); progressBarBackground.tint = 0x333333; LK.gui.top.addChild(progressBarBackground); var progressBarFill = LK.getAsset('wall', { anchorX: 0, anchorY: 0.5, scaleX: 0, scaleY: 0.4, x: -800, y: 80 }); progressBarFill.tint = 0x00ff00; LK.gui.top.addChild(progressBarFill); var phaseText = new Text2('Complete Tasks or Find Impostors!', { size: 50, fill: 0xFFFF00 }); phaseText.anchor.set(0.5, 0); phaseText.y = 100; LK.gui.top.addChild(phaseText); var playerCountText = new Text2('', { size: 40, fill: 0xFFFFFF }); playerCountText.anchor.set(0, 0); LK.gui.topRight.addChild(playerCountText); // Role selection UI var roleSelectionTitle = new Text2('Choose Your Role', { size: 80, fill: 0xFFFFFF }); roleSelectionTitle.anchor.set(0.5, 0.5); roleSelectionTitle.x = 1024; roleSelectionTitle.y = 800; game.addChild(roleSelectionTitle); var crewButton = LK.getAsset('voteButton', { anchorX: 0.5, anchorY: 0.5, x: 700, y: 1200, scaleX: 1.5, scaleY: 1.5 }); crewButton.tint = 0x00ff00; game.addChild(crewButton); var crewButtonText = new Text2('CREW MEMBER', { size: 50, fill: 0xFFFFFF }); crewButtonText.anchor.set(0.5, 0.5); crewButtonText.x = 700; crewButtonText.y = 1200; game.addChild(crewButtonText); var impostorButton = LK.getAsset('voteButton', { anchorX: 0.5, anchorY: 0.5, x: 1348, y: 1200, scaleX: 1.5, scaleY: 1.5 }); impostorButton.tint = 0xff0000; game.addChild(impostorButton); var impostorButtonText = new Text2('IMPOSTOR', { size: 50, fill: 0xFFFFFF }); impostorButtonText.anchor.set(0.5, 0.5); impostorButtonText.x = 1348; impostorButtonText.y = 1200; game.addChild(impostorButtonText); // Role selection instructions var instructionText = new Text2('Choose your role and start the game!', { size: 40, fill: 0xFFFF00 }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 1400; game.addChild(instructionText); // Create spaceship walls var walls = []; function createWalls() { // Outer perimeter walls var topWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 10, x: 1024, y: 200 })); walls.push(topWall); var bottomWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 10, x: 1024, y: 2500 })); walls.push(bottomWall); var leftWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 10, x: 200, y: 1366 })); walls.push(leftWall); var rightWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 10, x: 1800, y: 1366 })); walls.push(rightWall); // Upper corridor walls var upperLeftWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, x: 550, y: 600 })); walls.push(upperLeftWall); var upperRightWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, x: 1500, y: 600 })); walls.push(upperRightWall); // Central corridor walls var centralTopWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, x: 1024, y: 1000 })); walls.push(centralTopWall); var centralBottomWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 4, x: 1024, y: 1700 })); walls.push(centralBottomWall); // Room dividers var leftRoomWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 3, x: 700, y: 1000 })); walls.push(leftRoomWall); var rightRoomWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 3, x: 1350, y: 1000 })); walls.push(rightRoomWall); // Lower corridor walls var lowerLeftWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, x: 550, y: 2100 })); walls.push(lowerLeftWall); var lowerRightWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, x: 1500, y: 2100 })); walls.push(lowerRightWall); // Engine room walls var engineLeftWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 2, x: 400, y: 1800 })); walls.push(engineLeftWall); var engineRightWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 2, x: 1650, y: 1800 })); walls.push(engineRightWall); // Security room walls var securityWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, x: 1024, y: 800 })); walls.push(securityWall); // Medical bay walls var medicalWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 1.5, x: 1200, y: 1500 })); walls.push(medicalWall); // Reactor room walls var reactorWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5, scaleY: 1.5, x: 850, y: 1500 })); walls.push(reactorWall); // Add spaceship floor tiles for (var floorX = 300; floorX < 1800; floorX += 100) { for (var floorY = 300; floorY < 2400; floorY += 100) { var floorTile = game.addChild(LK.getAsset('shipFloor', { anchorX: 0.5, anchorY: 0.5, x: floorX, y: floorY })); // Send floor tiles to back game.setChildIndex(floorTile, 0); } } // Add main corridor highlights var mainCorridor = game.addChild(LK.getAsset('shipHall', { anchorX: 0.5, anchorY: 0.5, scaleX: 8, scaleY: 4, x: 1024, y: 1366 })); game.setChildIndex(mainCorridor, 1); // Add upper corridor var upperCorridor = game.addChild(LK.getAsset('shipHall', { anchorX: 0.5, anchorY: 0.5, scaleX: 6, scaleY: 2, x: 1024, y: 700 })); game.setChildIndex(upperCorridor, 1); // Add lower corridor var lowerCorridor = game.addChild(LK.getAsset('shipHall', { anchorX: 0.5, anchorY: 0.5, scaleX: 6, scaleY: 2, x: 1024, y: 2000 })); game.setChildIndex(lowerCorridor, 1); } // Create emergency button var emergencyButton = game.addChild(LK.getAsset('emergencyButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); emergencyButton.down = function (x, y, obj) { if (gamePhase === 'playing' && meetingCooldown <= 0) { startEmergencyMeeting(); } }; // Create kill button (initially hidden) killButton = LK.getAsset('killButton', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); killButton.alpha = 0; killButton.visible = false; LK.gui.center.addChild(killButton); var killButtonText = new Text2('KILL', { size: 40, fill: 0xFFFFFF }); killButtonText.anchor.set(0.5, 0.5); killButton.addChild(killButtonText); killButton.down = function (x, y, obj) { if (killTarget && currentPlayer && currentPlayer.isImpostor && currentPlayer.canKill()) { if (currentPlayer.kill(killTarget)) { updatePlayerCount(); hideKillButton(); } } }; // Role selection button handlers crewButton.down = function (x, y, obj) { if (gamePhase === 'roleSelection') { selectRole(false); // false = crew member } }; impostorButton.down = function (x, y, obj) { if (gamePhase === 'roleSelection') { selectRole(true); // true = impostor } }; // Initialize players function selectRole(isImpostor) { // Hide role selection UI roleSelectionTitle.destroy(); crewButton.destroy(); crewButtonText.destroy(); impostorButton.destroy(); impostorButtonText.destroy(); instructionText.destroy(); // Initialize game with selected role initializePlayers(isImpostor); updatePlayerCount(); gamePhase = 'playing'; phaseText.setText('Complete Tasks or Find Impostors!'); } function initializePlayers(playerIsImpostor) { var colors = [0x00ff00, 0x0000ff, 0xff00ff, 0x00ffff, 0xffa500, 0xffff00, 0x8a2be2, 0xffc0cb]; // Create current player first with selected role currentPlayer = new Player(playerIsImpostor, colors[0], 0); currentPlayer.x = 400 + Math.random() * 1200; currentPlayer.y = 400 + Math.random() * 1800; currentPlayer.targetX = currentPlayer.x; currentPlayer.targetY = currentPlayer.y; players.push(currentPlayer); game.addChild(currentPlayer); // Create other players var remainingImpostors = playerIsImpostor ? impostorCount - 1 : impostorCount; for (var i = 1; i < 8; i++) { var isImpostor = i <= remainingImpostors; var player = new Player(isImpostor, colors[i], i); // Random spawn position player.x = 400 + Math.random() * 1200; player.y = 400 + Math.random() * 1800; player.targetX = player.x; player.targetY = player.y; players.push(player); game.addChild(player); } } // Initialize tasks function initializeTasks() { var taskTypes = ['basic', 'electrical', 'engine', 'reactor', 'navigation', 'medical']; var taskAreas = [{ x: 400, y: 500, width: 300, height: 200 }, // Upper left area { x: 1200, y: 500, width: 300, height: 200 }, // Upper right area { x: 400, y: 1200, width: 300, height: 200 }, // Center left area { x: 1200, y: 1200, width: 300, height: 200 }, // Center right area { x: 400, y: 2000, width: 300, height: 200 }, // Lower left area { x: 1200, y: 2000, width: 300, height: 200 }, // Lower right area { x: 800, y: 800, width: 400, height: 300 }, // Central area { x: 800, y: 1600, width: 400, height: 300 } // Lower central area ]; for (var i = 0; i < totalTasks; i++) { // Distribute tasks across different areas var area = taskAreas[i % taskAreas.length]; var taskX = area.x + Math.random() * area.width; var taskY = area.y + Math.random() * area.height; // Assign task type based on distribution var taskType = taskTypes[Math.floor(Math.random() * taskTypes.length)]; // Ensure variety - don't have too many of the same type consecutively if (i > 0 && tasks[i - 1].taskType === taskType && Math.random() < 0.5) { taskType = taskTypes[Math.floor(Math.random() * taskTypes.length)]; } var task = new Task(taskX, taskY, i, taskType); tasks.push(task); game.addChild(task); } } function updateTaskProgress() { taskProgressText.setText('Tasks: ' + completedTasks + '/' + totalTasks); // Update progress bar var progressPercentage = completedTasks / totalTasks; progressBarFill.scaleX = progressPercentage * 8; // Check win condition if (completedTasks >= totalTasks) { endGame('crew'); } } function updatePlayerCount() { var aliveCrew = players.filter(function (p) { return p.isAlive && !p.isImpostor; }).length; var aliveImpostors = players.filter(function (p) { return p.isAlive && p.isImpostor; }).length; playerCountText.setText('Crew: ' + aliveCrew + ' | Impostors: ' + aliveImpostors); // Check win conditions if (aliveImpostors >= aliveCrew) { endGame('impostors'); } else if (aliveImpostors === 0) { endGame('crew'); } } function startEmergencyMeeting() { gamePhase = 'voting'; votingPhase = true; meetingCooldown = meetingCooldownTime; LK.getSound('emergency').play(); phaseText.setText('Emergency Meeting - Vote!'); // Create vote buttons var alivePlayers = players.filter(function (p) { return p.isAlive; }); var buttonWidth = 200; var startX = (2048 - alivePlayers.length * buttonWidth) / 2; for (var i = 0; i < alivePlayers.length; i++) { var button = new VoteButton(alivePlayers[i].playerId, startX + i * buttonWidth, 2400); voteButtons.push(button); game.addChild(button); } // Reset player voting ability players.forEach(function (p) { if (p.isAlive) { p.canVote = true; } }); } function endVoting() { votingPhase = false; // Find player with most votes var maxVotes = 0; var ejectedPlayer = null; for (var i = 0; i < voteButtons.length; i++) { if (voteButtons[i].votes > maxVotes) { maxVotes = voteButtons[i].votes; ejectedPlayer = players.find(function (p) { return p.playerId === voteButtons[i].playerId; }); } } // Eject player with most votes if (ejectedPlayer && maxVotes > 0) { ejectedPlayer.eliminate(); if (ejectedPlayer.isImpostor) { phaseText.setText('Impostor Ejected!'); } else { phaseText.setText('Innocent Ejected!'); } } else { phaseText.setText('No One Ejected!'); } // Clean up vote buttons voteButtons.forEach(function (button) { button.destroy(); }); voteButtons = []; // Return to playing phase after delay LK.setTimeout(function () { gamePhase = 'playing'; phaseText.setText('Complete Tasks or Find Impostors!'); updatePlayerCount(); }, 3000); } function showKillButton(target) { if (killButton && currentPlayer && currentPlayer.isImpostor) { killTarget = target; killButton.alpha = 1; killButton.visible = true; // Flash effect to draw attention tween(killButton, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, onFinish: function onFinish() { tween(killButton, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); } }); } } function hideKillButton() { if (killButton) { killTarget = null; killButton.alpha = 0; killButton.visible = false; } } // Collision detection function function checkWallCollision(x, y, playerWidth, playerHeight) { var playerLeft = x - playerWidth / 2; var playerRight = x + playerWidth / 2; var playerTop = y - playerHeight / 2; var playerBottom = y + playerHeight / 2; for (var i = 0; i < walls.length; i++) { var wall = walls[i]; var wallLeft = wall.x - wall.width / 2; var wallRight = wall.x + wall.width / 2; var wallTop = wall.y - wall.height / 2; var wallBottom = wall.y + wall.height / 2; // Check if player rectangle intersects with wall rectangle if (playerLeft < wallRight && playerRight > wallLeft && playerTop < wallBottom && playerBottom > wallTop) { return true; } } return false; } function endGame(winner) { gamePhase = 'gameOver'; if (winner === 'crew') { phaseText.setText('Crew Wins!'); LK.showYouWin(); } else { phaseText.setText('Impostors Win!'); LK.showGameOver(); } } // AI behavior for other players function updateAI() { players.forEach(function (player) { if (player === currentPlayer || !player.isAlive) return; // Crew member AI - complete tasks if (!player.isImpostor && gamePhase === 'playing') { // Find nearby incomplete tasks var nearbyTasks = tasks.filter(function (task) { if (task.isCompleted) return false; var distance = Math.sqrt(Math.pow(task.x - player.x, 2) + Math.pow(task.y - player.y, 2)); return distance < 100; }); // If near a task, complete it if (nearbyTasks.length > 0) { var task = nearbyTasks[0]; task.completionProgress++; // Complete task if enough progress if (task.completionProgress >= task.requiredClicks) { task.complete(); player.completeTask(); completedTasks++; updateTaskProgress(); } } else { // Move towards nearest incomplete task var incompleteTasks = tasks.filter(function (task) { return !task.isCompleted; }); if (incompleteTasks.length > 0) { // Find closest task var closestTask = incompleteTasks[0]; var closestDistance = Math.sqrt(Math.pow(closestTask.x - player.x, 2) + Math.pow(closestTask.y - player.y, 2)); for (var i = 1; i < incompleteTasks.length; i++) { var task = incompleteTasks[i]; var distance = Math.sqrt(Math.pow(task.x - player.x, 2) + Math.pow(task.y - player.y, 2)); if (distance < closestDistance) { closestTask = task; closestDistance = distance; } } // Move towards closest task with some randomness if (Math.random() < 0.1) { player.moveTo(closestTask.x + (Math.random() - 0.5) * 50, closestTask.y + (Math.random() - 0.5) * 50); } } } } // Random movement for all players (less frequent now) else if (Math.random() < 0.01) { player.moveTo(400 + Math.random() * 1200, 400 + Math.random() * 1800); } // Impostor AI if (player.isImpostor && gamePhase === 'playing') { // Try to kill nearby crew members var nearbyTargets = players.filter(function (p) { if (p === player || !p.isAlive || p.isImpostor) return false; var distance = Math.sqrt(Math.pow(p.x - player.x, 2) + Math.pow(p.y - player.y, 2)); return distance < 120; }); if (nearbyTargets.length > 0 && player.canKill()) { player.kill(nearbyTargets[0]); updatePlayerCount(); } } }); } // Initialize game createWalls(); initializeTasks(); // Don't initialize players yet - wait for role selection // Game controls game.down = function (x, y, obj) { if (gamePhase === 'playing' && currentPlayer && currentPlayer.isAlive) { currentPlayer.moveTo(x, y); } }; game.update = function () { if (gamePhase === 'roleSelection') { // Don't update game logic during role selection return; } // Update camera to follow current player if (currentPlayer && currentPlayer.isAlive && gamePhase === 'playing') { // Calculate target camera position (center player on screen) var targetX = 1024 - currentPlayer.x; // Center horizontally var targetY = 1366 - currentPlayer.y; // Center vertically // Smooth camera movement with lerp var lerpFactor = 0.1; var currentX = game.x; var currentY = game.y; game.x = currentX + (targetX - currentX) * lerpFactor; game.y = currentY + (targetY - currentY) * lerpFactor; // Clamp camera to keep game world bounds in view var minX = 1024 - 1800; // Don't go past right edge var maxX = 1024 - 200; // Don't go past left edge var minY = 1366 - 2500; // Don't go past bottom edge var maxY = 1366 - 200; // Don't go past top edge game.x = Math.max(minX, Math.min(maxX, game.x)); game.y = Math.max(minY, Math.min(maxY, game.y)); } // Update cooldowns if (meetingCooldown > 0) { meetingCooldown -= 16.67; // Roughly 1 frame at 60fps } // Update AI if (LK.ticks % 30 === 0) { // Update AI twice per second for better task completion updateAI(); } // Update current player impostor kill opportunities if (currentPlayer && currentPlayer.isImpostor && gamePhase === 'playing') { var nearbyTargets = players.filter(function (p) { if (p === currentPlayer || !p.isAlive || p.isImpostor) return false; var distance = Math.sqrt(Math.pow(p.x - currentPlayer.x, 2) + Math.pow(p.y - currentPlayer.y, 2)); return distance < 120; }); // Show kill button if there are targets and can kill if (nearbyTargets.length > 0 && currentPlayer.canKill()) { // Add visual indicator for kill opportunity if (LK.ticks % 30 < 15) { nearbyTargets[0].alpha = 0.7; } else { nearbyTargets[0].alpha = 1.0; } // Show kill button for closest target if (!killButton.visible) { showKillButton(nearbyTargets[0]); } } else { // Hide kill button if no targets or can't kill if (killButton.visible) { hideKillButton(); } // Reset target alphas players.forEach(function (p) { if (!p.isImpostor) { p.alpha = 1.0; } }); } } };
===================================================================
--- original.js
+++ change.js
@@ -20,8 +20,10 @@
self.maxTasks = 5;
self.canVote = true;
self.lastKillTime = 0;
self.killCooldown = 30000; // 30 seconds
+ self.currentTask = null; // Track current task being worked on
+ self.taskCompletionTimer = 0; // Timer for task completion
var playerGraphics = self.attachAsset(self.isImpostor ? 'impostor' : 'crewmate', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -868,10 +870,53 @@
// AI behavior for other players
function updateAI() {
players.forEach(function (player) {
if (player === currentPlayer || !player.isAlive) return;
- // Random movement
- if (Math.random() < 0.02) {
+ // Crew member AI - complete tasks
+ if (!player.isImpostor && gamePhase === 'playing') {
+ // Find nearby incomplete tasks
+ var nearbyTasks = tasks.filter(function (task) {
+ if (task.isCompleted) return false;
+ var distance = Math.sqrt(Math.pow(task.x - player.x, 2) + Math.pow(task.y - player.y, 2));
+ return distance < 100;
+ });
+ // If near a task, complete it
+ if (nearbyTasks.length > 0) {
+ var task = nearbyTasks[0];
+ task.completionProgress++;
+ // Complete task if enough progress
+ if (task.completionProgress >= task.requiredClicks) {
+ task.complete();
+ player.completeTask();
+ completedTasks++;
+ updateTaskProgress();
+ }
+ } else {
+ // Move towards nearest incomplete task
+ var incompleteTasks = tasks.filter(function (task) {
+ return !task.isCompleted;
+ });
+ if (incompleteTasks.length > 0) {
+ // Find closest task
+ var closestTask = incompleteTasks[0];
+ var closestDistance = Math.sqrt(Math.pow(closestTask.x - player.x, 2) + Math.pow(closestTask.y - player.y, 2));
+ for (var i = 1; i < incompleteTasks.length; i++) {
+ var task = incompleteTasks[i];
+ var distance = Math.sqrt(Math.pow(task.x - player.x, 2) + Math.pow(task.y - player.y, 2));
+ if (distance < closestDistance) {
+ closestTask = task;
+ closestDistance = distance;
+ }
+ }
+ // Move towards closest task with some randomness
+ if (Math.random() < 0.1) {
+ player.moveTo(closestTask.x + (Math.random() - 0.5) * 50, closestTask.y + (Math.random() - 0.5) * 50);
+ }
+ }
+ }
+ }
+ // Random movement for all players (less frequent now)
+ else if (Math.random() < 0.01) {
player.moveTo(400 + Math.random() * 1200, 400 + Math.random() * 1800);
}
// Impostor AI
if (player.isImpostor && gamePhase === 'playing') {
@@ -926,10 +971,10 @@
if (meetingCooldown > 0) {
meetingCooldown -= 16.67; // Roughly 1 frame at 60fps
}
// Update AI
- if (LK.ticks % 60 === 0) {
- // Update AI once per second
+ if (LK.ticks % 30 === 0) {
+ // Update AI twice per second for better task completion
updateAI();
}
// Update current player impostor kill opportunities
if (currentPlayer && currentPlayer.isImpostor && gamePhase === 'playing') {
crewmate among us. In-Game asset. 2d. High contrast. No shadows
electricalTask. In-Game asset. 2d. High contrast. No shadows
emergencyButton. In-Game asset. 2d. High contrast. No shadows
voteButton among us. In-Game asset. 2d. High contrast. No shadows
killButton among us. In-Game asset. 2d. High contrast. No shadows
medicalTask. In-Game asset. 2d. High contrast. No shadows
engineTask among us. In-Game asset. 2d. High contrast. No shadows
navigationTask among us. In-Game asset. 2d. High contrast. No shadows
shipFloor casella. In-Game asset. 2d. High contrast. No shadows
shiphall among us. In-Game asset. 2d. High contrast. No shadows
among us task. In-Game asset. 2d. High contrast. No shadows
wall among us. In-Game asset. 2d. High contrast. No shadows
taskCompleted among us. In-Game asset. 2d. High contrast. No shadows
reactorTask among us. In-Game asset. 2d. High contrast. No shadows
taskButton among us. In-Game asset. 2d. High contrast. No shadows
sabotageButton among us. In-Game asset. 2d. High contrast. No shadows
reportbutton among us. In-Game asset. 2d. High contrast. No shadows
cameraView among us. In-Game asset. 2d. High contrast. No shadows
cameraFrame among us. In-Game asset. 2d. High contrast. No shadows
cameraButton among us. In-Game asset. 2d. High contrast. No shadows
cablePanel among us. In-Game asset. 2d. High contrast. No shadows
cableWire among us. In-Game asset. 2d. High contrast. No shadows
among us door. In-Game asset. 2d. High contrast. No shadows
among us doorButton. In-Game asset. 2d. High contrast. No shadows
among us doorClosed. In-Game asset. 2d. High contrast. No shadows
among us sabotageEffect. In-Game asset. 2d. High contrast. No shadows
among us sabotageIndicator. In-Game asset. 2d. High contrast. No shadows
among us cableConnector. In-Game asset. 2d. High contrast. No shadows
among us sabotageReactorButton. In-Game asset. 2d. High contrast. No shadows
among us sabotageOxygenButton. In-Game asset. 2d. High contrast. No shadows
among us sabotageElectricityButton. In-Game asset. 2d. High contrast. No shadows
among us sabotageDoorsButton. In-Game asset. 2d. High contrast. No shadows
among us sabotageConnectionsButton. In-Game asset. 2d. High contrast. No shadows
among us sewerEntrance. In-Game asset. 2d. High contrast. No shadows