Game Makecode Arcade Artificial Intelligence
Intermediate
60 mins
Teacher/Student led
+85 XP
What you need:
Chromebook/Laptop/PC or iPad/Tablet
Arcade computer

Monster Battle Arena

In this lesson, you will code a monster battle game, learning about combat mechanics, health systems, and AI behaviors along the way. Your game will involve player-controlled and AI-controlled monsters battling it out in a thrilling arena!
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 - Create New Project

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

    2 - 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:

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


    3 - Create AI Monster

    Now, let's create an AI monster for our player to fight against. Add the following code:

    This will create a new sprite for the AI-controlled monster with the image you design.

    4 - Implementing AI Behavior

    In this step, we will make our monster move around the screen in a way that appears random and intelligent. This is a simple form of Artificial Intelligence (AI) behavior. Remember, 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.

    Let's add the following code:

    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.


    5 - Health System

    The way that the Health System will work in the game is that both the player and monster will start off with a health value of 10. Then they will lose health points in the combat (in the next steps).

    Create the following 2 new variables:

    • 'myHealth' this will store the player's health value.
    • 'monsterHealth' this will store the monster's health value.

    Add the new code in at the bottom of the 'on start' to set the health values to 10 at the start of the game:

    Also add the following code so that the player's and monster's health is displayed during the game.


    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