hey, I dont have time to write more on this.. didnt actually make a tutorial out of it yet..
the reason is, I am traveling to england with my class.
we are supposed to go at school there.. well I can give you what I have done so far (I skipped training yesterday for this, so you better appreciate it (j/k)
well here it is and bye, see you in a week
[edit]
sorry I forgot to give you it... well here you are:
remstart
1st Person Shooter + Gravity + Jumping + Strafing + Crouching (duh)
________________________________________________________________________________________________________________________________________________________________________
ok, this was not much of a tutorial, but if you need any help just ask me on apollo or at my board http://n0id.proboards28.com
anyway, I hope you can learn from this code.
this is a bit buggy at the moment... I will fix it later, but I start on the 3rd person thing first, allthough It is the same as this,
only the player object should not be hidden and the camera should be set to follow that object.
remend
set display mode 800,600,32 : cls
sync on : sync rate 75 : autocam off : hide mouse : backdrop on
Dim PlayerAction(0)
Dim PlayerSpeed(0)
dim PlayerData(0)
PlayerData(0) = 1 : ` player object number
load player
` ____________________________ <-- got this snippet from the masked coder.
make matrix 1,10000,10000,70,70
randomize matrix 1,400
for a = 0 to 69
SET MATRIX HEIGHT 1, a, 35, 200
SET MATRIX HEIGHT 1, a, 40, 100
next a
update matrix 1
set matrix wireframe off 1
`____________________________ <-- ...
fog on
fog distance 3000
Do
Handle Camera
Sync : Loop
function handle camera()
oldx#=camera position x()
oldy#=camera position y()-30
oldz#=camera position z()
IF upkey()=1 or "w"=inkey$() THEN forward=1 ELSE forward=0
IF downkey()=1 or "s"=inkey$() THEN backwards=1 ELSE backwards=0
IF leftkey()=1 or "a"=inkey$() THEN left=1 ELSE left=0
IF rightkey()=1 or "d"=inkey$() THEN right=1 ELSE right=0
if controlkey()=1 or "c"=inkey$() THEN crouch=1 else crouch=0
if shiftkey()=1 or "e"=inkey$() THEN jump=1 else jump=0
action = Move Player( forward, backward, left, right, crouch, jump, collide )
x#=camera position x()
y#=camera position y()-30
z#=camera position z()
endfunction action
function load player()
` load object "man.x",PlayerData(0)
` append object "idle.x",PlayerData(0),PlayerData(1)
` append object "walk.x",PlayerData(0),PlayerData(2)
` append object "strafe.x",PlayerData(0),PlayerData(3)
` append object "jump.x",PlayerData(0),PlayerData(4)
make object cube PlayerData(0), 100
endfunction
function Move Player( forward, backward, left, right, crouch, jump, collide )
` integers
player_idle = 0
player_walk = 1
player_jump = 2
player_crou = 3
player_action = player_idle
` real
Player_Jump_Force# = 5.0
` store Old Player Position
x# = object position x(PlayerData(0))
y# = object position y(PlayerData(0))
z# = object position z(PlayerData(0))
` camera
wvtx=object angle x(PlayerData(0))
wvty=object angle y(PlayerData(0))
wvtz=object angle z(PlayerData(0))
wcax=wrapvalue(wvtx)
wcay=wrapvalue(wvty)
wcaz=wrapvalue(wvtz)
` MOVEMENT
if forward = 1
if player_action <> player_jump
player_action = player_walk
x# = newxvalue( x# , cya# , PlayerSpeed(0) )
z# = newzvalue( z# , cya# , PlayerSpeed(0) )
endif
endif
if backward = 1
if player_action <> player_jump
player_action = player_walk
x# = newxvalue( x# , cya# , PlayerSpeed(0) * -1 )
z# = newzvalue( z# , cya# , PlayerSpeed(0) * -1 )
endif
endif
if left = 1
if player_action <> player_jump
player_action = player_walk
x# = newxvalue( x# , cya# - 90 , PlayerSpeed(0) )
z# = newzvalue( z# , cya# - 90 , PlayerSpeed(0) )
endif
endif
if right = 1
if player_action <> player_jump
player_action = player_walk
x# = newxvalue( x# , cya# + 90 , PlayerSpeed(0) )
z# = newzvalue( z# , cya# + 90 , PlayerSpeed(0) )
endif
endif
if crouch = 1
if player_action <> player_jump
player_action = player_crou
PlayerSpeed(0) = 2
endif
else
PlayerSpeed(0) = 5
endif
if jump = 1
if player_action <> player_jump
player_action = player_jump
if gravity# = 0.0 then player_jump_stage = 1
endif
endif
` add gravity
if gravity# > 0.0
gravity_power# = gravity_power# - 0.4
gravity# = gravity# - gravity_power#
y# = y# - gravity#
endif
` Make sure Player does not go outside the temporary level (remove this to be able to go anywhere)
if x#<5 then x# = 5
if x#>9995 then x# = 9995
if z#<5 then z# = 5
if z#>9995 then z# = 9995
y3# = _Check_for_ground(x#,y#,z#,80.0,1)
` Jump Code
if player_jump_stage = 1
gravity# = player_jump_Force#
y# = y# + gravity#
if ( y# <= y3# + 40 ) or ( y# <= y3# + 20 )
player_action = player_idle
Player_Jump_Stage = 0
endif
endif
` store Camera Axes
Mouse_Mode$ = "normal" : smooth# = 10.0
cya#=wrapvalue(cya#+(mousemovex()/smooth#))
if Mouse_Mode$="normal" then cxa#=cxa#+(mousemovey()/smooth#) else cxa#=cxa#-(mousemovey()/smooth#)
if cxa#<-75.0 then cxa#=-75.0
if cxa#>75.0 then cxa#=75.0
cx#=newxvalue(x#,cya#,sin(cxa#)*10)
cz#=newzvalue(z#,cya#,sin(cxa#)*10)
` Handle Collision with Matrices
if y# <= y3# + 40
gravity# = 0.0
gravity_power# = 0.0
if player_action <> player_jump
y# = y3# + 40
endif
if player_action = player_crou
y# = y3# + 20
endif
position object PlayerData(0), x# , y# , z#
position camera x# , y# , z#
position listener x# , y# , z#
rotate camera wrapvalue(cxa#),cya#,0
rotate object PlayerData(0), 0 , camera angle y() , 0
rotate listener wrapvalue(cxa#),cya#,0
endif
` Check if Not on Matrix or Object
if (y# > y3#+40 )
gravity# = 2.1
endif
PlayerAction(0) = Player_Action
position object PlayerData(0) , x# , y# , z#
position camera x# , y# , z#
position listener x# , y# , z#
rotate camera wrapvalue(cxa#),cya#,0
rotate object PlayerData(0), 0 , camera angle y() , 0
rotate listener wrapvalue(cxa#),cya#,0
endfunction
` ____________________________ <-- got this snippet from freddix.
Function _Check_for_ground(x#,y#,z#,ysize#,mat)
if mat>0
for b = 1 to mat
mPosX = matrix position x(b)
mPosZ = matrix position z(b)
mMaxX = mPosX + (70 * 70)
mMaxZ = mPosZ + (70 * 70)
if ( x# > mPosX and x# < mMaxX ) and ( z# > mPosZ and z# < mMaxZ )
matrix_height# = get ground height( b, int(x#) - mPosX, int(z#) - mPosZ )
if y# > matrix_height#
if int( y# - matrix_height# ) < ysize# then y# = matrix_height#
else
if int( matrix_height# - y#) < ysize# then y#= matrix_height#
endif
endif
Next b
EndIf
EndFunction y#
`____________________________ <-- ...
This is a Map Editor ver 2 DEMO Out now! [ahref]http://www.tiame.tk[/ahref]