The QBasic Forum     RULES     Other Subforums, Links and Downloads    Index of Threads

 Return to Index  

Two player PONG clone...

February 16 2003 at 7:01 AM
  (no login)

Here's a small, two-player PONG clone I made. It's pretty simple, but I plan to add targets, levels, and aiming ability in next release. Email me what you think, kickflip_dude@email.com
Controls are:
TOP PADDLE: LEFT - 'z' RIGHT - 'x'
BOTTOM PADDLE: LEFT - ',' RIGHT - '.'

'-----Start
'########################################################################
'# Whacka Da Balla v1.0 #
'# By Zack - #
'# A simple, two player Pong clone I made. #
'# The programming is commented pretty well, I think, so you shouldn't #
'# have a problem understanding it. Animation engine is simple. #
'# Controls are: Move top paddle LEFT-'z' Move top paddle RIGHT-'x' #
'# Move bottom paddle LEFT-',' Move bottom paddle RIGHT-'.' #
'# Please send any comments/suggestions/love letters/marriage proposals #
'# to kickflip_dude@email.com #
'# Please feel free to distribute this game, but please don't change #
'# anything. #
'########################################################################
DEFINT A-Z 'All integers, for speed

player = 1 'Serve against player 1 first

initGame:
SCREEN 7, 0, 1, 0 'Screen 7 (320x200), 1 page
SLEEP 1
CLS
bx = 160 'bx and by are variables for the ball
by = 100

SELECT CASE player 'Check who to serve to, vx and vy are velocity vars
CASE 1:
vx = 1
vy = 1
CASE 2:
vx = -1
vy = -1
END SELECT

px1a = 150 'Variables for the paddle
px2a = 180
py1a = 199
py2a = 195
px1b = 150
px2b = 180
py1b = 1
py2b = 5

CIRCLE (bx, by), 7, 2 'Init the ball and paddles
LINE (px1a, py1a)-(px2a, py2a), 1, B
LINE (px1b, py1b)-(px2b, py2b), 3, B

LINE (0, 0)-(0, 200), 5 'Make borders around playing area
LINE (280, 0)-(280, 200), 5
PCOPY 1, 0

DO
press$ = INKEY$

CIRCLE (bx, by), 7, 0 'Move the ball. (Like I said, simple animation engine)
bx = bx + vx
by = by + vy
CIRCLE (bx, by), 7, 2

IF press$ = "," AND px1a - 9 >= 0 THEN 'Player 1 move LEFT
LINE (px1a, py1a)-(px2a, py2a), 0, B
px1a = px1a - 9
px2a = px2a - 9
LINE (px1a, py1a)-(px2a, py2a), 1, B
END IF

IF press$ = "." AND px2a + 9 <= 279 THEN 'Player 1 move RIGHT
LINE (px1a, py1a)-(px2a, py2a), 0, B
px1a = px1a + 9
px2a = px2a + 9
LINE (px1a, py1a)-(px2a, py2a), 1, B
END IF

IF press$ = "z" AND px1b - 9 >= 0 THEN 'Player 2 move LEFT
LINE (px1b, py1b)-(px2b, py2b), 0, B
px1b = px1b - 9
px2b = px2b - 9
LINE (px1b, py1b)-(px2b, py2b), 3, B
END IF

IF press$ = "x" AND px2b + 9 <= 279 THEN 'Player 2 move RIGHT
LINE (px1b, py1b)-(px2b, py2b), 0, B
px1b = px1b + 9
px2b = px2b + 9
LINE (px1b, py1b)-(px2b, py2b), 3, B
END IF

'If the ball misses player 1's paddle, goto initGame at beginning of program
IF bx + 7 < px1a AND by + 7 >= 195 OR bx - 7 > px2a AND by + 7 >= 195 THEN
score2 = score2 + 1
player = 1
GOSUB initGame
END IF

'If the ball misses player 2's paddle, goto initGame at beginning of program
IF bx + 7 < px1b AND by - 7 <= 6 OR bx - 7 > px2b AND by - 7 <= 5 THEN
score1 = score1 + 1
player = 2
GOSUB initGame
END IF

IF bx >= 272 THEN vx = vx * -1 'Make Sure ball doesn't go off screen
IF bx <= 8 THEN vx = vx * -1
IF by + 7 >= py2a THEN vy = vy * -1 'If you hit the ball, change direction
IF by - 7 <= py2b THEN vy = vy * -1

LOCATE 1, 37: PRINT score2
LOCATE 23, 37: PRINT score1;

PCOPY 1, 0

LOOP UNTIL press$ = CHR$(27) 'Exit when you press ESCAPE (chr$(13))

CLS
PCOPY 1, 0
COLOR 1
PRINT "Game";
COLOR 2
PRINT " Over!!!"
PCOPY 1, 0
'-----End

 
 Respond to this message   
Response TitleAuthorDate
 Oops... Feb 16, 2003