xxxxxxxxxx
48
/*****************************************
Class for Zombie
- Make Zombie Jumpe
- Zombie hits Pumpkin
- Move and show Zombie
*****************************************/
class Zombie {
constructor() {
// OOP
this.r = 150; // size
this.x = 50; // change to 50
this.y = height - this.r; // where the zombie sits at the buttom
this.vy = 0; // velocity going in the vertical direction
this.gravity = 2.5;
}
jump() {
if (this.y == height - this.r) {
this.vy = -30;
// if only zombie is at the bottom then push zombie up
}
}
hits(pumpkin) {
let x1 = this.x + this.r * 0.5;
let y1 = this.y + this.r * 0.5; // the middle of the object
let x2 = pumpkin.x + pumpkin.r * 0.5;
let y2 = pumpkin.y + pumpkin.r * 0.5;
//
return collideCircleCircle(x1, y1, this.r, x2, y2, pumpkin.r);
// checking collision using library used in the coding train video, using a circle so that there is more room between the images - using the diameter of the circle
}
move() {
this.y += this.vy;
this.vy += this.gravity;
this.y = constrain(this.y, 0, height - this.r);
// so it doesn't keep falling, adds a ground level
}
show() {
image(zImg, this.x, this.y, this.r, this.r);
}
}