diff --git a/frontend/game.ts b/frontend/game.ts index 5f03dc3..fdeda1b 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -2,4 +2,12 @@ function setup() { createCanvas(400, 400) background(187) line(0,0, 400,400) +} + +function draw() { + +} + +function keyPressed() { + } \ No newline at end of file diff --git a/frontend/models/Entity.ts b/frontend/models/Entity.ts index d5594a4..b753b28 100644 --- a/frontend/models/Entity.ts +++ b/frontend/models/Entity.ts @@ -1,7 +1,8 @@ -class Entity { - private _position: Position; - private _width: number; - private _height: number; +abstract class Entity { + private _position: Position; + private _width: number; + private _height: number; + private _fill: number; get position(): Position { return this._position; @@ -26,4 +27,17 @@ class Entity { set height(value: number) { this._height = value; } -} \ No newline at end of file + + constructor(position: Position, width: number, height: number, fill: number) { + this.position = position; + this.width = width; + this.height = height; + this._fill = fill; + } + + public abstract update(); + public draw() { + fill(this._fill); + rect(this.position.x, this.position.y, this.width, this.height); + } +} diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts new file mode 100644 index 0000000..325e94c --- /dev/null +++ b/frontend/models/Raspberry.ts @@ -0,0 +1,32 @@ +class Raspberry extends Entity{ + private lift: number = -10; + private gravity: number = 1; + private velocity: number = 0; + + update() { + this.applyGravity(); + this.forceBoundaries(); + } + + private applyGravity() { + if (this.position.y - this.height > 0) { + this.velocity += this.gravity; + } + } + + private forceBoundaries() { + if (this.position.y > height) { + this.position.y = height; + this.velocity = 0; + } + + if (this.position.y < 0) { + this.position.y = 0; + this.velocity = 0; + } + } + + public boost() { + this.velocity += this.lift; + } +} \ No newline at end of file