bissl mini refactor
This commit is contained in:
parent
b88b364343
commit
2a440e09e0
1 changed files with 12 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ const PIPE_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
||||||
const BACKGROUND_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
const BACKGROUND_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
||||||
const RASPBERRY_IMAGE_PATH: string = "resources/raspberry-rocket.png";
|
const RASPBERRY_IMAGE_PATH: string = "resources/raspberry-rocket.png";
|
||||||
const OBSTACLE_WIDTH: number = 88;
|
const OBSTACLE_WIDTH: number = 88;
|
||||||
|
const OBSTACLE_COUNT: number = 3;
|
||||||
let obstacleOffset: number;
|
let obstacleOffset: number;
|
||||||
let backgroundImage: any;
|
let backgroundImage: any;
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ function setup() {
|
||||||
* Sets up the constants needed for the game.
|
* Sets up the constants needed for the game.
|
||||||
*/
|
*/
|
||||||
function setupObstacleConsts() {
|
function setupObstacleConsts() {
|
||||||
obstacleOffset = width / 3;
|
obstacleOffset = width / OBSTACLE_COUNT;
|
||||||
Obstacle.distanceBetweenPipes = height / 2.5
|
Obstacle.distanceBetweenPipes = height / 2.5
|
||||||
Obstacle.startX = width;
|
Obstacle.startX = width;
|
||||||
}
|
}
|
||||||
|
|
@ -55,11 +56,19 @@ function setupGame() {
|
||||||
*/
|
*/
|
||||||
function setupObstacles() {
|
function setupObstacles() {
|
||||||
obstacles = [];
|
obstacles = [];
|
||||||
for (let i = 0; i < 3; i++) {
|
instantiateObstacles(OBSTACLE_COUNT);
|
||||||
|
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a certain amount of obstacles.
|
||||||
|
* @param number
|
||||||
|
*/
|
||||||
|
function instantiateObstacles(number: number) {
|
||||||
|
for (let i = 0; i < number; i++) {
|
||||||
obstacles.push(
|
obstacles.push(
|
||||||
new Obstacle(new Position(width + obstacleOffset * i, 0), OBSTACLE_WIDTH, height, PIPE_IMAGE_PATH));
|
new Obstacle(new Position(width + obstacleOffset * i, 0), OBSTACLE_WIDTH, height, PIPE_IMAGE_PATH));
|
||||||
}
|
}
|
||||||
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,7 +104,6 @@ function gameLoop() {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
collisionCheck(obstacles[0]);
|
collisionCheck(obstacles[0]);
|
||||||
checkRaspberryScore();
|
checkRaspberryScore();
|
||||||
obstacles[0].draw();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue