xxxxxxxxxx
49
class Dino {
constructor() {
this.r = 64;
this.x = this.r;
this.y = height - this.r
this.vy = 0;
this.gravity = 1.5;
this.jumpStatus = false;
}
checkCollision(c) {
if (c.x < this.x + this.r / 2 && c.x + this.r > this.x && c.y > height - this.y && c.y < this.y + this.r) {
noLoop();
textSize(this.r/2);
textAlign(CENTER, CENTER);
let word = "You're dead!";
text(word, width/2, height/2);
fill(0, 102, 153);
text(word, width/2, height/2+this.r/2);
fill(0, 102, 153, 51);
text(word, width/2, height/2+this.r/2+this.r/2);
}
}
jump() {
if (this.jumpStatus == false) {
this.vy = -30;
this.jumpStatus = true;
}
}
move() {
this.y += this.vy;
if (this.y >= height - this.r) {
this.vy = 0;
this.y = height - this.r;
this.jumpStatus = false;
} else {
if (this.jumpStatus == true) {
this.vy += this.gravity;
}
}
}
show() {
rect(this.x, this.y, this.r / 2, this.r);
}
}