TGC Codebase Backup



Street Lamps by Hamish McHaggis

12th Oct 2003 6:30
Summary

Street lamps with haze around them, and a lit floor.



Description

The haze is made using a simple particle effect with textured, ghosted planes layered on top of each other. The glow on the floor is a lightmap.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `#####################
`# Lamp haze
`# By Joseph Thomson
`# 12/10/03
`#####################

`Variables
numLamps as word = 10
numPlanes as word = 5

dim lampX(numLamps) as float
dim lampZ(numLamps) as float

`Setup
sync on
sync rate 60
autocam off
hide mouse

`Create a bitmap for the haze effect
create bitmap 1,30,30
set current bitmap 1

`Draw a circle in the middle of the bitmap
for x=1 to 360
   for y=1 to 10
      dot 15+sin(x)*y,15+cos(x)*y
   next y
next x

`Blur the bitmap to get a smooth texture and get the image
blur bitmap 1,8
get image 1,0,0,30,30
delete bitmap 1

`Create a bitmap for the lightmap
create bitmap 1,100,100
set current bitmap 1

randomize timer()

`Draw a bit of light on the whole lightmap
ink rgb(100,100,100),0
box 0,0,100,100

`Set light to full intensity
ink rgb(255,255,255),0
`Loop through lamps
for l=1 to numLamps
   `Set a random position for them
   lampX(l)=(rnd(1000)-500)*0.8
   lampZ(l)=(rnd(1000)-500)*0.8
   `Draw a circle of white where the lamp is
   for x=1 to 360
      for y=1 to 5
         dot (lampX(l)+500)/10+sin(x)*y,100-(lampZ(l)+500)/10+cos(x)*y
      next y
   next x
next l

`Blur the bitmap to get a smooth texture and get the image
blur bitmap 1,8
get image 2,0,0,100,100
delete bitmap 1

`Loop through lamps
for l=1 to numLamps
   `Make the head of the lamp
   make object box (l-1)*2+1,6,8,6
   position object (l-1)*2+1,lampX(l),50,lampZ(l)
   color object (l-1)*2+1,rgb(100,100,100)
   `Make the stem of the lamp
   make object box (l-1)*2+2,2,50,2
   position object (l-1)*2+2,lampX(l),23,lampZ(l)
   color object (l-1)*2+2,rgb(200,200,200)
   `Loop through the haze planes
   for x=1 to numPlanes
      `Make them increasing in size each loop
      make object plain 100+l*20+x,5+x*5,5+x*5
      `Texture the plane with the haze texture
      texture object 100+l*20+x,1
      `Ghost the object and make the black seethrough and make it un-affected by ambient light
      ghost object on 100+l*20+x
      set object transparency 100+l*20+x,1
      set object ambient 100+l*20+x,0
      `Fade the plane, more as the plane gets bigger, fade the plane more the further it is away from the camera
      fade object 100+l*20+x,50-sqrt((camera position x()-lampX(l))^2+(camera position y()-50)^2+(camera position z()-lampZ(l))^2)/20
   next x
next l

`Colour backdrop
backdrop on
color backdrop rgb(0,0,50)

`Make the floor and apply the lightmap to it
make object box 1000,1000,5,1000
position object 1000,0,0,0
color object 1000,rgb(30,30,30)
set light mapping on 1000,2

position camera 0,30,0

do
   `Loop through lamps and planes
   for l=1 to numLamps
      for x=1 to numPlanes
         `If the plane is in screen...
         if object in screen(100+l*20+x)=1
            `Position it where the lamp is
            position object 100+l*20+x,lampX(l),50,lampZ(l)
            `Point it at the camera
            point object 100+l*20+x,camera position x(),camera position y(),camera position z()
            `Move it towards the camera so it doesn't intersect the lamp object
            move object 100+l*20+x,6+x*2
            `If the camera moves fade the plane, more as the plane gets bigger, fade the plane more the further it is away from the camera
            if upkey()+downkey()>0 then fade object 100+l*20+x,50-sqrt((camera position x()-lampX(l))^2+(camera position y()-50)^2+(camera position z()-lampZ(l))^2)/20
            show object 100+l*20+x
         `Otherwise hide the object
         else
            hide object 100+l*20+x
         endif
      next x
   next l

   `Move the camera variables with mouse
   a#=wrapvalue(a#+mousemovex()/5)
   look#=wrapvalue(look#+mousemovey()/5)
   `Move camera with up+downkeys
   rotate camera 0,a#,0
   move camera upkey()-downkey()*2
   rotate camera look#,a#,0

   text 0,0,str$(screen fps())
   sync
loop