Browse Source

stuff

master
mortie 6 years ago
parent
commit
4fece602b6
7 changed files with 31 additions and 13 deletions
  1. 1
    1
      js/Level.js
  2. 5
    0
      js/Rect.js
  3. 1
    1
      js/Texture.js
  4. 7
    0
      js/Tile.js
  5. 7
    5
      js/tiles.js
  6. 6
    3
      js/traits/TCollider.js
  7. 4
    3
      js/traits/TPhysics.js

+ 1
- 1
js/Level.js View File

@@ -47,7 +47,7 @@ export default class Level {
if (!bounds)
return;

ent.t.collider.collideStructure(bounds);
ent.t.collider.collideStructure(s, bounds);
});
});


+ 5
- 0
js/Rect.js View File

@@ -20,6 +20,11 @@ export default class Rect {
(this.left <= other.right && this.right >= other.left) &&
(this.top <= other.bottom && this.bottom >= other.top));
}
bottomIntersects(other) {
return (
(this.left <= other.right && this.right >= other.left) &&
(this.bottom <= other.bottom && this.bottom >= other.top));
}

contains(other) {
return (

+ 1
- 1
js/Texture.js View File

@@ -32,7 +32,7 @@ export default class Texture {
if (e instanceof Array) {
this.fillCanvas(e);
} else {
assets.tiles.drawTile(this.ctx, e.tile, e.x, e.y);
assets.tiles.drawTile(this.ctx, e.name, e.x, e.y);
}
});
}

+ 7
- 0
js/Tile.js View File

@@ -0,0 +1,7 @@
export default class Tile {
constructor(x, y, name) {
this.x = x;
this.y = y;
this.name = name;
}
}

+ 7
- 5
js/tiles.js View File

@@ -1,13 +1,15 @@
import Tile from "./Tile.js"

export default {
fromLine: function(width, tile) {
fromLine: function(width, name) {
if (width <= 1) {
return [ { x: 0, y: 0, tile: tile+"-lr" }];
return [ new Tile(0, 0, name+"-lr") ];
} else {
return [
{ x: 0, y: 0, tile: tile+"-l", },
new Tile(0, 0, name+"-l"),
Array.from({ length: width - 2 }, (_, i) =>
({ x: i + 1, y: 0, tile: tile })),
{ x: width - 1, y: 0, tile: tile+"-r" },
new Tile(i + 1, 0, name)),
new Tile(width - 1, 0, name+"-r"),
];
}
},

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

@@ -7,16 +7,19 @@ export default class Collider extends Trait {
this.collides = false;
this.cEntity = null;
this.cStructure = null;
this.cBounds = null;
}

collideEntity(e) {
this.cEntity = e;
this.collides = true;
this.cEntity = e;
this.cBounds = e.bounds;
}

collideStructure(s) {
this.cStructure = s;
collideStructure(s, b) {
this.collides = true;
this.cStructure = s;
this.cBounds = b;
}

postUpdate() {

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

@@ -27,19 +27,20 @@ export default class TPhysics extends Trait {
if (
this.entity.has("collider") &&
collider.collides &&
this.velocity.y >= 0) {
this.velocity.y >= 0 &&
this.entity.bounds.bottomIntersects(collider.cBounds)) {

// Structures are static; just teleport us to the top of them
if (collider.cStructure) {
this.velocity.y = 0;
this.entity.bounds.bottom = collider.cStructure.top;
this.entity.bounds.bottom = collider.cBounds.top;
this.onGround = true;

// If we're colliding with an entity, and that entity is
// a platform, teleport us to the top of them.
} else if (collider.cEntity.has("platform")) {
this.velocity.y = 0;
this.entity.bounds.bottom = collider.cEntity.bounds.top;
this.entity.bounds.bottom = collider.cBounds.top;
this.onGround = true;

if (collider.cEntity.has("physics")) {

Loading…
Cancel
Save