This commit is contained in:
Anuken
2020-12-13 10:27:44 -05:00
parent d6546a38c0
commit ddd9f2259c
2 changed files with 13 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ public class Damage{
private static Tile furthest;
private static Rect rect = new Rect();
private static Rect hitrect = new Rect();
private static Vec2 tr = new Vec2();
private static Vec2 tr = new Vec2(), seg1 = new Vec2(), seg2 = new Vec2();
private static Seq<Unit> units = new Seq<>();
private static GridBits bits = new GridBits(30, 30);
private static IntQueue propagation = new IntQueue();
@@ -120,6 +120,7 @@ public class Damage{
collidedBlocks.clear();
tr.trns(angle, length);
Intc2 collider = (cx, cy) -> {
Building tile = world.build(cx, cy);
boolean collide = tile != null && collidedBlocks.add(tile.pos());
@@ -138,10 +139,14 @@ public class Damage{
};
if(hitter.type.collidesGround){
world.raycastEachWorld(x, y, x + tr.x, y + tr.y, (cx, cy) -> {
seg1.set(x, y);
seg2.set(seg1).add(tr);
world.raycastEachWorld(x, y, seg2.x, seg2.y, (cx, cy) -> {
collider.get(cx, cy);
if(large){
for(Point2 p : Geometry.d4){
for(Point2 p : Geometry.d4){
Tile other = world.tile(p.x + cx, p.y + cy);
if(other != null && (large || Intersector.intersectSegmentRectangle(seg1, seg2, other.getBounds(Tmp.r1)))){
collider.get(cx + p.x, cy + p.y);
}
}

View File

@@ -441,6 +441,10 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return rect.setCentered(drawx(), drawy(), block.size * tilesize, block.size * tilesize);
}
public Rect getBounds(Rect rect){
return rect.set(x * tilesize - tilesize/2f, y * tilesize - tilesize/2f, tilesize, tilesize);
}
@Override
public void hitbox(Rect rect){
getHitbox(rect);