raspberry flies

This commit is contained in:
s-prechtl 2022-12-13 09:24:33 +01:00
parent dbff8cfb56
commit 7dd557f968
3 changed files with 19 additions and 19 deletions

View file

@ -12,7 +12,7 @@ function setup() {
backgroundImage = loadImage(backgroundImagePath); backgroundImage = loadImage(backgroundImagePath);
createCanvas(1000, 1000); createCanvas(1000, 1000);
obstacleOffset = width / 4; obstacleOffset = width / 3;
raspberry = new Raspberry(); raspberry = new Raspberry();
raspberry.image = raspberryImagePath; raspberry.image = raspberryImagePath;
@ -32,31 +32,30 @@ function setup() {
new Pipe(width + obstacleOffset * 2, obstacleWidth, height), new Pipe(width + obstacleOffset * 2, obstacleWidth, height),
pipeImagePath pipeImagePath
)); ));
obstacles.push(new Obstacle(
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
new Pipe(width + obstacleOffset * 3, obstacleWidth, height),
pipeImagePath
));
obstacles.forEach((obstacle) => obstacle.resetPosition(false)); obstacles.forEach((obstacle) => obstacle.resetPosition(false));
} }
function draw() { function draw() {
background(backgroundImage) background(backgroundImage)
raspberry.draw();
raspberry.update(); raspberry.update();
raspberry.draw();
obstacles.forEach((obstacle) => { obstacles.forEach((obstacle) => {
obstacle.draw();
obstacle.update(); obstacle.update();
obstacle.draw();
if(obstacle.position.x < -obstacleWidth) { if(obstacle.position.x < -obstacleWidth) {
obstacle.resetPosition(true); obstacle.resetPosition(true);
} }
}); });
} }
// function keyPressed() {
// function keyPressed() { if (key == "K" || key == "k") {
// raspberry.boost();
// } console.log("BOOOST")
}
}

View file

@ -3,7 +3,7 @@ class Obstacle extends Entity {
private pipeBottom: Pipe; private pipeBottom: Pipe;
private readonly distanceBetweenPipes: number; private readonly distanceBetweenPipes: number;
private readonly padding: number = 300; private readonly padding: number = 300;
private readonly speed: number = 8; private readonly speed: number = 3;
private static startX: number; private static startX: number;

View file

@ -1,9 +1,9 @@
class Raspberry extends Entity { class Raspberry extends Entity {
private readonly lift: number = -10; private readonly lift: number = -20;
private readonly gravity: number = 1; private readonly gravity: number = 1.314159265358979323846264338;
private _velocity: number = 0; private _velocity: number = 0;
private _image: any; private _image: any;
private static readonly maxVelocity: number = 5; private static readonly maxVelocity: number = 100;
//region Getter & Setter //region Getter & Setter
@ -13,7 +13,7 @@ class Raspberry extends Entity {
} }
set velocity(value: number) { set velocity(value: number) {
this._velocity = (this.velocity > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value; this._velocity = (Math.abs(this.velocity) > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value;
} }
get image(): any { get image(): any {
@ -37,11 +37,12 @@ class Raspberry extends Entity {
private applyGravity(): void { private applyGravity(): void {
this.velocity += this.gravity; this.velocity += this.gravity;
this.position.y += this.velocity;
} }
private forceBoundaries(): void { private forceBoundaries(): void {
if (this.position.y > height) { if (this.position.y+this.height > height) {
this.position.y = height; this.position.y = height-this.height;
this.velocity = 0; this.velocity = 0;
} }