Commented everything except some Methods in Raspberry.ts

This commit is contained in:
dhain 2022-12-20 09:40:21 +01:00
parent fafbfa1b32
commit 6c459c1581
7 changed files with 87 additions and 19 deletions

View file

@ -8,8 +8,12 @@ class Obstacle extends Entity implements Collidable {
private static startX: number;
/**
* Constructs the Obstacle using the top and bottom Pipe
* Constructs the Obstacle with the given image
* (fill is not used here)
* @param position starting position of the obstacle
* @param obstacleWidth width of the obstacle
* @param obstacleHeight height of the obstacle
* @param pipeImagePath path to the image to be used
*/
constructor(position: Position, obstacleWidth: number, obstacleHeight: number, pipeImagePath: string) {
super(position, obstacleWidth, obstacleHeight, 0);
@ -22,18 +26,32 @@ class Obstacle extends Entity implements Collidable {
Obstacle.startX = width;
}
public resetPosition(resetX: boolean): void {
/**
* Resets the position of the obstacle to the Obstacle.startX variable
* Randomises the height of the pipes using the padding variable
*/
public resetPosition(): void {
this.randomizeHeight();
this.pipeBottom.position.x = Obstacle.startX;
this.pipeTop.position.x = Obstacle.startX;
}
/**
* Randomizes the height of the pipes
*/
public randomizeHeight(): void {
this.pipeTop.height = this.randomRange(this.padding, height - this.padding - this.distanceBetweenPipes);
this.pipeTop.position.y = 0;
this.pipeBottom.position.y = this.pipeTop.height + this.distanceBetweenPipes;
this.pipeBottom.height = height - this.pipeTop.height - this.padding;
if (resetX) {
this.pipeBottom.position.x = Obstacle.startX;
this.pipeTop.position.x = Obstacle.startX;
}
}
/**
* Creates a random number between the min and max parameter
* @param min minimum number
* @param max maximum number
*/
private randomRange(min: number, max: number): number {
return Math.random() * (max - min) + min;
}
@ -49,6 +67,10 @@ class Obstacle extends Entity implements Collidable {
this.pipeBottom.draw();
}
/**
* Determines when the obstacle is colliding with another entity
* @param o other entity
*/
public collides(o: Entity): boolean {
return this.pipeTop.collides(o) || this.pipeBottom.collides(o);
}