bo wrote on Apr 19th, 2010, 6:34pm:I've created a snake game, and trying to get the snake to grow every time it "hits" or intersects with the flashing circles (food) that pop up, but the intersection isn't working.
you can view the game and download the code here: http://www.imagearts.ryerson.ca/lbonsell/snake/snakegame.html
THANKS!
Funny - someone posted with a very similar problem the other day.
Question: What do you pass to your intersect() function
Answer:
Quote: if (intersect(snake.headx, snake.heady, snake.headsize,
food.x, food.y, food.diameter) == true) {
food.activate();
}
Question: Where are these properties defined
Answer: In the Snake constructor which gets called only
once - when the snake is first created:
Code:Snake() {
headx = mouseX;
heady = mouseY;
headsize = 20;
}
Solution: assign mouseX/Y to headx/y properties on each frame - perhaps in the Snake display method...