## Introduction

Previously, we've learned to add sprites and animations.

In this guide, weâ€™ll show you how to add an enemy sprite as well as a game scoring system with Blocks in MakeCode Arcade, then program it onto the Meowbit so you can take it with you.

Complete this guide to finish creating your version of the classic snake game!

1. ## Step 1 Overview

• This guide continues on from the previous, Sprite Animation with MakeCode Arcade, where we got started with creating the classic snake game. First, we looked into how to create the snake, which involved two separate sprites: the snake's body and the snake's head. Then you were introduced to variables and functions which were used to get the snake to move. We then animated the snake head using the Animation extension. Afterwards, Math blocks were used to randomly position our cupcake sprite. Finally, we learned to upload the program to the Meowbit.

In this guide, we will add a game scoring mechanism to complete the game.Â

2. ## Step 2 on sprite of kind ... overlaps ... of kind ...

• MakeCode Arcade has a built-in function to detect sprite interactions with other objects, or even between sprites of the same kind.

Overlap is the primary way to do this. You can find blocks of these kinds under the Sprites tab.

• Make sure that you are using an Image block under the Sprites tab. This block has a rectangle within a curved block. Otherwise, it won't work!

You can see the difference between the two 'snakeHeadSprite' blocks in the third image. When seen in the Javascript interface, the correct block uses "SpriteKindLegacy" instead of "SpriteKind".Â

• Add a change score by 1 block within the Overlap block.Â

• Add a set ... position to x ... y ... block to randomly generate the positio nof the next cupcakeÂ

3. ## Step 3 Lengthen the snake

• Next, add a call to the lengthenSnake function within the Overlap block.

4. ## Step 4 Adding an enemy sprite

• To make the game a little harder, let's add an enemy sprite.Â  Create a new variable and call it whatever you want. We've called it slime.Â

• Set this sprite to the kind 'Enemy'.

• Similar to what was done for the cupcake sprite, randomly generate its starting position between the coordinates x: pick random 20 to 100 and y: pick random 20 to 100.Â

• Next, to get the enemy sprite to teleport, drag and drop an on game update every ... ms block from the Game tab, and set this to 2000ms.Â

• Place a set slime position to x pick random 20 to 100 y pick random 20 to 100 block within it. The enemy sprite will change positions every 2 seconds.Â

• Add a on sprite of kind snakeHeadSprite overlap otherSprite of kind Enemy block. Place a game over LOCK with dissolve effects block into it.

5. ## Step 5 Adding effects

• Add a ... start ... effect block to the on sprite of kind snakeHeadsprite overlaps otherSprite of kind Food block.

• Set it to cupcake and spray.

• Add a pause 100 ms block

• Then add a clear effects on cupcake block.