Qbasicnews.com

Full Version: Ahhh....Classic Pong (CODE)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This forum was intended for all to see how one person's idea can turn into something great!!! If you modified my pong code, could you post it here so everyone, including me, can see how everyone sees the same code differently.

Code:
TYPE pong
x AS INTEGER
y AS INTEGER
xmot AS INTEGER
ymot AS INTEGER
oldx AS INTEGER
oldy AS INTEGER
delay AS INTEGER
score AS INTEGER
END TYPE
DIM human AS pong
DIM ball AS pong
DIM ai AS pong
SCREEN 7, 0, 1, 0
delay = 1
human.x = 312: human.y = 85
ai.x = 0: ai.y = 85
ball.x = 150: ball.y = 100
ball.xmot = 1: ball.ymot = 1
LOCATE 13, 18: PRINT "PONG"
LOCATE 14, 13: PRINT "DIFFICULTY (1-4)"
PCOPY 1, 0
2 :
press$ = INKEY$
IF press$ = "1" THEN delay = 10
IF press$ = "2" THEN delay = 9
IF press$ = "3" THEN delay = 8
IF press$ = "4" THEN delay = 7
IF press$ = "" THEN GOTO 2
3 :
RANDOMIZE TIMER
ball.ymot = (INT(RND * 5)) - 3
IF ball.ymot = 0 THEN ball.ymot = ball.ymot - 1
ball.x = 150: ball.y = 100
human.x = 312: human.y = 85
ai.x = 0: ai.y = 85
LOCATE 1, 10: PRINT ai.score
LOCATE 1, 30: PRINT human.score
PCOPY 1, 0
IF human.score = 11 THEN
LOCATE 13, 8: PRINT "LOSE"
LOCATE 13, 29: PRINT "WIN"
PCOPY 1, 0
SLEEP
END
END IF
IF ai.score = 11 THEN
LOCATE 13, 28: PRINT "LOSE"
LOCATE 13, 9: PRINT "WIN"
PCOPY 1, 0
SLEEP
END
END IF
IF human.score <> 0 OR ai.score <> 0 THEN SLEEP
DO UNTIL press$ = CHR$(27)
LINE (0, 0)-(320, 200), 0, BF
CIRCLE (ball.x, ball.y), 7
PAINT (ball.x, ball.y), 15, 15
LINE (human.x, human.y)-(human.x + 7, human.y + 30), 15, BF
LINE (ai.x, ai.y)-(ai.x + 7, ai.y + 30), 15, BF
LOCATE 1, 10: PRINT ai.score
LOCATE 1, 30: PRINT human.score
PCOPY 1, 0
IF ball.x >= 312 THEN ball.xmot = -1
IF ball.y >= 192 THEN ball.ymot = -1
IF ball.x <= 7 THEN ball.xmot = 1
IF ball.y <= 7 THEN ball.ymot = 1
ball.oldx = ball.x: ball.oldy = ball.y
ball.x = ball.x + ball.xmot
ball.y = ball.y + ball.ymot
press$ = INKEY$
IF press$ = CHR$(0) + CHR$(72) AND human.y > 6 THEN human.y = human.y - 15
IF press$ = CHR$(0) + CHR$(80) AND human.y < 185 THEN human.y = human.y + 15
IF ai.delay = delay THEN
ai.delay = 0
IF ai.y + 26 < ball.y THEN ai.y = ai.y + 7
IF ai.y > ball.y THEN ai.y = ai.y - 7
ELSE
ai.delay = ai.delay + 1
END IF
IF ball.x = 14 THEN
IF ball.y >= ai.y - 6 AND ball.y <= ai.y + 36 THEN
PLAY "N20 L64"
ball.xmot = 1
GOTO 1
ELSE
human.score = human.score + 1
ball.xmot = -1
GOTO 3
END IF
END IF
IF ball.x = 306 THEN
IF ball.y >= human.y - 7 AND ball.y <= human.y + 37 THEN
PLAY "N20 L64"
ball.xmot = -1
GOTO 1
ELSE
ai.score = ai.score + 1
ball.xmot = 1
GOTO 3
END IF
END IF
1 :
LOOP
Mines on my webpage
|
|
|
\/