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

if (!bounds) if (!bounds)
return; return;


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



+ 5
- 0
js/Rect.js View File

(this.left <= other.right && this.right >= other.left) && (this.left <= other.right && this.right >= other.left) &&
(this.top <= other.bottom && this.bottom >= other.top)); (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) { contains(other) {
return ( return (

+ 1
- 1
js/Texture.js View File

if (e instanceof Array) { if (e instanceof Array) {
this.fillCanvas(e); this.fillCanvas(e);
} else { } 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

export default class Tile {
constructor(x, y, name) {
this.x = x;
this.y = y;
this.name = name;
}
}

+ 7
- 5
js/tiles.js View File

import Tile from "./Tile.js"

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

this.collides = false; this.collides = false;
this.cEntity = null; this.cEntity = null;
this.cStructure = null; this.cStructure = null;
this.cBounds = null;
} }


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


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


postUpdate() { postUpdate() {

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

if ( if (
this.entity.has("collider") && this.entity.has("collider") &&
collider.collides && 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 // Structures are static; just teleport us to the top of them
if (collider.cStructure) { if (collider.cStructure) {
this.velocity.y = 0; this.velocity.y = 0;
this.entity.bounds.bottom = collider.cStructure.top;
this.entity.bounds.bottom = collider.cBounds.top;
this.onGround = true; this.onGround = true;


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


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

Loading…
Cancel
Save