added text font
added text color for score
This commit is contained in:
parent
f57f2b0153
commit
e3ce189023
2 changed files with 43 additions and 24 deletions
|
|
@ -8,42 +8,24 @@ const raspberryImagePath: string = "resources/raspberry-rocket.png";
|
||||||
let obstacles: Obstacle[] = [];
|
let obstacles: Obstacle[] = [];
|
||||||
let raspberry: Raspberry;
|
let raspberry: Raspberry;
|
||||||
let paused: boolean;
|
let paused: boolean;
|
||||||
|
let score: number;
|
||||||
|
let hasAlreadyScored: boolean;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
backgroundImage = loadImage(backgroundImagePath);
|
backgroundImage = loadImage(backgroundImagePath);
|
||||||
|
|
||||||
createCanvas(2000, 1000);
|
createCanvas(2000, 1000);
|
||||||
obstacleOffset = width / 3;
|
obstacleOffset = width / 3;
|
||||||
|
|
||||||
|
textSize(150);
|
||||||
|
textFont("resources/JetBrains-Mono-Regular.ttf");
|
||||||
|
|
||||||
setupGame();
|
setupGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
|
||||||
background(backgroundImage)
|
|
||||||
if (!paused) {
|
|
||||||
raspberry.update();
|
|
||||||
}
|
|
||||||
raspberry.draw();
|
|
||||||
|
|
||||||
obstacles.forEach((obstacle) => {
|
|
||||||
if (!paused) {
|
|
||||||
obstacle.update();
|
|
||||||
checkObstacleReset(obstacle);
|
|
||||||
}
|
|
||||||
|
|
||||||
obstacle.draw();
|
|
||||||
});
|
|
||||||
if (!paused) {
|
|
||||||
if (obstacles[0].collides(raspberry)) {
|
|
||||||
setupGame();
|
|
||||||
}
|
|
||||||
obstacles[0].draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupGame() {
|
function setupGame() {
|
||||||
paused = true;
|
paused = true;
|
||||||
|
|
||||||
|
score = 0;
|
||||||
raspberry = new Raspberry();
|
raspberry = new Raspberry();
|
||||||
raspberry.image = raspberryImagePath;
|
raspberry.image = raspberryImagePath;
|
||||||
|
|
||||||
|
|
@ -70,14 +52,51 @@ function setupGame() {
|
||||||
obstacles.forEach((obstacle) => obstacle.resetPosition(false));
|
obstacles.forEach((obstacle) => obstacle.resetPosition(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
background(backgroundImage)
|
||||||
|
if (!paused) {
|
||||||
|
raspberry.update();
|
||||||
|
}
|
||||||
|
raspberry.draw();
|
||||||
|
|
||||||
|
obstacles.forEach((obstacle) => {
|
||||||
|
if (!paused) {
|
||||||
|
obstacle.update();
|
||||||
|
checkObstacleReset(obstacle);
|
||||||
|
}
|
||||||
|
|
||||||
|
obstacle.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!paused) {
|
||||||
|
if (obstacles[0].collides(raspberry)) {
|
||||||
|
setupGame();
|
||||||
|
}
|
||||||
|
checkRaspberryScore();
|
||||||
|
obstacles[0].draw();
|
||||||
|
}
|
||||||
|
push();
|
||||||
|
fill(200, 100, 60);
|
||||||
|
text(score, width / 2, height / 10, width, height);
|
||||||
|
pop();
|
||||||
|
}
|
||||||
|
|
||||||
function checkObstacleReset(obstacle: Obstacle) {
|
function checkObstacleReset(obstacle: Obstacle) {
|
||||||
if (obstacle.position.x < -obstacleWidth) {
|
if (obstacle.position.x < -obstacleWidth) {
|
||||||
obstacle.resetPosition(true);
|
obstacle.resetPosition(true);
|
||||||
obstacles.shift();
|
obstacles.shift();
|
||||||
obstacles.push(obstacle);
|
obstacles.push(obstacle);
|
||||||
|
hasAlreadyScored = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkRaspberryScore() {
|
||||||
|
if ((obstacles[0].position.x + obstacles[0].width / 2) < (raspberry.position.x + raspberry.width / 2)
|
||||||
|
&& !hasAlreadyScored) {
|
||||||
|
score += 1;
|
||||||
|
hasAlreadyScored = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function keyPressed() {
|
function keyPressed() {
|
||||||
if (key.toLowerCase() == "k") {
|
if (key.toLowerCase() == "k") {
|
||||||
|
|
|
||||||
BIN
frontend/resources/JetBrains-Mono-Regular.ttf
Normal file
BIN
frontend/resources/JetBrains-Mono-Regular.ttf
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue