Merge remote-tracking branch 'origin/models' into models

This commit is contained in:
dhain 2022-11-29 11:21:51 +01:00
commit 04ef8a872d
3 changed files with 59 additions and 5 deletions

View file

@ -2,4 +2,12 @@ function setup() {
createCanvas(400, 400)
background(187)
line(0,0, 400,400)
}
function draw() {
}
function keyPressed() {
}

View file

@ -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;
}
}
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);
}
}

View file

@ -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;
}
}