Removed unused images & Pipe image cropping now working

- removed unused images
- image cropping is now working (good enough)
- added htl-steyr-front.jpg as a background
- changed score font color
This commit is contained in:
dhain 2023-01-18 10:39:23 +01:00
parent f1babb7c13
commit 716d13c90b
11 changed files with 41 additions and 13 deletions

View file

@ -1,5 +1,5 @@
const PIPE_IMAGE_PATH: string = "resources/seesORsoos_sad_no-bg.png";
const BACKGROUND_IMAGE_PATH: string = "resources/raspberry-low-res.png";
const PIPE_IMAGE_PATH: string = "resources/dell-pc-min-min-small.png";
const BACKGROUND_IMAGE_PATH: string = "resources/htl-steyr-front.jpg";
const RASPBERRY_IMAGE_PATH: string = "resources/raspberry-rocket.png";
const FLOOR_IMAGE_PATH: string = "resources/table-min-min.png";
const FONT_PATH: string = "resources/PressStart2P-Regular.ttf";
@ -85,7 +85,8 @@ function setupObstacles() {
function instantiateObstacles(number: number) {
for (let i = 0; i < number; i++) {
obstacles.push(
new Obstacle(new Position(width + obstacleOffset * i, 0), OBSTACLE_WIDTH, height, pipeImage));
new Obstacle(new Position(width + obstacleOffset * i, 0), OBSTACLE_WIDTH, height, pipeImage)
);
}
}
@ -180,7 +181,7 @@ function die() {
*/
function displayScore() {
push();
fill(200, 100, 60);
fill(195, 33, 34);
text(score, 0, height / 10, width, height);
pop();
}

View file

@ -33,20 +33,47 @@ class Pipe extends Entity implements Collidable {
push();
noFill();
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);
let imageAspectRatio = this.image.height / this.image.width;
let computedImageHeight = imageAspectRatio * this.width;
this.drawImage(computedImageHeight, imageAspectRatio);
rect(this.position.x, this.position.y, this.width, this.height);
pop();
}
/**
* Draws the image of the pipe into it (tiling and not stretching)
* @param computedImageHeight image height on screen
* @param imageAspectRatio aspect ratio of the image
* @private
*/
private drawImage(computedImageHeight: number, imageAspectRatio: number): void {
if (this.height > computedImageHeight) {
let maxImageYPos = Math.ceil(this.height / computedImageHeight) * computedImageHeight;
for (let imageYPosition = 0; imageYPosition < maxImageYPos; imageYPosition += computedImageHeight) {
if(imageYPosition + computedImageHeight >= maxImageYPos) {
this.cropLastImage(imageYPosition, computedImageHeight, imageAspectRatio);
break;
}
image(this.image, this.position.x, this.position.y + imageYPosition, this.width, computedImageHeight);
}
} 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();
/**
* Crops the last image in the pipe so that is doesn't get stretched or compressed
* @param imageYPosition y-Position of the image
* @param computedImageHeight image height on screen
* @param imageAspectRatio aspect ratio of the image
* @private
*/
private cropLastImage(imageYPosition: number, computedImageHeight: number, imageAspectRatio: number): void {
let amountOfImages = Math.floor(imageYPosition / computedImageHeight);
let heightToEdge = this.height - (amountOfImages * computedImageHeight);
let croppedImage = this.image.get(0, 0, this.image.width, this.image.height - (heightToEdge * imageAspectRatio));
image(croppedImage, this.position.x, this.position.y + imageYPosition, this.width, heightToEdge);
}
/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 MiB