Hello there forum members, just thought I would do a little demo on how I emplimented a full 3rd person level with sparkys collition. with jump and camera collition, its simple code and easy to understand. Ive explained alot in the code, and i will explain more if asked. thanks
REM Project: Jacks Graduation
REM Created: 12/6/2009 11:47:59 PM
REM
REM ***** Main Source File *****
REM
Rem *****************************************************************************************
Rem ******** we put this here to tell ai to start *********
Rem *****************************************************************************************
ai start
rem *****************************************************************************************
Rem ******** set up general properties *********
Rem *****************************************************************************************
sync on:sync rate 30:autocam off:set display mode 1280,768,32:set dir "Files"
rem *****************************************************************************************
Rem ******** enter your name *********
Rem *****************************************************************************************
cls
load image "menu\1.jpg",1,1:load image "menu\hud.jpg",2,1:load music "audio\daydreaming.mp3",1:paste image 1,0,35:sync
do
play music 1
sync:SET CURSOR 425,1:INPUT "enter your name then press enter:>";name$
if returnkey()=1
delete image 1
delete image 2
delete music 1
gosub menu
endif
loop
rem *****************************************************************************************
Rem ******** main menu stuff *********
Rem *****************************************************************************************
menu:
BACKDROP OFF
load image "menu\1.jpg",1,1:load image "menu\hud.jpg",2,1:load music "audio\daydreaming.mp3",1
cls
paste image 1,0,35:sync
rem *****************************************************************************************
Rem ******** MENU TEXT COLOR *********
Rem *****************************************************************************************
Global Standard : Standard = RGB(255,255,255):Global Selected : Selected = RGB(280,280,255)
Rem *****************************************************************************************
Rem ******** MENU LOOP *********
Rem *****************************************************************************************
Do
set cursor 1,1:PRINT "Welcome, ";name$
sync:show mouse:play music 1:TEXT 250,100,"JACKS GRADUATION":If HyperLink(250,250,"Play a new game") = 1 Then gosub playlevalone
If HyperLink(250,450,"Exit Game") = 1 Then end
loop
Rem *****************************************************************************************
Rem ******** load leval one this is how to set it up *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** put in your load stuff first then read from file *********
Rem *****************************************************************************************
open to read 1,name$+".dat"
read float 1,xc#
read float 1,yc#
read float 1,zc#
read float 1,axc#
read float 1,ayc#
read float 1,azc#
read long 1, points
read long 1,Seconds
read long 1,Minutes
for x=1 to 40
read float 1,x#
read float 1,y#
read float 1,z#
read float 1,ax#
read float 1,ay#
read float 1,az#
position object x,x#,y#,z#
xrotate object x,ax#
yrotate object x,ay#
zrotate object x,az#
next x
position camera 0,xc#,yc#,zc#
close file 1
Rem *****************************************************************************************
Rem ******** we goto the loop after load *********
Rem *****************************************************************************************
gosub loop1
Rem *****************************************************************************************
Rem ******** we load in the same stuff here for a new game *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** we put in a statement to jump to from the menu *********
Rem *****************************************************************************************
playlevalone:
rem delete menu music
delete music 1
Rem *****************************************************************************************
Rem ******** load music and images for loading *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** this will load in stuff for a loading bar *********
Rem *****************************************************************************************
load music "audio\power-juice.mp3",600:load image "menu\loading 1.jpg",2,0:load image "menu\loadingbarbox.png",3,0:load image "menu\loadingbar1.png",4,0:load image "menu\loadingbar2.png",5,0:load image "menu\loadingbar3.png",6,0:load image "menu\loadingbar4.png",7,0:load image "menu\loadingbar5.png",8,0:load image "menu\loadingbar6.png",9,0:load image "menu\loadingbar7.png",10,0:load image "menu\loadingbar8.png",11,0
Rem *****************************************************************************************
Rem ******** this will paist it to screen while loading *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** put this after so many objects to show loading *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** just change the loading bars image number *********
Rem *****************************************************************************************
cls
paste image 2,0,55:paste image 3,365,600:paste image 4,375,613:Text 555,650,"LOADING:":sync
loop music 600:hide mouse:disable escapekey
Rem *****************************************************************************************
Rem ******** global integers and floats *********
Rem *****************************************************************************************
Playr = 3
d# = 80.0
h# = 60.0
s# = 10.0
points=0
Timed=0
text1=1
collected1=2
minmode1=1
textsize1=1
guardpatrool1=1
guardpatrool2=1
guardpatrool3=1
guardpatrool4=1
mode=0
randomize timer()
global numSpheres as integer : numSpheres = 5
global radius# as double float : radius# = 7.0
global littleRadius# as double float : littleRadius# = 2.0
global rtimer as integer
global stimer as integer
global vtimer as integer
rem player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global gravity# as double float : gravity# = -0.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
global jumptimer as integer : jumptimer = 0
global syncmode as integer : syncmode = 5
global view as integer : view = 1
global hide as integer : hide = 0
type Save_Load_File
`position data
Obj_Pos_X#
Obj_Pos_Y#
Obj_Pos_Z#
`rotation data
Obj_Ang_X#
Obj_Ang_Y#
Obj_Ang_Z#
` size data
Obj_Size_X#
Obj_Size_Y#
Obj_Size_Z#
endtype
Rem *****************************************************************************************
Rem ******** position camera and make sky *********
Rem *****************************************************************************************
position camera 0,2251.35,67.0998,-3894.95
realrange#=15000.0
set camera range 2.0,realrange#
` load our skybox
load object "skybank\ww2\Cty\cty.X", 2
set object light 2, 0
set object texture 2, 3, 1
set object cull 2,1
sk#=(100*(realrange#-8000))/5.0
scale object 2,sk#,sk#,sk#
Rem *****************************************************************************************
Rem ******** load in all objects *********
Rem *****************************************************************************************
` load the level and make a static mesh for it
load object "levelbank\testlevel2\universe.dbo", 1:set object light 1, 0:sc_setupComplexObject 1,1,2
cls
paste image 2,0,55:paste image 3,365,600:paste image 5,375,613:Text 555,650,"LOADING:":sync
rem Load player model and shader effect
load object "entitybank\Characters\Civil Soldiers 08\civ_assault.X",3:load image "entitybank\Characters\Civil Soldiers 08\civ_assault_D2.tga",600,1:texture object 3,600:scale object 3,75,75,75:position object 3,2249, 515, -3850:sc_setupObject 3,0,1:yrotate object 3,180
cls
paste image 2,0,55:paste image 3,365,600:paste image 6,375,613:Text 555,650,"LOADING:":sync
cls
paste image 2,0,55:paste image 3,365,600:paste image 7,375,613:Text 555,650,"LOADING:":sync
load object "entitybank\plr\zombie 1.X",21:load image "entitybank\plr\zombie 1_D.jpg",555:texture object 21,555:scale object 21,90,90,90:position object 21,3100, 510, -2018:set object speed 21,50:sc_setupObject 21,1,1
rem load game items
rem new 2
cls
paste image 2,0,55:paste image 3,365,600:paste image 8,375,613:Text 555,650,"LOADING:":sync
load object "entitybank\Characters2\guard 1.X",33:load effect "entitybank\Characters2\guard 1.fx",2,1:set object effect 33,2:position object 33,2282, 503, -2415:fix object pivot 33:scale object 33,80,80,80:sc_setupComplexObject 33,1,2
load object "entitybank\Characters2\guard 1.X",34:set object effect 34,2:position object 34,3740, 503, -1610:fix object pivot 34:scale object 34,80,80,80:sc_setupComplexObject 34,1,2
cls
paste image 2,0,55:paste image 3,365,600:paste image 9,375,613:Text 555,650,"LOADING:":sync
load object "entitybank\Characters2\guard 1.X",35:set object effect 35,2:position object 35,100.1587, 503, -1462.73:fix object pivot 35:scale object 35,80,80,80:sc_setupComplexObject 35,1,2
load object "entitybank\Characters2\guard 1.X",36:set object effect 36,2:position object 36,3133, 503, -615:fix object pivot 36:scale object 36,80,80,80:sc_setupComplexObject 36,1,2
load object "entitybank\commando\VWEAP.X",41:load image "entitybank\commando\gun_D.dds",9:texture object 41,9:position object 41,2249, 515, -3850
Rem *****************************************************************************************
Rem ******** this will gluse a gun to your 3rd person player *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** things to know here, you should know the limb number *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** I just choose difrent onse till i got the right one *********
Rem *****************************************************************************************
scale object 41,95,95,95
OFFSET LIMB 3, 53, 4.2, -2, -0.5
glue object to limb 41,3,53,2
cls
paste image 2,0,55:paste image 3,365,600:paste image 10,375,613:Text 555,650,"LOADING:":sync
rem make trigger boxes
REM FRIEND 1 TRIGGERS
make object box 500,150,30,150:position object 500,3100, 502, -2018:set object collision on 500:hide object 500
make object box 501,150,30,150:position object 501,3100, 502, -2018:set object collision on 501:hide object 501
REM SECURITY GUARD 1 way point TRIGGERS
make object box 503,150,30,150:position object 503,2282, 503, -2415:hide object 503
make object box 504,150,30,150:position object 504,2249, 502, -3850:hide object 504
REM SECURITY GUARD 2 way point TRIGGERS
make object box 505,40,200,40:position object 505,3740, 503, -1610:hide object 505
make object box 506,40,200,40:position object 506,3421, 503, -1745:hide object 506
REM SECURITY GUARD 3 way point TRIGGERS
make object box 507,40,200,40:position object 507,100.157, 503, -1462:hide object 507
make object box 508,40,200,40:position object 508,239, 503, -1449:hide object 508
REM SECURITY GUARD 4 way point TRIGGERS
make object box 509,40,200,40:position object 509,3133, 503, -615:hide object 509
make object box 510,40,200,40:position object 510,2218, 503, -588:hide object 510
rem make collision boxes guard 1
make object box 502,40,200,40:position object 502,2282, 503, -2415:sc_setupComplexObject 502,1,2:hide object 502
rem make collision boxes guard 2
make object box 511,40,200,40:position object 511,3740, 503, -1610:sc_setupComplexObject 511,1,2:hide object 511
rem make collision boxes guard 3
make object box 512,40,200,40:position object 512,100.1587, 503, -1462.73:sc_setupComplexObject 512,1,2:hide object 512
rem make collision boxes guard 4
make object box 513,40,200,40:position object 513,3740, 503, -1610:sc_setupComplexObject 513,1,2:hide object 513
rem make collision trigger box 1 for guard 1
make object box 514,300,60,1500:position object 514,2282, 503, -3015:hide object 514
rem make collision trigger box 2 for guard 2
make object box 515,1000,60,1000:position object 515,3740, 503, -1610:hide object 515
rem make collision trigger box 3 for guard 3
make object box 516,1000,60,1000:position object 516,100.1587, 503, -1462.73:hide object 516
rem make collision trigger box 4 for guard 4
make object box 517,2000,60,1000:position object 517,3133, 503, -615:hide object 517
T=Timer()
set image colorkey 255,0,0
load music "audio\lovers-walk.mp3",1:load music "audio\Gravel fast.wav",2:load music "audio\you win 1.wav",3:load sound "audio\fire.wav",1:load sound "audio\blowkiss.wav",2:load sound "audio\pick.wav",3:load image "menu\Instructions hud.jpg",7:load image "entitybank\items\artifact.jpg",6
load image "texturebank\flash\flash7.dds",8
make object plain 518,5,5
texture object 518,8
glue object to limb 518,41,3,2
SET OBJECT TRANSPARENCY 518, 1
hide object 518
Rem *****************************************************************************************
Rem ******** this sprite is for the gun flash, we attach it to the gun in the loop *********
Rem *****************************************************************************************
create animated sprite 1,"texturebank\flash\sparks\decal.dds",4,4,20
hide light 0
make light 1
position light 1,3094,590,-2057
` come out of the media directory
delete music 600
cls
paste image 2,0,55:paste image 3,365,600:paste image 11,375,613:Text 555,650,"LOADING:":sync
Rem *****************************************************************************************
Rem ******** this will position the camera to the player *********
Rem *****************************************************************************************
loop1:
if object exist(3)=1 then position camera 0,object position x(3),object position y(3),object position z(3)
do
Rem *****************************************************************************************
Rem ******** this is a switch to switch between difrent functions *********
Rem *****************************************************************************************
Rem *****************************************************************************************
Rem ******** this switch switches between camera distances *********
Rem *****************************************************************************************
if mode=0 then positioncameratoplyrx()
if mode=1 then positioncameratoplyr()
if keystate(33)=1 then mode=1
if keystate(4)=1 then mode=0
Rem *****************************************************************************************
Rem ******** this will save your game to file as you players name *********
Rem *****************************************************************************************
if keystate (59)=1 then save1=1
if save1=1
if file exist(name$+".dat")=1 then delete file name$+".dat"
open to write 1,name$+".dat"
xc#=camera position x(0)
yc#=camera position y(0)
zc#=camera position z(0)
acx#=camera angle x(0)
ayc#=camera angle y(0)
azc#=camera angle z(0)
write float 1,xc#
write float 1,yc#
write float 1,zc#
write float 1,axc#
write float 1,ayc#
write float 1,azc#
write long 1, points
write long 1,Seconds
write long 1,Minutes
for x=1 to 40
x#=object position x(x)
y#=object position y(x)
z#=object position z(x)
ax#=object angle x(x)
ay#=object angle y(x)
az#=object angle z(x)
write float 1,x#
write float 1,y#
write float 1,z#
write float 1,ax#
write float 1,ay#
write float 1,az#
next x
close file 1
CENTER TEXT 500, 160, "Save Succesfull! Press enter key to continue."
`one endif was removed here
endif
if save1=1 and returnkey()=1 then save1=0
Rem *****************************************************************************************
Rem ******** this will pause your game *********
Rem *****************************************************************************************
If Inkey$()="p"
wait key
wait 200
Endif
Rem *****************************************************************************************
Rem ******** this is to display the game instructons to screen *********
Rem *****************************************************************************************
if displayinstructions=1
paste image 7,250,150,1
if returnkey()=1
displayinstructions=0
endif
endif
if keystate(23)=1
displayinstructions=1
if returnkey()=1
displayinstructions=0
endif
endif
Rem *****************************************************************************************
Rem ******** PRINT NAME TO SCREEN *********
Rem *****************************************************************************************
set cursor 1,1:PRINT "You are, ";name$
Rem *****************************************************************************************
Rem ******** this is a mode to make you run from walk ,RUN MODE *********
Rem *****************************************************************************************
if keystate (19)=1
runmode=1
endif
if runmode=1
if upkey()=1
move object 3,-3
move camera 2.5
animestate#=4
endif
endif
if keystate(20)=1
runmode=0
endif
Rem *****************************************************************************************
Rem ******** BACK TO MENU *********
Rem *****************************************************************************************
if escapekey()=1 then delete objects 1,100:delete music 1:delete music 2:delete music 3:delete sound 1:delete sound 2:delete sound 3:delete image 1:delete image 2:delete image 3:delete image 4:gosub menu
Rem *****************************************************************************************
Rem ******** LOOP LEVEL MUSIC *********
Rem *****************************************************************************************
loop music 1
Rem *****************************************************************************************
Rem ******** TEXT display instructions *********
Rem *****************************************************************************************
if textsize1=1 then SET TEXT SIZE 25
INK RGB(255,255,255),0:set cursor 0, 0
Rem *****************************************************************************************
Rem ******** Sky stays with camera *********
Rem *****************************************************************************************
if object exist(2)=1 then position object 2,camera position x(0),camera position y(0),camera position z(0)
Rem *****************************************************************************************
Rem ******** trigger boxes follows guards *********
Rem *****************************************************************************************
rem guard 1
if object exist(502)=1 then position object 502,object position x(33),object position y(33),object position z(33):sc_updateObject 502
rem guard 2
if object exist(511)=1 then position object 511,object position x(34),object position y(34),object position z(34):sc_updateObject 511
rem guard 3
if object exist(512)=1 then position object 512,object position x(35),object position y(35),object position z(35):sc_updateObject 512
rem guard 4
if object exist(513)=1 then position object 513,object position x(36),object position y(36),object position z(36):sc_updateObject 513
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 1 MOVES WITH TRIGGER ZONES *********
Rem *****************************************************************************************
if guardpatrool1=1
move object 33,2
animestatedg#=1
if object collision (33,503)=1 then move=1:move2=0
if move=1 then point object 33,object position x(504),object position y(504),object position z(504)
if object collision (33,504)=1 then move2=1:move=0
if move2=1 then point object 33,object position x(503),object position y(503),object position z(503)
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 2 MOVES WITH TRIGGER ZONES *********
Rem *****************************************************************************************
if guardpatrool2=1
animestatedg2#=1:move object 34,2
if object collision (34,505)=1 then move3=1:move4=0
if move3=1 then sc_updateobject 34:point object 34,object position x(506),object position y(506),object position z(506)
if object collision (34,506)=1 then move4=1:move3=0
if move4=1 then sc_updateobject 34:point object 34,object position x(505),object position y(505),object position z(505)
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 3 MOVES WITH TRIGGER ZONES *********
Rem *****************************************************************************************
if guardpatrool3=1
animestatedg3#=1:move object 35,2
if object collision (35,507)=1 then move5=1:move6=0
if move5=1 then sc_updateobject 35:point object 35,object position x(508),object position y(508),object position z(508)
if object collision (35,508)=1 then move6=1:move5=0
if move6=1 then sc_updateobject 35:point object 35,object position x(507),object position y(507),object position z(507)
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 4 MOVES WITH TRIGGER ZONES *********
Rem *****************************************************************************************
if guardpatrool4=1
animestatedg4#=1:move object 36,2
if object collision (36,509)=1 then move7=1:move8=0
if move7=1 then sc_updateobject 36:point object 36,object position x(510),object position y(510),object position z(510)
if object collision (36,510)=1 then move8=1:move7=0
if move8=1 then sc_updateobject 36:point object 36,object position x(509),object position y(509),object position z(509)
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 1 RUNS AND STOPS PLAYER *********
Rem *****************************************************************************************
if object collision (3,514)=1 and runmode=1
guardpatrool1=2
endif
if guardpatrool1=2
guard1attack=1
endif
if guard1attack=1
point object 33,object position x(3),object position y(3),object position z(3)
move object 33,3
endif
if object collision (3,502)=1
Inc Minutes
set object collision off 502
guard1timer=1
endif
if guard1timer=1
timer1=timer1+1
endif
if timer1=10000
set object collision on 502
guard1timer=0
timer1=0
endif
if object collision (3,514)=0
guard1attack=0
guardpatrool1=1
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 2 RUNS AND STOPS PLAYER *********
Rem *****************************************************************************************
if object collision (3,515)=1 and runmode=1
guardpatrool2=2
endif
if guardpatrool2=2
guard2attack=1
endif
if guard2attack=1
point object 34,object position x(3),object position y(3),object position z(3)
move object 34,1.5
endif
if object collision (3,511)=1
Inc Minutes
set object collision off 511
guard2timer=1
endif
if guard2timer=1
timer2=timer2+1
endif
if timer2=10000
set object collision on 511
guard2timer=0
timer2=0
endif
if object collision (3,515)=0
guard2attack=0
guardpatrool2=1
guard2time=0
guard2timer=0
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 3 RUNS AND STOPS PLAYER *********
Rem *****************************************************************************************
if object collision (3,516)=1 and runmode=1
guardpatrool3=2
endif
if guardpatrool3=2
guard3attack=1
endif
if guard3attack=1
point object 35,object position x(3),object position y(3),object position z(3)
move object 35,1
endif
if object collision (3,512)=1
Inc Minutes
set object collision off 512
guard3timer=1
endif
if guard3timer=1
timer3=timer3+1
endif
if timer3=10000
set object collision on 512
guard3timer=0
timer3=0
endif
if object collision (3,516)=0
guard3attack=0
guardpatrool3=1
guard3time=0
guard3timer=0
endif
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 4 RUNS AND STOPS PLAYER *********
Rem *****************************************************************************************
if object collision (3,517)=1 and runmode=1
guardpatrool4=2
endif
if guardpatrool4=2
guard4attack=1
endif
if guard4attack=1
point object 36,object position x(3),object position y(3),object position z(3)
move object 36,2
endif
if object collision (3,513)=1
Inc Minutes
set object collision off 517
guard4timer=1
endif
if guard4timer=1
timer4=timer4+1
endif
if timer4=10000
set object collision on 517
guard4timer=0
timer4=0
endif
if object collision (3,517)=0
guard4attack=0
guardpatrool4=1
guard4time=0
guard4timer=0
endif
Rem *****************************************************************************************
Rem ******** plr ANIMATIONS *********
Rem *****************************************************************************************
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
rem idle animation
if animestate#=0 then loop object 3,210,234:set object speed 3,20
rem walk animation
if animestate#=1 then loop object 3,235,259:set object speed 3,50
rem jump animation
if animestate#=2 then loop object 3:set object speed 3,50
rem crouch animation
if animestate#=3 then loop object 3,356,380
rem run animation
if animestate#=4 then loop object 3,300,318:set object speed 3,100
rem crounch walk
if animestate#=5 then loop object 3,381,405:set object speed 3,100
rem aim gun
if animestate#=7 then loop object 3,573,597:set object speed 3,100
rem shoot
if animestate#=8 then loop object 3,0,19:set object speed 3,100
rem run and shoot
if animestate#=9 then loop object 3,598,622:set object speed 3,100
Rem *****************************************************************************************
Rem ******** FRIENDS ANIMATIONS *********
Rem *****************************************************************************************
rem idle animation
if animestated#=0 then loop object 21,210,234:set object speed 21,100
rem talk animation
if animestated#=1 then loop object 21,3001,3218:set object speed 21,100
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 1 ANIMATIONS *********
Rem *****************************************************************************************
rem idle animation
if animestatedg#=0 then loop object 33,210,233:set object speed 33,100
rem walk animation
if animestatedg#=1 then loop object 33,235,259:set object speed 33,100
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 2 ANIMATIONS *********
Rem *****************************************************************************************
rem idle animation
if animestatedg2#=0 then loop object 34,2522,3000:set object speed 34,100
rem walk animation
if animestatedg2#=1 then loop object 34,235,259:set object speed 34,100
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 3 ANIMATIONS *********
Rem *****************************************************************************************
rem idle animation
if animestatedg3#=0 then loop object 35,2522,3000:set object speed 34,100
rem walk animation
if animestatedg3#=1 then loop object 35,235,259:set object speed 34,100
Rem *****************************************************************************************
Rem ******** SECURITY GUARD 4 ANIMATIONS *********
Rem *****************************************************************************************
rem idle animation
if animestatedg4#=0 then loop object 36,2522,3000:set object speed 36,100
rem walk animation
if animestatedg4#=1 then loop object 36,235,259:set object speed 36,100
Rem *****************************************************************************************
Rem ******** PLAYER MOVE *********
Rem *****************************************************************************************
` react to key presses and move the controller
key = 0
positioncameratoplyrx()
if leftkey()=1 then yrotate object 3,wrapvalue(object angle y(3)-2)
if rightkey()=1 then yrotate object 3,wrapvalue(object angle y(3)+2)
if upkey()=1 then move camera 1.5:key=1
if downkey()=1 then move camera -1.5:key=1
if upkey()=1 and keystate(57)=1 then move object 3,1:move camera 1:animestate#=2
if key = 1 then animestate#=1
if key = 0 then move object 3, 0.0:animestate#=0
if keystate(57)=1 and upkey()=1 then jump1=1
if keystate(57)=1 then jump1=1
if keystate(2)=1 and key = 0 then play sound 2:thumbsup=1
if thumbsup=1 then animestate#=3:timethumbsup=1
if timethumbsup=1 then timer1=timer1+1
if timer1=180 then thumbsup=0: timer1=0:timethumbsup=0
if keystate(46)=1 then crouch=1
if crouch=1 then animestate#=3:positioncameratoplyr()
if crouch=1 and keystate(46)=1 then crouch=0
if keystate(46)=1 and upkey()=1 then animestate#=5:move camera 0,1
if mouseclick()=1 then fight=1
if fight=1
play sound 1
show object 518
play sprite 1,1,4,80
paste sprite 1,mousex(),mousey()
animestate#=7
endif
if mouseclick()=1 and fight=1 then runmode=0
if mouseclick()=0 then hide object 518:fight=0
yrotate object 3,wrapvalue(object angle y(3)+(mousemovex()*0.2))
yrotate camera 0,wrapvalue(camera angle y(0)+(mousemovex()*0.2))
position mouse SCREEN_MID_X, SCREEN_MID_Y
rotate sprite 1,atanfull(sprite x(1)-MouseX(),sprite y(1)-MouseY())
Rem *****************************************************************************************
Rem ******** FUNCTION LOOPS *********
Rem *****************************************************************************************
movePlayer()
camera(num)
handleExtraSpheres(num)
sync
loop
Rem *****************************************************************************************
Rem ******** FUNCTIONS *********
Rem *****************************************************************************************
function positioncameratoplyr()
x#=object position x(3)
y#=object position y(3)
z#=object position z(3)
a#=object angle y(3)
d#=-20.0
h#=10.0
s#=50.0
set camera to follow x#,y#,z#,a#,d#,h#,s#,1
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
oldx# = object position x(3)
oldy# = object position y(3)
oldz# = object position z(3)
endfunction positioncameratoplyr
function positioncameratoplyrx()
x#=object position x(3)
y#=object position y(3)
z#=object position z(3)
a#=object angle y(3)
d#=-35.0
h#=60.0
s#=50.0
set camera to follow x#,y#,z#,a#,d#,h#,s#,1
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
oldx# = object position x(3)
oldy# = object position y(3)
oldz# = object position z(3)
endfunction positioncameratoplyrx
Function HyperLink(X,Y,String$)
If MouseX() > X And MouseX() < X + Text Width(String$) And MouseY() > Y And MouseY() < Y + Text Height(String$)
Ink Selected,0
Text X,Y,String$
Click = MouseClick()
Else
Ink Standard,0
Text X,Y,String$
Click = 0
EndIf
EndFunction Click
function handleExtraSpheres(num)
for i=33 to 33+num
rem move all the little spheres towards the player and slide them
oldx# = object position x(i)
oldy# = object position y(i)
oldz# = object position z(i)
x# = object position x(i)
y# = object position y(i)
z# = object position z(i)
rem little spheres collide with all (0)
collide = sc_sphereSlide(0,oldx#,oldy#,oldz#,x#,y#,z#,littleRadius#,i)
if collide>0
position object i,sc_getCollisionSlideX(),sc_getCollisionSlideY(),sc_getCollisionSlideZ()
endif
sc_updateObject i
next i
endfunction handleExtraSpheres
function movePlayer()
rem rotate player with mouse
oldx# = object position x(3)
oldy# = object position y(3)
oldz# = object position z(3)
rem apply gravity, and user changes to movement
angy# = object angle y(3)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if rightkey()=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if leftkey()=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if vy#=0 and jumptimer=0 then vy# = vy# + 5*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if downkey()=1 then vx# = vx# + 2 * sin(angy#) : vz# = vz# + 2 * cos(angy#)
if upkey()=1 then vx# = vx# + (-2) * sin(angy#) : vz# = vz# + (-2) * cos(angy#)
rem only jump if on ground, and a certain time after last jump
if ground=1
if keystate(57)=1 and jumptimer=0 then vy# = vy# + 3.3 : jumptimer = 20
if keystate(82)=1 and jumptimer=0 then vy# = vy# + 3.3 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
rem first handle gravity - seperated from horizontal movement
rem to achieve a more realistic effect
rem Method: simple - cast a sphere vertically down, if it hits the level then
rem position the object there (sticky collision) then move
rem on to horizontal movement
rem more complex - if we were to only use the simple method the player would be
rem allowed to climb almost vertical slopes. Alternative is to
rem get the normalY direction to work out how flat the gorund
rem below the player is, 0-slope# is flatter, slope#-1 is steeper.
rem if it's flat, use sticky collision, if it's steep slide the
rem player down the slope. Changing slope# determines how steep the
rem player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object 3,x#,oldy#,z#
sc_updateObject 3
endfunction movePlayer
Text 900,1,"timer"+":"+Min$+":"+Sec$
function camera(num)
oldx# = camera position x(0)
oldy# = camera position y(0)
oldz# = camera position z(0)
move camera 0,-0.2
x# = camera position x(0)
y# = camera position y(0)
z# = camera position z(0)
collide = sc_sphereSlide(1,oldx#,oldy#,oldz#,x#,y#,z#,littleRadius#,0)
if collide>0
position camera 0,sc_getCollisionSlideX(),sc_getCollisionSlideY(),sc_getCollisionSlideZ()
endif
endfunction camera
