[A83] Re: nibbles / snake


[Prev][Next][Index][Thread]

[A83] Re: nibbles / snake




At 14:37 2002-01-30, you wrote:

>I'm going to make my own nibbles/snake clone. But I got
>a lot of questions for that:
>
>1) where does the game remember where the snake is currently?
>2) How should I clear the end of the snake?
>3) Do I use a collision detection routine to check
>    if the snake touches an apple?
>4) How do I detect when the snake hits itself or the wall?
>5) How can I make those levels like in nibbles by Bill
>    Nagel, and how do I check if the snake hits those
>    extra walls? (is it the same as 4)??)


for black'n'white nibbles, with no background that the nibble moves over 
that it should not hit, you can make it really simple.
The level is just drawn once, and collision detection with walls and nibble 
itself is done by checking if the pixel it wants to move to is set or not. 
if it is, hit. if not, continue. very simple.
The level can look anyway you want, with walls all over the place.
you can add apples by for everytime it collides with something according to 
the above, check if it hit an apple, by comparing coordinates as mentioned 
in another post.
make sure apples never overlap walls even with its corners.

for the nibble, you can have a safe ram area that you fill with coordinates 
as the nibble moves.
the buffer needs to be as large so it can contain all coordinates of the 
maximum lenght of the nibble.
You have also one variable that tells how long the nibble is and what 
direction it moves.
then you have two ways to go from there. one sollution is based on a lot of 
data movement, and the other is based on moving a pointer. the first is 
slower (but fast enough) and probably easier to code, so I'll describe that 
one.

for each move, you first move all the coordinate data already stored, one 
step up down in memory with ldir, how much data to move you know from the 
length of the nibble. then you write a pixel based on the first coord in 
the queue, and the direction, and store this in the beginning of the queue, 
and then you check the last coordinate (that was moved "out of the queue" 
in the ldir move) in the queue and erase that pixel.
when the nibble grows, only increase the variable with the length of the 
nibble.
A good thing might be to first clear the whole queue with zeros and never 
clear pixels at coord 0,0 to simplify the actual growing of the nibble.
I'm not sure if I'm explaining this any good, but it is actually really 
simple. just think about it a little, and at least you have one programming 
difficoulty left in your nibble project :)

///Olle





References: