@@ -17,8 +17,8 @@ export default class Rect { | |||
intersects(other) { | |||
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) { |
@@ -26,13 +26,14 @@ class Behavior extends Trait { | |||
init() { | |||
this.initialPos = this.entity.pos.clone(); | |||
this.entity.t.physics.enabled = false; | |||
} | |||
reset() { | |||
this.entity.t.physics.enabled = false; | |||
this.shake = 0; | |||
this.entity.t.physics.velocity.set(0, 0); | |||
this.entity.pos.set(this.initialPos.x, this.initialPos.y); | |||
this.entity.t.physics.moved = true; | |||
this.state = 0; | |||
this.timer = 0; | |||
@@ -52,16 +53,13 @@ class Behavior extends Trait { | |||
}); | |||
} | |||
if (this.state !== 2) | |||
this.entity.t.physics.velocity.y -= | |||
this.entity.t.physics.gravity * dt; | |||
if (this.state === 1) { | |||
this.shaker.shake(this.shake); | |||
this.shake += this.shakeAccel * dt; | |||
this.timer -= dt; | |||
if (this.timer <= 0) { | |||
this.entity.t.physics.enabled = true; | |||
this.state = 2; | |||
this.timer = this.resetTime; | |||
} |
@@ -17,6 +17,7 @@ level.spawnStructure(structures.groundPillar(new Vec2(2, 3)), 14, 6); | |||
level.spawnStructure(structures.groundPillar(new Vec2(1, 5)), 20, 4); | |||
level.spawnEntity(new BrokenPlatform(level), 22, 6); | |||
level.spawnEntity(new BrokenPlatform(level), 30, 5); | |||
level.start(); | |||
@@ -14,7 +14,6 @@ export default class TPhysics extends Trait { | |||
this.onGround = false; | |||
this.groundBounds = null; | |||
this.groundVelocity = null; | |||
this.moved = false; | |||
} | |||
collideTop(bounds, velocity) { | |||
@@ -48,7 +47,7 @@ export default class TPhysics extends Trait { | |||
update(dt) { | |||
// Collide | |||
if (this.entity.has("collider") && !this.moved) { | |||
if (this.entity.has("collider")) { | |||
let collider = this.entity.t.collider; | |||
this.groundBounds = null; | |||
this.groundVelocity = null; | |||
@@ -74,7 +73,7 @@ export default class TPhysics extends Trait { | |||
this.onGround = | |||
this.groundVelocity && this.velocity.y >= this.groundVelocity.y; | |||
if (this.onGround && !this.moved) { | |||
if (this.onGround) { | |||
this.timeLastOnGround = this.entity.time; | |||
this.velocity.y = this.groundVelocity.y; | |||
} | |||
@@ -94,9 +93,7 @@ export default class TPhysics extends Trait { | |||
this.entity.pos.x += this.velocity.x * 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.moved = false; | |||
} | |||
} |