Jumping enabled
Rem Project: testing player control
Rem Created: 7-2-2007
Rem ***** Main Source File *****
sync on : sync rate 60 `Set the refresh rate to 60
set display mode 800,600,32 `Set the resolution of our program
autocam off `Tell our camera not to be repositioned after creating an
`object.
MapSize=250
Segments=64
global gravity# as float `This is our gravity. OMFG. :D
make matrix 1,mapsize,mapsize,segments,segments `Here is our matrix
sky=5001 `Our variable for the skysphere.
make object sphere sky,(-mapsize*2) `Here we create our sphere, and ensure it's big enough
color object sky,rgb(0,0,150) `to cover the map, by multiplying it by the mapsize.
position object sky,mapsize/2,0,mapsize/2 `We position our skysphere.
`Note that we divide the mapsize by 2 because our object
`has been rotated. :)
`player
player = 99
make object cube player,2.5
color object player,rgb(255,0,0)
position object player,0,get ground height(1,0,0),0
do
text 0,0,str$(screen fps()) `Simple text statement that'll show the frames per second.
text 0,30,str$(scancode()) `This text will show what key is being pressed.
`[===Player movement===[
`trying to get th player move in a function
`with case select no jumping so far
MoveMan(player)
`[===Perform gravity operation===]
PerformGravity(player)
`[====Camera movement====]
UpdateCamera(player)
`[===skysphere===]
`This will rotate the sky slowly, making it appear more realistic.
`it still is crap but it works
`yrotate object sky,object angle y(sky)+.1
sync
loop
function MoveMan(objNum)
`wasd controls
select scancode()
case 17
move object objnum,.2
loop object objnum,5,25
endcase
case 31
move object objnum,-.2
loop object objnum,5,25
endcase
case 30
MOVE OBJECT left objnum,.2
loop object objnum,5,25
endcase
case 32
MOVE OBJECT right objnum,.2
loop object objnum,5,25
endcase
case 57
`Decrease the gravity variable to -2.250 to make the player "fall up"
`but only if the player is not already in the air.
if object position y(objnum)<=get ground height(1,object position x(objnum),object position z(objnum))
gravity#=-2.250
endif
`we should also move the player up so that next loop it will see the player is not
`touching the ground, and will perform the gravity decrement on it
`(where a double-negative makes a positive). This also prevents the engine
`from setting gravity# back to 0 because it saw the player was touching the ground.
MOVE OBJECT up objnum,0.2
endcase
case 0
stop object objnum
endcase
endselect
yrotate object objnum,wrapvalue(object angle y(objnum)+(mousemovex()*0.2))
`xrotate object objnum,wrapvalue(object angle x(objnum)+(mousemovey()*0.2))
endfunction
function PerformGravity(ObjNum)
Plrx#=object position x(ObjNum)
Plry#=object position y(ObjNum)
Plrz#=object position z(ObjNum)
if Plry#>get ground height(1,Plrx#,Plrz#) `If the player is off the ground
dec Plry#,gravity# `then lower the player by the
`gravity variable. The player will
`go up when gravity# is negative.
inc gravity#,0.075 `Gradually increase gravity
`for realism.
else
Plry#=get ground height(1,Plrx#,Plrz#)
gravity#=0
endif
position object ObjNum,Plrx#,Plry#,Plrz#
endfunction
function UpdateCamera(ObjNum)
set camera to follow object position x(objnum),object position y(objnum),object position z(objnum),object angle y(objnum)+(mousemovex()*0.2),7.5,10,1,0
`(you can use the line below instead if you want a strictly stiff camera)
`position camera limb position x(objnum,1),limb position y(objnum,1),limb position z(objnum,1)
point camera object position x(objnum),object position y(objnum), object position z(objnum)
endfunction
You should check movement with the keystate(#) command. It allows for more than one control to be recognized at once. You can only do one thing at a time with scancode().