VictorColta Posted January 8, 2014 Share Posted January 8, 2014 Hi everybody!Look please at my Snake application on khanacademy and help me please to make fruit not to spawn on the gray wall. I don't understand what condition should i put in my checkFruits function, only you can help me. https://www.khanacademy.org/cs/snake-mania/2429405117 Quote Link to comment https://forums.phpfreaks.com/topic/285209-snake-javascript/ Share on other sites More sharing options...
.josh Posted January 8, 2014 Share Posted January 8, 2014 your wall is a "skeleton" in a 2d array but then as far as actually building it, you create it by filling in a rectangle based on a product (*10) of the coordinates. But then when checking the location of the fruit you are about to draw, you don't take that same *10 into account. You also do the same fill trick for your fruit but don't take into account that it's basically just a dot "skeleton" with a rectangle filled in by *10 factor. So IOW you are basically checking position based on the core "skeleton" points but not offsetting it by both the *10's you created, so you need to factor in current x/y positions *10 + *10. Incidentally, you have the same issue when checking for collision of snake vs. wall. If you look when you collide into a wall, you will see it actually stops in the center of the wall, where the "skeleton" coord is. Again, you are not factoring in the same *10 you used to make the boundaries. Quote Link to comment https://forums.phpfreaks.com/topic/285209-snake-javascript/#findComment-1464504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.