| } | } | ||||
| intersectSide(other) { | intersectSide(other) { | ||||
| if (this.midY < other.top) | |||||
| return "top"; | |||||
| else if (this.midY > other.bottom) | |||||
| return "bottom"; | |||||
| else if (this.midX < other.left) | |||||
| let mx = this.midX; | |||||
| let my = this.midY; | |||||
| let diffleft = mx - other.pos.x; | |||||
| let diffright = mx - (other.pos.x + other.size.x); | |||||
| let difftop = my - (other.pos.y + other.size.y); | |||||
| if (diffleft <= 0) | |||||
| return "left"; | return "left"; | ||||
| else | |||||
| else if (diffright >= 0) | |||||
| return "right"; | return "right"; | ||||
| else if (difftop >= 0) | |||||
| return "bottom"; | |||||
| else | |||||
| return "top"; | |||||
| } | } | ||||
| contains(other) { | contains(other) { |
| update(dt) { | update(dt) { | ||||
| if (this.shakeX > 0.1) | if (this.shakeX > 0.1) | ||||
| this.vec.x = (Math.random() - 0.5) * this.shakeX * dt; | this.vec.x = (Math.random() - 0.5) * this.shakeX * dt; | ||||
| else | |||||
| this.vec.x = 0; | |||||
| if (this.shakeY > 0.1) | if (this.shakeY > 0.1) | ||||
| this.vec.y = (Math.random() - 0.5) * this.shakeY * dt; | this.vec.y = (Math.random() - 0.5) * this.shakeY * dt; | ||||
| else | |||||
| this.vec.y = 0; | |||||
| var xRatio = 1 / (1 + (dt * this.decay)); | var xRatio = 1 / (1 + (dt * this.decay)); | ||||
| this.shakeX *= xRatio; | this.shakeX *= xRatio; |
| this.speedAir = 20; | this.speedAir = 20; | ||||
| this.jump = 8; | this.jump = 8; | ||||
| this.jumpTimeMax = 0.4; | |||||
| this.updrift = 87; | |||||
| this.jumpTimeMax = 0.45; | |||||
| this.updrift = 100; | |||||
| this.jumpLeeway = 0.1; | this.jumpLeeway = 0.1; | ||||
| this.map = { | this.map = { | ||||
| KeyA: 'left', | KeyA: 'left', | ||||
| KeyD: 'right', | KeyD: 'right', | ||||
| KeyW: 'up', | |||||
| KeyS: 'down', | |||||
| Space: "jump", | Space: "jump", | ||||
| }; | }; | ||||
| phys.velocity.x -= speed * dt; | phys.velocity.x -= speed * dt; | ||||
| if (this.pressed.right) | if (this.pressed.right) | ||||
| phys.velocity.x += speed * dt; | phys.velocity.x += speed * dt; | ||||
| if (this.pressed.down) | |||||
| phys.velocity.y += speed * dt; | |||||
| if (this.pressed.up) | |||||
| phys.velocity.y -= speed * dt; | |||||
| let canJump = | let canJump = | ||||
| !this.jumped && | !this.jumped && |
| } else if (side === "right" && this.velocity.x < velocity.x) { | } else if (side === "right" && this.velocity.x < velocity.x) { | ||||
| this.velocity.x = velocity.x; | this.velocity.x = velocity.x; | ||||
| this.entity.bounds.left = bounds.right; | this.entity.bounds.left = bounds.right; | ||||
| } else if (side === "bottom" && this.velocity.y < velocity.y) { | |||||
| this.velocity.y = velocity.y; | |||||
| this.entity.bounds.top = bounds.bottom; | |||||
| } | } | ||||
| } | } | ||||