How Move Player? Snake Game

Hello everyone!
I created my first game with Microsoft Make Code Arcade.
The game is the same as Snake, however I would like my character to start moving on his own when the game starts.
For now it only moves if I press the keys of the Meowbit.

The character is composed of two elements: head sprite and body sprite, because the body stretches when eating the sprite food and at the same time must follow the head sprite.

1 Like

Hi! Can you share your code? Here’s a video on how to do that:

2 Likes

Thank you!

Try something like this:

I removed the existing controller button pressed/repeat events and instead used them to set a variable called “direction”. Then, I added an on game update interval block to call the move functions based on the value of direction. That way, the snake will move in whatever direction was last pressed every 500ms. You can make the snake move faster by lowering that 500ms

2 Likes

Cool! I’m going to try it!!
thank you

@richard

Which why I want to be able to define an enum in block code. Otherwise you start defining too many variables. You also want to group variables together, such as my reply in

I now we can make extensions, but an enum would be really useful in the core code.

I am new to Arcade, but I would really love to see some improvements, and even work on implementing new block code. I had some good experience in TouchDevelop, and would like to see more of the functions made their in Arcade.

3 Likes

We don’t have a way to define a new set of types in blocks, but you can define enum-like consts with a few special attributes in ts, that a user can add to – it’s the way that spritekinds are created: https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/spritekind.ts I think it would be cool to explore a way for users to define new ones of their own for consts / have thought about it a bit, but it seems a bit more niche / harder to explain for new users / likely would only be used by particularly advanced users

Enums are not as nice to generate usually as they aren’t very extensible currently (an extension and a user program can’t nicely define members of the same enum as they would get duplicate definition errors / values would conflict)

I can relate to what you are saying. Perhaps if you could design constants that might be better. Again for the block programmer, I am not sure if that helps.