TGC Codebase Backup



Alien Animation Code by Ian T

30th Aug 2003 9:33
Summary

Code that handles the animating of the competiton Alien model.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Code by Mouse
`Uses Alien competition model
`You have to supply a grass image
`Uncomment the two skysphere lines if you have a sky.jpg image you can use
`Thanks to TheDarthster for help with angle functions!

`Setup
autocam off : sync on : sync rate 60 : randomize timer() : backdrop on : color backdrop rgb(0,0,0) : hide mouse
set camera range 0,0.1,2500 : color backdrop RGB(24,189,113) : set ambient light 60 : fog on : fog color RGB(100,180,180) : fog distance 800

`Objects
make object sphere 500,2000,15,25 : scale object texture 500,2,1 : scale object 500,130,20,130
`load image "sky.jpg",600 : texture object 500,600 : set object 500,1,1,0,0,0,0,0 : set object specular 500,5 : set object light 500,0
load object "Alien.x",550 : scale object 550,10,10,10 : rotate object 550,0,180,0 : fix object pivot 550

`Matrix
load image "grass.bmp",1 : make matrix 1,8000,8000,20,20 : prepare matrix texture 1,1,1,1 : position matrix 1,-2500,10,-2500

`Variables
stamina=2000

`Loop
do

  `Snapping
  If object position x(550)>400 then position object 550,object position x(550)-400,object position y(550),object position z(550) : position camera camera position x()-400, camera position y(),camera position z()
  If object position x(550)<-400 then position object 550,object position x(550)+400,object position y(550),object position z(550) : position camera camera position x()+400, camera position y(),camera position z()
  If object position z(550)>400 then position object 550,object position x(550),object position y(550),object position z(550)-400 : position camera camera position x(), camera position y(),camera position z()-400
  If object position z(550)<-400 then position object 550,object position x(550),object position y(550),object position z(550)+400 : position camera camera position x(), camera position y(),camera position z()+400

  `Record Variables
  orot#=rotx#

  `Stamina
  stamina=stamina+1 : if stamina<-50 : stamina=-50 : endif : if stamina>2000 : stamina=2000 : endif

  `Mouselook
  mmx=mousemovex() : mmy=mousemovey() : rotx#=wrapvalue(rotx#+(mmx/2)) : roty#=wrapvalue(roty#+(mmy/2))
  if roty#<150 and roty#>90 : roty#=90 : endif : if roty#>250 and roty#<300 : roty#=300 : endif
  heightval=heightval+mmy : if heightval<10 : heightval=10 : endif : if heightval>75 : heightval=75 : endif

  `Stamina Box
  ink rgb(0,0,60),0 : box screen width()-35,30,screen width()-20,230 : ink rgb(0,0,255),0 : box screen width()-35,230-(stamina*200)/2000,screen width()-20,230
  line screen width()-35,30,screen width()-20,30 : line screen width()-35,30,screen width()-35,230 : line screen width()-35,230,screen width()-20,230 : line screen width()-20,230,screen width()-20,30
  ink rgb(255,255,255),0

  `Checks
  if object frame(550)=550 then moving=0 : play object 550,0,0 : stamina=stamina-5

  `Fall
  if stamina<5 and moving<2 then moving=4 : play object 550,200,250 : ftimer=1
  if ftimer>0 : ftimer=ftimer+1 : endif : if ftimer>175 : ftimer=0 : play object 550,250,299 : moving=100 : endif
  if object frame(550)=299 then play object 550,0,0 : moving=0

  `Moving
  if moving<2 then moving=0
  if inkey$()="w" and moving<2 then move object 550, 1 : moving=1 : stamina=stamina-1
  if inkey$()="s" and moving<2 then move object 550, -0.7 : moving=1 : stamina=stamina-1

  `Walking
  fixed=0
  if moving=0 and object frame(550)=670 then play object 550,720,750 : fixed=1
  if moving=0 and object frame(550)=720 then play object 550,720,750 : fixed=1
  if moving=1 and object frame(550)=670 and object playing(550)=0 then play object 550,670,720 : fixed=1
  if moving=1 and object frame(550)=720 then play object 550,670,720 : fixed=1
  if moving=1 and fixed=0 and object playing(550)=0 then play object 550,650,670 : fixed=1

  `Jump
  if inkey$()="e" and jump#=0 and ftimer=0 and moving=0 then fall#=1.5 : play object 550,501,525 : moving=2
  if moving=2 : move object 550,1.5 : stamina=stamina-5 : endif : if object frame(550)=525 and jump#=<10 : play object 550,525,550 : moving=3 : endif
  fall#=fall#-0.03 : jump#=jump#+fall# : if fall#<-10 : fall#=-10 : endif : if jump#<0 : jump#=0 : endif

  `Idle
  if moving=0 and object playing(550)=0 then idle=idle+1
  if moving>0 then idle=0
  if idle>175 : temp=rnd(1) : if temp=1 : moving=9 : endif : if temp=0 : moving=11 : endif : endif
  if moving=9 then play object 550,0,100 : idle=0 : moving=10
  if moving=11 then play object 550,400,500 : idle=0 : moving=12
  if object frame(550)=100 and moving=10 then play object 550,0,0 : moving=0
  if object frame(550)=500 and moving=12 then play object 550,0,0 : moving=0

  `Attack
  temp=0
  if moving=0 and spacekey()=1 and ftimer=0
    temp=rnd(1)
    if temp=1 then moving=5
    if temp=0 then moving=7
  endif
  if moving=5 then play object 550,150,199 : moving=6
  if moving=7 then play object 550,300,349 : moving=8
  if object frame(550)=199 then play object 550,0,0 : moving=0
  if object frame(550)=349 then play object 550,0,0 : moving=0


  position object 550, object position x(550),jump#+10,object position z(550)
  if moving<2 : obrot#=curveangle(rotx#,obrot#,15) : endif : rotate object 550,0,obrot#,0
  set camera to follow object position x(550),object position y(550),object position z(550),rotx#,heightval+40,heightval,10,0
  point camera object position x(550),object position y(550)+7,object position z(550) : if orot#<>rotx# then idle=0

  `Skysphere
  `position object 500,object position x(550),object position y(550),object position z(550)

  sync
loop