DBP source for my laser demo.
Rem Project: lazer
Rem Created: 1/28/2004 11:32:07 PM
Rem ***** Main Source File *****
set display mode 800,600,32
sync on
sync rate 60
autocam off
color backdrop 0
REM ================================
REM =========== VARIABLES ==========
REM ================================
particleTotal = 100
type particle
angle1 as float
angle2 as float
time as float
velocity as float
originX as float
originY as float
originZ as float
lifespan as float
alive as integer
endtype
dim particles(particleTotal) as particle
gravity# = 2
particleSize = 1
burnTotal = 800
dim burn_life(burnTotal)
rem life of burn spot in milliseconds
burn_lifespan = 8000
REM ================================
REM ============ IMAGES ============
REM ================================
load image "symbol.jpg", 2,1
load image "particle_blue.jpg", 3
load image "burn_mark.jpg", 3
`load image "burn_mark2.jpg", 4
REM ================================
REM ============ SOUNDS ============
REM ================================
load sound "bounce.wav", 1
load sound "lightning.wav", 2
load sound "background.wav", 3 : loop sound 3
load sound "clickon.wav", 4
REM ================================
REM ============ OBJECTS ===========
REM ================================
rem structure
load object "structure.x", 1
xrotate object 1,90
rem platform base, which the lazer will shoot onto
load object "base.x", 2
xrotate object 2,90
texture object 2, 2
load object "lazer.x", 3
position object 3, 0, 100, 0
ghost object on 3
hide object 3
REM CREATE PARTICLES
REM Initialize particle variables
for t = 1 to particleTotal
make object plain t+10, particleSize, particleSize
texture object t+10, 3
set object t+10, 1,1,0,0,0,0
ghost object on t+10
next t
REM MAKE BURN SPOT OBJECTS
for t=1 to burnTotal
make object plain t+10000,5,5
xrotate object t+10000,90
texture object t+10000,3
set object t+10000, 1,1,0,1,0,1
ghost object on t+10000
next t
REM ================================
REM ============ LIGHTS ============
REM ================================
set ambient light 40
set light range 0,50
color light 0,rgb(100,100,255)
hide light 0
REM ================================
REM =========== MAIN LOOP ==========
REM ================================
DO
rem rotate camera around the structure
a#=wrapvalue(a#-0.03)
cx#=newxvalue(0,wrapvalue(a#+180),150)
cz#=newzvalue(0,wrapvalue(a#+180),150)
position camera cx#,80,cz#
point camera 0,0,0
rem get the coordinates of the mouse on the structure's base
obj = pick object(mousex(),mousey(),2,2)
emitterX# = camera position X()+get pick vector x()
emitterY# = camera position y()+get pick vector y()
emitterZ# = camera position z()+get pick vector z()
if mouseclick() and obj = 2
set ambient light rnd(20)+30
point object 3, emitterX#, 0, emitterZ#
gosub _make_burn_mark
show light 0
if on = 0
play sound 4
initializeParticles = 1
show object 3
loop sound 2
endif
on = 1
else
if on=1
on=0
hide light 0
initializeParticles = 0
hide object 3
stop sound 2
endif
endif
for t=1 to burnTotal
if timer() > burn_life(t) + burn_lifespan then hide object t+10000
next t
if on = 1
rem scale lazer to proper length
scale object 3, 60, 60, sqrt(emitterX#^2 + 10000 + emitterZ#^2)-4
if initializeParticles = 1
initializeParticles = 0
for i = 1 to particleTotal
`if particles(i).lifespan > 0 or object position y(i+10) > 0
`else
gosub _initialize_particle
show object i+10
`endif
next i
endif
endif
if on = 1 or particles_left = 1 then gosub _show_particles
text 1,1,str$(screen fps())
sync
LOOP
REM Handle the particles
_show_particles:
REM Particle loop
particles_left = 0
for i = 1 to particleTotal
if particles(i).alive = 1
particles_left = 1
particles(i).time = particles(i).time + 0.2
pd# = particles(i).velocity * cos(particles(i).angle1) * particles(i).time
py# = particles(i).velocity * sin(particles(i).angle1) * particles(i).time-(0.5*gravity#)*(particles(i).time^2) + particles(i).originY
px# = newxvalue(particles(i).originX, particles(i).angle2, pd#)
pz# = newzvalue(particles(i).originZ, particles(i).angle2, pd#)
REM Particle dies if lifespan is over
REM Reinitialize variables after death
onGround = 0
if py# < 0 then onGround = 1
if particles(i).time >= particles(i).lifespan or onGround = 1
if onGround = 1 then play sound 1
if on = 1
gosub _initialize_particle
else
hide object i+10
particles(i).alive = 0
endif
endif
position object i+10, px#, py#, pz#
set object to camera orientation i+10
endif
next i
RETURN
REM Give birth to a new baby particle (I hope it's a boy)
_initialize_particle:
particles(i).alive = 1
particles(i).time = 0
particles(i).lifespan = rnd(5)
particles(i).velocity = rnd(5)+5
particles(i).angle1 = rnd(80)+50
particles(i).angle2 = rnd(360)
particles(i).originX = emitterX#
particles(i).originY = emitterY#
particles(i).originZ = emitterZ#
RETURN
_make_burn_mark:
inc n
if n = burnTotal then n = 1
position object n+10000,emitterX#,5.5,emitterZ#
show object n+10000
burn_life(n)=timer()
RETURN
"eureka" - Archimedes