| intersects(other) { | intersects(other) { | ||||
| return ( | return ( | ||||
| (this.left <= other.right && this.right >= other.left) && | |||||
| (this.top <= other.bottom && this.bottom >= other.top)); | |||||
| (this.left < other.right && this.right > other.left) && | |||||
| (this.top < other.bottom && this.bottom > other.top)); | |||||
| } | } | ||||
| intersectSide(other) { | intersectSide(other) { |
| init() { | init() { | ||||
| this.initialPos = this.entity.pos.clone(); | this.initialPos = this.entity.pos.clone(); | ||||
| this.entity.t.physics.enabled = false; | |||||
| } | } | ||||
| reset() { | reset() { | ||||
| this.entity.t.physics.enabled = false; | |||||
| this.shake = 0; | this.shake = 0; | ||||
| this.entity.t.physics.velocity.set(0, 0); | this.entity.t.physics.velocity.set(0, 0); | ||||
| this.entity.pos.set(this.initialPos.x, this.initialPos.y); | this.entity.pos.set(this.initialPos.x, this.initialPos.y); | ||||
| this.entity.t.physics.moved = true; | |||||
| this.state = 0; | this.state = 0; | ||||
| this.timer = 0; | this.timer = 0; | ||||
| }); | }); | ||||
| } | } | ||||
| if (this.state !== 2) | |||||
| this.entity.t.physics.velocity.y -= | |||||
| this.entity.t.physics.gravity * dt; | |||||
| if (this.state === 1) { | if (this.state === 1) { | ||||
| this.shaker.shake(this.shake); | this.shaker.shake(this.shake); | ||||
| this.shake += this.shakeAccel * dt; | this.shake += this.shakeAccel * dt; | ||||
| this.timer -= dt; | this.timer -= dt; | ||||
| if (this.timer <= 0) { | if (this.timer <= 0) { | ||||
| this.entity.t.physics.enabled = true; | |||||
| this.state = 2; | this.state = 2; | ||||
| this.timer = this.resetTime; | this.timer = this.resetTime; | ||||
| } | } |
| level.spawnStructure(structures.groundPillar(new Vec2(1, 5)), 20, 4); | level.spawnStructure(structures.groundPillar(new Vec2(1, 5)), 20, 4); | ||||
| level.spawnEntity(new BrokenPlatform(level), 22, 6); | level.spawnEntity(new BrokenPlatform(level), 22, 6); | ||||
| level.spawnEntity(new BrokenPlatform(level), 30, 5); | |||||
| level.start(); | level.start(); | ||||
| this.onGround = false; | this.onGround = false; | ||||
| this.groundBounds = null; | this.groundBounds = null; | ||||
| this.groundVelocity = null; | this.groundVelocity = null; | ||||
| this.moved = false; | |||||
| } | } | ||||
| collideTop(bounds, velocity) { | collideTop(bounds, velocity) { | ||||
| update(dt) { | update(dt) { | ||||
| // Collide | // Collide | ||||
| if (this.entity.has("collider") && !this.moved) { | |||||
| if (this.entity.has("collider")) { | |||||
| let collider = this.entity.t.collider; | let collider = this.entity.t.collider; | ||||
| this.groundBounds = null; | this.groundBounds = null; | ||||
| this.groundVelocity = null; | this.groundVelocity = null; | ||||
| this.onGround = | this.onGround = | ||||
| this.groundVelocity && this.velocity.y >= this.groundVelocity.y; | this.groundVelocity && this.velocity.y >= this.groundVelocity.y; | ||||
| if (this.onGround && !this.moved) { | |||||
| if (this.onGround) { | |||||
| this.timeLastOnGround = this.entity.time; | this.timeLastOnGround = this.entity.time; | ||||
| this.velocity.y = this.groundVelocity.y; | this.velocity.y = this.groundVelocity.y; | ||||
| } | } | ||||
| this.entity.pos.x += this.velocity.x * dt; | this.entity.pos.x += this.velocity.x * dt; | ||||
| this.entity.pos.y += this.velocity.y * dt; | this.entity.pos.y += this.velocity.y * dt; | ||||
| if (this.onGround && !this.moved) | |||||
| if (this.onGround) | |||||
| this.entity.bounds.bottom = this.groundBounds.top; | this.entity.bounds.bottom = this.groundBounds.top; | ||||
| this.moved = false; | |||||
| } | } | ||||
| } | } |