2014년 12월 8일 월요일

Snake


I'm making a Snake game with App Inventor 2 but I don't know how to grow the snake, everything workes except how to grow the snake.

--
You advance the snake by drawing its head in the next square
in the direction its headed, and adding the head's position at 
position 1 of a list of its prior positions.

To grow the snake, fail to clear the board of its tail
(the last position in the list).

--
Thanks, but i'm a bit new to AI2 and i don't know excactly what you mean.
I'll send the code, hope you could help me.


--
Be aware that many do not want to load .aia's (takes too much time from our precious volunteer hours). Next time, post a screenshot of relevant blocks.
Anyway, in your movebody procedure, you should have some if-then-else logic: 
if the heading = 0, then x-body = x-head - 10 and y-body = y-head,
if the heading is 90 then x-body = x-head and y-body = y-head - 10 etc.
If necessary, do some tutorials te get familiar with if-then-else logic and how to adjust the blocks in AI2.
But then the fun starts, because you have only one body part now. You will need to add more sprites if you want to have a longer snake, keep the positions in a list, as Abraham said.

--
Okay thanks, i thought i wouldn't need more sprites because i can just muliply the one i have but i'll figure something out if you want screens i cant send

--
Unfortunately you cannot clone sprites programmatically in AI2. But you can of course use the same image for all the sprites.
After I wrote my reply I realized that you can avoid all the if-then-else if you do the positioning of the body in the event blocks, because there you know already what the heading will be, the thing on which the x and y setting of the body depends. Later you could do something even more fancy by having arguments to the procedure movebody, giving it the increments to x and y as input. But I advise to wait with that until you have more experience and also to complete one of the screens first. Maybe you can then find a way to combine both the sensor and the arrow versions.

--
I ment i can send screens btw, but could you help me out a bit step by step.
Here is my block's picture





--
That is not quite the idea. We help you if you are stuck and try to point into the right direction and for the rest: it is your effort, your game.
Your picture looks ok to me though.

--
Just a quick thing: my canvas flickers when the snake is moving, sometimes it stops randomly but it's pretty strange any help?

--
refer to: search for snake

--

댓글 4개: