Browse Source

stuff

master
mortie 6 years ago
parent
commit
07f1df0641
4 changed files with 9 additions and 13 deletions
  1. 2
    2
      js/Rect.js
  2. 3
    5
      js/entities/BrokenPlatform.js
  3. 1
    0
      js/main.js
  4. 3
    6
      js/traits/TPhysics.js

+ 2
- 2
js/Rect.js View File

@@ -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) {

+ 3
- 5
js/entities/BrokenPlatform.js View File

@@ -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;
}

+ 1
- 0
js/main.js View File

@@ -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();


+ 3
- 6
js/traits/TPhysics.js View File

@@ -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;
}
}

Loading…
Cancel
Save