This commit is contained in:
Anuken
2026-08-28 17:04:22 -04:00
parent 98cec2df46
commit 3f65bdd383
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -555,6 +555,30 @@ public class World{
}
}
public static void raycastEachNoDiagonalWorld(float x0, float y0, float x1, float y1, Raycaster cons){
raycastEachNoDiagonal(toTile(x0), toTile(y0), toTile(x1), toTile(y1), cons);
}
public static void raycastEachNoDiagonal(int startX, int startY, int endX, int endY, Raycaster cons){
int xDist = Math.abs(endX - startX);
int yDist = -Math.abs(endY - startY);
int xStep = (startX < endX ? +1 : -1);
int yStep = (startY < endY ? +1 : -1);
int error = xDist + yDist;
while(true){
if(cons.accept(startX, startY) || (startX == endX && startY == endY)) break;
if(2 * error - yDist > xDist - 2 * error){
error += yDist;
startX += xStep;
}else{
error += xDist;
startY += yStep;
}
}
}
public static boolean raycast(int x1, int y1, int x2, int y2, Raycaster cons){
int x = x1, dx = Math.abs(x2 - x), sx = x < x2 ? 1 : -1;
int y = y1, dy = Math.abs(y2 - y), sy = y < y2 ? 1 : -1;
+1 -1
View File
@@ -263,7 +263,7 @@ public class Damage{
if(hitter.type.collidesGround && hitter.type.collidesTiles){
seg1.set(x, y);
seg2.set(seg1).add(vec);
World.raycastEachWorld(x, y, seg2.x, seg2.y, (cx, cy) -> {
World.raycastEachNoDiagonalWorld(x, y, seg2.x, seg2.y, (cx, cy) -> {
Building tile = world.build(cx, cy);
boolean collide = tile != null && tile.collide(hitter) && hitter.checkUnderBuild(tile, cx * tilesize, cy * tilesize)
&& ((tile.team != team && tile.collide(hitter)) || hitter.type.testCollision(hitter, tile)) && collidedBlocks.add(tile.pos());