diff --git a/game.js b/game.js index 6c85c03..7d54a38 100644 --- a/game.js +++ b/game.js @@ -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(); diff --git a/gameworld.js b/gameworld.js index db2e776..ff8f590 100644 --- a/gameworld.js +++ b/gameworld.js @@ -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() {