Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Need help for a WASD controlled FPS w/ mouselooking

Author
Message
NeoHavic
21
Years of Service
User Offline
Joined: 4th Dec 2002
Location:
Posted: 6th Dec 2002 03:37
Can someone please help me with code for a FPS, kinda like ICED???

I have this so far...

rem Make a simple scene for the camera to look at
make matrix 1,10000.0,10000.0,25,25
load bitmap "floor1.bmp",1
get image 1,0,0,256,256
delete bitmap 1
prepare matrix texture 1,1,2,2
randomize matrix 1,50.0
set matrix height 1,12,12,300.0
update matrix 1

rem Set variables for character position
cx#=2500
cz#=2500

rem Activate manual sync
sync on
hide mouse

rem Begin loop
do

set cursor 0,0
print "mcy#=",mcy#
print "mcx#=",mcx#
print "Camera Angle Y=",camera angle y()

rem Use MOUSEMOVE to alter camera angles
mcx#=wrapvalue(mcx#+mousemovey()*.5)
mcy#=wrapvalue(mcy#+mousemovex()*.5)
rotate camera mcx#,mcy#,0

rem Control camera with arrow keys
if upkey()=1 then cz#=cz#+10
if downkey()=1 then cz#=cz#+10
if leftkey()=1 then cx#=cx#-10
if rightkey()=1 then cx#=cx#+10
if mouseclick()=1 then randomize matrix 1,300

rem Position camera to the ground height
cy#=get ground height(1,cx#,cz#)+100.0
position camera cx#,cy#,cz#


rem Syncronise
sync

rem End loop
loop

thanx!
Tywald
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 6th Dec 2002 13:02
Hi NeoHavic!

I have a piece of code here that might help you.
These lines controls your movement whit the cursorkeys:

IF UPKEY() = 1
Player_X#=NEWXVALUE(Player_X#,Camera_AngleY#,+0.5)
Player_Z#=NEWZVALUE(Player_Z#,Camera_AngleY#,+0.5)
ENDIF
IF DOWNKEY() = 1
Player_X#=NEWXVALUE(Player_X#,Camera_AngleY#,-0.5)
Player_Z#=NEWZVALUE(Player_Z#,Camera_AngleY#,-0.5)
ENDIF
IF LEFTKEY() = 1
Player_X#=NEWXVALUE(Player_X#,WRAPVALUE(Camera_AngleY#-90.0),0.5)
Player_Z#=NEWZVALUE(Player_Z#,WRAPVALUE(Camera_AngleY#-90.0),0.5)
ENDIF
IF RIGHTKEY() = 1
Player_X#=NEWXVALUE(Player_X#,WRAPVALUE(Camera_AngleY#+90.0),0.5)
Player_Z#=NEWZVALUE(Player_Z#,WRAPVALUE(Camera_AngleY#+90.0),0.5)
ENDIF

And these lines to control the camera view whit the mouse:

Camera_AngleY#=WRAPVALUE(Camera_AngleY#+(MOUSEMOVEX()/)) `<- Change to 3.0 to change sensetivity.
Camera_AngleX#=Camera_AngleX#+(MOUSEMOVEY()/3.0) `<- Use a negative value to invert the mouse.
IF Camera_AngleX#<-80.0 THEN Camera_AngleX#=-80.0
IF Camera_AngleX#>80.0 THEN Camera_AngleX#=80.0

`Update the camera and player position
POSITION CAMERA 1,Player_X#,Player_Y#,Player_Z#
ROTATE CAMERA 1,WRAPVALUE(Camera_AngleX#),Camera_AngleY#,0

If you want to use other keys than the cursorkey i suggest that you use the KEYSTATE() command.

Example:
Forward_Key = 17 `<- 17 is the scancode for a key. (w on my keyboard)

IF KEYSTATE(Forward_Key) = 1
Blaha
Blaha
ENDIF

Just replace the UPKEY().
Good Luck fixing the rest of the keys.
- Tywald

Yarbles
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 6th Dec 2002 14:04
Look at the example that I posted in code snippets.

The Yellow Jester does not play but gently pulls the strings
And smiles as the puppets dance in the court of the Crimson King.
NeoHavic
21
Years of Service
User Offline
Joined: 4th Dec 2002
Location:
Posted: 6th Dec 2002 19:03
Thanx a lot ill try it out

Login to post a reply

Server time is: 2024-11-23 18:05:13
Your offset time is: 2024-11-23 18:05:13