From ba2d9f17e12881a32a037ebb756ade1a78f5f6e4 Mon Sep 17 00:00:00 2001 From: dhain Date: Tue, 6 Dec 2022 13:48:47 +0100 Subject: [PATCH] raspberry now has an image --- frontend/game.ts | 3 ++- frontend/models/Pipe.ts | 2 +- frontend/models/Raspberry.ts | 25 +++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/frontend/game.ts b/frontend/game.ts index da00f4c..2dafa32 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -1,9 +1,9 @@ const pipeImagePath: string = "resources/raspberry-low-res.png"; const obstacleWidth: number = 42; let obstacleOffset: number; - const backgroundImagePath: string = "resources/raspberry-low-res.png"; let backgroundImage: any; +const raspberryImagePath: string = "resources/raspberry-rocket.png"; let obstacles: Obstacle[] = []; let raspberry: Raspberry; @@ -15,6 +15,7 @@ function setup() { obstacleOffset = width / 4; raspberry = new Raspberry(); + raspberry.image = raspberryImagePath; obstacles.push(new Obstacle( new Pipe(width, obstacleWidth, height), diff --git a/frontend/models/Pipe.ts b/frontend/models/Pipe.ts index 6a0a63e..4ed0b46 100644 --- a/frontend/models/Pipe.ts +++ b/frontend/models/Pipe.ts @@ -2,7 +2,7 @@ class Pipe extends Entity { private _image: any; //region Getter & Setter - get image() { + get image(): any { return this._image; } diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts index 8f6c627..9a5b873 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/models/Raspberry.ts @@ -2,10 +2,11 @@ class Raspberry extends Entity { private lift: number = -10; private gravity: number = 1; private _velocity: number = 0; + private _image: any; private static maxVelocity: number = 5; constructor() { - super(new Position(2 * width / 6, height / 2), 10, 10, 0); + super(new Position(width / 6, height / 2), 180, 70, 0); } //region Getter & Setter @@ -16,8 +17,16 @@ class Raspberry extends Entity { set velocity(value: number) { this._velocity = (this.velocity > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value; } + + get image(): any { + return this._image; + } - //endregion + set image(path: string) { + this._image = loadImage(path); + } + +//endregion public update(): void { this.applyGravity(); @@ -45,4 +54,16 @@ class Raspberry extends Entity { public boost(): void { this.velocity += this.lift; } + + public draw(): void { + image(this.image, this.position.x, this.position.y, this.width, this.height); + noFill(); + noStroke(); + rect( + this.position.x, + this.position.y, + this.width, + this.height + ); + } } \ No newline at end of file