News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Floor Lighting

Started by kevin, September 15, 2008, 08:22:34 AM

Previous topic - Next topic

kevin

 Floor Lighting 

  This examples creates a basic floor lighting effect using gouraud shaded sprites.   


  Requires PB V1.64


   
 

kevin

#1
  Here's a version of the above demo for PlayBasicFX.

PlayBASIC Code: [Select]
   img=getFreeimage()
Load3dimage "gfx\panelfloor.jpg",img
scaleimage img,150,150,1+4


Type Tile
Spr
endtype

Dim Map(1000) as tile

iw=getimagewidth(img)
ih=getimageheight(img)
sw=getscreenwidth()
sh=getscreenheight()
index=1
for ylp=0 to sh-1 step Ih
for xlp=0 to sw-1 step Iw
spr=newsprite(xlp,ylp,Img)
SpriteDrawmode Spr,2
spritetransparent spr,off
map(index).spr=spr
inc index
next
next


; lightXpos=getScreenWidth()
; lightYpos=50
; lightZpos=getScreenHeight()
lightcolour=rgb(055,255,155)


Do
cls 0

lightxpos#=mousex()
lightzpos#=mousey()


drawallsprites

for lp=0 to getarrayelements(Map(),1)
Spr=map(lp).spr
if Spr
for vertex=0 to 3
x#=getspritevertexX(Spr,vertex)
y#=getspritevertexY(Spr,vertex)
col=vertex*2550
dist#=getdistance2d(x#,y#,lightxpos#,lightzpos#)
thisrgb=255-(dist#*0.25)
if ThisRgb>255 then ThisRGb=255
if ThisRgb<0 then ThisRgb=0
ThisRGB=rgb(thisrgb,thisrgb,thisrgb)
PokeSpriteFaceRGB spr,0,Vertex,rgbalphamult(Thisrgb,lightcolour)
next
endif
next


if Mousebutton()
lightColour=rndrgb()
endif
Sync
loop