Merge remote-tracking branch 'origin/models' into models
This commit is contained in:
commit
04ef8a872d
3 changed files with 59 additions and 5 deletions
|
|
@ -2,4 +2,12 @@ function setup() {
|
||||||
createCanvas(400, 400)
|
createCanvas(400, 400)
|
||||||
background(187)
|
background(187)
|
||||||
line(0,0, 400,400)
|
line(0,0, 400,400)
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyPressed() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
class Entity {
|
abstract class Entity {
|
||||||
private _position: Position;
|
private _position: Position;
|
||||||
private _width: number;
|
private _width: number;
|
||||||
private _height: number;
|
private _height: number;
|
||||||
|
private _fill: number;
|
||||||
|
|
||||||
get position(): Position {
|
get position(): Position {
|
||||||
return this._position;
|
return this._position;
|
||||||
|
|
@ -26,4 +27,17 @@ class Entity {
|
||||||
set height(value: number) {
|
set height(value: number) {
|
||||||
this._height = value;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
32
frontend/models/Raspberry.ts
Normal file
32
frontend/models/Raspberry.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue