CodeBase - Lecon 4 a 14
Return to the CodeBase listing
Category: Complete Applications
Version: 1.0
Information
Uploaded: 1st Mar 2005 00:29
Modified: 1st Jan 1970 01:00
Author: Anonymous Coder
Summary
` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `--------------------------- `Limit Rush `Lesson 13 `Level Complete `--------------------------- `http://www.binarymoon.co.uk `Ben aka Mop `--------------------------- `-------- `INCLUDES `-------- `include the MatEdit LoadMatrix files #include "LoadMatrix.dba" `------ `ARRAYS `------ `declare the MatEdit variables Dim BigMatrix(600,600,1) Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2) Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1) Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500) Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100) Dim MOffsetX(25): Dim MOffsetY(25) Dim MWire(20): Dim MGhost(20): Dim Lock(20) Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20) Dim MatWidth#(20): Dim MatHeight#(20) Dim TilesX(20): Dim TilesZ(20) Dim MatHi#(20): Dim MatLo#(20) `-------------- ` Hot Spot Data `-------------- Dim HotSpot(0) Dim oldHotSpot(0) `-------- ` Gravity `-------- Dim gravity#(0): gravity#(0) = 0.1 `--------- `Player Movement Arrays `--------- Dim xSpeed#(4) Dim ySpeed#(4) Dim zSpeed#(4) Dim friction#(4) Dim moveDist#(4) Dim targetCount(4) `---------- `Initialize Variables `---------- ArenaXZ_SF = 15000 `Arena Scaling Factor ArenaY_SF = 15000 LightXZ_SF# = .46 LightY_SF# = .55 `set up the program sync on sync rate 30 hide mouse autocam off `load the matrix LoadMatrix("map",1) `temporary load level info load object "media/arena.x",100 load object "media/arena_light.x",101 `scale the arena scale object 100, ArenaXZ_SF, ArenaY_SF, ArenaXZ_SF scale object 101, ArenaXZ_SF*LightXZ_SF#, ArenaY_SF*LightY_SF#, ArenaXZ_SF*LightXZ_SF# `position arena position object 100,247,189,247 position object 101,247,189,247 `add mip-mapping set matrix texture 1,2,1 set object texture 100,0,1 set object texture 101,2,1 `set fake light properties set object 101,1,1,0,1,0,0,1 ghost object on 101 `set fog properties fog on fog distance 2000 fog color RGB(128,0,0) `set ambient light amount set ambient light 10 `colour main light color light 0,RGB(0,0,160) `make a light make light 1 set point light 1,250,200,250 color light 1,RGB(255,255,100) `============================== `make a temporary player object `============================== restore data_player_positions id = 1 make object cube id,3 hide limb id,0 `load hovercraft model load object "media/hovercraft.x",10+id load image "media/hovercraft_"+str$(id)+".bmp",40+id texture object 10+id,40+id scale object 10+id,95,95,95 set object texture 10+id,0,1 glue object to limb 10+id,id,0 ` load position read xPos# read zPos# yPos# = get ground height(1,xPos#,zPos#) ` load angle read yAng# ` update the players position position object id,xPos#,yPos#,zPos# yrotate object id,yAng# id = 1 friction#(id) = .97 moveDist#(id) = .065 xSpeed#(id) = 0 zSpeed#(id) = 0 `================================== `load target object (beam of light) `================================== load object "media/light_beam.x",200 load object "media/light_beam2.x",201 make object plain 202,15,15 load image "media/light_3.bmp",30 texture object 202,30 scale object 200,500,1500,500 scale object 201,500,750,500 ghost object on 200 ghost object on 201 `ghost object on 202 set object 200,1,1,0,1,0,0,1 set object 201,1,1,0,1,0,0,1 set object 202,1,1,0,1,0,0,1 `target light make light 3 set point light 3,0,0,0 set light range 3,1000 color light 3,RGB(0,128,255) show light 3 `--------------- `data statements `--------------- data_player_positions: data 262.5,212.5,0 data 212.5,262.5,90 data 262.5,312.5,180 data 312.5,262.5,270 `--------- `MAIN LOOP `--------- main: ` set target new_target() do yAng# = object angle y(1) `the following is temporary. There will be more but it will made later `get keyboard input for movement if upkey()=1 then forward = 1 else forward = 0 if downkey()=1 then backward = 1 else backward = 0 if leftkey()=1 then left = 1 else left = 0 if rightkey()=1 then right = 1 else right = 0 `update the player move_player(1, forward, backward, left, right) `update chase camera chase_cam(1) `display current frame rate text 5,5, "FPS = " + str$(screen fps()) text 5,45, "Hot Spot = " + str$(CheckHotSpot(1)) ` create new target if player reaches target if checkHotspot(1)=hotSpot(0) new_target() targetCount(1)= targetCount(1) + 1 if targetCount(1) = 10 then End_Game() endif `update taret animation gosub update_target `update the screen sync loop `========================== ` End the Game `========================== function End_Game() repeat text 25,50 ,"Congratulation!" text 25,60, "Press Space Key to Exit" sync until spacekey() = 1 end endfunction `=========================== ` Pick a new target location `=========================== function new_target() ` create new hot spot target repeat HotSpot(0) = rnd(7) + 1 until HotSpot(0) <> OldHotSpot(0) ` save new hot spot as old hot spot OldHotSpot = HotSpot `locate the center of the hot spot tile xPos# = (FKey(HotSpot(0),0) * Info(0) - Info(0)/2) zPos# = (FKey(HotSpot(0),1) * Info(1) - Info(1)/2) `locate the height of the hot spot tile yPos# = get ground height(1,xPos#,zPos#) `position beam of light position object 200, xPos#,yPos#,zPos# position object 201, xPos#,yPos#,zPos# position object 202, xPos#,yPos#,zPos# ` Positon lighting position light 3,xPos#,yPos#+10,zPos# endfunction `====================================================== ` Work out the current hotspot the player is on (if any) `====================================================== function CheckHotSpot(id) ` reset the currentHotSpot return variable currentHotSpot = 0 `work out the current tile position of the player tileX = int(object position x(id)/Info(0)) + 1 tileZ = int(object position z(id)/Info(1)) + 1 `check for a hot spot match for hotSpot =1 to 10 if tileX = FKey(hotSpot,0) and tileZ = FKey(hotSpot,1) currentHotSpot = hotSpot exit endif next hotSpot endfunction currentHotSpot `============= `chase cam `============= function chase_cam(id) `work out the angle of the object being chased yAng#= wrapvalue(object angle y(id)+180) `grab the objects current position xPos# = object position x(id) yPos# = object position y(id) zPos# = object position z(id) `other variables camDist = 15 camHeight = 1 `work out new position xCamPos# = newxvalue(xPos#,yAng#,camDist) zCamPos# = newzvalue(zPos#,yAng#,camDist) `camera collision if xCamPos#>485 then xCamPos#=485 if zCamPos#>485 then zCamPos#=485 if xCamPos#<15 then XCamPos#=15 if zCamPos#<15 then zCamPos#=15 `work out camera height yCamPos# = get ground height (1,xCamPos#,zCamPos#)+camHeight if yCamPos# < yPos#+camHeight then yCamPos# = yPos#+camHeight `smooth out the camera effects xCamPos#=curvevalue(xCamPos#,camera position x(),4) yCamPos#=curvevalue(yCamPos#,camera position y(),4) zCamPos#=curvevalue(zCamPos#,camera position z(),4) `update camera position position camera xCamPos#,yCamPos#+camHeight,zCamPos# point camera xPos#, yPos#+camHeight, zPos# endfunction `-------------------------- ` move the specified player `-------------------------- function move_player(id, forward, backward, left, right) `---------------------------------- ` set object floor offset `---------------------------------- floor_offset# = 2.0 `----------------------------------- ` get the required object properties `----------------------------------- xPos# = object position x(id) yPos# = object position y(id) zPos# = object position z(id) yAng# = object angle y(id) `----------------------------- ` Sort out the basic movements `----------------------------- if forward = 1 `move forward code here xSpeed#(id) = xSpeed#(id) + newxvalue(0,yAng#,moveDist#(id)) zSpeed#(id) = zSpeed#(id) + newzvalue(0,yAng#,moveDist#(id)) endif if backward = 1 `move backward code here xSpeed#(id) = xSpeed#(id) + newxvalue(0,yAng#,moveDist#(id) * -1) zSpeed#(id) = zSpeed#(id) + newzvalue(0,yAng#,moveDist#(id) * -1) endif if left = 1 `move left code here yrotate object id, wrapvalue(yAng#-4) endif if right = 1 ` move right code here yrotate object id, wrapvalue(yAng#+4) endif `--------------------------------------------------- ` sort out friction and other physics related things `--------------------------------------------------- ` Work out value with friction and gravity xSpeed#(id) = xSpeed#(id) * friction#(id) zSpeed#(id) = zSpeed#(id) * friction#(id) ySpeed#(id) = ySpeed#(id) + gravity#(0) ` Work out the new position xPos# = xPos# + xSpeed#(id) zPos# = zPos# + zSpeed#(id) yPos# = yPos# - ySpeed#(id) `collision if xPos#>490 then xPos#=490 if zPos#>490 then zPos#=490 if xPos#<5 then xPos#=5 if zPos#<5 then zPos#=5 ` Work out the height of the character if yPos# < get ground height(1, xPos#, zPos#)+ floor_offset# ySpeed#(id) = ySpeed#(id) = (yPos# - get ground height(1, xPos#, zPos#)) yPos# = get ground height(1, xPos#, zPos#) + floor_offset# `------------------------------ `tilt the vehicle to the ground `------------------------------ distVal#=1 `work out the positions of the front, back, left and right of the vehicle ang#=yAng# frontX#=newxvalue(xPos#,ang#,distVal#) frontZ#=newzvalue(zPos#,ang#,distVal#) ang#=yAng#+180 backX#=newxvalue(xPos#,ang#,distVal#) backZ#=newzvalue(zPos#,ang#,distVal#) ang#=yAng#+90 leftX#=newxvalue(xPos#,ang#,distVal#) leftZ#=newzvalue(zPos#,ang#,distVal#) ang#=yAng#-90 rightX#=newxvalue(xPos#,ang#,distVal#) rightZ#=newzvalue(zPos#,ang#,distVal#) `work out the different heights frontHeight# = get ground height(1,frontX#,frontZ#) backHeight# = get ground height(1,backX#,backZ#) leftHeight# = get ground height(1,leftX#,leftZ#) rightHeight# = get ground height(1,rightX#,rightZ#) `Work out tilt values xAng#=wrapvalue((frontHeight#-backHeight#)*30) zAng#=wrapvalue((leftHeight#-rightHeight#)*30) `Work out tilt values xAng#=curveangle((frontHeight#-backHeight#)*30,object angle x(id+10),5) zAng#=curveangle((leftHeight#-rightHeight#)*30,object angle z(id+10),5) `----------------- `slide down slopes `----------------- xMoveDist#=(backHeight#-frontHeight#)/30 zMoveDist#=(leftHeight#-rightHeight#)/30 `adjust forward/ backward momentum xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,xMoveDist#) zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,xMoveDist#) `adjust left/ right momentum xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#-90,zMoveDist#) zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#-90,zMoveDist#) `update the vehicle rotation rotate object id+10,xAng#,180,zAng# endif ` Reposition the player object position object id, xPos#, yPos# , zPos# `display camera object postition for player 1 if id = 1 text 5,15, "X Position = " + str$(xPos#) text 5,25, "Y Position = " + str$(yPos#) text 5,35, "Z Position = " + str$(zPos#) endif endfunction `================= ` rotate the taget `================= update_target: yrotate object 200, wrapvalue(object angle y(200)+2) yrotate object 201, wrapvalue(object angle y(201)-2) yrotate object 202, wrapvalue(object angle y(202)-60) return
Full Description
` This code was downloaded from The Game Creators<br /> ` It is reproduced here with full permission<br /> ` http://www.thegamecreators.com<br /> <br /> `---------------------------<br /> `Limit Rush<br /> `Lesson 13<br /> `Level Complete<br /> `---------------------------<br /> `http://www.binarymoon.co.uk<br /> `Ben aka Mop<br /> `---------------------------<br /> <br /> `--------<br /> `INCLUDES<br /> `--------<br /> `include the MatEdit LoadMatrix files<br /> #include "LoadMatrix.dba"<br /> <br /> `------<br /> `ARRAYS<br /> `------<br /> `declare the MatEdit variables<br /> Dim BigMatrix(600,600,1)<br /> Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)<br /> Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)<br /> Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)<br /> Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)<br /> Dim MOffsetX(25): Dim MOffsetY(25)<br /> Dim MWire(20): Dim MGhost(20): Dim Lock(20)<br /> Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)<br /> Dim MatWidth#(20): Dim MatHeight#(20)<br /> Dim TilesX(20): Dim TilesZ(20)<br /> Dim MatHi#(20): Dim MatLo#(20)<br /> <br /> `--------------<br /> ` Hot Spot Data<br /> `--------------<br /> Dim HotSpot(0)<br /> Dim oldHotSpot(0)<br /> <br /> `--------<br /> ` Gravity<br /> `--------<br /> Dim gravity#(0): gravity#(0) = 0.1<br /> <br /> `---------<br /> `Player Movement Arrays<br /> `---------<br /> Dim xSpeed#(4)<br /> Dim ySpeed#(4)<br /> Dim zSpeed#(4)<br /> Dim friction#(4)<br /> Dim moveDist#(4)<br /> Dim targetCount(4)<br /> <br /> `----------<br /> `Initialize Variables<br /> `----------<br /> ArenaXZ_SF = 15000 `Arena Scaling Factor<br /> ArenaY_SF = 15000<br /> LightXZ_SF# = .46<br /> LightY_SF# = .55<br /> <br /> <br /> `set up the program<br /> sync on<br /> sync rate 30<br /> hide mouse<br /> autocam off<br /> <br /> `load the matrix<br /> LoadMatrix("map",1)<br /> <br /> `temporary load level info<br /> load object "media/arena.x",100<br /> load object "media/arena_light.x",101<br /> <br /> `scale the arena<br /> scale object 100, ArenaXZ_SF, ArenaY_SF, ArenaXZ_SF<br /> scale object 101, ArenaXZ_SF*LightXZ_SF#, ArenaY_SF*LightY_SF#, ArenaXZ_SF*LightXZ_SF#<br /> <br /> `position arena<br /> position object 100,247,189,247<br /> position object 101,247,189,247<br /> <br /> <br /> `add mip-mapping<br /> set matrix texture 1,2,1<br /> set object texture 100,0,1<br /> set object texture 101,2,1<br /> <br /> `set fake light properties<br /> set object 101,1,1,0,1,0,0,1<br /> ghost object on 101<br /> <br /> `set fog properties<br /> fog on<br /> fog distance 2000<br /> fog color RGB(128,0,0)<br /> <br /> `set ambient light amount<br /> set ambient light 10<br /> <br /> `colour main light<br /> color light 0,RGB(0,0,160)<br /> <br /> `make a light<br /> make light 1<br /> set point light 1,250,200,250<br /> color light 1,RGB(255,255,100)<br /> <br /> `==============================<br /> `make a temporary player object<br /> `==============================<br /> restore data_player_positions<br /> id = 1<br /> make object cube id,3<br /> hide limb id,0<br /> <br /> `load hovercraft model<br /> load object "media/hovercraft.x",10+id<br /> load image "media/hovercraft_"+str$(id)+".bmp",40+id<br /> texture object 10+id,40+id<br /> scale object 10+id,95,95,95<br /> <br /> <br /> set object texture 10+id,0,1<br /> glue object to limb 10+id,id,0<br /> <br /> ` load position<br /> read xPos#<br /> read zPos#<br /> yPos# = get ground height(1,xPos#,zPos#)<br /> ` load angle<br /> read yAng#<br /> ` update the players position<br /> position object id,xPos#,yPos#,zPos#<br /> yrotate object id,yAng#<br /> <br /> <br /> id = 1<br /> friction#(id) = .97<br /> moveDist#(id) = .065<br /> xSpeed#(id) = 0<br /> zSpeed#(id) = 0<br /> <br /> <br /> <br /> `==================================<br /> `load target object (beam of light)<br /> `==================================<br /> load object "media/light_beam.x",200<br /> load object "media/light_beam2.x",201<br /> <br /> make object plain 202,15,15<br /> <br /> load image "media/light_3.bmp",30<br /> texture object 202,30<br /> <br /> scale object 200,500,1500,500<br /> scale object 201,500,750,500<br /> <br /> ghost object on 200<br /> ghost object on 201<br /> `ghost object on 202<br /> <br /> set object 200,1,1,0,1,0,0,1<br /> set object 201,1,1,0,1,0,0,1<br /> set object 202,1,1,0,1,0,0,1<br /> <br /> `target light<br /> make light 3<br /> set point light 3,0,0,0<br /> set light range 3,1000<br /> color light 3,RGB(0,128,255)<br /> show light 3<br /> <br /> `---------------<br /> `data statements<br /> `---------------<br /> data_player_positions:<br /> <br /> data 262.5,212.5,0<br /> data 212.5,262.5,90<br /> data 262.5,312.5,180<br /> data 312.5,262.5,270<br /> <br /> <br /> <br /> <br /> `---------<br /> `MAIN LOOP<br /> `---------<br /> main:<br /> ` set target<br /> new_target()<br /> do<br /> <br /> yAng# = object angle y(1)<br /> <br /> `the following is temporary. There will be more but it will made later<br /> `get keyboard input for movement<br /> if upkey()=1 then forward = 1 else forward = 0<br /> if downkey()=1 then backward = 1 else backward = 0<br /> if leftkey()=1 then left = 1 else left = 0<br /> if rightkey()=1 then right = 1 else right = 0<br /> <br /> `update the player<br /> move_player(1, forward, backward, left, right)<br /> <br /> <br /> `update chase camera<br /> chase_cam(1)<br /> <br /> `display current frame rate<br /> text 5,5, "FPS = " + str$(screen fps())<br /> text 5,45, "Hot Spot = " + str$(CheckHotSpot(1))<br /> <br /> ` create new target if player reaches target<br /> if checkHotspot(1)=hotSpot(0)<br /> new_target()<br /> targetCount(1)= targetCount(1) + 1<br /> if targetCount(1) = 10 then End_Game()<br /> endif<br /> <br /> `update taret animation<br /> gosub update_target<br /> <br /> `update the screen<br /> sync<br /> loop<br /> <br /> `==========================<br /> ` End the Game<br /> `==========================<br /> function End_Game()<br /> repeat<br /> text 25,50 ,"Congratulation!"<br /> text 25,60, "Press Space Key to Exit"<br /> sync<br /> until spacekey() = 1<br /> <br /> end<br /> <br /> endfunction<br /> <br /> <br /> <br /> <br /> `===========================<br /> ` Pick a new target location<br /> `===========================<br /> function new_target()<br /> <br /> ` create new hot spot target<br /> repeat<br /> HotSpot(0) = rnd(7) + 1<br /> until HotSpot(0) <> OldHotSpot(0)<br /> <br /> ` save new hot spot as old hot spot<br /> OldHotSpot = HotSpot<br /> <br /> `locate the center of the hot spot tile<br /> xPos# = (FKey(HotSpot(0),0) * Info(0) - Info(0)/2)<br /> zPos# = (FKey(HotSpot(0),1) * Info(1) - Info(1)/2)<br /> <br /> `locate the height of the hot spot tile<br /> yPos# = get ground height(1,xPos#,zPos#)<br /> <br /> `position beam of light<br /> position object 200, xPos#,yPos#,zPos#<br /> position object 201, xPos#,yPos#,zPos#<br /> position object 202, xPos#,yPos#,zPos#<br /> <br /> ` Positon lighting<br /> position light 3,xPos#,yPos#+10,zPos#<br /> <br /> endfunction<br /> <br /> `======================================================<br /> ` Work out the current hotspot the player is on (if any)<br /> `======================================================<br /> function CheckHotSpot(id)<br /> <br /> ` reset the currentHotSpot return variable<br /> currentHotSpot = 0<br /> <br /> `work out the current tile position of the player<br /> tileX = int(object position x(id)/Info(0)) + 1<br /> tileZ = int(object position z(id)/Info(1)) + 1<br /> <br /> `check for a hot spot match<br /> for hotSpot =1 to 10<br /> if tileX = FKey(hotSpot,0) and tileZ = FKey(hotSpot,1)<br /> currentHotSpot = hotSpot<br /> exit<br /> endif<br /> next hotSpot<br /> <br /> endfunction currentHotSpot<br /> <br /> `=============<br /> `chase cam<br /> `=============<br /> function chase_cam(id)<br /> <br /> `work out the angle of the object being chased<br /> yAng#= wrapvalue(object angle y(id)+180)<br /> <br /> <br /> `grab the objects current position<br /> xPos# = object position x(id)<br /> yPos# = object position y(id)<br /> zPos# = object position z(id)<br /> <br /> `other variables<br /> camDist = 15<br /> camHeight = 1<br /> <br /> `work out new position<br /> xCamPos# = newxvalue(xPos#,yAng#,camDist)<br /> zCamPos# = newzvalue(zPos#,yAng#,camDist)<br /> <br /> `camera collision<br /> if xCamPos#>485 then xCamPos#=485<br /> if zCamPos#>485 then zCamPos#=485<br /> if xCamPos#<15 then XCamPos#=15<br /> if zCamPos#<15 then zCamPos#=15<br /> <br /> `work out camera height<br /> yCamPos# = get ground height (1,xCamPos#,zCamPos#)+camHeight<br /> if yCamPos# < yPos#+camHeight then yCamPos# = yPos#+camHeight<br /> <br /> `smooth out the camera effects<br /> xCamPos#=curvevalue(xCamPos#,camera position x(),4)<br /> yCamPos#=curvevalue(yCamPos#,camera position y(),4)<br /> zCamPos#=curvevalue(zCamPos#,camera position z(),4)<br /> <br /> `update camera position<br /> position camera xCamPos#,yCamPos#+camHeight,zCamPos#<br /> point camera xPos#, yPos#+camHeight, zPos#<br /> <br /> <br /> <br /> endfunction<br /> <br /> `--------------------------<br /> ` move the specified player<br /> `--------------------------<br /> function move_player(id, forward, backward, left, right)<br /> <br /> `----------------------------------<br /> ` set object floor offset<br /> `----------------------------------<br /> floor_offset# = 2.0<br /> <br /> `-----------------------------------<br /> ` get the required object properties<br /> `-----------------------------------<br /> xPos# = object position x(id)<br /> yPos# = object position y(id)<br /> zPos# = object position z(id)<br /> yAng# = object angle y(id)<br /> <br /> `-----------------------------<br /> ` Sort out the basic movements<br /> `-----------------------------<br /> if forward = 1<br /> `move forward code here<br /> xSpeed#(id) = xSpeed#(id) + newxvalue(0,yAng#,moveDist#(id))<br /> zSpeed#(id) = zSpeed#(id) + newzvalue(0,yAng#,moveDist#(id))<br /> endif<br /> <br /> if backward = 1<br /> `move backward code here<br /> xSpeed#(id) = xSpeed#(id) + newxvalue(0,yAng#,moveDist#(id) * -1)<br /> zSpeed#(id) = zSpeed#(id) + newzvalue(0,yAng#,moveDist#(id) * -1)<br /> endif<br /> <br /> if left = 1<br /> `move left code here<br /> yrotate object id, wrapvalue(yAng#-4)<br /> endif<br /> <br /> if right = 1<br /> ` move right code here<br /> yrotate object id, wrapvalue(yAng#+4)<br /> endif<br /> <br /> `---------------------------------------------------<br /> ` sort out friction and other physics related things<br /> `---------------------------------------------------<br /> ` Work out value with friction and gravity<br /> xSpeed#(id) = xSpeed#(id) * friction#(id)<br /> zSpeed#(id) = zSpeed#(id) * friction#(id)<br /> ySpeed#(id) = ySpeed#(id) + gravity#(0)<br /> <br /> ` Work out the new position<br /> xPos# = xPos# + xSpeed#(id)<br /> zPos# = zPos# + zSpeed#(id)<br /> yPos# = yPos# - ySpeed#(id)<br /> <br /> `collision<br /> if xPos#>490 then xPos#=490<br /> if zPos#>490 then zPos#=490<br /> if xPos#<5 then xPos#=5<br /> if zPos#<5 then zPos#=5<br /> <br /> <br /> ` Work out the height of the character<br /> if yPos# < get ground height(1, xPos#, zPos#)+ floor_offset#<br /> ySpeed#(id) = ySpeed#(id) = (yPos# - get ground height(1, xPos#, zPos#))<br /> yPos# = get ground height(1, xPos#, zPos#) + floor_offset#<br /> <br /> `------------------------------<br /> `tilt the vehicle to the ground<br /> `------------------------------<br /> distVal#=1<br /> <br /> `work out the positions of the front, back, left and right of the vehicle<br /> ang#=yAng#<br /> frontX#=newxvalue(xPos#,ang#,distVal#)<br /> frontZ#=newzvalue(zPos#,ang#,distVal#)<br /> <br /> ang#=yAng#+180<br /> backX#=newxvalue(xPos#,ang#,distVal#)<br /> backZ#=newzvalue(zPos#,ang#,distVal#)<br /> <br /> ang#=yAng#+90<br /> leftX#=newxvalue(xPos#,ang#,distVal#)<br /> leftZ#=newzvalue(zPos#,ang#,distVal#)<br /> <br /> ang#=yAng#-90<br /> rightX#=newxvalue(xPos#,ang#,distVal#)<br /> rightZ#=newzvalue(zPos#,ang#,distVal#)<br /> <br /> `work out the different heights<br /> frontHeight# = get ground height(1,frontX#,frontZ#)<br /> backHeight# = get ground height(1,backX#,backZ#)<br /> leftHeight# = get ground height(1,leftX#,leftZ#)<br /> rightHeight# = get ground height(1,rightX#,rightZ#)<br /> <br /> `Work out tilt values<br /> xAng#=wrapvalue((frontHeight#-backHeight#)*30)<br /> zAng#=wrapvalue((leftHeight#-rightHeight#)*30)<br /> <br /> `Work out tilt values<br /> xAng#=curveangle((frontHeight#-backHeight#)*30,object angle x(id+10),5)<br /> zAng#=curveangle((leftHeight#-rightHeight#)*30,object angle z(id+10),5)<br /> <br /> `-----------------<br /> `slide down slopes<br /> `-----------------<br /> xMoveDist#=(backHeight#-frontHeight#)/30<br /> zMoveDist#=(leftHeight#-rightHeight#)/30<br /> <br /> `adjust forward/ backward momentum<br /> xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,xMoveDist#)<br /> zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,xMoveDist#)<br /> <br /> `adjust left/ right momentum<br /> xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#-90,zMoveDist#)<br /> zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#-90,zMoveDist#)<br /> <br /> <br /> `update the vehicle rotation<br /> rotate object id+10,xAng#,180,zAng#<br /> <br /> endif<br /> <br /> ` Reposition the player object<br /> position object id, xPos#, yPos# , zPos#<br /> <br /> `display camera object postition for player 1<br /> if id = 1<br /> text 5,15, "X Position = " + str$(xPos#)<br /> text 5,25, "Y Position = " + str$(yPos#)<br /> text 5,35, "Z Position = " + str$(zPos#)<br /> endif<br /> <br /> endfunction<br /> <br /> `=================<br /> ` rotate the taget<br /> `=================<br /> update_target:<br /> <br /> yrotate object 200, wrapvalue(object angle y(200)+2)<br /> yrotate object 201, wrapvalue(object angle y(201)-2)<br /> yrotate object 202, wrapvalue(object angle y(202)-60)<br /> <br /> return
Comments
No comments yet.