So much stuff happened idek
This commit is contained in:
+27
-25
@@ -1,3 +1,4 @@
|
||||
import Entity from './entity.js';
|
||||
export class Zombie {
|
||||
constructor(game, map, x, y) {
|
||||
this.game = game;
|
||||
@@ -11,16 +12,25 @@ export class Zombie {
|
||||
this.speedY = 0;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.hitbox = Entity.hitbox;
|
||||
this.padding = function(w, h) {
|
||||
return {t:1, b:0, l:6, r:6};
|
||||
};
|
||||
}
|
||||
|
||||
update(audio) {
|
||||
let floor = this.map.floor(this.x, this.y, this.width, this.height);
|
||||
|
||||
//direction = Math.floor(Math.random() * 2)?-1:1;
|
||||
let frameRand = Math.floor(Math.random() * 5) + 40;
|
||||
if(this.game.frame % frameRand == 0) {
|
||||
this.direction = Math.floor(Math.random() * 2)?-1:1;
|
||||
}
|
||||
|
||||
//if(this.x > this.game.width-10) {
|
||||
if(this.x < 50 || this.x > 150) {
|
||||
this.direction = this.direction * -1;
|
||||
if(this.x < 50) {
|
||||
this.direction = 1;
|
||||
} else if(this.x > game.width - 50 - this.width) {
|
||||
this.direction = -1;
|
||||
}
|
||||
|
||||
this.speedX = this.direction * this.speed;
|
||||
@@ -51,30 +61,22 @@ export class Zombie {
|
||||
}
|
||||
ctx.drawImage(img, this.x, this.y, this.width, this.height);
|
||||
|
||||
if(hitboxes) {
|
||||
// T R B L
|
||||
// 0 1 2 3
|
||||
ctx.globalAlpha = 0.4;
|
||||
//let hitbox = this.hitbox();
|
||||
// Draw Health Bar
|
||||
let healthPadding = 5;
|
||||
let healthHeight = 2;
|
||||
let healthWidth = this.width/2;
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(this.x + healthWidth/2, this.y-healthPadding, healthWidth, healthHeight);
|
||||
ctx.fillStyle = 'green';
|
||||
ctx.fillRect(this.x+healthWidth/2, this.y-healthPadding, (this.hearts/3*healthWidth), healthHeight);
|
||||
|
||||
ctx.fillStyle = 'green';
|
||||
//ctx.fillRect(hitbox[3], hitbox[0], hitbox[1]-this.x, hitbox[2]-this.y);
|
||||
ctx.fillRect(this.x, this.y, this.width, this.height);
|
||||
if(hitboxes) {
|
||||
let hitbox = this.hitbox(this);
|
||||
let padding = this.padding(this.width, this.height);
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.globalAlpha = 0.4;
|
||||
ctx.fillRect(hitbox.l, hitbox.t, hitbox.r-this.x-padding.l, hitbox.b-this.y-padding.t);
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
}
|
||||
|
||||
/*hitbox() {
|
||||
let paddingTop = (this.height * 0.05);
|
||||
let paddingBottom = (0) - paddingTop;
|
||||
let paddingLeft = (this.width * 0.20);
|
||||
let paddingRight = (0) - paddingLeft*2;
|
||||
|
||||
let top = this.y + paddingTop;
|
||||
let right = this.x + this.width + paddingRight;
|
||||
let bottom = this.y + this.height + paddingBottom;
|
||||
let left = this.x + paddingLeft;
|
||||
return [top, right, bottom, left];
|
||||
}*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user