我正在用 Java 制作平铺(平铺大小为 16 像素)级别的滚动游戏。现在我正在处理照明系统。我用这个代码为每个光(黄色块和瓷砖)计算了光梯度(如图所示):
visMap = new int[level.getWidth() * level.getHeight()];
int lighted = 0;
for (int x = 0; x < level.getWidth(); x++) {
for (int y = 0; y < level.getHeight(); y++) {
double xd = (this.x >> 4) - x;
double yd = (this.y >> 4) - y;
double distance = Math.sqrt(xd * xd + yd * yd);
double p = power * 1.0;
double bright = p - distance;
visMap[x + y * level.getWidth()] = (int) (bright * power);
}
}
现在我正试图让方块以某种方式阻挡光线(就像在现实生活中一样)。有什么好的方法吗?提前致谢, Zaplik
图片:点击