A downloadable game

BASIC 10 Liner entry


Game Name:

Trick Shoot-TEN

Category:

PUR-80

Computer/BASIC:

Commodore 64 BASIC V2


Game Description:

Trick shooting contest! Raise the ball to the right height, drop it on the ramp, and bounce it into the basket. As you make more and more shots, the baskets get smaller appear at more random locations. How many trick shots you can make in a row?

Game Instructions:

Hold the space bar down until the desired ball height is reached – then let go! Watch as the ball drops onto the ramp and bounces toward the basket. After scoring, tap the space bar to start the next round. Your current score is shown at the top center of the screen while the high score is displayed at the top left. To start a new game, press the space bar.

Game Features:

- Displays both the current score and the high score

- Increasing difficulty - the basket gets smaller and the placement becomes more random

- True parabolic calculations

- Beautiful PETSCII graphics

- Unique game sounds for ball movement, scores, and end of game

How to run the game in the VICE emulator:

1. Launch the x64sc.exe version of the VICE emulator

2. Drag the file “c64 trick shoot-ten.d64” onto the emulator

The code:

No lines are greater than 80 characters when entered using standard commodore screen codes and abbreviated commands.

- In VICE: c64 program lisiting screen 1.png, c64 program lisiting screen 2.png

- In ASCII with screen code descriptions

0 R=53280:POKER,6:M=54273:POKEM+23,15:L=(-10+S)*(10-S>0)+3:X=0:Y=12:C=223:IFB<STHENB=S
1 PRINT"{white}{clear}";B;TAB(17);S:T=24:GOSUB8:C=102:O=(9+(RND(0)*SAND15)):Y=INT(14+(RND(0)*SAND7))
2 FORJ=1TO2:FORX=OTOL+O:T=24:GOSUB8:NEXTX:Y=Y+1:NEXTJ:X=0:Y=11:T=24:C=81:GOSUB8:WAIT203,60
3 Y=ABS(Y-1):GOSUB8:IF       PEEK(203)=60THEN3
4 H=(12-Y):K=Y+1:FORI=1TO11-Y:Y=Y+1:GOSUB8:NEXT
5 X=X+1:Y=INT(.1*(X-H)^2+K):ONSGN(22-Y)+2GOTO7:GOSUB8:ONABS(PEEK(P+40)-101)GOTO6:GOTO5
6 PRINT"{home}{down*2} {light green}score!":S=S+1:POKER,13:Y=2:FORJ=1TO4:GOSUB9:Y=Y-.5:NEXT:WAIT203,60:GOTO0
7 PRINT"{home}{down*2} {pink}game over":POKER,10:Y=14:FORJ=1TO12:GOSUB9:Y=Y+.5:NEXT:WAIT203,60:S=0:GOTO0
8 P=1024+Y*40+X:POKEP,C:POKE1024+Z+T*40,32:Z=X:T=Y
9 POKEM,255-10*Y:POKEM+3,33:POKEM+3,32:RETURN

- In ASCII with abbreviated commands and screen code descriptions 

0R=53280:pOR,6:M=54273:pOM+23,15:L=(-10+S)*(10-S>0)+3:X=0:Y=12:C=223:IFB<StHB=S
1?"{white}{clear}";B;tA17);S:T=24:goS8:C=102:O=(9+(rN(0)*SaN15)):Y=INT(14+(rN(0)*SaN7))
2fOJ=1TO2:fOX=OTOL+O:T=24:goS8:nEX:Y=Y+1:nEJ:X=0:Y=11:T=24:C=81:goS8:wA203,60
3Y=aB(Y-1):goS8:IFpE(203)=60tH3
4H=(12-Y):K=Y+1:fOI=1TO11-Y:Y=Y+1:goS8:nE
5X=X+1:Y=INT(.1*(X-H)^2+K):ONsG(22-Y)+2gO7:goS8:ONaB(pE(P+40)-101)gO6:gO5
6?"{home}{down*2} {light green}score!":S=S+1:pOR,13:Y=2:fOJ=1TO4:goS9:Y=Y-.5:nE:wA203,60:gO0
7?"{home}{down*2} {pink}game over":pOR,10:Y=14:fOJ=1TO12:goS9:Y=Y+.5:nE:wA203,60:S=0:gO0
8P=1024+Y*40+X:pOP,C:pO1024+Z+T*40,32:Z=X:T=Y
9pOM,255-10*Y:pOM+3,33:pOM+3,32:reT

Variables:

Variable, Name, Description

B, Best, High score

C, Char, Screen code of character to print to screen

H, H, Parabola formula value

I, I temp, Temporary loop variable

J, J temp, Temporary loop variable

K, K, Parabola formula value

L, Length, Length of basket

M, Music, Base address +1 of SID

O, Offset, Offset of the basket from left

P, Position, Current ball position in screen memory

R, border, 53280 for border color changes

S, Score, Score of current game

T, T Pos, Last Y location drawn

X, X Pos, X location to draw character

Y, Y Pos, Y location to draw character

Z, Z Pos, Last X location drawn

How it works:

The code relies heavily on the subroutine at lines 8 and 9, so I’ll start there (by line #):

8: Draws the specified character (screen code), C, on the screen at the X,Y location. It also blanks (space=32) the last location drawn to (Z,T) so that the ball animation doesn’t leave a trail. A GOSUB to line 8 doesn’t return, but falls through to line 9 before RETURNing.

9: Plays a short tone based on the Y location last drawn to. A character higher on the screen (lower Y) gets a higher pitch so that the ball arch makes a pleasing rising and falling sound with the ball position. Line 9 is also called directly when wanting to play a sound without drawing to the screen (e.g. the scoring and game over sounds)

0: Sets border (R) color to blue, sets sound (M) volume to full (15), calculates the length (L) for the next basket (target), sets X,Y to 0,12 and character to 223 (ramp), and checks the if the high score (B) needs to be updated. The length (L) should reduce one every round until 3 and then hold at that. Since commodore BASIC V2 doesn’t support ELSE in IF THEN statements (no L=L-1:IF L<3 THEN L=3 ELSE), innovative means are needed. The equation (10-S>0) is used to stop decrementing at zero. It evaluates as TRUE (-1) or FALSE (0). Therefore, if the score is 9 or less, (10-S>0)=-1; but if the score is 10 or more, (10-S>0)=0. (-10+S) will start at -10 and count down (actually up since it is negative) as the score (S) increases. Examples: If S=0; (-10+S)*(10-S>0)=(-10)*(-1)=10. If S=8; (-10+S)*(10-S>0)=(-2)*(-1)=2. If S=11; (-10+S)*(10-S>0)=(1)*(0)=0. A constant of 3 is added so that the basket is never less than three characters wide. So the width starts at 13 and goes down to 3.

1: Sets text to white, clears the screen and prints the high score (B) and current score (S), sets least Y position (T) to a harmless value for the erasing in line 8, calls routine at 8 to draw ramp character, sets C to 102 (the checkerboard pattern), calculates the offset (O) of the basket (target) from the left edge of the screen, and calculates the Y value of the basket (target). For the offset, RND(0)*S makes a random value up to the current value of S and therefore the random placement grows as your score grows. ANDing with 15 caps the value at 15. A constant 9 is added so that offsets can vary from 9 to 24. For the Y value, RND(0)*S makes a random value up to the current value of S and therefore the random placement grows as your score grows. ANDing with 7 caps the value at 7. A constant 14 is added so that the Y value of the basket can vary from 14 to 21.

2: FOR J loops through drawing the two lines of the basket (target), FOR X draws from the offset (O) to the offset plus the length (O+L), last Y is set to harmless location (T=24), draw routine and loop increasing the Y (next line) between the two J loops. Sets X,Y = 0,12, T=24 (harmless last Y) and C=81 and calls the draw routine to draw the ball on the ramp. Waits for the spacebar.

3: Moves the ball up (Y-1) as long as the space bar is held down (PEEK(203)=60). The ABS stops the ball Y value from becoming a negative number and creates a fun bouncing at the top of the screen. The extra space is to drive my friend David crazy. Line three is short but loops back onto itself. Once the space bar is released, the code falls to line 4.

4: The constants for the parabola equation (H.K) are calculated based on the Y value when the space bar was released. The FOR NEXT loop moves the ball back down to the ramp. The parabola equation was derived from: https://www.radfordmathematics.com/functions/quadratic-functions-parabola/vertex...

5: Now the ball moves through its parabolic arc. X is incremented by one and the Y value is calculated by the equation. ONSGN(22-Y)+2GOTO7 branches to line 7 (game over) if the ball’s Y value is greater than 22. Since commodore BASIC V2 doesn’t support ELSE in IF THEN statements (no IF Y>22 THEN 7 ELSE), innovative means are needed. SGN(22-Y) checks the sign of 22-Y. When it’s negative (22>Y), then it produces a value of -1. ON branches with a value of 1. So SGN(22>Y)+2 = -1+2 = 1 when Y>22. ONABS(PEEK(P+40)-101)GOTO6 branches to line 6 when the character under the ball is the checkerboard pattern. PEEK(P+40) gets the screen code of the character below the ball. We are looking for 102, the checkerboard character. ON branches with a value of 1. So PEEK(P+40)-101=102-101=1 if the character below the ball is the checkerboard pattern. The ON command errors on negative values so the ABS is used to protect against that (e.g. space=32, so PEEK(P+40)-101=32-101=-69 without the ABS).

6. This is the score routine. This line prints a nice message, adds one to the score, changes border to green (13), sets the Y value to something low (2), executes a FOR J loop that calls the sound routine 4 times reducing Y between loops making a nice chirping sound signaling the score, waits for the space bar to be pushed, and then GOTOs 0.

7. This is the game over routine. This line prints the game over message, changes border to red (10), sets the Y value to something high (14), executes a FOR J loop that calls the sound routine 12 times increasing Y between loops making a decreasing low sound signaling the end of the game, waits for the space bar to be pushed, set the score to 0, and then GOTOs 0.

Download

Download
c64 entry.txt 8.8 kB
Download
c64 trick shoot-ten.d64 170 kB
Download
c64 entry.docx 805 kB

Leave a comment

Log in with itch.io to leave a comment.