Skip to content

Commit

Permalink
Update PLAT.BAS
Browse files Browse the repository at this point in the history
More robust controller support (incl. detection) and pause implemented
  • Loading branch information
TheNetNomad authored Jul 25, 2022
1 parent c7aed4d commit 67ea8f3
Showing 1 changed file with 88 additions and 20 deletions.
108 changes: 88 additions & 20 deletions PLAT.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ VAR I = 0
VAR J = 0
DIM AS VECTOR3 PLAYER_POS = VECTOR3(0,0,0)
DIM AS DOUBLE OLDTIME = 0
DIM AS DOUBLE GAMETIME = 0
DIM AS DOUBLE ROTATION = 0
DIM AS DOUBLE SIN_CAM = 0
DIM AS DOUBLE COS_CAM = 0
Expand All @@ -38,15 +39,27 @@ VAR COLLIDETEST = FALSE
VAR SPEED = 0
VAR CORRECTION_OFFSET = 0
VAR SOLVEDCOLLISION = FALSE
VAR JOYSTICKID = 0
VAR STRIG = 0
DIM X_AXIS AS SINGLE
DIM Y_AXIS AS SINGLE
DIM SHOULDER AS SINGLE
DIM CSTICK_X AS SINGLE
DIM CSTICK_Y AS SINGLE
DIM DPAD_X AS SINGLE
DIM DPAD_Y AS SINGLE
CONST FORWARDS = TRUE
CONST BACKWARDS = FALSE
VAR DIRECTION = FORWARDS
VAR ISHURT = 0
VAR IFRAMES = 0
VAR ISONGROUND = FALSE
VAR ISPAUSED = FALSE

FOR I = 0 TO 10
GETJOYSTICK(I,STRIG)
IF STRIG <> -1 THEN JOYSTICKID = I
NEXT I

VAR CHERRIES = 0
VAR LIVES = 3
Expand Down Expand Up @@ -184,8 +197,32 @@ DIM AS SOUND CHERRYSFX = LOADSOUND("CHERRYSFX.WAV")
'PLAYSOUNDMULTI(BGM)

MAIN:
OLDTIME = GETTIME()



GETJOYSTICK(JOYSTICKID,STRIG,X_AXIS,Y_AXIS,SHOULDER,CSTICK_Y,CSTICK_X,,DPAD_X,DPAD_Y)

IF DEBOUNCE = 0 AND BIT(STRIG,7) THEN
DEBOUNCE = 20
IF ISPAUSED THEN ISPAUSED = FALSE ELSE ISPAUSED = TRUE

IF ISPAUSED THEN
BEGINDRAWING()
DRAWTEXT("PAUSED",SCREEN_HEIGHT * (2.25/5),SCREEN_WIDTH * (1/3),80,BLACK)
ENDDRAWING()

END IF
END IF

IF DEBOUNCE > 0 THEN DEBOUNCE -= 1

IF ISPAUSED THEN
SLEEP 10
GOTO REST
END IF

GAMETIME += GETTIME() - OLDTIME


BEGINDRAWING()
CLEARBACKGROUND(SKYBLUE)
BEGINMODE3D(CAMERA)
Expand Down Expand Up @@ -216,10 +253,10 @@ MAIN:
ENDMODE3D()
DRAWRECTANGLE(0,0,SCREEN_WIDTH,40,BLACK)

IF OLDTIME MOD 60 < 10 THEN
DRAWTEXT("TIME: " + STR(INT(OLDTIME / 60)) + ":0" + STR(OLDTIME MOD 60), SCREEN_WIDTH * (2/5),0,40, WHITE)
IF GAMETIME MOD 60 < 10 THEN
DRAWTEXT("TIME: " + STR(INT(GAMETIME / 60)) + ":0" + STR(GAMETIME MOD 60), SCREEN_WIDTH * (2/5),0,40, WHITE)
ELSE
DRAWTEXT("TIME: " + STR(INT(OLDTIME / 60)) + ":" + STR(OLDTIME MOD 60), SCREEN_WIDTH * (2/5),0,40, WHITE)
DRAWTEXT("TIME: " + STR(INT(GAMETIME / 60)) + ":" + STR(GAMETIME MOD 60), SCREEN_WIDTH * (2/5),0,40, WHITE)
END IF

DRAWTEXT("CHERRIES: " + STR(CHERRIES), 10,0,40, WHITE)
Expand All @@ -228,10 +265,9 @@ MAIN:

'IF NOT ISSOUNDPLAYING(BGM) THEN PLAYSOUNDMULTI(BGM)

GETJOYSTICK(0,STRIG,X_AXIS,Y_AXIS)
'GETJOYSTICK(0,STRIG,X_AXIS,Y_AXIS)


IF (ISKEYDOWN(KEY_SPACE) OR STRIG > 0) AND (PLAYER_POS.Y = JUMP_FLOOR AND ISJUMPREADY) THEN
IF (ISKEYDOWN(KEY_SPACE) OR (STRIG AND 15) > 0) AND (PLAYER_POS.Y = JUMP_FLOOR AND ISJUMPREADY) THEN
ISJUMPING = TRUE
HANGTIME = 10
ISJUMPREADY = FALSE
Expand All @@ -256,7 +292,7 @@ MAIN:
IF BOXSPHERECOLLISION(VECTOR3(PLAYER_POS.X, PLAYER_POS.Y - FALLING_SPEED, PLAYER_POS.Z),PLAYER_RADIUS,CUBE_POSITIONS(I),CUBE_DIMENSIONS(I)) THEN
COLLIDETEST = TRUE
JUMP_FLOOR = PLAYER_POS.Y
IF ISFALLING AND ((NOT ISKEYDOWN(KEY_UP) AND NOT ISKEYDOWN(KEY_DOWN)) OR Y_AXIS < .9) THEN
IF ISFALLING AND ((NOT (ISKEYDOWN(KEY_UP) OR DPAD_Y = -1) AND NOT (ISKEYDOWN(KEY_DOWN) OR DPAD_Y = 1) ) OR Y_AXIS < .9) THEN
IF SPEED > 5 THEN SPEED = 5
END IF
ISFALLING = FALSE
Expand All @@ -266,7 +302,7 @@ MAIN:

IF COLLIDETEST = FALSE THEN PLAYER_POS.Y -= FALLING_SPEED
ELSE
IF ISFALLING AND ((NOT ISKEYDOWN(KEY_UP) AND NOT ISKEYDOWN(KEY_DOWN)) OR Y_AXIS > -.9) THEN
IF ISFALLING AND ((NOT (ISKEYDOWN(KEY_UP) OR DPAD_Y = -1) AND NOT (ISKEYDOWN(KEY_DOWN) OR DPAD_Y = 1) ) OR Y_AXIS > -.9) THEN
IF SPEED > 5 THEN SPEED = 5
END IF
JUMP_FLOOR = 0
Expand All @@ -285,14 +321,38 @@ MAIN:
ELSE
IF CAMERA_Y_OFF > 7 THEN IF CAMERA_Y_OFF < 8 THEN CAMERA_Y_OFF = 7 ELSE CAMERA_Y_OFF -= .5
END IF

IF X_AXIS <> -1000 AND CSTICK_X <> -1000 THEN
IF ABS(X_AXIS) > ABS(CSTICK_X) THEN
ROTATION = X_AXIS/9
ELSE
ROTATION = CSTICK_X/9
ENDIF
ELSEIF X_AXIS <> -1000 THEN
ROTATION = X_AXIS/9
END IF

IF X_AXIS = -1000 OR (ABS(X_AXIS) < .1 AND ABS(CSTICK_X) < .1) THEN
IF SHOULDER = -1000 OR ABS(SHOULDER) < .9 THEN
IF (ISKEYDOWN(KEY_LEFT) OR DPAD_X = -1) THEN
ROTATION = -.075
ELSEIF (ISKEYDOWN(KEY_RIGHT) OR DPAD_X = 1) THEN
ROTATION = .075
ELSE
ROTATION = 0
END IF
ELSE
IF SHOULDER > .9 THEN
ROTATION = -.075
ELSEIF SHOULDER < -.9 THEN
ROTATION = .075
ELSE
ROTATION = 0
END IF
END IF
END IF


IF X_AXIS <> -1000 THEN ROTATION = X_AXIS/9

IF X_AXIS = -1000 OR ABS(X_AXIS) < .1 THEN
IF ISKEYDOWN(KEY_LEFT) THEN ROTATION = -.075 ELSE IF ISKEYDOWN(KEY_RIGHT) THEN ROTATION = .075 ELSE ROTATION = 0
END IF

SIN_CAM = SIN(ROTATION)
COS_CAM = COS(ROTATION)
Expand All @@ -301,15 +361,17 @@ MAIN:
TEMPZ = CAMERA.POSITION.Z - PLAYER_POS.Z

CAMERA.POSITION.X = (COS_CAM * TEMPX - SIN_CAM * TEMPZ) + PLAYER_POS.X
CAMERA.POSITION.Y = PLAYER_POS.Y + CAMERA_Y_OFF
CAMERA.POSITION.Y = PLAYER_POS.Y + CAMERA_Y_OFF + (CSTICK_Y * 10)
CAMERA.POSITION.Z = (SIN_CAM * TEMPX + COS_CAM * TEMPZ) + PLAYER_POS.Z

CAMERA.TARGET = VECTOR3(PLAYER_POS.X, PLAYER_POS.Y + CAMERA_HEIGHT, PLAYER_POS.Z)

TEMPX = PLAYER_POS.X - CAMERA.POSITION.X
TEMPZ = PLAYER_POS.Z - CAMERA.POSITION.Z

IF ISKEYDOWN(KEY_UP) THEN
'PRINT DPAD_X

IF (ISKEYDOWN(KEY_UP) OR DPAD_Y = -1) THEN
IF DIRECTION = BACKWARDS THEN IF SPEED > 0 THEN SPEED -= 1 ELSE DIRECTION = FORWARDS

IF DIRECTION = FORWARDS THEN
Expand All @@ -319,7 +381,7 @@ MAIN:
SPEED += 1
END IF
END IF
ELSEIF ISKEYDOWN(KEY_DOWN) THEN
ELSEIF (ISKEYDOWN(KEY_DOWN) OR DPAD_Y = 1) THEN
IF DIRECTION = FORWARDS THEN IF SPEED > 0 THEN SPEED -= 1 ELSE DIRECTION = BACKWARDS

IF DIRECTION = BACKWARDS THEN
Expand Down Expand Up @@ -359,7 +421,7 @@ MAIN:
END IF
END IF

IF (NOT ISKEYDOWN(KEY_UP) AND NOT ISKEYDOWN(KEY_DOWN)) AND (ABS(Y_AXIS) < .1 OR Y_AXIS = -1000) THEN
IF (NOT (ISKEYDOWN(KEY_UP) OR DPAD_Y = -1) AND NOT (ISKEYDOWN(KEY_DOWN) OR DPAD_Y = 1) ) AND (ABS(Y_AXIS) < .1 OR Y_AXIS = -1000) THEN
IF SPEED > 0 AND NOT (ISJUMPING OR ISFALLING) THEN SPEED -= 1
END IF

Expand Down Expand Up @@ -520,12 +582,18 @@ MAIN:

PLAYER_POS = VECTOR3(0,0,0)
CAMERA.POSITION = VECTOR3(PLAYER_POS.X, PLAYER_POS.Y + CAMERA_Y_OFF, PLAYER_POS.Z + CAMERA_Z_OFF)
FOR I = 0 TO UBOUND(CHERRY_EXISTS)
CHERRY_EXISTS(I) = TRUE
NEXT I

END IF
END IF
END IF

REST:
IF GETTIME() - OLDTIME < 1 / 60 THEN SLEEP 1:GOTO REST
OLDTIME = GETTIME()
REST_WAIT:
IF GETTIME() - OLDTIME < 1 / 60 THEN SLEEP 1:GOTO REST_WAIT

IF NOT WINDOWSHOULDCLOSE() THEN GOTO MAIN

Expand Down

0 comments on commit 67ea8f3

Please sign in to comment.