TGC Codebase Backup



A Small Particle Tutor by Morpheus

30th Mar 2006 19:00
Summary

My particle tutor, its very small and the tutoring is done in the comment lines with a running program to show the result.



Description

Too lazy to write a long description. Its a tutorial on particles.

All the media is in the RAR file, although you could just take that source code then make two identical blank bitmaps probably and just name them floor and sky.

Have fun!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Particles Tutorial v1 by Max Neave
`Done 31/3/06
`Hope this is of use to people for making their programs look much cooler

`main menu

`turn the 3d backdrop on
backdrop on
`set the colour of the backdrop (pointless here since it gets changed later)
color backdrop rgb (40,0,0)
`set the text size (duh)
set text size 48
`set ink to white
ink rgb(255,255,255),1

`set the display resolution so it doesnt look like crap
set display mode 1024,768,32

do
`set the 2d mouse position (also fairly pointless here)
set cursor 0,30
`MENU
`This is the position of the current button
ink rgb(255,0,0),1
text 0,40,"Particle Tutor v1 By Maxwell Neave"
ink rgb(0,120,0),1
text 0,55,"I recommend you read the comment lines in the code to understand the workings"
ink rgb(100,100,0),1
text 0,730,"All media items are hand made in MS Paint"
ink rgb(255,255,255),1
text 0,100,"Begin Particle Tutor!"

`The first statement tells us that if the mouse cursor x position is between 0 and 160
`and the mouse cursor y position is between 100 and 110, the colour of the text will change.
if mousex()>=0 and mousex()<=160 and mousey()>=100 and mousey()<=110
ink rgb(0,255,255),1
text 0,100,"Begin Particle Tutor!"
ink rgb(255,255,255),1
endif

`This statement does the same as the above, except it checks for a mouseclick in
`the same area, it then goes to the required subroutine if the mouse is clicked
if mousex()>=0 and mousex()<=160 and mousey()>=90 and mousey()<=110 and mouseclick()=1
text 180,100,"Make program go now..."

goto start
endif

loop

`main program initiating subroutine
start:
cls
`change the backdrop colour to black
color backdrop rgb (0,0,0)

`autocamera off, hide the mouse
autocam off
hide mouse

`set camera range and sync rate
set camera range 1,3000
sync on
sync rate 60

`set fog
Fog on
Fog distance 2500
Fog color RGB(0,0,0)

`load matrix texture
load bitmap "floor.bmp",1
get image 1,0,0,128,128
delete bitmap 1

`make matrix (the ground)
make matrix 1,3000,3000,30,30

`Prepare matrix with a texture cut into a 2x2 texture grid
prepare matrix texture 1,1,2,2

`Fill matrix with first texture tile
fill matrix 1,0.0,1
for fillmatrix=0 to 10
   for fillmatrix2=0 to 10
      if rnd(2)=0 then set matrix tile 1,x,y,2
      set matrix tile 1,0,y,3
      set matrix tile 1,10,y,3
      set matrix tile 1,x,0,3
      set matrix tile 1,x,10,3
      set matrix tile 1,x,5,4
      set matrix tile 1,x,5,4
   next fillmatrix2
next fillmatrix
update matrix 1

`create player object hide it
make object sphere 655,150
position object 655,100,100,100
hide object 655

`Stops the drawing of unseen polygons (efficient)
SET OBJECT CULL 655,1

`make sky
`load the image for the sky
load image "sky.bmp",4
`make a sphere, set its size to negative so the texture shows on the inside
make object sphere 69,-4500
`position the object around the matrix
position object 69,1500,0,1500
`apply the texture
texture object 69,4

`==================================
`small generalised explosion (like a bomb going off, or a lemming from the top of a tall building)

`this one requires a balance between velocity and speed
`velocity decides how high the particles will go and hence how long they
`then take to reach the ground again
`speed is how fast this process happens, too fast and no one will see the explosion
`set particle emissions gives the explosion effect of lots of particles at once in a short burst

`These particles are RED

make particles 1,22,5,20
set particle emissions 1,500
set particle speed 1,0.04
set particle velocity 1,6
position particles 1,200,10,1500
color particles 1,255,0,0
set particle floor 1,0
set particle gravity 1,1.5

`======================================
`large high explosion (like a cannon shell or someone being decapitated with a shotgun)

`same as the above, except using gravity to limit how high the particles travel due to velocity
`this has higher velocity and slightly decreased speed to get the timing just right
`basically the explosion starts off fast by velocity then the "dust" settles slowly by gravity
`set particle emissions gives the explosion effect of lots of particles at once in a short burst

`These particles are GREEN

make particles 2,23,5,20
set particle emissions 2,250
position particles 2,1500,10,200
color particles 2,0,255,0
set particle velocity 2,20
set particle speed 2,0.035
set particle floor 2,0
set particle gravity 2,4

`=======================================
`downward particles (like rain or mass aerial suicide maybe)
`stand directly underneath for most rain like effect

`rain particles are merely default particles set at a high height and 0 "floor"
`they simply fall to the ground, the speed sets how fast they do

`note that if they had high velocity they would go turn into a "fountain"
`this tells us the particle object emmits particles upwards by default

`These particles are BLUE

make particles 3,24,5,20
set particle floor 3,0
position particles 3,500,400,800
color particles 3,0,0,255
set particle speed 3,0.01

`========================================
`upward chaotic particles (like a fountain or a burst cartoid artery)

`fountain particles are particles with a high speed and velocity, like a water jet
`the velocity is the particles energy to defeat gravity here, hence why they go up in the air
`the chaos makes the particles wobble slighlty, i thought it looked cool

`note that speed here merely defines how far the objects progress per frame or how fast the
`particle animation is over

`These particles are WHITE

make particles 4,24,5,20
set particle floor 4,0
position particles 4,1500,10,1500
set particle speed 4,0.035
set particle velocity 4,25
set particle chaos 4,10


`=========================================================================

`start main loop
`i cant be bothered commenting on this bit properly so you can guess most of it yourself
do
set cursor 0,0
`show the fps(frames per second)
print "Particle Tutorial by Maxwell Neave"
print "Colours: Red=Bomb Explosion, Green=Shell Explosion, Blue=Rain, White=Fountain"
print " "
print "Frames Per Second: ", screen fps()
`Player position
x1= object position x(655)
z1= object position z(655)
y1= object position y(655)

`Make sure the player is on the map
if x1<=0 then position object 655,x1+50,y1,z1
if x1>=3000 then position object 655,x1-50,y1,z1

if z1<=0 then position object 655,x1,y1,z1+50
if z1>=3000 then position object 655,x1,y1,z1-50

   `CAMERA SETTINGS
`position camera at location and angle of object 1 (player)
position camera object position x(655),object position y(655),object position z(655)
rotate camera object angle x(655),object angle y(655),object angle z(655)

`camera look using mouse
cya#=wrapvalue(cya#+(mousemovex()/3.0))
cxa#=cxa#+(mousemovey()/3.0)

if cxa#<-45.0 then cxa#=-45.0
if cxa#>45.0 then cxa#=45.0

cx#=newxvalue(x#,cya#,sin(cxa#)*10)
cz#=newzvalue(z#,cya#,sin(cxa#)*10)

rotate camera wrapvalue(cxa#),cya#,0
rotate object 655,0,camera angle y(),0
position camera object position x(655),object position y(655),object position z(655)

   `MOVEMENT
`forward backward movement
if upkey()=1 then move object 655,9
if downkey()=1 then move object 655,-9

`strafing
if leftkey()=1 then move object left 655,9
if rightkey()=1 then move object right 655,9

`jumping - not really needed, too lazy to delete it
`if player presses the control key and ajump=1 set jumpb to 1 and height to 23
`and play the jump sound
if controlkey()=1 and ajump=1
   jumpb=1
   height=23

endif
`if jumpb=1 height=height-1 and the players Y position is set to Y+height
if jumpb=1
   height=height-1
   position object 655,object position x(655),object position y(655)+height,object position z(655)
endif

`if the players Y position exceeds 100 then stop the player being able to jump
`if its less than 100 then position the player back to original height
if object position y(655)>100 then ajump=0 else ajump=1
if object position y(655)<100
   position object 655,object position x(655),100,object position z(655)
   jump=0
   height=0
endif

`end program loop
sync
loop