Lecon 4 a 14 by Anonymous Coder1st Mar 2005 0:29
|
---|
Summary ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `--------------------------- `Limit Rush `Lesson 13 Description ` This code was downloaded from The Game Creators Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ` 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 |