FIREWORK by TheComet10th Jul 2007 6:36
|
---|
Summary This shows a rocket taking off and exploding in the air. I would only run this program on a fast computer(it takes up a lot of processing time and internal memory). Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem ************************************ rem * FIREWORK * rem ************************************ rem * author : THE COMET * rem * date : 15,11,2006 * rem ************************************ rem setup screen BACKDROP OFF sync on sync rate 100 hide mouse set camera range 1,10000 rem load textures load image "cottag02.bmp",1 load image "fire.bmp",2 rem make red particles for t=50001 to 50500 center text 320,20,"LOADING RED PARTICLES... PLEASE WAIT" make object cube t,25 color object t,rgb(255,0,0) next t rem make green particles center text 320,80,"LOADING GREEN PARTICLES... PLEASE WAIT" for t=60001 to 60500 make object cube t,25 color object t,rgb(0,255,0) next t rem make explosion sphere make object sphere 9,10 texture object 9,2 ghost object on 9 hide object 9 rem number of particles rem input "how many particles do you want? (max=1000)",pmax pmax=200 rem particles are loading... center text 320,130,"...PROCESSING " + str$(pmax) + " FIRE PARTICLES..." rem load particles For x = 0 to pmax Make object cube x+10,50 Texture object x+10,2 Set object x+10,1,0,0 Ghost object on x+10 Hide object x+10 Next x pn=10 for z=pmax+1 to pmax+pmax+2 Make object cube z+10,50 Texture object z+10,2 Set object z+10,1,0,0 Ghost object on z+10 Hide object z+10 text 320,50,"max=" + str$(pmax) text 320,50,"made: " + str$(z) next z pn2=pmax+10 rem make rocket if file exist("plane.x")=1 load object "plane.x",2 position object 2,1,1,1 texture object 2,1 scale object 2,1000,1000,1000 yrotate object 2,180 xrotate object 2,90 fix object pivot 2 hide object 2 else rem make a simple sphere make object sphere 2,1 position object 2,1,1,1 hide object 2 endif rem make objects for particles to come from make object sphere 3,5 : hide object 3 make object sphere 4,5 : hide object 4 rem coordinants for particle objects bx#=object position x(2) by#=object position y(2) bz#=object position z(2) rem position particle objects position object 3,bx#-5,by#,bz# position object 4,bx#+5,by#,bz# glue object to limb 3,2,9 glue object to limb 4,2,9 rem load explosion center text 320,170,"LOADING WHITE PARTICLES... PLEASE WAIT" gosub particles rem sync sync on sync rate 100 backdrop on color backdrop 0 rem loop position camera 0,4500,-6000 point camera 0,4000,0 m=5 mouse=0 bulletlife=0 move=0 d=0 r=0 sc=100 red=50001 green=60001 pn=10 pn2=pmax+1 do rem user help center text 320,20,"...PRESS MOUSE TO START..." if mouse=1 position camera 0,4500,-6000 point camera 0,4000,0 rem move rocket up inc r d=d+r position object 2,0,d,0 rem bulletpositions bx#=object position x(2) by#=object position y(2) bz#=object position z(2) lx#=object position x(3) ly#=object position y(3) lz#=object position z(3) lx2#=object position x(4) ly2#=object position y(4) lz2#=object position z(4) rem position particle objects if y>315 or y<45 position object 3,bx#-5,by#,bz# position object 4,bx#+5,by#,bz# endif if y>90-46 and y<90+46 position object 3,bx#,by#,bz#+5 position object 4,bx#+5,by#,bz#-5 endif if y>180-46 and y<180+46 position object 3,bx#-5,by#,bz# position object 4,bx#+5,by#,bz# endif if y>270-46 and y<270+46 position object 3,bx#,by#,bz#+5 position object 4,bx#,by#,bz#-5 endif endif rem trigger bullet if mouseclick()=1 show object 2 position object 2,x#,y#,z# show object 2 bulletlife=1 mouse=1 endif if bulletlife>0 then gosub bullet rem rotate red particles for t=50001 to 50500 rotate object t,rnd(180),rnd(180),rnd(180) rem and efect by gravity random2=rnd(800)-400 point object t,random2,0,0 move object t,40 next t rem rotate green particles for t=60001 to 60500 rotate object t,rnd(180),rnd(180),rnd(180) rem and efect by gravity random3=rnd(800)-400 point object t,random3,0,0 move object t,40 next t rem if <space> is pressed... if d>6000 rem ...get a random point... x#=bx# y#=by#+10 z#=bz# rem ...and request an explosion,max particles,intensity,80 life request_explosion(x#,y#,z#,max(1),inten#,120) endif rem If rocket reached its height stop and fade fire-track if d>6000 inc sc,20 mouse=0 for t=10 to pmax+pmax+12 rem scale object t,sc,sc,sc rem fade object t,sc next t rem If rocket reached its height stop and fade fire-track if d>6000 inc sc,20 mouse=0 for t=10 to pmax+pmax+12 rem scale object t,sc,sc,sc rem fade object t,sc next t rem reset positions position object 2,0,0,0 bx#=0 by#=0 bz#=0 d=0 r=0 endif rem if fading is done, hide rocket-trail if sc=2000 d=0 r=0 sc=100 endif endif rem this function must be called once every cycle to deal with the particles handle_explosion rem refresh screen sync rem loop loop bullet: rem control bullet rem move object 2,sp rem control particles inc Pn inc pn2 rem always point particles to player for t=10 to pmax point object t,bX#,bY#,bZ# next t if Pn=pmax+1 then Pn=10 Scale object Pn,100,100,100 rem Position object Pn,bX#,bY#,bZ# point object Pn,bX#,bY#,bZ# Zrotate object Pn,rnd(180) Show object Pn if Pn2=pmax+pmax+2 then Pn2=pmax+1 Scale object Pn2,100,100,100 rem Position object Pn2,bX#,bY#,bZ# point object Pn2,bX#,bY#,bZ# Zrotate object Pn2,rnd(180) Show object Pn2 position object pn,bx#,by#,bz# position object pn2,bx#,by#,bz# rem position red particles inc red if red=50500 then red=50001 random=rnd(800)-400 position object red,random,by#-10,0 rem position green particles inc green if green=60500 then green=60001 random4=rnd(800)-400 position object green,random4,by#-10,0 rem kill bullet if bulletlife<0 bulletlife=0 hide object 2 endif return particles: rem Arrays for position, velocity and life of each particle dim partx#(40000) dim party#(40000) dim partz#(40000) dim partxvel#(40000) dim partyvel#(40000) dim partzvel#(40000) dim partlife(40000) inten#=400 camz#=50 rem User prompt dim max(1) max(1)=40000 center text 320,20,"...PROCESSING "+str$(max(1))+" PARTICLES..." rem Make the particle objects, starting from object 50 sync on for t=39001 to 40000 : make object plain (50+t),40,40 : hide object (50+t) : next t return rem functions: rem ----------------- rem request explosion function request_explosion(ex#,ey#,ez#,particles,intensity#,life) t=39001:p=0 repeat t=t+1 rem if the particular particle (gettit?) is not busy... (is dead): if partlife(t)=0 p=p+1 rem ...make it alive... partlife(t)=life + rnd(life/5) rem ....put it at the center of the explosion.... partx#(t)=ex# party#(t)=ey# partz#(t)=ez# rem ...and give it some push. partyvel#(t)=rnd(intensity#)-(intensity#/2) partxvel#(t)=rnd(intensity#)-(intensity#/2) partzvel#(t)=rnd(intensity#)-(intensity#/2) rem ...oh, and make it visible! show object (50+t) endif rem if the number of particles requested is met, exit the loop if p>=particles then exit until t>=max(1) endfunction rem ---------------- rem handle explosion function handle_explosion() for t=39001 to 40000 rem if the particle is alive... if partlife(t)>1 partlife(t) = partlife(t) - 1 position object 50+t,partx#(t),party#(t),partz#(t) rem calculate friction partxvel#(t)=partxvel#(t)*0.95 partyvel#(t)=partyvel#(t)*0.95 partzvel#(t)=partzvel#(t)*0.95 rem and gravity... partyvel#(t)=partyvel#(t)-0.5 rem and add the acceleration values to the actual coordinates. partx#(t) = partx#(t) + partxvel#(t) party#(t) = party#(t) + partyvel#(t) partz#(t) = partz#(t) + partzvel#(t) rem if it hits the ground, reverse its horisontal acceleration so it bounces if party#(t)<=0 then partyvel#(t)=partyvel#(t)*-0.7 rem do some random rotation so it looks good... rotate object t+50,wrapvalue(object angle x(t+50)+rnd(50)),wrapvalue(object angle y(t+50)+rnd(50)),0 endif rem if particle is close to dying... if partlife(t)=1 rem ...make it dead partlife(t)=0 rem ...and hide it too. hide object 50+t endif next t endfunction |