Hi all.
I've just started with Dark Basic and have been following through a tutorial book making simple games.
I've gotten to making pong, but i can't get it to work. Even the code they have produced doesn't seem to work. It is not picking up the collision between the paddles and the ball for some reason.
All i can think of is there is something wrong in the following lines:
IF POINT(BallX, BallY) > 0
I know there is another way of detecting collisions ( sprites? ) but i'd like to do it the way the tutorial has done, if still possible, by fixing it.
Anyone got any ideas? Thanks.
REM ***** Main Source File *****
REM *************** Declare and Initialize Global Variables **************
GLOBAL PlayerOnePoints AS INTEGER = 0
GLOBAL PlayerTwoPoints AS INTEGER = 0
GLOBAL BallX AS INTEGER = 320
GLOBAL BallY AS INTEGER = 240
GLOBAL SpeedX AS INTEGER = 3
GLOBAL SpeedY AS INTEGER = 1
`Specify coordinates for player 1's paddle
GLOBAL PaddleX2 AS INTEGER = 15
GLOBAL PaddleY2 AS INTEGER = 200
`Specify coordinates for player 2's paddle
GLOBAL PaddleX1 AS INTEGER = 615
GLOBAL PaddleY1 AS INTEGER = 200
REM ******** Define Environment Settings and Pre-load Data Files *********
INK RGB(255, 255, 0), 0
LOAD SOUND "type.wav", 1
LOAD SOUND "fire.wav", 2
SET SOUND VOLUME 1, 100
SET SOUND VOLUME 2, 85
REM ********************** Main Processing Section ***********************
DisplaySplashScreen()
SYNC ON
SYNC RATE 60
DO
CLS
ProcessPlayerMoves()
UpdateBallPosition()
ManageVerticalCollisions()
ProcessPlayerMisses()
DrawBallAndPaddles()
ProcessPlayerHits()
UpdateScore()
IF (PlayerOnePoints = 10) OR (PlayerTwoPoints = 10) THEN EndOfGame()
SYNC
LOOP
REM ************************* Procedure Section **************************
FUNCTION ProcessPlayerMoves()
IF SHIFTKEY()
DEC PaddleY2, 3
IF PaddleY2 < 0 THEN PaddleY2 = 0
ENDIF
IF CONTROLKEY()
INC PaddleY2, 3
IF PaddleY2 > 405 THEN PaddleY2 = 405
ENDIF
IF UPKEY()
DEC PaddleY1, 3
IF PaddleY1 < 0 THEN PaddleY1 = 0
ENDIF
IF DOWNKEY()
INC PaddleY1, 3
IF PaddleY1 > 405 THEN PaddleY1 = 405
ENDIF
ENDFUNCTION
FUNCTION UpdateBallPosition()
INC BallX, SpeedX
INC BallY, SpeedY
ENDFUNCTION
FUNCTION ManageVerticalCollisions()
IF BallY < 5 OR BallY > 475
SpeedY = SpeedY * - 1
PLAY SOUND 1
ENDIF
ENDFUNCTION
FUNCTION ProcessPlayerMisses()
IF BallX < 9
PLAY SOUND 2
INC PlayerTwoPoints, 1
ResetBallAndPaddles()
SpeedX = 3
SLEEP 2000
ENDIF
IF BallX > 631
PLAY SOUND 2
INC PlayerOnePoints, 1
ResetBallAndPaddles()
SpeedX = -3
SLEEP 2000
ENDIF
ENDFUNCTION
FUNCTION DisplaySplashScreen()
SET TEXT SIZE 48
CENTER TEXT 320, 170, "Welcome to DB PONG!"
SET TEXT SIZE 16
CENTER TEXT 320, 250, "Press any key to continue"
WAIT KEY
CLS
ENDFUNCTION
FUNCTION DrawBallAndPaddles()
CIRCLE BallX, BallY, 8
BOX PaddleX1, PaddleY1, PaddleX1 + 10, PaddleY1 + 75
BOX PaddleX2, PaddleY2, PaddleX2 + 10, PaddleY2 + 75
ENDFUNCTION
FUNCTION ProcessPlayerHits()
IF POINT(BallX, BallY) > 0
SpeedX = SpeedX * - 1
PLAY SOUND 1
ENDIF
ENDFUNCTION
FUNCTION ResetBallAndPaddles()
BallX = 320
BallY = 240
PaddleX1 = 615
PaddleY1 = 200
PaddleX2 = 15
PaddleY2 = 200
ENDFUNCTION
FUNCTION UpdateScore()
TEXT 50, 10, "Player 1: " + STR$(PlayerOnePoints) + " Points"
TEXT 440, 10, "Player 2: " + STR$(PlayerTwoPoints) + " Points"
ENDFUNCTION
FUNCTION EndOfGame()
SYNC OFF
CLS
SET TEXT SIZE 48
CENTER TEXT 320, 120, "Game over!"
SET TEXT SIZE 24
CENTER TEXT 320, 210, "Player 1: " + STR$(PlayerOnePoints) + " Points"
CENTER TEXT 320, 240, "Player 2: " + STR$(PlayerTwoPoints) + " Points"
SET TEXT SIZE 16
CENTER TEXT 320, 300, "Press any key to start a new game"
WAIT KEY
PlayerOnePoints = 0
PlayerTwoPoints = 0
CLS
SYNC ON
ENDFUNCTION