A downloadable game

BASIC TENLINER CONTEST 2022

Title: ViperTen16

Language: Basic v3.5 for Commodore 16 - Plus/4 

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:

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

0 print"{white}{clear}viperten for c16/plus4 - joy in port2":a=3112:b=102:c=-1024:px=10
1 py=13:f=3072:e=49:x(0)=1:z=5:dimp(30):fori=atoa+920step40:pokei,b:pokei+39,b
2 color4,7,0:color0,7,0:w=160:pokei+c,2:pokei+39+c,2:next:x=rnd(-ti):data0,-1,1
3 fori=atoa+38:pokei,b:pokei+920,b:pokei+c,2:pokei+920+c,2:next:data0,0,1,-1,0
4 restore:fori=1to4:readx(i),y(i):next:o=int(rnd(1)*919):ifpeek(a+o)-32goto4
5 pokea+o,e:ifz>29thenprint"{clear}"tab(252)"congratulations!":end
6 j=int((joy(2)+1)/2):px=px+x(j):py=py+y(j):ifjthenx(0)=x(j):y(0)=y(j)
7 h=f+py*40+px:c=peek(h):ifc=borc=wthenprint"{147}you lose!":end
8 fori=zto1step-1:p(i)=p(i-1):next:ifc=ethene=e+1:z=z+3:pokeh,w:goto4
9 p(0)=h:pokep(0),w:pokep(z),32:goto6

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


Code comment

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

§ LINE 0:

0 print"{white}{clear}viperten for c16/plus4 - joy in port2":a=3112:b=102:c=-1024:px=10

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

'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 1: 

1 py=13:f=3072:e=49:x(0)=1:z=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).

'x(0)' value that increases the position of the snake.

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

Initializes an array that contains the snake chars.

Draw the the right and left edges.

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

§ LINE 2: 

2 color4,7,0:color0,7,0:w=160:pokei+c,2:pokei+39+c,2:next:x=rnd(-ti):data0,-1,1

Sets border & background colors.

'w' contains the snake char value.

Colors the top and bottom edges in red.

The data contain the first three values that the x() and y() arrays can take for position increment.

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

§ LINE 3: 

3 fori=atoa+38:pokei,b:pokei+920,b:pokei+c,2:pokei+920+c,2:next:data0,0,1,-1,0

Draws and colors the left and right edges red.

The data contains the other five values that the x() and y() arrays can take for position increment.

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

§ LINE 4:

4 restore:fori=1to4:readx(i),y(i):next:o=int(rnd(1)*919):ifpeek(a+o)-32goto4

Clears the pointer of the next data value. Read data values.

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

Check if the position is free.

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

§ LINE 5:

5 pokea+o,e:ifz>29thenprint"{clear}"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 6:

6 j=int((joy(2)+1)/2):px=px+x(j):py=py+y(j):ifjthenx(0)=x(j):y(0)=y(j)

1 is added to the joy value and then divide by 2 to have 1,2,3 and 4 instead of 1,3,5 and 7 at the four cardinal points.

Updates the snake's x/y position.

If there is no joy movement, the increase in position doesn't change.

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

§ LINE 7:

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

Calculate the snake's position.

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

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

§ LINE 8:

8 fori=zto1step-1:p(i)=p(i-1):next:ifc=ethene=e+1:z=z+3:pokeh,w:goto4

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.

Loop from line 4.

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

§ LINE 9:

9 p(0)=h:pokep(0),w:pokep(z),32:goto6

Refresh the snake's head and tail and loop from line 6.

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

Download

Download
viperten16.prg 563 bytes
Download
viperten16.bas 722 bytes
Download
viperten16.txt 5.2 kB

Install instructions

How to run the game:

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

To run the game I used the C16-Plus/4 Emulator VICE v3.5 (xplus4.exe) with no expansion memory.

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

Use joystick to move the snake around the screen.

Leave a comment

Log in with itch.io to leave a comment.