reset button now resets robot and obstacles
parent
f59c20686b
commit
3934ec2ae1
9
game.js
9
game.js
|
|
@ -8,9 +8,8 @@ const ctx = gameCanvas.getContext("2d");
|
||||||
const gameWorld = new GameWorld();
|
const gameWorld = new GameWorld();
|
||||||
|
|
||||||
let pyodideWorker = startPyodideWorker();
|
let pyodideWorker = startPyodideWorker();
|
||||||
let robots = createInitialRobots();
|
let robots = null;//createInitialRobots();
|
||||||
console.log(robots);
|
//gameWorld.addRobot(robots["player"]);
|
||||||
gameWorld.addRobot(robots["player"]);
|
|
||||||
let paused = false;
|
let paused = false;
|
||||||
|
|
||||||
let scale = 1; // Zoom level
|
let scale = 1; // Zoom level
|
||||||
|
|
@ -95,6 +94,8 @@ function resetGame() {
|
||||||
|
|
||||||
// Reset the robots to their initial state
|
// Reset the robots to their initial state
|
||||||
robots = createInitialRobots();
|
robots = createInitialRobots();
|
||||||
|
gameWorld.reset();
|
||||||
|
gameWorld.addRobot(robots["player"]);
|
||||||
|
|
||||||
// Clear the console
|
// Clear the console
|
||||||
consoleElement.innerHTML = "";
|
consoleElement.innerHTML = "";
|
||||||
|
|
@ -123,7 +124,7 @@ function gameLoop() {
|
||||||
requestAnimationFrame(gameLoop);
|
requestAnimationFrame(gameLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetGame(); // Initialize the game and robots
|
||||||
// Start game loop
|
// Start game loop
|
||||||
gameLoop();
|
gameLoop();
|
||||||
|
|
||||||
|
|
|
||||||
13
gameworld.js
13
gameworld.js
|
|
@ -16,6 +16,17 @@ export class GameWorld {
|
||||||
this.robots = [];
|
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([
|
this.addObstacle([
|
||||||
{ x: -100, y: -100 }, // Vertex 1
|
{ x: -100, y: -100 }, // Vertex 1
|
||||||
{ x: 100, y: -100 }, // Vertex 2
|
{ x: 100, y: -100 }, // Vertex 2
|
||||||
|
|
@ -31,8 +42,6 @@ export class GameWorld {
|
||||||
{ x: 280, y: 420 } // Vertex 4
|
{ x: 280, y: 420 } // Vertex 4
|
||||||
], { x: 400, y: 0 });
|
], { x: 400, y: 0 });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue