Skip to content

Commit

Permalink
add speed HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKappmeyer committed Oct 20, 2023
1 parent ec2162d commit 94a3c80
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,25 @@ function draw() {
textSize(12);
textAlign(LEFT, CENTER);
text("Länge: " + snake.body.length, 5, 10);
text("Highscore: " + snake.highscore, 5, 20);
text("Speed: " + int(25000 / MOVETIME_MS), 5, 30);
text("Boost: ", 5, 45);
text("Highscore: " + snake.highscore, 5, 25);
text("Speed: ", 5, 40);
text("Boost: ", 5, 55);

// draw: speed HUD
stroke(0);
noFill()
rect(50, 35, 70, 10);

fill(100, 0, 0, 150);
rect(50, 35, 3000/MOVETIME_MS, 10);

// draw: boost HUD
drawBoostHud();
stroke(0);
noFill()
rect(50, 50, 70, 10);

fill(0, 100, 0, 150);
rect(50, 50, (snake.currentBoostCapacity / MAX_BOOST) * 70, 10);

// draw: pause overlay
if (!running) {
Expand All @@ -86,15 +99,6 @@ function draw() {
}
}

function drawBoostHud() {
stroke(0);
noFill()
rect(50, 40, 70, 10);

fill(0, 0, 0, 150);
rect(50, 40, (snake.currentBoostCapacity / MAX_BOOST) * 70, 10);
}

// ------------------------------------------------------------------- input
const W_KEY = 87;
const S_KEY = 83;
Expand Down

0 comments on commit 94a3c80

Please sign in to comment.