From 4a401758846c74113de922e066559a592bf814f1 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 29 Nov 2022 13:18:19 +0100 Subject: [PATCH] raspberry --- frontend/game.ts | 9 ++++++--- frontend/models/Raspberry.ts | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/game.ts b/frontend/game.ts index cfa2b5c..c600517 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -1,17 +1,20 @@ let obstacle: Obstacle; - +let raspberry: Raspberry; function setup() { createCanvas(400, 400) background(187) line(0,0, 400,400) + raspberry = new Raspberry(); obstacle = new Obstacle(new Pipe(new Position(width, 0), 20, 50, 0), new Pipe(new Position(width, 300), 20, 50, 0)) } function draw() { background(187) - // obstacle.draw() - // obstacle.update() + raspberry.draw(); + raspberry.update(); + obstacle.draw(); + obstacle.update(); } // // function keyPressed() { diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts index 325e94c..a600c59 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/models/Raspberry.ts @@ -1,7 +1,20 @@ class Raspberry extends Entity{ private lift: number = -10; private gravity: number = 1; - private velocity: number = 0; + private _velocity: number = 0; + private static maxVelocity = 5; + + constructor() { + super(new Position(2*width/6, height/2), 10, 10, 0); + } + + get velocity(): number { + return this._velocity; + } + + set velocity(value: number) { + this._velocity = (this.velocity > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value; + } update() { this.applyGravity();