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



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

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



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

+ 1
- 0
js/main.js View File

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



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

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

Loading…
Cancel
Save