# How Move Player? Snake Game

**URL:** <https://forum.makecode.com/t/how-move-player-snake-game/2319>\
**Category:** Arcade\
**Created:** [June 5, 2020, 11:40am UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319 "2020-06-05T11:40:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adcoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/adcoding/32/27305_2.png) [@adcoding](https://forum.makecode.com/u/adcoding)\
**Post date:** [June 5, 2020, 11:40am UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/1 "2020-06-05T11:40:58Z")

</div>

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.

 ![Schermata 2020-06-05 alle 13.40.38](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/d/d074ce2451b3227aec430520107a229cb03fed82.png)

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [June 5, 2020, 3:35pm UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/2 "2020-06-05T15:35:42Z")

</div>

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

[![](https://img.youtube.com/vi/A8Kpq5H7DZA/maxresdefault.jpg "How to Share Arcade Games") ](https://www.youtube.com/watch?v=A8Kpq5H7DZA)

---

<div class="post-metadata">

**Author:** ![adcoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/adcoding/32/27305_2.png) [@adcoding](https://forum.makecode.com/u/adcoding)\
**Post date:** [June 9, 2020, 12:39pm UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/3 "2020-06-09T12:39:01Z")

</div>

Thank you!

> **[Snake and Apples](https://arcade.makecode.com/79034-57056-76582-56323)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [June 9, 2020, 4:45pm UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/4 "2020-06-09T16:45:46Z")

</div>

Try something like this:

 ![Screen Shot 2020-06-09 at 9.41.37 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/af1dabcddab655ece619211227d7e30e6c851276.png)

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

---

<div class="post-metadata">

**Author:** ![adcoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/adcoding/32/27305_2.png) [@adcoding](https://forum.makecode.com/u/adcoding)\
**Post date:** [June 11, 2020, 9:03am UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/5 "2020-06-11T09:03:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 3, 2020, 11:58am UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/6 "2020-10-03T11:58:24Z")

</div>

@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

> [@Need Some Ideas Plz](https://forum.makecode.com/t/need-some-ideas-plz/3533/39):
>
> @UnderwaterAstronaut I like how you change the animation of your sprite depending on the direction it is facing in: [https://arcade.makecode.com/96109-55229-74632-47006](https://arcade.makecode.com/96109-55229-74632-47006)@richard I know you can define and code enums in TypeScript, but is there any block code to define an enum? For instance, in block code define an variable having the name ‘DirectionFacing’ with the values Left, Right, Up, Down This produces the script enum DirectionFacing { Left, Right, Up, Down } Assume the variable d…

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.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 4, 2020, 10:42pm UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/7 "2020-10-04T22:42:39Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 5, 2020, 12:32am UTC](https://forum.makecode.com/t/how-move-player-snake-game/2319/8 "2020-10-05T00:32:58Z")

</div>

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.
