Jordi .B

unread,
Dec 5, 2014, 12:09:54 PM12/5/14
to mitappinv...@googlegroups.com

Hi all,

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.

Abraham Getzler

unread,
Dec 5, 2014, 12:50:42 PM12/5/14
to mitappinv...@googlegroups.com
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).

ABG

Jordi .B

unread,
Dec 6, 2014, 5:22:37 AM12/6/14
to mitappinv...@googlegroups.com
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.

Jordi.B
Snake.aia

Ghica

unread,
Dec 6, 2014, 12:15:02 PM12/6/14
to mitappinv...@googlegroups.com
Jordi,
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.
Cheers, Ghica.

Jordi .B

unread,
Dec 6, 2014, 1:22:18 PM12/6/14
to mitappinv...@googlegroups.com
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

Cheers, Jordi.B

Ghica

unread,
Dec 7, 2014, 5:52:15 AM12/7/14
to mitappinv...@googlegroups.com
Jordi,
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.
Cheers, Ghica

Jordi .B

unread,
Dec 7, 2014, 8:12:02 AM12/7/14
to mitappinv...@googlegroups.com
Hi,

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

Cheers, Jordi
blocks.PNG

Ghica

unread,
Dec 7, 2014, 8:40:18 AM12/7/14
to mitappinv...@googlegroups.com
Hi Jordi,
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.
Cheers, Ghica.

Jordi .B

unread,
Dec 29, 2014, 12:55:44 PM12/29/14
to mitappinv...@googlegroups.com
Hi,

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

Cheers, Jordi
Reply all
Reply to author
Forward
0 new messages