Cool Rain Effects by Webber20th Aug 2011 17:51
|
---|
Summary Rain effects made with triangles. Description An endless grass plain, with endless clouds, and endless rain. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Project: Cool Rain Effects `Author: The Game Guy Rem Set up sync on : sync rate 30 : hide mouse color backdrop RGB(81,105,111) : autocam off : set camera range 0,.1,10000 Rem Creates a grass texture using random lines V# = .5 : cls RGB(128,128,80) `Colors the background for i = 1 to 10000 `Creates 10000 lines inc V#,.0001 : ink RGB(112*V#,128*V#,20*V#),0 `Changes the colors of the grass y1 = rnd(256) : y2 = rnd(256) `Randomizes the positions of the lines s1 = rnd(30)-15 : s2 = rnd(30)-15 `The length of each line line y1,y2,y1+s1,y2+s2 `Draws the lines line y1-256,y2,y1+s1-256,y2+s2 : line y1,y2-256,y1+s1,y2+s2-256 `makes the lines seamless line y1+256,y2,y1+s1+256,y2+s2 : line y1,y2+256,y1+s1,y2+s2+256 next i : get image 1,0,0,256,256 `Gets the grass image Rem Creates random dots for a simple splash effect cls ink rgb(255,255,255),0 for i = 1 to 10 dot rnd(128),rnd(128) next i get image 2,0,0,128,128 Rem Loads the image for the clouds load image "Clouds.jpg",3 `load sound "rain01.wav",1 `loop sound 1 Rem invisible object used for positioning the camera make object triangle 1,0,0,0,0,0,0,0,0,0 Rem make the grass plain make object plain 1000,2000,2000 texture object 1000,1 scale object texture 1000,1000,1000 pitch object down 1000,90 Rem make the rain splash effects make object plain 1001,1000,1000 pitch object down 1001,90 scale object texture 1001,100,100 texture object 1001,2 set object transparency 1001,5 Rem Create the clouds make object plane 1002,40000,40000 texture object 1002,3 scale object texture 1002,20,20 ghost object on 1002,2 pitch object down 1002,90 position object 1002,0,100,0 Rem Makes a duplicate of the clouds for a second layer instance object 1003,1002 pitch object up 1003,90 position object 1003,0,110,0 Rem Creates the rain particles particles = 1000 for i = 10001 to particles+10000 if i = 10001 `creates the rain particles source object make object triangle i,0.04,0,0,0,0,0,-0.02,3.5,0 ghost object on i,2 endif if i > 10001 then instance object i,10001 `copys the rain particles position object i,(rnd(140)-70)/2.0,(rnd(180))/2.0,(rnd(140)-70)/2.0 rotate object i,0,rnd(180),0 pitch object down i,(rnd(30)-15.0)/2.0 next i Rem Variables Speed# = 0.5 Slide# = 1.0 JumpStrength# = 0.2 Kirby = 0 Rem Main Loop DO Rem display frames per second set cursor 0,0 : print "FPS: ";screen fps() Rem Mouse variables MMX# = mousemovex() : MMY# = mousemovey() Rem Camera and Object rotation Programing rotate object 1,0,0,0 mox# = mox# + MMX#*Speed# turn object right 1,mox# rotate camera 0,0,0,0 turn camera right 0,mox# cax# = cax# + MMY#*Speed# if cax# > 90 then cax# = 89 if cax# < -90 then cax# = -89 pitch camera down 0,cax# Rem speed adjust MZS# = .06 * Speed# MXS# = .04 * Speed# Rem Arrowkey input if upkey() then ZS# = ZS# + MZS# if downkey() then ZS# = ZS# - MZS# if rightkey() then XS# = XS# + MXS# if leftkey() then XS# = XS# - MXS# Rem Adjusts the slide amount if the player is in the air or on the ground if ground = 1 then Slid# = 1.5 if ground = 0 then Slid# = 4 Rem Speed Adjust Z if ZS# > 0 then ZS# = ZS# -MZS#/(Slid#*Slide#) `can be used for sliding if ZS# < 0 then ZS# = ZS# +MZS#/(Slid#*Slide#) if upkey() = 0 and Downkey() = 0 if ZS# > 0 then ZS# = ZS# -(0.001 * Speed#) if ZS# < 0 then ZS# = ZS# +(0.001 * Speed#) if ZS# > -MZS#/4 and ZS# < MZS#/4 then ZS# = 0 endif Rem Speed Adjust X if XS# > 0 then XS# = XS# -MXS#/(Slid#*Slide#) `can be used for sliding if XS# < 0 then XS# = XS# +MXS#/(Slid#*Slide#) if Rightkey() = 0 and Leftkey() = 0 if XS# > 0 then XS# = XS# -(0.001 * Speed#) if XS# < 0 then XS# = XS# +(0.001 * Speed#) if XS# > -MXS#/4 and XS# < MXS#/4 then XS# = 0 endif if ZS# > MZS#*10 then ZS# = MZS#*10 if ZS# < -MZS#*10 then ZS# = -MZS#*10 if XS# > MXS#*10 then XS# = MXS#*10 if XS# < -MXS#*10 then XS# = -MXS#*10 Rem Move and position the camera move object 1,ZS# move object right 1,XS# if ground = 1 if mouseclick() = 1 `makes the player jump gravity# = -JumpStrength# ground = 0 endif endif if Kirby = 1 `allows the player to jump in the air if mouseclick() = 0 then ground = 1 if gravity# < 100 then gravity# = gravity# +.01 else if ground2 = 0 if object position y(1) > 3 then ground = 0 endif endif Rem the gravity controls move object down 1,gravity# if ground = 0 gravity# = gravity# +.01 endif if object position y(1) < 1 then position object 1,object position x(1),1,object position z(1) if object position y(1) = 1 if mouseclick() = 0 then ground = 1 endif Rem positions the camera position camera 0,object position x(1),object position y(1),object position z(1) REM RAIN PARTICLES LOOP for i = 10001 to particles+10000 move object down i,2.5 `moves the rain particles down Rem repositions the particles if object position y(i) < object position y(1)-30 position object i,(rnd(140)-70)/2.0+Object position x(1),object position y(i)+50+rnd(20)+Object position y(1),(rnd(140)-70)/2.0+Object position z(1) Rem adjust new rain angles rotate object i,0,mox#,0 pitch object down i,ZS#*50 roll object right i,XS#*50 turn object right i,rnd(360) pitch object down i,(rnd(30)-15.0)/2.0 endif Rem Makes the rain particles follow the player if object position x(i) > object position x(1)+50 then position object i,object position x(i)-100,object position y(i),object position z(i) if object position x(i) < object position x(1)-50 then position object i,object position x(i)+100,object position y(i),object position z(i) if object position z(i) > object position z(1)+50 then position object i,object position x(i),object position y(i),object position z(i)-100 if object position z(i) < object position z(1)-50 then position object i,object position x(i),object position y(i),object position z(i)+100 next i Rem makes splash effects position object 1001,object position x(1)+rnd(20)-10,.2,object position z(1)+rnd(20)-10 Rem Moves the clouds move object up 1002,0.5 move object up 1003,0.3 Rem Makes the clouds endless for i = 1002 to 1003 if object position x(i) > object position x(1)+1000 then position object i,object position x(i)-2000,object position y(i),object position z(i) if object position x(i) < object position x(1)-1000 then position object i,object position x(i)+2000,object position y(i),object position z(i) if object position z(i) > object position z(1)+1000 then position object i,object position x(i),object position y(i),object position z(i)-2000 if object position z(i) < object position z(1)-1000 then position object i,object position x(i),object position y(i),object position z(i)+2000 next i Rem Makes the grass plain endless i = 1000 if object position x(i) > object position x(1)+1 then position object i,object position x(i)-2,object position y(i),object position z(i) if object position x(i) < object position x(1)-1 then position object i,object position x(i)+2,object position y(i),object position z(i) if object position z(i) > object position z(1)+1 then position object i,object position x(i),object position y(i),object position z(i)-2 if object position z(i) < object position z(1)-1 then position object i,object position x(i),object position y(i),object position z(i)+2 sync loop end |