This commit is contained in:
s-prechtl 2022-12-13 10:56:05 +01:00
parent db9fdf5932
commit f1bc1780ef

View file

@ -7,6 +7,7 @@ const raspberryImagePath: string = "resources/raspberry-rocket.png";
let obstacles: Obstacle[] = []; let obstacles: Obstacle[] = [];
let raspberry: Raspberry; let raspberry: Raspberry;
let paused: boolean;
function setup() { function setup() {
backgroundImage = loadImage(backgroundImagePath); backgroundImage = loadImage(backgroundImagePath);
@ -19,24 +20,30 @@ function setup() {
function draw() { function draw() {
background(backgroundImage) background(backgroundImage)
raspberry.draw(); if (!paused) {
raspberry.update(); raspberry.update();
}
raspberry.draw();
obstacles.forEach((obstacle) => { obstacles.forEach((obstacle) => {
if (!paused) {
obstacle.update();
checkObstacleReset(obstacle);
}
obstacle.draw(); obstacle.draw();
obstacle.update();
checkObstacleReset(obstacle);
}); });
if (!paused) {
if (obstacles[0].collides(raspberry)) { if (obstacles[0].collides(raspberry)) {
setupGame(); setupGame();
} }
obstacles[0].draw(); obstacles[0].draw();
} }
}
function setupGame() { function setupGame() {
paused = true;
raspberry = new Raspberry(); raspberry = new Raspberry();
raspberry.image = raspberryImagePath; raspberry.image = raspberryImagePath;
raspberry.showHitbox = true; raspberry.showHitbox = true;
@ -77,4 +84,9 @@ function keyPressed() {
if (key.toLowerCase() == "k") { if (key.toLowerCase() == "k") {
raspberry.boost(); raspberry.boost();
} }
if (key == "Escape") {
paused = true;
} else if (paused) {
paused = false;
}
} }