A downloadable game

BASIC TENLINER CONTEST 2022

Title: ViperTen128

Language: Basic v7 for Commodore 128

Category: PUR80

Author: Felix Nardella aka "Kimono"


Goal:

====

The goal of this game to control a snake to move and collect food (the numbers from 1 to 9) in the screen map. If you collect all the 9 numbers, you win and the game is over. If you try to move the snake with a movement contrary to its movement (eg move it to the right while it is going to the left), you lose and the game is over.

In the same place where a number is eaten, an obstacle is left. If the snake touch one of the obstacles or the edges of the screen, the game is over. To start the game again just write RUN and press RETURN.


Source:

=====================

1 print"{white}{147}viperten128 - joy in port2":poke53280,6:a=1064:b=102:c=54272:px=20
2 py=13:f=1024:e=49:dx=1:z=5:dimp(30):fori=atoa+920step40:pokei,b:pokei+39,b
3 w=160:pokei+c,2:pokei+39+c,2:next:x=rnd(-ti)
4 fori=atoa+38:pokei,b:pokei+920,b:pokei+c,2:pokei+920+c,2:next
5 o=rnd(0)*960:ifpeek(a+o)-32goto5
6 pokea+o,e:ifz>29thenprint"{147}"tab(252)"congratulations!":end
7 j=peek(56320):ifj-127thendx=sgn(jand4)-sgn(jand8):dy=sgn(jand1)-sgn(jand2)
8 px=px+dx:py=py+dy:h=f+py*40+px:c=peek(h):ifc=borc=wthenprint"{147}you lose!":end
9 fori=zto1step-1:p(i)=p(i-1):next:ifc=ethene=e+1:z=z+3:pokeh,w:goto5
10 p(0)=h:pokep(0),w:pokep(z),32:poke0,47:goto7

Tip: Copy/paste the program-Code into CBM prg Studio IDE (http://www.ajordison.co.uk/)


Code comment

============

§ LINE 1:

1 print"{white}{147}viperten128 - joy in port2":poke53280,6:a=1064:b=102:c=54272:px=20

Set the font color to white, clear screen and print the title of the game. Set border color.

'a' base value of the second line of the screen location (1024 + 40).

'b' value of character poke code.

'c' value of base value of color ram (- screen location).

'px' value of snake's x position.

=========================================================================

§ LINE 2: 

2 py=13:f=1024:e=49:dx=1:s=5:dimp(30):fori=atoa+920step40:pokei,b:pokei+39,b

'py' value of snake's y position.

'f' base value of the screen location.

'e' character poke code of first number (food).

'dx' value that increases the position of the snake.

's' value of the snake's initial length.

Initializes an array that contains the snake chars.

Draw the the right and left edges.

=========================================================================

§ LINE 3: 

3 w=160:v=54296:pokei+c,2:pokei+39+c,2:next:x=rnd(-ti)

'w' contains the snake char value.

'v' sound volume.

Colors the left and right edges red.

Initialising random numbers

=========================================================================

§ LINE 4: 

4 fori=atoa+38:pokei,b:pokei+920,b:pokei+c,2:pokei+920+c,2:next

Draw and color the top and bottom edges in red.

=========================================================================

§ LINE 5:

5 o=int(rnd(0)*919):ifpeek(a+o)-32goto5

Generates a random number to determine where to place food (numbers 1 to 9).

Check if the position is free.

=========================================================================

§ LINE 6:

6 pokea+o,e:ifs>29thenprint"{147}"tab(252)"congratulations!":end

Place the food on the screen.

If the length of the snake is greater than 29, you win and the game is over.

=========================================================================

§ LINE 7:

7 j=peek(56320):ifj-127thendx=sgn(jand4)-sgn(jand8):dy=sgn(jand1)-sgn(jand2)

'j' joystick position value.

Determines the x and y increments from the joy values. The SGN function is used to return 1 if the switch is off or 0 if it is on.

=========================================================================

§ LINE 8:

8 px=px+dx:py=py+dy:h=f+(py*40)+px:c=peek(h):ifc=borc=wthenprint"{147}you lose!":end

Updates the snake's x/y position.

If the snake touches the edges you lose and the game is over.

=========================================================================

§ LINE 9:

9 fori=sto1step-1:p(i)=p(i-1):next:ifc=ethene=e+1:s=s+3:pokeh,w:pokev,15:pokev,0:goto5

Retraces the entire length of the snake contained in the array. If the snake eats a number, it increases the number to reposition it on the screen and increases the length of the snake. It plays a "tick" (only using SID 6581 version).

=========================================================================

§ LINE 10:

10 p(0)=h:pokep(0),w:pokep(z),32:poke0,47:goto7

Refresh the snake's head and tail. Brings back the value of the location 0 to its original value (47), due to an unintended bug in the code and loop from line 7.

Unfortunately, this causes a bit of glitches that cannot be eliminated during the game (only in this version).

Download

Download
ViperTen128.prg 515 bytes
Download
ViperTen128.bas 661 bytes
Download
ViperTen128.txt 4 kB

Install instructions

How to run the game:

===================

To run the game I used the C=64 Emulator VICE v3.5 (x128.exe).

Then just drag and drop the file "viperten128.prg" on the emulator screen and the game will load and start automatically.

Use joystick in Port 2 to move the snake around the screen.

Leave a comment

Log in with itch.io to leave a comment.