mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Terrain collision.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import RetroSprite from "./RetroSprite.js";
|
||||
import RetroArchitectureTile from "./RetroArchitectureTile.js";
|
||||
import GeometryRectCollection from "../geometry/GeometryRectCollection.js";
|
||||
import GeometryPoint from "../geometry/GeometryPoint.js";
|
||||
|
||||
export default class RetroArchitecture
|
||||
{
|
||||
@@ -67,10 +68,10 @@ export default class RetroArchitecture
|
||||
return false;
|
||||
}
|
||||
|
||||
getTileForPosition(position)
|
||||
getTileForPosition(position, offsetX = 0, offsetY = 0)
|
||||
{
|
||||
let x = parseInt(position.x / this.tileWidth);
|
||||
let y = parseInt(position.y / this.tileHeight);
|
||||
let x = parseInt(position.x / this.tileWidth) + offsetX;
|
||||
let y = parseInt(position.y / this.tileHeight) + offsetY;
|
||||
|
||||
if (x < 0 || x >= this.columns || y < 0 || y >= this.rows) {
|
||||
return null;
|
||||
@@ -79,13 +80,28 @@ export default class RetroArchitecture
|
||||
return {x: x, y: y};
|
||||
}
|
||||
|
||||
getCeilingHeight(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(position, 0);
|
||||
|
||||
while (tilePosition !== null && tilePosition.y > 0) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
return tilePosition.y * this.tileHeight + this.tileHeight;
|
||||
}
|
||||
|
||||
tilePosition.y--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
getGroundHeight(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(position);
|
||||
|
||||
while (tilePosition !== null && tilePosition.y < this.rows) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
return tilePosition.y * this.tileHeight
|
||||
return tilePosition.y * this.tileHeight;
|
||||
}
|
||||
|
||||
tilePosition.y++;
|
||||
@@ -94,6 +110,36 @@ export default class RetroArchitecture
|
||||
return this.tileHeight * this.rows;
|
||||
}
|
||||
|
||||
getWallRight(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), 1, -1);
|
||||
|
||||
while (tilePosition !== null && tilePosition.x < this.columns) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
return tilePosition.x * this.tileWidth - this.tileWidth * 0.5;
|
||||
}
|
||||
|
||||
tilePosition.x++;
|
||||
}
|
||||
|
||||
return this.tileWidth * this.columns;
|
||||
}
|
||||
|
||||
getWallLeft(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), -1,-1);
|
||||
|
||||
while (tilePosition !== null && tilePosition.x > 0) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
return tilePosition.x * this.tileWidth + this.tileWidth * 1.5;
|
||||
}
|
||||
|
||||
tilePosition.x--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
draw(context)
|
||||
{
|
||||
for (let y = 0; y < this.rows; y++) {
|
||||
|
||||
Reference in New Issue
Block a user