A downloadable game

BASIC TENLINER CONTEST 2022

Title: ViperTen20

Language: Basic v2 for Commodore Vic-20

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}viperten20 - use joy":poke36879,110:a=7702:b=102:c=30720:x=1:y=10:f=7680
2 s=3:dimp(30):fori=atoa+462step22:pokei,b:pokei+21,b:pokei+c,2:pokei+21+c,2
3 next:e=49:dx=1:fori=atoa+21:pokei,b:pokei+462,b:pokei+c,2:pokei+462+c,2:next
4 o=rnd(0)*460:ifpeek(a+o)-32goto4
5 pokea+o,e:ifs>11thenprint"{147}"tab(245)"congratulations!":end
6 poke37154,127:j=peek(37152)and128:poke37154,255:j=jor(peek(37137)and127)
7 ifj-255thendx=sgn(jand16)-sgn(jand128):dy=sgn(jand4)-sgn(jand8)
8 x=x+dx:y=y+dy:h=f+y*22+x:c=peek(h):ifc=borc=160thenprint"{147}you lose!":end
9 fori=sto1step-1:p(i)=p(i-1):next:ifc=ethene=e+1:s=s+1:pokeh,160:goto4
10 p(0)=h:pokep(0),160:pokep(s),32:goto6

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


Code comment

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

§ LINE 1:

1 print"{white}{147}viperten20 - use joy":poke36879,110:a=7702:b=102:c=30720:x=1:y=10:f=7680

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

Set border & background color.

'a' base value of the second line of the screen location (7680 + 22).

'b' value of character poke code.

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

'f' base value of the screen location.

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

§ LINE 2: 

2 s=3:dimp(30):fori=atoa+462step22:pokei,b:pokei+21,b:pokei+c,2:pokei+21+c,2

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

Initializes an array that contains the snake chars.

Draws and colors the the right and left edges.

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

§ LINE 3: 

3 next:e=49:dx=1:fori=atoa+21:pokei,b:pokei+462,b:pokei+c,2:pokei+462+c,2:next

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

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

Draws and colors the top and bottom edges in red.

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

§ LINE 4: 

4 o=rnd(0)*460:ifpeek(a+o)-32goto4

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:ifs>11thenprint"{147}"tab(245)"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 poke37154,127:j=peek(37152)and128:poke37154,255:j=jor(peek(37137)and127)

It disables the keyboard before reading the right switch of the joystick. After that it is restored.

'j' joystick position value.

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

§ LINE 7:

7 ifj-255thendx=sgn(jand16)-sgn(jand128):dy=sgn(jand4)-sgn(jand8)

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 x=x+dx:y=y+dy:h=f+y*22+x:c=peek(h):ifc=borc=160thenprint"{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+1:pokeh,160: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 10:

10 p(0)=h:pokep(0),160:pokep(s),32:goto6

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

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

Download

Download
viperten20.prg 535 bytes
Download
viperten20.bas 688 bytes
Download
viperten20.txt 4 kB

Install instructions

How to run the game:

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

To run the game I used the Vic-20 Emulator VICE v3.5 (xvic.exe) with no expansion memory.

Then just drag and drop the file "viperten20.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.