From dbff8cfb5675c164a2a8df02006da1a202b5e154 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 13 Dec 2022 08:39:17 +0100 Subject: [PATCH 1/2] reformatted --- frontend/models/Raspberry.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts index 0116c9f..c9d0d18 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/models/Raspberry.ts @@ -5,11 +5,9 @@ class Raspberry extends Entity { private _image: any; private static readonly maxVelocity: number = 5; - constructor() { - super(new Position(width / 6, height / 2), 180, 70, 0); - } - //region Getter & Setter + + get velocity(): number { return this._velocity; } @@ -28,6 +26,10 @@ class Raspberry extends Entity { //endregion + constructor() { + super(new Position(width / 6, height / 2), 180, 70, 0); + } + public update(): void { this.applyGravity(); this.forceBoundaries(); From 7dd557f9687e8557878188d2dacb115a6844771a Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 13 Dec 2022 09:24:33 +0100 Subject: [PATCH 2/2] raspberry flies --- frontend/game.ts | 23 +++++++++++------------ frontend/models/Obstacle.ts | 2 +- frontend/models/Raspberry.ts | 13 +++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/game.ts b/frontend/game.ts index 2dafa32..3b88d6a 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -12,7 +12,7 @@ function setup() { backgroundImage = loadImage(backgroundImagePath); createCanvas(1000, 1000); - obstacleOffset = width / 4; + obstacleOffset = width / 3; raspberry = new Raspberry(); raspberry.image = raspberryImagePath; @@ -32,31 +32,30 @@ function setup() { new Pipe(width + obstacleOffset * 2, obstacleWidth, height), 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)); } function draw() { background(backgroundImage) - raspberry.draw(); raspberry.update(); + raspberry.draw(); obstacles.forEach((obstacle) => { - obstacle.draw(); obstacle.update(); + obstacle.draw(); if(obstacle.position.x < -obstacleWidth) { obstacle.resetPosition(true); } + + }); } -// -// function keyPressed() { -// -// } \ No newline at end of file +function keyPressed() { + if (key == "K" || key == "k") { + raspberry.boost(); + console.log("BOOOST") + } +} \ No newline at end of file diff --git a/frontend/models/Obstacle.ts b/frontend/models/Obstacle.ts index b75be4a..0407678 100644 --- a/frontend/models/Obstacle.ts +++ b/frontend/models/Obstacle.ts @@ -3,7 +3,7 @@ class Obstacle extends Entity { private pipeBottom: Pipe; private readonly distanceBetweenPipes: number; private readonly padding: number = 300; - private readonly speed: number = 8; + private readonly speed: number = 3; private static startX: number; diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts index c9d0d18..2d6b8a3 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/models/Raspberry.ts @@ -1,9 +1,9 @@ class Raspberry extends Entity { - private readonly lift: number = -10; - private readonly gravity: number = 1; + private readonly lift: number = -20; + private readonly gravity: number = 1.314159265358979323846264338; private _velocity: number = 0; private _image: any; - private static readonly maxVelocity: number = 5; + private static readonly maxVelocity: number = 100; //region Getter & Setter @@ -13,7 +13,7 @@ class Raspberry extends Entity { } 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 { @@ -37,11 +37,12 @@ class Raspberry extends Entity { private applyGravity(): void { this.velocity += this.gravity; + this.position.y += this.velocity; } private forceBoundaries(): void { - if (this.position.y > height) { - this.position.y = height; + if (this.position.y+this.height > height) { + this.position.y = height-this.height; this.velocity = 0; }