Game Arcade
Advanced
60 mins
Teacher/Student led
250 points
What you need:
Chromebook/Laptop/PC or iPad/Tablet

Monster Battle Arena

In this lesson, you'll learn how to create a thrilling 'Monster Battle Arena' game using MakeCode Arcade. You'll design player-controlled and AI-controlled characters, implement combat mechanics, health systems, and AI behaviours. By the end, you'll have a fully functional game to play and share with friends.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Introduction

    Welcome to the 'Monster Battle Arena' lesson! In this lesson, you will learn how to create a fun and exciting monster battle game using MakeCode Arcade. You will create a player-controlled sprite and an AI-controlled monster, and they will battle it out in an arena. You will learn about combat mechanics, health systems, and AI behaviors. By the end of this lesson, you will have your own monster battle game that you can play and share with your friends. Let's get started!


    2 - Create New Project

    Go to MakeCode Arcade (https://arcade.makecode.com/) and create a new project. Name this project 'Monster Battle Arena'.

    3 - Create your player

    First, we are going to create our player's sprite. Add the following code to create your player and control it with the buttons:

    let mySprite = sprites.create(img`
        . . . . . . f f f f . . . . . . 
        . . . . f f f 2 2 f f f . . . . 
        . . . f f f 2 2 2 2 f f f . . . 
        . . f f f e e e e e e f f f . . 
        . . f f e 2 2 2 2 2 2 e e f . . 
        . . f e 2 f f f f f f 2 e f . . 
        . . f f f f e e e e f f f f . . 
        . f f e f b f 4 4 f b f e f f . 
        . f e e 4 1 f d d f 1 4 e e f . 
        . . f e e d d d d d d e e f . . 
        . . . f e e 4 4 4 4 e e f . . . 
        . . e 4 f 2 2 2 2 2 2 f 4 e . . 
        . . 4 d f 2 2 2 2 2 2 f d 4 . . 
        . . 4 4 f 4 4 5 5 4 4 f 4 4 . . 
        . . . . . f f f f f f . . . . . 
        . . . . . f f . . f f . . . . . 
        `, SpriteKind.Player)
    controller.moveSprite(mySprite)
    

    This will create a new sprite for your player using the image you design or the sprite you select from the gallery.

    Once you've added your code, try moving your player around using the joystick or arrow keys on your keyboard.

    4 - Create AI Monster

    Now, let's create an monster for our player to fight against and make it start up the top left of the screen. We'll also add code to make both our player sprite and the monster sprite stay on the screen.

    Add the following new code and choose a sprite from the gallery. In this example we've chosen a snake:

    let mySprite = sprites.create(img`
        . . . . . . f f f f . . . . . . 
        . . . . f f f 2 2 f f f . . . . 
        . . . f f f 2 2 2 2 f f f . . . 
        . . f f f e e e e e e f f f . . 
        . . f f e 2 2 2 2 2 2 e e f . . 
        . . f e 2 f f f f f f 2 e f . . 
        . . f f f f e e e e f f f f . . 
        . f f e f b f 4 4 f b f e f f . 
        . f e e 4 1 f d d f 1 4 e e f . 
        . . f e e d d d d d d e e f . . 
        . . . f e e 4 4 4 4 e e f . . . 
        . . e 4 f 2 2 2 2 2 2 f 4 e . . 
        . . 4 d f 2 2 2 2 2 2 f d 4 . . 
        . . 4 4 f 4 4 5 5 4 4 f 4 4 . . 
        . . . . . f f f f f f . . . . . 
        . . . . . f f . . f f . . . . . 
        `, SpriteKind.Player)
    controller.moveSprite(mySprite)
    let monster = sprites.create(img`
        . . . . . . c c c c c c c . . . 
        . . . . . c f f 6 6 f f 7 c . . 
        . . . . c 7 6 6 6 6 6 6 7 6 c . 
        . . . c 7 7 7 7 7 7 7 7 7 7 c . 
        . . . c 7 8 1 f f 1 6 7 7 7 c . 
        . . . f 6 f 1 f f 1 f 7 7 7 f . 
        . . . f 6 f 2 2 2 2 f 7 7 7 f . 
        . . c c 6 f 2 2 2 2 f 7 7 6 f . 
        . c 7 7 7 7 2 2 2 2 7 7 f c . . 
        c 7 1 1 1 7 7 7 7 7 c c 7 7 c . 
        f 1 1 1 1 1 7 7 7 f c 6 7 7 7 c 
        f 1 1 1 1 1 1 6 f c c 6 6 6 c c 
        f 6 1 1 1 1 1 6 6 c 6 6 6 c . . 
        f 6 1 1 1 1 1 6 6 6 6 6 6 c . . 
        . f 6 1 1 1 1 6 6 6 6 6 c . . . 
        . . f f c c c c c c c c . . . . 
        `, SpriteKind.Enemy)
    monster.setPosition(0, 0)
    mySprite.setStayInScreen(true)
    monster.setStayInScreen(true)
    Rename your enemy sprite from mySprite2 to monster.

    Set your monster sprite to be a kind Enemy.

    Make sure you set monster in the set position block.

    Make sure you set mySprite and monster in the set stay in screen blocks.


    5 - Making the Monster Move

    In this step, we will make our monster move around the screen in a way that appears random and intelligent. This isn't true AI, but it's a great way to make the monster seem like it's thinking and moving on its own.

    Add the following code:

    let monster: Sprite = null
    game.onUpdateInterval(1000, function () {monster.vx = randint(-100, 100); monster.vy = randint(-100, 100)})
    This code will change the monster's velocity in random directions every 1,000 milliseconds, making it move around the screen. The code generates a random number between -100 and 100, which is then set as the monster's velocity in the x (horizontal) and y (vertical) directions. This makes the monster move in a different, random direction every half a second, giving the illusion of intelligent movement.
    When the updated code runs, the monster should move around the screen, changing direction and speed every second.


    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more