Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # frontend/model/Obstacle.ts
This commit is contained in:
commit
8d4e0ec3f1
2 changed files with 56 additions and 25 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
// TODO: Refactor
|
|
||||||
const PIPE_IMAGE_PATH: string = "resources/raspberry-low-res.png";
|
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";
|
||||||
|
|
@ -12,11 +11,15 @@ let paused: boolean;
|
||||||
let score: number;
|
let score: number;
|
||||||
let hasAlreadyScored: boolean;
|
let hasAlreadyScored: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* p5 setup function.
|
||||||
|
*/
|
||||||
function setup() {
|
function setup() {
|
||||||
backgroundImage = loadImage(BACKGROUND_IMAGE_PATH);
|
backgroundImage = loadImage(BACKGROUND_IMAGE_PATH);
|
||||||
createCanvas(2000, 1000);
|
createCanvas(2000, 1000);
|
||||||
obstacleOffset = width / 3;
|
obstacleOffset = width / 3;
|
||||||
|
Obstacle.distanceBetweenPipes = height / 2.5
|
||||||
|
|
||||||
textSize(150);
|
textSize(150);
|
||||||
textFont("resources/PressStart2P-Regular.ttf");
|
textFont("resources/PressStart2P-Regular.ttf");
|
||||||
|
|
||||||
|
|
@ -24,11 +27,10 @@ function setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up everything needed for the game
|
* Sets up everything needed for the game.
|
||||||
*/
|
*/
|
||||||
function setupGame() {
|
function setupGame() {
|
||||||
paused = true;
|
paused = true;
|
||||||
|
|
||||||
score = 0;
|
score = 0;
|
||||||
hasAlreadyScored = false;
|
hasAlreadyScored = false;
|
||||||
raspberry = new Raspberry(RASPBERRY_IMAGE_PATH);
|
raspberry = new Raspberry(RASPBERRY_IMAGE_PATH);
|
||||||
|
|
@ -51,24 +53,14 @@ function setupGame() {
|
||||||
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
obstacles.forEach((obstacle) => obstacle.randomizeHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Split into funciton
|
/**
|
||||||
|
* Draws and updates the game.
|
||||||
|
*/
|
||||||
function draw() {
|
function draw() {
|
||||||
background(backgroundImage)
|
update();
|
||||||
if (!paused) {
|
background(backgroundImage);
|
||||||
raspberry.update();
|
|
||||||
}
|
|
||||||
raspberry.draw();
|
raspberry.draw();
|
||||||
|
drawObstacles();
|
||||||
// Reset Obstacles Position
|
|
||||||
obstacles.forEach((obstacle) => {
|
|
||||||
if (!paused) {
|
|
||||||
obstacle.update();
|
|
||||||
checkObstacleReset(obstacle);
|
|
||||||
}
|
|
||||||
|
|
||||||
obstacle.draw();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check for collisions with pipes and set score
|
// Check for collisions with pipes and set score
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
if (obstacles[0].collides(raspberry)) {
|
if (obstacles[0].collides(raspberry)) {
|
||||||
|
|
@ -77,13 +69,45 @@ function draw() {
|
||||||
checkRaspberryScore();
|
checkRaspberryScore();
|
||||||
obstacles[0].draw();
|
obstacles[0].draw();
|
||||||
}
|
}
|
||||||
|
displayScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the game score.
|
||||||
|
*/
|
||||||
|
function displayScore(){
|
||||||
push();
|
push();
|
||||||
fill(200, 100, 60);
|
fill(200, 100, 60);
|
||||||
text(score, width / 2, height / 10, width, height);
|
text(score, width / 2, height / 10, width, height);
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates all objects.
|
||||||
|
*/
|
||||||
|
function update() {
|
||||||
|
if (!paused) {
|
||||||
|
raspberry.update();
|
||||||
|
}
|
||||||
|
obstacles.forEach((obstacle: Obstacle) => {
|
||||||
|
if (!paused) {
|
||||||
|
obstacle.update();
|
||||||
|
// Reset Obstacles Position
|
||||||
|
checkObstacleReset(obstacle);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the obstacles.
|
||||||
|
*/
|
||||||
|
function drawObstacles() {
|
||||||
|
obstacles.forEach((obstacle) => {
|
||||||
|
obstacle.draw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if obstacle positions should be reset and reset if so
|
* Check if obstacle positions should be reset and reset if so
|
||||||
* @param obstacle obstacle to check
|
* @param obstacle obstacle to check
|
||||||
|
|
@ -108,16 +132,19 @@ function checkRaspberryScore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for key events.
|
||||||
|
*/
|
||||||
function keyPressed() {
|
function keyPressed() {
|
||||||
// Jump
|
// Jump
|
||||||
if (key.toLowerCase() == "k") {
|
if (key.toLowerCase() == "k") {
|
||||||
raspberry.boost();
|
raspberry.boost();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause the Game
|
// Pause the Game
|
||||||
if (key == "Escape") {
|
if (key == "Escape") {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
} else if (paused) {
|
} else if (paused) {
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
class Obstacle extends Entity implements Collidable {
|
class Obstacle extends Entity implements Collidable {
|
||||||
private pipeTop: Pipe;
|
private pipeTop: Pipe;
|
||||||
private pipeBottom: Pipe;
|
private pipeBottom: Pipe;
|
||||||
|
private static _distanceBetweenPipes: number;
|
||||||
private readonly padding: number = 150;
|
private readonly padding: number = 150;
|
||||||
private readonly speed: number = 3;
|
private readonly speed: number = 3;
|
||||||
|
|
||||||
public static distanceBetweenPipes: number;
|
private static startX: number;
|
||||||
public static startX: number;
|
|
||||||
|
static set distanceBetweenPipes(value: number) {
|
||||||
|
this._distanceBetweenPipes = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the Obstacle with the given image
|
* Constructs the Obstacle with the given image
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue