Tuesday, February 21, 2017

Commodore 64 making a simple bouncing ball in Basic

Today I tried to make a C64 program again! It was maybe almost 30 years since the last time.

I thought I should do a program in Basic and it should be a "ball" that bounces from side to side on the screen.

Lets start:

10  DX=1                                                                                                    
The variable DX should store the direction of the movement

20  PO=1                                                                                                      
The variable PO (position) should store the position of the ball. Lets start at position 1

30  PRINT CHR$(147)                                                                               
Do a clear screen

40  FOR I=1 TO PO : PRINT " "; : NEXT                                                 
Let's loop through 1 to position. Print a space to the output and append a semicolon to tell our C64 to skip the newline, NEXT takes us on another leap in the loop

50  PRINT "O"                                                                                           
Write the ball to the output. With newline

60 PO=PO+DX                                                                                          
Add the direction variable to the position variable.

70 IF PO=39 THEN DX=-1                                                                      
Check if position is 39 then change the direction variable to -1 to turn

80 IF PO=1 THEN DX=1                                                                          
Check if position is 1 again. Then change the direction to 1 to turn

90 GOTO 30                                                                                              
The best part! Goto line 30 and start over again!

The emulator I used for this program is the CCS64: http://www.ccs64.com/

The complete program:

Have a nice day!

No comments:

Post a Comment