reset button now resets robot and obstacles

master
Jake 2025-03-29 23:21:01 +08:00
parent f59c20686b
commit 3934ec2ae1
2 changed files with 16 additions and 6 deletions

View File

@ -8,9 +8,8 @@ const ctx = gameCanvas.getContext("2d");
const gameWorld = new GameWorld();
let pyodideWorker = startPyodideWorker();
let robots = createInitialRobots();
console.log(robots);
gameWorld.addRobot(robots["player"]);
let robots = null;//createInitialRobots();
//gameWorld.addRobot(robots["player"]);
let paused = false;
let scale = 1; // Zoom level
@ -95,6 +94,8 @@ function resetGame() {
// Reset the robots to their initial state
robots = createInitialRobots();
gameWorld.reset();
gameWorld.addRobot(robots["player"]);
// Clear the console
consoleElement.innerHTML = "";
@ -123,7 +124,7 @@ function gameLoop() {
requestAnimationFrame(gameLoop);
}
resetGame(); // Initialize the game and robots
// Start game loop
gameLoop();

View File

@ -16,6 +16,17 @@ export class GameWorld {
this.robots = [];
}
reset(){
this.robots = []
this.obstacles = []
Matter.World.clear(this.world); // Clear the world without resetting the engine
console.log(this.obstacles.length);
this.addObstacle([
{ x: -100, y: -100 }, // Vertex 1
{ x: 100, y: -100 }, // Vertex 2
@ -31,8 +42,6 @@ export class GameWorld {
{ x: 280, y: 420 } // Vertex 4
], { x: 400, y: 0 });
}
update() {