The "light buffer array" is just a 2d array (100 elements by 16 elements) used to represent the sprite color values for each light. You are right, I changed it from an int array to a byte array forgot that numbers will be 0-16 which easily fits within the byte limits. I'm drawing sprites by calling the drawimage command. I'd like to do this with the native Blitzmax library if possible but if I need to go to OpenGL I can. The code will just bloat more for all of those image conversion and mapping and drawing commands. Does that help any?
Function interpolate_color3:color(r:Float, g:Float, b:Float, r2:Float, g2:Float, b2:Float, r3:Float, g3:Float, b3:Float, p:Float)
Local c:color = New color
'p is the decimal percent along the gradient
If p < 0.5
p= p /.5
Local result_red:Float = r + ((r2 - r) * p)
Local result_green:Float = g + ((g2 - g) * p)
Local result_blue:Float = b + ((b2 - b) * p)
c.set_rgb(result_red, result_green, result_blue)
Return c
EndIf
If p
p=p/1.0
' we now have to subtract .0.5 from p since we nove to the next gradient!
Local result_red:Float = r2 + ((r3 - r2) * p)
Local result_green:Float = g2 + ((g3 - g2) * p)
Local result_blue:Float = b2 + ((b3 - b2) * p)
c.set_rgb(result_red, result_green, result_blue)
Return c
EndIf
EndFunction
' fill the intensity lookup table
For Local p:Float = 0 To 15
color_lookup[p] = interpolate_color3(0, 0, 0, 20, 70, 255, 128, 255, 255, Float(p) / 15)
Next
' fill the buffer
For Local x:Int = 0 To 99
For Local y:Int = 0 To 15
buffer[x, y] = 0
Next
Next
Global T:Int =0
While not KeyDown(KEY_ESCAPE)
Cls
update_game()
t:+1
If t=50
Local E:enemy = New enemy
e.x=96
e.y=rand(1,13)
e.timer=0
listaddlast(enemies,e)
t=0
End If
For Local x:Int = 0 To 99
For Local y:Int = 0 To 15
'is there any color there? check before drawing a sprite
If buffer[x,y]
SetColor(color_lookup[buffer[x, y]].r,color_lookup[buffer[x, y]].g,color_lookup[buffer[x, y]].b)
Drawoval(x * 8, y * 8,8,8)
setcolor(255,255,255)
DrawImage(light, x * 8, y * 8, 1)
EndIf
' clear that pixel after drawing
buffer[x,y]=rand(0,5)
Next
Next
Flip
Wend