Skip to content

Instantly share code, notes, and snippets.

@NoelFB
Created June 9, 2011 23:13
Show Gist options
  • Save NoelFB/1017972 to your computer and use it in GitHub Desktop.
Save NoelFB/1017972 to your computer and use it in GitHub Desktop.
// render light circles
for (i = 0; i < lights.length; i ++)
{
l = lights[i];
var isSet:Object = new Object();
for (j = 0; j < l.distance * 2; j++)
{
isSet[j] = new Object();
}
for (j = 0; j < 360; j += 1)
{
var depth:int = 1;
var maxDepth:int = 1;
for (k = 1; k < l.distance; k++)
{
// get the grid point
var t_x:int = l.distance + k * Math.cos(j * Math.PI / 180);
var t_y:int = l.distance + k * Math.sin(j * Math.PI / 180);
if (isSet[t_x][t_y])
continue;
isSet[t_x][t_y] = true;
t_x += l.x - l.distance;
t_y += l.y - l.distance;
if (t_x < 0 || t_x > Global.width || t_y < 0 || t_y > Global.height)
continue;
if (Global.terrain.getBlock(t_x, t_y) != Terrain.BLOCK_AIR)
depth --;
if (depth <= 0)
break;
var percent:int = k / l.distance;
var strength:Number = strength * percent * (depth / maxDepth);
map[t_x][t_y] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment