More refactor more comments
This commit is contained in:
parent
a20abff918
commit
1bb33d6fb1
3 changed files with 15 additions and 9 deletions
|
|
@ -19,6 +19,7 @@ function setup() {
|
||||||
createCanvas(2000, 1000);
|
createCanvas(2000, 1000);
|
||||||
obstacleOffset = width / 3;
|
obstacleOffset = width / 3;
|
||||||
Obstacle.distanceBetweenPipes = height / 2.5
|
Obstacle.distanceBetweenPipes = height / 2.5
|
||||||
|
Obstacle.startX = width;
|
||||||
|
|
||||||
textSize(150);
|
textSize(150);
|
||||||
textFont("resources/PressStart2P-Regular.ttf");
|
textFont("resources/PressStart2P-Regular.ttf");
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,14 @@ abstract class Entity {
|
||||||
this._showHitbox = false;
|
this._showHitbox = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the entity.
|
||||||
|
*/
|
||||||
public abstract update(): void;
|
public abstract update(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the entity.
|
||||||
|
*/
|
||||||
public draw(): void {
|
public draw(): void {
|
||||||
push();
|
push();
|
||||||
fill(this.fill);
|
fill(this.fill);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@ class Obstacle extends Entity implements Collidable {
|
||||||
private readonly padding: number = 150;
|
private readonly padding: number = 150;
|
||||||
private readonly speed: number = 3;
|
private readonly speed: number = 3;
|
||||||
|
|
||||||
private static startX: number;
|
private static _startX: number;
|
||||||
|
|
||||||
|
static set startX(value: number) {
|
||||||
|
this._startX = value;
|
||||||
|
}
|
||||||
|
|
||||||
static set distanceBetweenPipes(value: number) {
|
static set distanceBetweenPipes(value: number) {
|
||||||
this._distanceBetweenPipes = value;
|
this._distanceBetweenPipes = value;
|
||||||
|
|
@ -25,9 +29,7 @@ class Obstacle extends Entity implements Collidable {
|
||||||
this.pipeBottom = new Pipe(position.x, obstacleWidth, obstacleHeight);
|
this.pipeBottom = new Pipe(position.x, obstacleWidth, obstacleHeight);
|
||||||
this.pipeTop.image = pipeImagePath;
|
this.pipeTop.image = pipeImagePath;
|
||||||
this.pipeBottom.image = pipeImagePath;
|
this.pipeBottom.image = pipeImagePath;
|
||||||
|
this.pipeTop.position.y = 0;
|
||||||
//TODO: Put into setupGame()
|
|
||||||
Obstacle.startX = width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,9 +38,8 @@ class Obstacle extends Entity implements Collidable {
|
||||||
*/
|
*/
|
||||||
public resetPosition(): void {
|
public resetPosition(): void {
|
||||||
this.randomizeHeight();
|
this.randomizeHeight();
|
||||||
|
this.pipeBottom.position.x = Obstacle._startX;
|
||||||
this.pipeBottom.position.x = Obstacle.startX;
|
this.pipeTop.position.x = Obstacle._startX;
|
||||||
this.pipeTop.position.x = Obstacle.startX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,8 +47,6 @@ class Obstacle extends Entity implements Collidable {
|
||||||
*/
|
*/
|
||||||
public randomizeHeight(): void {
|
public randomizeHeight(): void {
|
||||||
this.pipeTop.height = this.randomRange(this.padding, height - this.padding - Obstacle._distanceBetweenPipes);
|
this.pipeTop.height = this.randomRange(this.padding, height - this.padding - Obstacle._distanceBetweenPipes);
|
||||||
//TODO: Soi des do sei?
|
|
||||||
this.pipeTop.position.y = 0;
|
|
||||||
this.pipeBottom.position.y = this.pipeTop.height + Obstacle._distanceBetweenPipes;
|
this.pipeBottom.position.y = this.pipeTop.height + Obstacle._distanceBetweenPipes;
|
||||||
this.pipeBottom.height = height - this.pipeTop.height - this.padding;
|
this.pipeBottom.height = height - this.pipeTop.height - this.padding;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue