Hey everyone,
I'm completely new to DarkBasic Pro. I'm following a book that has example games to create as it teaches you. I'm on the first one, called "Simple Pong" and things keep going wrong.
First, after copying the code correctly (i quadruple checked, so I know it's right) I tried to run the game and all it did was crash. I searched around and found that someone mentioned I should upgrade to the latest version of DarkBasic pro. I downloaded the latest version and installed it, and now whenever I run the program, it no longer crashes but I have a new issue.
Everytime I run the game, the ball in the center only moves up and down, which of course is useless. It doesn't crash and the paddles move but the ball never strays from the enter of the screen. Can someone help me? Here is the code:
REM Project: Simple Pong Game
REM Created: 12/27/2009 3:41:54 PM
REM
REM ***** Main Source File *****
rem make some variables
ballx as integer = 320
bally as integer = 240
speedx as integer = -2
speedy as integer = 1
px1 as integer = 600
py1 as integer = 240
px2 as integer = 20
py2 as integer = 240
score1 as integer = 0
score2 as integer = 0
rem slow down the game
sync on
sync rate 40
rem the game runs in a loop
do
cls
rem check shift/ctrl keys to move the left paddle
if shiftkey()
dec py2, 2
if py2 < 0 then py2 = 0
endif
if controlkey()
inc py2, 2
if py2 > 470 then py2 = 470
endif
rem check up/down keys to move the right paddle
if upkey()
dec py1, 2
if py1 < 0 then py1 = 0
endif
if downkey()
inc py1, 2
if py1 > 470 then py1 = 470
endif
rem move the ball
inc ballx, speedx
inc bally, speedy
rem bounce ball off top/bottom of the screen
if bally < 0 or bally > 470 then speedy = speedy * -1
rem see if left player missed the ball
rem if so, player 2 scores, reset the ball
if ballx < 0
inc score2, 1
ballx = 320
bally = 240
speedx = 2
sleep 500
endif
rem see if right player missed the ball
rem if so, player 1 scores, reset the ball
if ballx > 630
inc score1, 1
ballx = 320
bally = 240
speedx = -2
sleep 500
endif
rem draw the ball
circle ballx, bally, 10
rem draw the paddles
box px1, py1, px1+16, py1+64
box px2, py2, px2+16, py2+64
rem let's see if the ball has hit a paddle
if point(ballx+5,bally+5) > 0
speedx = speedx * -1
endif
rem print the scores
text 0, 0, "SCORE" + str$(score1)
text 550, 0, "SCORE" + str$(score2)
rem draw the screen
sync
loop