Pause
This commit is contained in:
parent
db9fdf5932
commit
f1bc1780ef
1 changed files with 20 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ const raspberryImagePath: string = "resources/raspberry-rocket.png";
|
|||
|
||||
let obstacles: Obstacle[] = [];
|
||||
let raspberry: Raspberry;
|
||||
let paused: boolean;
|
||||
|
||||
function setup() {
|
||||
backgroundImage = loadImage(backgroundImagePath);
|
||||
|
|
@ -19,24 +20,30 @@ function setup() {
|
|||
|
||||
function draw() {
|
||||
background(backgroundImage)
|
||||
raspberry.draw();
|
||||
if (!paused) {
|
||||
raspberry.update();
|
||||
}
|
||||
raspberry.draw();
|
||||
|
||||
obstacles.forEach((obstacle) => {
|
||||
if (!paused) {
|
||||
obstacle.update();
|
||||
checkObstacleReset(obstacle);
|
||||
}
|
||||
|
||||
obstacle.draw();
|
||||
obstacle.update();
|
||||
|
||||
checkObstacleReset(obstacle);
|
||||
});
|
||||
|
||||
if (!paused) {
|
||||
if (obstacles[0].collides(raspberry)) {
|
||||
setupGame();
|
||||
}
|
||||
obstacles[0].draw();
|
||||
}
|
||||
}
|
||||
|
||||
function setupGame() {
|
||||
paused = true;
|
||||
|
||||
raspberry = new Raspberry();
|
||||
raspberry.image = raspberryImagePath;
|
||||
raspberry.showHitbox = true;
|
||||
|
|
@ -77,4 +84,9 @@ function keyPressed() {
|
|||
if (key.toLowerCase() == "k") {
|
||||
raspberry.boost();
|
||||
}
|
||||
if (key == "Escape") {
|
||||
paused = true;
|
||||
} else if (paused) {
|
||||
paused = false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue