forked from jzitnik/twodcraft
25 lines
916 B
Java
25 lines
916 B
Java
package cz.jzitnik.tui;
|
|
|
|
public class ScreenMovingCalculationProvider {
|
|
public static int[] calculate(int x, int y, int terminalHeight, int terminalWidth, int worldX, int worldY) {
|
|
int spriteWidth = 50;
|
|
int spriteHeight = 25;
|
|
|
|
int viewXRadius = (terminalWidth / 2) / spriteWidth;
|
|
int viewYRadius = ((terminalHeight - 30) / 2) / spriteHeight;
|
|
|
|
// Ensure at least one sprite is visible
|
|
viewXRadius = Math.max(viewXRadius, 1);
|
|
int viewUpRadius = Math.max(viewYRadius, 1);
|
|
int viewDownRadius = Math.max(viewYRadius, 1);
|
|
|
|
// Calculate visible area boundaries
|
|
int startX = Math.max(0, x - viewXRadius);
|
|
int endX = Math.min(worldX, x + viewXRadius + 1);
|
|
int startY = Math.max(0, y - viewUpRadius);
|
|
int endY = Math.min(worldY, y + viewDownRadius + 1);
|
|
|
|
return new int[] {startX, endX, startY, endY};
|
|
}
|
|
}
|