added PressStart2P-Regular.ttf font
const rename and obstacle for-loop refactor
This commit is contained in:
parent
637a867c7e
commit
a16f1203ff
3 changed files with 16 additions and 27 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
// TODO: Refactor
|
// TODO: Refactor
|
||||||
const pipeImagePath: string = "resources/raspberry-low-res.png";
|
const PIPE_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
||||||
const obstacleWidth: number = 88;
|
const BACKGROUND_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
||||||
|
const RASPBERRY_IMAGE_PATH: string = "resources/raspberry-rocket.png";
|
||||||
|
const OBSTACLE_WIDTH: number = 88;
|
||||||
let obstacleOffset: number;
|
let obstacleOffset: number;
|
||||||
const backgroundImagePath: string = "resources/raspberry-low-res.png";
|
|
||||||
let backgroundImage: any;
|
let backgroundImage: any;
|
||||||
const raspberryImagePath: string = "resources/raspberry-rocket.png";
|
|
||||||
|
|
||||||
let obstacles: Obstacle[] = [];
|
let obstacles: Obstacle[] = [];
|
||||||
let raspberry: Raspberry;
|
let raspberry: Raspberry;
|
||||||
|
|
@ -13,12 +13,12 @@ let score: number;
|
||||||
let hasAlreadyScored: boolean;
|
let hasAlreadyScored: boolean;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
backgroundImage = loadImage(backgroundImagePath);
|
backgroundImage = loadImage(BACKGROUND_IMAGE_PATH);
|
||||||
createCanvas(2000, 1000);
|
createCanvas(2000, 1000);
|
||||||
obstacleOffset = width / 3;
|
obstacleOffset = width / 3;
|
||||||
|
|
||||||
textSize(150);
|
textSize(150);
|
||||||
textFont("resources/JetBrains-Mono-Regular.ttf");
|
textFont("resources/PressStart2P-Regular.ttf");
|
||||||
|
|
||||||
setupGame();
|
setupGame();
|
||||||
}
|
}
|
||||||
|
|
@ -31,29 +31,18 @@ function setupGame() {
|
||||||
|
|
||||||
score = 0;
|
score = 0;
|
||||||
raspberry = new Raspberry();
|
raspberry = new Raspberry();
|
||||||
raspberry.image = raspberryImagePath;
|
raspberry.image = RASPBERRY_IMAGE_PATH;
|
||||||
|
|
||||||
// Create all obstacles
|
// Create all obstacles
|
||||||
// TODO: Loop
|
|
||||||
obstacles = [];
|
obstacles = [];
|
||||||
obstacles.push(new Obstacle(
|
for (let i = 0; i < 3; i++) {
|
||||||
new Position(width, 0),
|
obstacles.push(new Obstacle(
|
||||||
obstacleWidth,
|
new Position(width + obstacleOffset * i, 0),
|
||||||
height,
|
OBSTACLE_WIDTH,
|
||||||
pipeImagePath,
|
height,
|
||||||
));
|
PIPE_IMAGE_PATH,
|
||||||
obstacles.push(new Obstacle(
|
));
|
||||||
new Position(width + obstacleOffset, 0),
|
}
|
||||||
obstacleWidth,
|
|
||||||
height,
|
|
||||||
pipeImagePath,
|
|
||||||
));
|
|
||||||
obstacles.push(new Obstacle(
|
|
||||||
new Position(width + obstacleOffset * 2, 0),
|
|
||||||
obstacleWidth,
|
|
||||||
height,
|
|
||||||
pipeImagePath,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Randomize position of all Obstacles
|
// Randomize position of all Obstacles
|
||||||
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
||||||
|
|
@ -97,7 +86,7 @@ function draw() {
|
||||||
* @param obstacle obstacle to check
|
* @param obstacle obstacle to check
|
||||||
*/
|
*/
|
||||||
function checkObstacleReset(obstacle: Obstacle) {
|
function checkObstacleReset(obstacle: Obstacle) {
|
||||||
if (obstacle.position.x < -obstacleWidth) {
|
if (obstacle.position.x < -OBSTACLE_WIDTH) {
|
||||||
obstacle.resetPosition();
|
obstacle.resetPosition();
|
||||||
obstacles.shift();
|
obstacles.shift();
|
||||||
obstacles.push(obstacle);
|
obstacles.push(obstacle);
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
frontend/resources/PressStart2P-Regular.ttf
Normal file
BIN
frontend/resources/PressStart2P-Regular.ttf
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue