Hello all!
I have actually been a member of this forum before, but I put down DBPro to work on other things, and I am now coming back. I have run into a bit of a problem using functions in my program.
The following works, I am able to use WASD to control the camera, smoothly moving by increments of 50, and turning 90 degrees.
#CONSTANT Menu = 1
GLOBAL Strafe_Left = 16
GLOBAL Strafe_Right = 18
GLOBAL Turn_Left = 30
GLOBAL Turn_Right = 32
GLOBAL Forward = 17
GLOBAL Backward = 31
#CONSTANT Flr = 50
#CONSTANT Ceiling = 100
#CONSTANT Wall = 150
#CONSTANT WEB_STONE_WALL = 1
#CONSTANT STONE_WALL = 2
MAKE OBJECT SPHERE 600, -810
COLOR OBJECT 600, RGB(0,0,0)
Make Object Cube 1, 50
Position Object 1, 0, 0, 50
REM make map
DIM Map(50,50)
FOR x = 1 TO 12
FOR y = 1 TO 12
Map(x,y) = 0
NEXT y
NEXT x
START_X = 0: START_Y = 0: START_Z = 0:
POSITION CAMERA START_X, START_Z, START_Y
ROTATE CAMERA 0, 0, 0
DONE = 0
REPEAT
IF KEYSTATE(MENU) = 1 THEN DONE = 100
IF KEYSTATE(Forward) = 1 AND Command = 0
Frwrd = 50
Command = 1
ENDIF
IF KEYSTATE(Backward) = 1 AND Command = 0
Bckwrd = 50
Command = 1
ENDIF
IF KEYSTATE(Turn_Left) = 1 AND Command = 0
Turn_L = 90
Command = 1
ENDIF
IF KEYSTATE(Turn_Right) = 1 AND Command = 0
Turn_R = 90
Command = 1
ENDIF
IF KEYSTATE(Strafe_Left) = 1 AND Command = 0
Strf_L = 50
Command = 1
ENDIF
IF KEYSTATE(Strafe_Right) = 1 AND Command = 0
Strf_R = 50
Command = 1
ENDIF
IF Frwrd > 0
MOVE CAMERA 1
DEC Frwrd
IF Frwrd = 0 THEN Command = 0
ENDIF
IF Bckwrd > 0
MOVE CAMERA -1
DEC Bckwrd
IF Bckwrd = 0 THEN Command = 0
ENDIF
IF Turn_L > 0
TURN CAMERA LEFT 1
DEC Turn_L
IF Turn_L = 0 THEN Command = 0
ENDIF
IF Turn_R > 0
TURN CAMERA RIGHT 1
DEC Turn_R
IF Turn_R = 0 THEN Command = 0
ENDIF
UNTIL Done = 100
END
However, when I move the bulk of the control code to a function, called Player_Move(), It stops turning by 90 degrees, and moving in increments of 50, it seems like it cycles within my function until the timers have counted down before exiting. Any ideas how to prevent this?
Here is the code with the function:
#CONSTANT Menu = 1
GLOBAL Strafe_Left = 16
GLOBAL Strafe_Right = 18
GLOBAL Turn_Left = 30
GLOBAL Turn_Right = 32
GLOBAL Forward = 17
GLOBAL Backward = 31
#CONSTANT Flr = 50
#CONSTANT Ceiling = 100
#CONSTANT Wall = 150
#CONSTANT WEB_STONE_WALL = 1
#CONSTANT STONE_WALL = 2
MAKE OBJECT SPHERE 600, -810
COLOR OBJECT 600, RGB(0,0,0)
Make Object Cube 1, 50
Position Object 1, 0, 0, 50
REM make map
DIM Map(50,50)
FOR x = 1 TO 12
FOR y = 1 TO 12
Map(x,y) = 0
NEXT y
NEXT x
START_X = 0: START_Y = 0: START_Z = 0:
POSITION CAMERA START_X, START_Z, START_Y
ROTATE CAMERA 0, 0, 0
DONE = 0
REPEAT
IF KEYSTATE(MENU) = 1 THEN DONE = 100
Player_Move()
UNTIL Done = 100
END
FUNCTION Player_Move()
IF KEYSTATE(Forward) = 1 AND Command = 0
Frwrd = 50
Command = 1
ENDIF
IF KEYSTATE(Backward) = 1 AND Command = 0
Bckwrd = 50
Command = 1
ENDIF
IF KEYSTATE(Turn_Left) = 1 AND Command = 0
Turn_L = 90
Command = 1
ENDIF
IF KEYSTATE(Turn_Right) = 1 AND Command = 0
Turn_R = 90
Command = 1
ENDIF
IF KEYSTATE(Strafe_Left) = 1 AND Command = 0
Strf_L = 50
Command = 1
ENDIF
IF KEYSTATE(Strafe_Right) = 1 AND Command = 0
Strf_R = 50
Command = 1
ENDIF
IF Frwrd > 0
MOVE CAMERA 1
DEC Frwrd
IF Frwrd = 0 THEN Command = 0
ENDIF
IF Bckwrd > 0
MOVE CAMERA -1
DEC Bckwrd
IF Bckwrd = 0 THEN Command = 0
ENDIF
IF Turn_L > 0
TURN CAMERA LEFT 1
DEC Turn_L
IF Turn_L = 0 THEN Command = 0
ENDIF
IF Turn_R > 0
TURN CAMERA RIGHT 1
DEC Turn_R
IF Turn_R = 0 THEN Command = 0
ENDIF
ENDFUNCTION