Added ceiling to jump calculations, increased the features available when displaying devtools and fixed the toggle glitch
This commit is contained in:
@@ -14,6 +14,15 @@ export class Ghost {
|
||||
this.scared = 0;
|
||||
}
|
||||
update(audio) {
|
||||
// This is in case the ghost is tracking a single point instead of another entity
|
||||
if(this.target.speedX === undefined) {
|
||||
this.target.speedX = 0;
|
||||
} if(this.target.speedY === undefined) {
|
||||
this.target.speedY = 0;
|
||||
} if(this.target.speed === undefined) {
|
||||
this.target.speed = 0;
|
||||
}
|
||||
|
||||
// if the ghost is hiding, only move after player gets a certain distance away
|
||||
let distance = Math.sqrt(Math.pow(this.x - this.target.x, 2) + Math.pow(this.y - this.target.y, 2));
|
||||
|
||||
|
||||
+26
-4
@@ -19,7 +19,15 @@ export class Player {
|
||||
|
||||
update(input, audio) {
|
||||
|
||||
// TODO: Make ceiling and floor based on hitbox
|
||||
//let h = this.hitbox;
|
||||
//let width = h.r-h.l;
|
||||
//let height = h.b-h.t;
|
||||
|
||||
//let floor = this.map.floor(h.l, h.t, width, height);
|
||||
//let ceiling = this.map.ceiling(h.l, h.t, h.r-h.l, h.b-h.t);
|
||||
let floor = this.map.floor(this.x, this.y, this.width, this.height);
|
||||
let ceiling = this.map.ceiling(this.x, this.y, this.width, this.height);
|
||||
|
||||
// Left / Right
|
||||
if(input.includes('ArrowRight') && this.speedX < this.speed) {
|
||||
@@ -35,14 +43,14 @@ export class Player {
|
||||
}
|
||||
|
||||
// Jump
|
||||
if(input.includes('ArrowUp') && this.y == floor && this.speedY == 0) {
|
||||
if(input.includes('ArrowUp') && this.y+this.height == floor && this.speedY == 0) {
|
||||
this.speedY = -this.speed*2;
|
||||
audio.play("pip_jump");
|
||||
}
|
||||
|
||||
// Down
|
||||
if(input.includes('ArrowDown')) {
|
||||
if(this.y < floor) {
|
||||
if(this.y+this.height < floor) {
|
||||
// Speed Fall
|
||||
this.speedY += 1;
|
||||
} else {
|
||||
@@ -69,8 +77,13 @@ export class Player {
|
||||
this.speedY += this.map.gravity;
|
||||
|
||||
// if skipping the platform when falling, set to platform
|
||||
if(this.y <= floor && this.y+this.speedY >= floor) {
|
||||
this.y = floor;
|
||||
if(this.y+this.height <= floor && this.y+this.height+this.speedY >= floor) {
|
||||
// Land on platforms
|
||||
this.y = floor-this.height;
|
||||
this.speedY = 0;
|
||||
} else if(this.y >= ceiling && this.y+this.speedY <= ceiling) {
|
||||
// Hit your head on platforms
|
||||
this.y = ceiling;
|
||||
this.speedY = 0;
|
||||
} else {
|
||||
this.y += this.speedY;
|
||||
@@ -104,6 +117,15 @@ export class Player {
|
||||
ctx.fillStyle = 'blue';
|
||||
ctx.globalAlpha = 0.4;
|
||||
ctx.fillRect(hitbox.l, hitbox.t, hitbox.r-this.x-padding.l, hitbox.b-this.y-padding.t);
|
||||
|
||||
// Draw Floor Marker
|
||||
let floor = this.map.floor(this.x, this.y, this.width, this.height);
|
||||
ctx.fillStyle = 'yellow';
|
||||
ctx.fillRect(this.x, floor, this.width, 10);
|
||||
|
||||
// Draw Ceiling Marker
|
||||
let ceiling = this.map.ceiling(this.x, this.y, this.width, this.height);
|
||||
ctx.fillRect(this.x, ceiling, this.width, 10);
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ export class Zombie {
|
||||
this.speedY += this.map.gravity;
|
||||
|
||||
// if skipping the platform when falling, set to platform
|
||||
if(this.y <= floor && this.y+this.speedY >= floor) {
|
||||
this.y = floor;
|
||||
if(this.y+this.height <= floor && this.y+this.height+this.speedY >= floor) {
|
||||
this.y = floor-this.height;
|
||||
this.speedY = 0;
|
||||
} else {
|
||||
this.y += this.speedY;
|
||||
|
||||
Reference in New Issue
Block a user