Began to implement more models
This commit is contained in:
parent
59523f4a41
commit
6ca169fef8
3 changed files with 59 additions and 5 deletions
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