mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Gravity and ground height.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import RetroSprite from "./RetroSprite.js";
|
||||
import GeometryRect from "../geometry/GeometryRect.js";
|
||||
import RetroArchitectureTile from "./RetroArchitectureTile.js";
|
||||
import GeometryRectCollection from "../geometry/GeometryRectCollection.js";
|
||||
|
||||
export default class RetroArchitecture
|
||||
{
|
||||
@@ -24,6 +24,29 @@ export default class RetroArchitecture
|
||||
}
|
||||
}
|
||||
|
||||
getCollisionRects(rect)
|
||||
{
|
||||
let posX = Math.floor(rect.position.x / this.tileWidth) - 2;
|
||||
let posY = Math.floor(rect.position.y / this.tileHeight) - 2;
|
||||
let rangeX = parseInt( posX + rect.width / this.tileWidth) + 4;
|
||||
let rangeY = parseInt(posY + rect.height / this.tileHeight) + 4;
|
||||
|
||||
let collection = new GeometryRectCollection();
|
||||
|
||||
for (let y = Math.max(0, posY); y < rangeY; y++) {
|
||||
for (let x = Math.max(0, posX); x < rangeX; x++) {
|
||||
if (y < this.matrix.length && x < this.matrix[y].length && this.matrix[y][x] !== null) {
|
||||
let intersection = this.matrix[y][x].rect.getRectIntersection(rect);
|
||||
if (intersection !== null) {
|
||||
collection.addRect(intersection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
hasRectCollision(rect)
|
||||
{
|
||||
let posX = Math.floor(rect.position.x / this.tileWidth) - 2;
|
||||
|
||||
@@ -46,6 +46,21 @@ export default class RetroSprite
|
||||
return this.canvas.height;
|
||||
}
|
||||
|
||||
getFootHeight()
|
||||
{
|
||||
return new GeometryPoint(this.position.x, this.position.y + this.getHeight());
|
||||
}
|
||||
|
||||
getPositionLeftFoot()
|
||||
{
|
||||
return new GeometryPoint(this.position.x - this.getWidth() * 0.5, this.position.y);
|
||||
}
|
||||
|
||||
getPositionRightFoot()
|
||||
{
|
||||
return new GeometryPoint(this.position.x + this.getWidth() * 0.5, this.position.y);
|
||||
}
|
||||
|
||||
draw(context)
|
||||
{
|
||||
context.drawImage(this.canvas, this.position.x, this.position.y);
|
||||
|
||||
Reference in New Issue
Block a user