Collide with all tile layers
This commit is contained in:
parent
64a21c91a3
commit
499814553f
@ -27,7 +27,7 @@ export default class Player extends Actor {
|
|||||||
this.x += this.xVel
|
this.x += this.xVel
|
||||||
this.y += this.yVel
|
this.y += this.yVel
|
||||||
|
|
||||||
const tur = this.game.currentRoom.tilesUnderRectangle(this.game.currentRoom.json.layers[0], this).filter(x => x)
|
const tur = this.game.currentRoom.tilesUnderRectangle(this).filter(x => x)
|
||||||
const colliders = tur.filter(tile => tile.properties.find(prop => prop.name == "collides" && prop.value))
|
const colliders = tur.filter(tile => tile.properties.find(prop => prop.name == "collides" && prop.value))
|
||||||
if (tur.length >= 1) {
|
if (tur.length >= 1) {
|
||||||
this.x -= this.xVel
|
this.x -= this.xVel
|
||||||
|
12
src/room.js
12
src/room.js
@ -26,14 +26,22 @@ export default class Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw(ctx) {
|
draw(ctx) {
|
||||||
this.json.layers.forEach(this.drawLayer.bind(this, ctx))
|
this.tileLayers.forEach(this.drawTileLayer.bind(this, ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
drawLayer(ctx, layer) {
|
drawLayer(ctx, layer) {
|
||||||
if (layer.type == "tilelayer") this.drawTileLayer(ctx, layer)
|
if (layer.type == "tilelayer") this.drawTileLayer(ctx, layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
tilesUnderRectangle(layer, rect) {
|
get tileLayers() {
|
||||||
|
return this.json.layers.filter(layer => layer.type == "tilelayer")
|
||||||
|
}
|
||||||
|
|
||||||
|
tilesUnderRectangle(rect) {
|
||||||
|
return this.tileLayers.map(layer => this.tilesUnderRectangleInLayer(layer, rect)).flat()
|
||||||
|
}
|
||||||
|
|
||||||
|
tilesUnderRectangleInLayer(layer, rect) {
|
||||||
return [{ x: rect.x, y: rect.y },
|
return [{ x: rect.x, y: rect.y },
|
||||||
{ x: rect.x + rect.width, y: rect.y },
|
{ x: rect.x + rect.width, y: rect.y },
|
||||||
{ x: rect.x, y: rect.y + rect.height },
|
{ x: rect.x, y: rect.y + rect.height },
|
||||||
|
@ -224,6 +224,141 @@
|
|||||||
"type":"bool",
|
"type":"bool",
|
||||||
"value":true
|
"value":true
|
||||||
}]
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":180,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":182,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":184,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":200,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":201,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":202,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":203,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":204,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":205,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":220,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":221,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":222,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":223,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":224,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":225,
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"collides",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
}]
|
||||||
}],
|
}],
|
||||||
"tilewidth":64,
|
"tilewidth":64,
|
||||||
"type":"tileset",
|
"type":"tileset",
|
||||||
|
Loading…
Reference in New Issue
Block a user