Floor & Positioning & small Obstacle rework

- added images for pipes and floor
- floor is now working
- raspberry is falling on floor correctly
- images are now getting preloaded
- font ia getting preloaded
- obstacle and pipe constructor now take p5.Image instead of a string with the path
- removed everything to do with drawing background posters

- started working on pipe tiling instead of streching
This commit is contained in:
dhain 2023-01-17 11:10:26 +01:00
parent d069987bb0
commit f1babb7c13
10 changed files with 68 additions and 80 deletions

View file

@ -6,33 +6,16 @@ class Pipe extends Entity implements Collidable {
* Pipe's image.
* @private
*/
private _image: p5.Image;
//region Getter & Setter
/**
* Gets the image.
*/
get image(): p5.Image {
return this._image;
}
/**
* Sets the image.
* @param path Path to image
*/
set image(path: any) {
this._image = loadImage(path);
}
//endregion
private readonly image: p5.Image;
/**
* Constructs the pipe.
* @param positionX starting x-Position
* @param width pipe width
* @param height pipe height
* @param image path to image.
* @param image image object
*/
constructor(positionX: number, width: number, height: number, image: string) {
constructor(positionX: number, width: number, height: number, image: p5.Image) {
super(new Position(positionX, 0), width, height, 0);
this.image = image;
}
@ -40,7 +23,8 @@ class Pipe extends Entity implements Collidable {
/**
* YAGNI.
*/
public update(): void {}
public update(): void {
}
/**
* Draws the pipe.
@ -48,7 +32,19 @@ class Pipe extends Entity implements Collidable {
public draw(): void {
push();
noFill();
image(this.image, this.position.x, this.position.y, this.width, this.height);
if (this.height > this.image.height) {
let maxImageYPos = Math.ceil(this.height / this.image.height) * this.image.height;
for (let imageYPos = 0; imageYPos < maxImageYPos; imageYPos += this.image.height) {
console.log("maximageypos: " + maxImageYPos);
console.log("image height: " + this.image.height);
console.log("imageypos: " + imageYPos);
image(this.image, this.position.x, this.position.y + imageYPos, this.width, this.image.height);
}
} else {
image(this.image, this.position.x, this.position.y, this.width, this.height);
}
rect(this.position.x, this.position.y, this.width, this.height);
pop();
}