raspberry now has an image
This commit is contained in:
parent
d43cfbe9e7
commit
ba2d9f17e1
3 changed files with 26 additions and 4 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
const pipeImagePath: string = "resources/raspberry-low-res.png";
|
const pipeImagePath: string = "resources/raspberry-low-res.png";
|
||||||
const obstacleWidth: number = 42;
|
const obstacleWidth: number = 42;
|
||||||
let obstacleOffset: number;
|
let obstacleOffset: number;
|
||||||
|
|
||||||
const backgroundImagePath: string = "resources/raspberry-low-res.png";
|
const backgroundImagePath: string = "resources/raspberry-low-res.png";
|
||||||
let backgroundImage: any;
|
let backgroundImage: any;
|
||||||
|
const raspberryImagePath: string = "resources/raspberry-rocket.png";
|
||||||
|
|
||||||
let obstacles: Obstacle[] = [];
|
let obstacles: Obstacle[] = [];
|
||||||
let raspberry: Raspberry;
|
let raspberry: Raspberry;
|
||||||
|
|
@ -15,6 +15,7 @@ function setup() {
|
||||||
obstacleOffset = width / 4;
|
obstacleOffset = width / 4;
|
||||||
|
|
||||||
raspberry = new Raspberry();
|
raspberry = new Raspberry();
|
||||||
|
raspberry.image = raspberryImagePath;
|
||||||
|
|
||||||
obstacles.push(new Obstacle(
|
obstacles.push(new Obstacle(
|
||||||
new Pipe(width, obstacleWidth, height),
|
new Pipe(width, obstacleWidth, height),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ class Pipe extends Entity {
|
||||||
private _image: any;
|
private _image: any;
|
||||||
|
|
||||||
//region Getter & Setter
|
//region Getter & Setter
|
||||||
get image() {
|
get image(): any {
|
||||||
return this._image;
|
return this._image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ class Raspberry extends Entity {
|
||||||
private lift: number = -10;
|
private lift: number = -10;
|
||||||
private gravity: number = 1;
|
private gravity: number = 1;
|
||||||
private _velocity: number = 0;
|
private _velocity: number = 0;
|
||||||
|
private _image: any;
|
||||||
private static maxVelocity: number = 5;
|
private static maxVelocity: number = 5;
|
||||||
|
|
||||||
constructor() {
|
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
|
//region Getter & Setter
|
||||||
|
|
@ -16,8 +17,16 @@ class Raspberry extends Entity {
|
||||||
set velocity(value: number) {
|
set velocity(value: number) {
|
||||||
this._velocity = (this.velocity > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value;
|
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 {
|
public update(): void {
|
||||||
this.applyGravity();
|
this.applyGravity();
|
||||||
|
|
@ -45,4 +54,16 @@ class Raspberry extends Entity {
|
||||||
public boost(): void {
|
public boost(): void {
|
||||||
this.velocity += this.lift;
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue