I am making a snake game. I need to know how to make little fruit pop up in different area on the form. also I would like to know how to make a barrier for the snake so if it hits the wall it will die. Thanx in advance for any replies.
Printable View
I am making a snake game. I need to know how to make little fruit pop up in different area on the form. also I would like to know how to make a barrier for the snake so if it hits the wall it will die. Thanx in advance for any replies.
For the fruits use a random number generator.
For the barrier, simply do an out-of-bounds check for the head each step.
Your code for the random fruit position should look like this:
VB Code:
Private Function MoveFruit() Randomize X = Int(Rnd * MapWidth) * FruitWidth Y = Int(Rnd * MapHeight) * FruitHeight Fruit.Move X, Y End Function
MapWidth and MapHeight would be the number of tiles wide the map is, not pixels.