View on GitHub

adventure

A MakeCode project

# Lesson Plan: MakeCode Arcade Game Development Introduction

Objective

By the end of this lesson, students will be able to create a game using MakeCode Arcade that incorporates core game mechanics, enemy AI, scoring, timers, and additional features such as sound and visual effects.

Materials

Target Audience

Teens with little or no familiarity with programming concepts.

Project

info.onScore(12, function () {
    game.setGameOverMessage(true, "You did it!")
    game.gameOver(true)
})
info.onCountdownEnd(function () {
    game.setGameOverMessage(false, "You ran out of time")
    game.gameOver(false)
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    sprites.destroy(otherSprite)
    info.changeScoreBy(1)
    music.play(music.melodyPlayable(music.baDing), music.PlaybackMode.UntilDone)
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    game.gameOver(false)
    game.setGameOverMessage(false, "Better luck next time")
})
let Collect_Item: Sprite = null
let Player1 = sprites.create(img`
    . f f f . f f f f . f f f . 
    f f f f f c c c c f f f f f 
    f f f f b c c c c b f f f f 
    f f f c 3 c c c c 3 c f f f 
    . f 3 3 c c c c c c 3 3 f . 
    . f c c c c 4 4 c c c c f . 
    . f f c c 4 4 4 4 c c f f . 
    . f f f b f 4 4 f b f f f . 
    . f f 4 1 f d d f 1 4 f f . 
    . . f f d d d d d d f f . . 
    . . e f e 4 4 4 4 e f e . . 
    . e 4 f b 3 3 3 3 b f 4 e . 
    . 4 d f 3 3 3 3 3 3 c d 4 . 
    . 4 4 f 6 6 6 6 6 6 f 4 4 . 
    . . . . f f f f f f . . . . 
    . . . . f f . . f f . . . . 
    `, SpriteKind.Player)
controller.moveSprite(Player1)
Player1.setStayInScreen(true)
tiles.setCurrentTilemap(tilemap`level1`)
for (let index = 0; index < 12; index++) {
    Collect_Item = sprites.create(img`
        . . . . . . . . . . . 6 6 6 6 6 
        . . . . . . . . . 6 6 7 7 7 7 8 
        . . . . . . 8 8 8 7 7 8 8 6 8 8 
        . . e e e e c 6 6 8 8 . 8 7 8 . 
        . e 2 5 4 2 e c 8 . . . 6 7 8 . 
        e 2 4 2 2 2 2 2 c . . . 6 7 8 . 
        e 2 2 2 2 2 2 2 c . . . 8 6 8 . 
        e 2 e e 2 2 2 2 e e e e c 6 8 . 
        c 2 e e 2 2 2 2 e 2 5 4 2 c 8 . 
        . c 2 e e e 2 e 2 4 2 2 2 2 c . 
        . . c 2 2 2 e e 2 2 2 2 2 2 2 e 
        . . . e c c e c 2 2 2 2 2 2 2 e 
        . . . . . . . c 2 e e 2 2 e 2 c 
        . . . . . . . c e e e e e e 2 c 
        . . . . . . . . c e 2 2 2 2 c . 
        . . . . . . . . . c c c c c . . 
        `, SpriteKind.Food)
    tiles.placeOnRandomTile(Collect_Item, assets.tile`transparency16`)
}
let Enemy1 = sprites.create(img`
    . . . . c c c c c c . . . . . . 
    . . . c 6 7 7 7 7 6 c . . . . . 
    . . c 7 7 7 7 7 7 7 7 c . . . . 
    . c 6 7 7 7 7 7 7 7 7 6 c . . . 
    . c 7 c 6 6 6 6 c 7 7 7 c . . . 
    . f 7 6 f 6 6 f 6 7 7 7 f . . . 
    . f 7 7 7 7 7 7 7 7 7 7 f . . . 
    . . f 7 7 7 7 6 c 7 7 6 f c . . 
    . . . f c c c c 7 7 6 f 7 7 c . 
    . . c 7 2 7 7 7 6 c f 7 7 7 7 c 
    . c 7 7 2 7 7 c f c 6 7 7 6 c c 
    c 1 1 1 1 7 6 f c c 6 6 6 c . . 
    f 1 1 1 1 1 6 6 c 6 6 6 6 f . . 
    f 6 1 1 1 1 1 6 6 6 6 6 c f . . 
    . f 6 1 1 1 1 1 1 6 6 6 f . . . 
    . . c c c c c c c c c f . . . . 
    `, SpriteKind.Enemy)
tiles.placeOnRandomTile(Enemy1, assets.tile`transparency16`)
Enemy1.follow(Player1, 60)
info.setScore(0)
info.startCountdown(10)

Lesson Outline

Introduction

LEVEL 1 - Core Game Mechanics

1.1. Setting Up the Player1 Sprite

   let Player1 = sprites.create(img`
    . f f f . f f f f . f f f . 
    f f f f f c c c c f f f f f 
    f f f f b c c c c b f f f f 
    f f f c 3 c c c c 3 c f f f 
    . f 3 3 c c c c c c 3 3 f . 
    . f c c c c 4 4 c c c c f . 
    . f f c c 4 4 4 4 c c f f . 
    . f f f b f 4 4 f b f f f . 
    . f f 4 1 f d d f 1 4 f f . 
    . . f f d d d d d d f f . . 
    . . e f e 4 4 4 4 e f e . . 
    . e 4 f b 3 3 3 3 b f 4 e . 
    . 4 d f 3 3 3 3 3 3 c d 4 . 
    . 4 4 f 6 6 6 6 6 6 f 4 4 . 
    . . . . f f f f f f . . . . 
    . . . . f f . . f f . . . . 
    `, SpriteKind.Player)
controller.moveSprite(Player1)
Player1.setStayInScreen(true)

1.2. Creating and Placing Fruit

Continue adding to the current code within the ||loops: on start|| block the following:

### ~hint

- Make sure that the ``||scene:tilemap||`` is **10 by 8 units**.  Change the size in the Tilemap Editor.
- For now we will leave the ``||scene:tilemap||`` blank.  We'll create our world later on.
- Make sure that the ``||scene:tilemap||`` is placed before the ``||scene:place it randomly||`` block.

~

  // @hide
  let Player1 = sprites.create(img`
  . f f f . f f f f . f f f . 
  f f f f f c c c c f f f f f 
  f f f f b c c c c b f f f f 
  f f f c 3 c c c c 3 c f f f 
  . f 3 3 c c c c c c 3 3 f . 
  . f c c c c 4 4 c c c c f . 
  . f f c c 4 4 4 4 c c f f . 
  . f f f b f 4 4 f b f f f . 
  . f f 4 1 f d d f 1 4 f f . 
  . . f f d d d d d d f f . . 
  . . e f e 4 4 4 4 e f e . . 
  . e 4 f b 3 3 3 3 b f 4 e . 
  . 4 d f 3 3 3 3 3 3 c d 4 . 
  . 4 4 f 6 6 6 6 6 6 f 4 4 . 
  . . . . f f f f f f . . . . 
  . . . . f f . . f f . . . . 
  `, SpriteKind.Player)
  // @hide
  controller.moveSprite(Player1)
  // @hide
  Player1.setStayInScreen(true)
  
  let Fruit = sprites.create(img`
  . . . . . . . . . . . 6 6 6 6 6 
  . . . . . . . . . 6 6 7 7 7 7 8 
  . . . . . . 8 8 8 7 7 8 8 6 8 8 
  . . e e e e c 6 6 8 8 . 8 7 8 . 
  . e 2 5 4 2 e c 8 . . . 6 7 8 . 
  e 2 4 2 2 2 2 2 c . . . 6 7 8 . 
  e 2 2 2 2 2 2 2 c . . . 8 6 8 . 
  e 2 e e 2 2 2 2 e e e e c 6 8 . 
  c 2 e e 2 2 2 2 e 2 5 4 2 c 8 . 
  . c 2 e e e 2 e 2 4 2 2 2 2 c . 
  . . c 2 2 2 e e 2 2 2 2 2 2 2 e 
  . . . e c c e c 2 2 2 2 2 2 2 e 
  . . . . . . . c 2 e e 2 2 e 2 c 
  . . . . . . . c e e e e e e 2 c 
  . . . . . . . . c e 2 2 2 2 c . 
  . . . . . . . . . c c c c c . . 
  `, SpriteKind.Food)
  tiles.setCurrentTilemap(tilemap`level1`)
  tiles.placeOnRandomTile(Fruit, assets.tile`transparency16`)

1.3. Collision Detection - Player1 catches Fruit

```blocks
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
sprites.destroy(otherSprite)
})
```
- GIF of how to add the **otherSprite** block to the ``||sprites: destroy||`` block.
- ![add otherSprite to destroy](https://res.cloudinary.com/garcila/image/upload/v1694377306/arcade_overlap.gif)

LEVEL 2 - Adding an Enemy

2.1. Add Enemy1 Add to the current code within the ||loops: on start|| block the following:

### ~alert

Player1 Does not stand a chance, as Enemy1 is too fast. To balance the game and increase its playability click on the plus button within the follow block and change the speed of the Enemy1.

```block
// @hide
let Enemy1 = sprites.create(img`
. . . . c c c c c c . . . . . . 
. . . c 6 7 7 7 7 6 c . . . . . 
. . c 7 7 7 7 7 7 7 7 c . . . . 
. c 6 7 7 7 7 7 7 7 7 6 c . . . 
. c 7 c 6 6 6 6 c 7 7 7 c . . . 
. f 7 6 f 6 6 f 6 7 7 7 f . . . 
. f 7 7 7 7 7 7 7 7 7 7 f . . . 
. . f 7 7 7 7 6 c 7 7 6 f c . . 
. . . f c c c c 7 7 6 f 7 7 c . 
. . c 7 2 7 7 7 6 c f 7 7 7 7 c 
. c 7 7 2 7 7 c f c 6 7 7 6 c c 
c 1 1 1 1 7 6 f c c 6 6 6 c . . 
f 1 1 1 1 1 6 6 c 6 6 6 6 f . . 
f 6 1 1 1 1 1 6 6 6 6 6 c f . . 
. f 6 1 1 1 1 1 1 6 6 6 f . . . 
. . c c c c c c c c c f . . . . 
`, SpriteKind.Enemy)
Enemy1.follow(Player1, 60) ```

### ~

```block
// @hide
let Player1 = sprites.create(img`
. f f f . f f f f . f f f . 
f f f f f c c c c f f f f f 
f f f f b c c c c b f f f f 
f f f c 3 c c c c 3 c f f f 
. f 3 3 c c c c c c 3 3 f . 
. f c c c c 4 4 c c c c f . 
. f f c c 4 4 4 4 c c f f . 
. f f f b f 4 4 f b f f f . 
. f f 4 1 f d d f 1 4 f f . 
. . f f d d d d d d f f . . 
. . e f e 4 4 4 4 e f e . . 
. e 4 f b 3 3 3 3 b f 4 e . 
. 4 d f 3 3 3 3 3 3 c d 4 . 
. 4 4 f 6 6 6 6 6 6 f 4 4 . 
. . . . f f f f f f . . . . 
. . . . f f . . f f . . . . 
`, SpriteKind.Player)
// @hide    
controller.moveSprite(Player1)
// @hide
Player1.setStayInScreen(true)
// @hide
let Fruit = sprites.create(img`
    . . . . . . . . . . . 6 6 6 6 6 
    . . . . . . . . . 6 6 7 7 7 7 8 
    . . . . . . 8 8 8 7 7 8 8 6 8 8 
    . . e e e e c 6 6 8 8 . 8 7 8 . 
    . e 2 5 4 2 e c 8 . . . 6 7 8 . 
    e 2 4 2 2 2 2 2 c . . . 6 7 8 . 
    e 2 2 2 2 2 2 2 c . . . 8 6 8 . 
    e 2 e e 2 2 2 2 e e e e c 6 8 . 
    c 2 e e 2 2 2 2 e 2 5 4 2 c 8 . 
    . c 2 e e e 2 e 2 4 2 2 2 2 c . 
    . . c 2 2 2 e e 2 2 2 2 2 2 2 e 
    . . . e c c e c 2 2 2 2 2 2 2 e 
    . . . . . . . c 2 e e 2 2 e 2 c 
    . . . . . . . c e e e e e e 2 c 
    . . . . . . . . c e 2 2 2 2 c . 
    . . . . . . . . . c c c c c . . 
    `, SpriteKind.Food)
// @hide
tiles.setCurrentTilemap(tilemap`level1`)
// @hide
tiles.placeOnRandomTile(Fruit, assets.tile`transparency16`)

let Enemy1 = sprites.create(img`
    . . . . c c c c c c . . . . . . 
    . . . c 6 7 7 7 7 6 c . . . . . 
    . . c 7 7 7 7 7 7 7 7 c . . . . 
    . c 6 7 7 7 7 7 7 7 7 6 c . . . 
    . c 7 c 6 6 6 6 c 7 7 7 c . . . 
    . f 7 6 f 6 6 f 6 7 7 7 f . . . 
    . f 7 7 7 7 7 7 7 7 7 7 f . . . 
    . . f 7 7 7 7 6 c 7 7 6 f c . . 
    . . . f c c c c 7 7 6 f 7 7 c . 
    . . c 7 2 7 7 7 6 c f 7 7 7 7 c 
    . c 7 7 2 7 7 c f c 6 7 7 6 c c 
    c 1 1 1 1 7 6 f c c 6 6 6 c . . 
    f 1 1 1 1 1 6 6 c 6 6 6 6 f . . 
    f 6 1 1 1 1 1 6 6 6 6 6 c f . . 
    . f 6 1 1 1 1 1 1 6 6 6 f . . . 
    . . c c c c c c c c c f . . . . 
    `, SpriteKind.Enemy)
tiles.placeOnRandomTile(Enemy1, assets.tile`transparency16`)
Enemy1.follow(Player1, 60)
```

2.2 Losing the Game - Enemy1 catches Player1

2.3. Winning the Game

We can now lose the game, but we also want to be able to win it! Let’s code our way to victory.

```block
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    sprites.destroy(otherSprite)
    game.setGameOverMessage(true, "You did it!")
    game.gameOver(true)
})
```

LEVEL 3 - Multiple Fruits and Score:

We have a working game, but we can make it better by increasing the number of fruit to catch. We need to find a way to easily add fruits in random places and we may as well add a scoring system to win the game once all the fruits have been captured.

3.1 - Adding multiple Fruits

~

3.2 - Add a score and modify the winning condition

info.onScore(12, function () {
    game.setGameOverMessage(true, "You did it!")
    game.gameOver(true)
})

LEVEL 4 - Timer, Tiles and Sound:

To add more excitment to the game we’ll add some preassure to the Player1 by forcing the picking of all the fruits before a certain time (10 seconds)

4.1 - Adding a Timer

4.3 - Customize the game by Adding Elements to the Backgrouned

To embelish and personalize your game, click on the gray square within the ||scene: set tilemap|| block and add elements to the background.

Here are some examples:

Congratulations!

All the Code!

info.onScore(12, function () {
    game.setGameOverMessage(true, "You did it!")
    game.gameOver(true)
})
info.onCountdownEnd(function () {
    game.setGameOverMessage(false, "You ran out of time")
    game.gameOver(false)
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    sprites.destroy(otherSprite)
    info.changeScoreBy(1)
    music.play(music.melodyPlayable(music.baDing), music.PlaybackMode.UntilDone)
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    game.gameOver(false)
    game.setGameOverMessage(false, "Better luck next time")
})
let Collect_Item: Sprite = null
let Player1 = sprites.create(img`
    . f f f . f f f f . f f f . 
    f f f f f c c c c f f f f f 
    f f f f b c c c c b f f f f 
    f f f c 3 c c c c 3 c f f f 
    . f 3 3 c c c c c c 3 3 f . 
    . f c c c c 4 4 c c c c f . 
    . f f c c 4 4 4 4 c c f f . 
    . f f f b f 4 4 f b f f f . 
    . f f 4 1 f d d f 1 4 f f . 
    . . f f d d d d d d f f . . 
    . . e f e 4 4 4 4 e f e . . 
    . e 4 f b 3 3 3 3 b f 4 e . 
    . 4 d f 3 3 3 3 3 3 c d 4 . 
    . 4 4 f 6 6 6 6 6 6 f 4 4 . 
    . . . . f f f f f f . . . . 
    . . . . f f . . f f . . . . 
    `, SpriteKind.Player)
controller.moveSprite(Player1)
Player1.setStayInScreen(true)
tiles.setCurrentTilemap(tilemap`level1`)
for (let index = 0; index < 12; index++) {
    Collect_Item = sprites.create(img`
        . . . . . . . . . . . 6 6 6 6 6 
        . . . . . . . . . 6 6 7 7 7 7 8 
        . . . . . . 8 8 8 7 7 8 8 6 8 8 
        . . e e e e c 6 6 8 8 . 8 7 8 . 
        . e 2 5 4 2 e c 8 . . . 6 7 8 . 
        e 2 4 2 2 2 2 2 c . . . 6 7 8 . 
        e 2 2 2 2 2 2 2 c . . . 8 6 8 . 
        e 2 e e 2 2 2 2 e e e e c 6 8 . 
        c 2 e e 2 2 2 2 e 2 5 4 2 c 8 . 
        . c 2 e e e 2 e 2 4 2 2 2 2 c . 
        . . c 2 2 2 e e 2 2 2 2 2 2 2 e 
        . . . e c c e c 2 2 2 2 2 2 2 e 
        . . . . . . . c 2 e e 2 2 e 2 c 
        . . . . . . . c e e e e e e 2 c 
        . . . . . . . . c e 2 2 2 2 c . 
        . . . . . . . . . c c c c c . . 
        `, SpriteKind.Food)
    tiles.placeOnRandomTile(Collect_Item, assets.tile`transparency16`)
}
let Enemy1 = sprites.create(img`
    . . . . c c c c c c . . . . . . 
    . . . c 6 7 7 7 7 6 c . . . . . 
    . . c 7 7 7 7 7 7 7 7 c . . . . 
    . c 6 7 7 7 7 7 7 7 7 6 c . . . 
    . c 7 c 6 6 6 6 c 7 7 7 c . . . 
    . f 7 6 f 6 6 f 6 7 7 7 f . . . 
    . f 7 7 7 7 7 7 7 7 7 7 f . . . 
    . . f 7 7 7 7 6 c 7 7 6 f c . . 
    . . . f c c c c 7 7 6 f 7 7 c . 
    . . c 7 2 7 7 7 6 c f 7 7 7 7 c 
    . c 7 7 2 7 7 c f c 6 7 7 6 c c 
    c 1 1 1 1 7 6 f c c 6 6 6 c . . 
    f 1 1 1 1 1 6 6 c 6 6 6 6 f . . 
    f 6 1 1 1 1 1 6 6 6 6 6 c f . . 
    . f 6 1 1 1 1 1 1 6 6 6 f . . . 
    . . c c c c c c c c c f . . . . 
    `, SpriteKind.Enemy)
tiles.placeOnRandomTile(Enemy1, assets.tile`transparency16`)
Enemy1.follow(Player1, 60)
info.setScore(0)
info.startCountdown(10)

Open this page at https://german-kcj.github.io/single-aws—no-code/

Use as Extension

This repository can be added as an extension in MakeCode.

Edit this project Build status badge

To edit this repository in MakeCode.

Blocks preview

This image shows the blocks code from the last commit in master. This image may take a few minutes to refresh.

A rendered view of the blocks

Metadata (used for search, rendering)

Open this page at https://german-kcj.github.io/adventure/

Use as Extension

This repository can be added as an extension in MakeCode.

Edit this project Build status badge

To edit this repository in MakeCode.

Blocks preview

This image shows the blocks code from the last commit in master. This image may take a few minutes to refresh.

A rendered view of the blocks

Metadata (used for search, rendering)