I’m developing a copy of the classic Snake game to teach some people the concepts of Xojo.

The game area is Canvas 640*480 and the Snake’s dimension are 16*16 pixel cubes, so the snake fits exactly 40 times in the play area.

The cookie/coin/food (whatever it is that the snake eats) is also a 16*16 cube. I’m trying to figure out how to place the snake and cookie aligned to each other so that the snake’s path/trajectory fits exactly to the alignment of the cookie.

To place a cookie I use the following code:

[code] 'Constants

Const PLAYFIELD_WIDTH = 640

Const PLAYFIELD_HEIGHT = 480

Const SNAKEUNIT = 16

```
'Randomize
Dim r As New Random
'ranges for x and y
Dim FoodX As Integer = r.InRange(0,PLAYFIELD_WIDTH-(SNAKEUNIT/2))
Dim FoodY As Integer = r.InRange(0, PLAYFIELD_HEIGHT-(SNAKEUNIT/2))
'correct x and y values to fit into the matrix
FoodX = FoodX-(FoodX mod 16) - (SNAKEUNIT/2)
FoodY = FoodY-(FoodY mod 16) - (SNAKEUNIT/2)[/code]
```

So the X and Y are random and I have to correct them.

But cookie and snake do not align to each other. I use the same code a s a starting point for the snake. What is wrong here?