0 REM PADLBALL.BAS.txt

10 REM Initialize the DAZZLER
20 DZOP "I" : REM Initialize DAZZLER
30 DZOP "Z" : REM Clear the screen initially
40 REM Set the color to Yellow (19) for the paddle
50 DZOP "C",1 : REM Enter Color Mode
55 DZOP "C", 19 : REM Set color to Yellow for the paddle
55 GOSUB 6000
56 FOR PAUSE = 0 TO 2999 : NEXT PAUSE
60 XPOS = 127 : REM Initial X position of the paddle
70 BALLX = 135 : REM Initial X position of the ball (above the paddle)
80 BALLY = 10 : REM Initial Y position of the ball
90 BALLDX = 1 : REM Initial X direction (1 = right, -1 = left)
100 BALLDY = 1 : REM Initial Y direction (1 = up, -1 = down)
110 REM Draw the paddle at the initial position
120 FOR X = XPOS TO XPOS + 19 : REM Loop to draw 20-dot wide bar
130 DZOP "P", X, 0 : REM Position cursor at each X
140 DZOP "D" : REM Plot the dot
150 NEXT X : REM End of initial draw
160 REM Main loop starts here
170 GOSUB 400 : REM Check for key press (paddle movement)
180 GOSUB 300 : REM Update ball position and check for bounce
185 DZOP "Z" : REM Clear the screen for the next ball move
190 GOSUB 200 : REM Redraw paddle and ball only if moved
195 GOTO 170 : REM Loop back to wait for next key press
200 REM Redraw paddle and ball
210 DZOP "C", 19 : REM Set color to Yellow for the paddle
220 FOR X = XPOS TO XPOS + 19 : REM Loop to draw 20-dot wide paddle
230 DZOP "P", X, 0 : REM Position cursor at each X
240 DZOP "D" : REM Plot the dot
250 NEXT X : REM End of paddle drawing
260 REM Draw the ball in Red
270 DZOP "C", 17 : REM Set color to Red for the ball
275 REM Ensure the ball stays within bounds before plotting
276 IF BALLX < 5 THEN BALLX = 5
277 IF BALLX > 250 THEN BALLX = 250
278 IF BALLY < 1 THEN BALLY = 1
279 IF BALLY > 250 THEN BALLY = 250
280 DZOP "P", BALLX, BALLY : REM Position cursor for the ball
290 DZOP "D" : REM Plot the ball
300 REM Update ball position and check for bounces
310 BALLX = BALLX + BALLDX : REM Move ball in X direction
320 BALLY = BALLY + BALLDY : REM Move ball in Y direction
330 REM Check for bouncing off the walls within X bounds (X=5, X=250)
340 IF BALLX <= 5 THEN BALLDX = 1 : REM Bounce right off left boundary
350 IF BALLX >= 250 THEN BALLDX = -1 : REM Bounce left off right boundary
360 REM Check for bouncing off the top (Y=250)
370 IF BALLY >= 250 THEN BALLDY = -1 : REM Ball moves down (negative Y direction)
380 REM Check for bouncing off the paddle
390 IF BALLY = 1 AND BALLX >= XPOS AND BALLX <= XPOS + 19 THEN GOSUB 4000 : REM Ball hits paddle
395 IF BALLY < 0 THEN GOSUB 5000 : REM Ball missed paddle, game over
400 REM Key press check routine for paddle movement
410 K$ = INKEY$ : REM Get key press
420 IF K$ = "L" THEN XPOS = XPOS + 10 : REM Move right by 10 dots
430 IF K$ = "J" THEN XPOS = XPOS - 10 : REM Move left by 10 dots
440 IF XPOS < 0 THEN XPOS = 0 : REM Prevent going off-screen to the left
450 IF XPOS > 235 THEN XPOS = 235 : REM Prevent going off-screen to the right (255 - 20 width)
460 RETURN : REM Return to main loop
4000 REM Ball bounces up at a new random X angle when hitting the paddle
4001 BALLDY = 1 : REM Ball starts moving up (positive Y direction)
4002 BALLDX = INT(RND * 3) - 1 : REM Randomize X direction (-1, 0, or 1)
4003 IF BALLDX = 0 THEN BALLDX = 1 : REM Ensure some X movement
4004 RETURN : REM Return to main loop
5000 REM Game Over routine
5010 DZOP "Z" : REM Clear the screen
5020 PRINT "GAME OVER!"
5030 END : REM End the program

6000 REM *** Subroutine to display text on the screen ***
6010 Y=200 : GOSUB 6100 : REM Print "PADDLE BALL" at X=1, Y=200
6020 Y=100 : GOSUB 6200 : REM Print "BY WALT PERKO" at X=0, Y=100
6030 Y=25  : GOSUB 6300 : REM Print "CREATED 2024" at X=0, Y=25
6040 RETURN

6100 REM *** Display "PADDLE BALL" ***
6110 X=0  : REM Start each line at X=0
6120 MSG$ = "PADDLE BALL" : GOSUB 6400
6130 RETURN

6200 REM *** Display "BY WALT PERKO" ***
6210 X=0  : REM Start each line at X=0
6220 MSG$ = "BY WALT PERKO" : GOSUB 6400
6230 RETURN

6300 REM *** Display "CREATED 2024" ***
6310 X=0  : REM Start each line at X=0
6320 MSG$ = "CREATED 2024" : GOSUB 6400
6330 RETURN

6400 REM *** Display each character from MSG$ ***
6410 FOR I = 1 TO LEN(MSG$)
6420   CH$ = MID$(MSG$, I, 1)               : REM Get each character
6430   CH = ASC(CH$)                        : REM Convert to ASCII
6440   IF CH >= 32 AND CH <= 126 THEN GOSUB 6500  : REM Display visible characters
6450   REM Adjust spacing based on character width
6460   IF CH$ = "I" OR CH$ = "L" OR CH$ = "J" THEN X = X + 14
6470   IF CH$ = "M" OR CH$ = "W" THEN X = X + 28
6480   IF CH$ <> "I" AND CH$ <> "L" AND CH$ <> "J" AND CH$ <> "M" AND CH$ <> "W" THEN X = X + 20
6490 NEXT I
6495 RETURN

6500 REM *** Subroutine to display a single character ***
6510 DZOP "C", 18    : REM Set color to white (23)
6520 IF X <= 255 THEN DZOP "P", X, Y  : REM Move to position X, Y only if X <= 255
6530 DZOP "C", CH    : REM Display the character using its ASCII code
6550 RETURN
