Collide with all tile layers

This commit is contained in:
Bill Rossi 2025-06-07 11:07:53 -04:00
parent 64a21c91a3
commit 499814553f
3 changed files with 146 additions and 3 deletions

View File

@ -27,7 +27,7 @@ export default class Player extends Actor {
this.x += this.xVel
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))
if (tur.length >= 1) {
this.x -= this.xVel

View File

@ -26,14 +26,22 @@ export default class Room {
}
draw(ctx) {
this.json.layers.forEach(this.drawLayer.bind(this, ctx))
this.tileLayers.forEach(this.drawTileLayer.bind(this, ctx))
}
drawLayer(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 },
{ x: rect.x + rect.width, y: rect.y },
{ x: rect.x, y: rect.y + rect.height },

View File

@ -224,6 +224,141 @@
"type":"bool",
"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,
"type":"tileset",