StarterVillage

Week 1

Your Hero Comes to Life

Part of Make Your First Mini-Game.

Our very first class is all about getting comfortable in GameMaker and bringing a hero to life. By the end of the hour your learner has a character they coded themselves, walking and animating around the screen.

Class file

Download your course file here

This is the project your learner starts from in the very first class. Download it ahead of time so they can dive right in. Enrolled students get the password in their Outschool welcome message.

MiniQuest_W1_Start.zip · 26 MB

What this class covers

Getting to know GameMaker
A friendly tour of the workspace, the same professional tool used to make real games, so your learner knows where the art, the characters, the rooms, and the code all live before we start building.
Putting a hero on screen
Your learner creates their hero and places it into the forest clearing, ready to control.
Moving in four directions
Your learner writes the code that reads the keyboard and walks the hero up, down, left, and right.
A walk that feels alive
The hero turns to face the way it is going and animates as it moves, then settles on a standing pose when it stops.

A look inside the class

The GameMaker workspace, with panels for the room, the asset browser, and the player object, and the pixel-art hero placed in a green room.

Getting to know the GameMaker workspace, where the art, characters, rooms, and code all live.

Getting to know the GameMaker workspace, where the art, characters, rooms, and code all live.
GameMaker code in the player's Step event: reading the arrow keys to move, facing the way the hero walks, and animating while moving.

The real code your learner writes to walk the hero up, down, left, and right.

The real code your learner writes to walk the hero up, down, left, and right.

Bonus challenges

Optional, just-for-fun challenges to try on your own between classes. Never needed to keep up.

  1. Tune the hero's walking speed.

    Open obj_player and click its Create event. One line decides how fast your hero moves:

    spd = 2;
    The obj_player Create event in GameMaker, with the line spd = 2; highlighted.

    Change the 2 to a new number, then press Run to feel it. Try 0.5 for a slow tiptoe, then 4 for a zoom. What speed feels right for a forest adventure?

  2. Add WASD controls alongside the arrow keys.

    Right now only the arrow keys move your hero. Let's make W, A, S, and D work too. In the Step event, find the two lines that start with var move_x and var move_y, and swap them for these:

    var move_x = keyboard_check(vk_right) - keyboard_check(vk_left)
               + keyboard_check(ord("D")) - keyboard_check(ord("A"));
    var move_y = keyboard_check(vk_down)  - keyboard_check(vk_up)
               + keyboard_check(ord("S")) - keyboard_check(ord("W"));
    The obj_player Step event in GameMaker, showing the move_x and move_y lines extended with WASD key checks.

    Press Run. Now the arrow keys and WASD both work. Pressing D or Right each send your hero to the right.

  3. Add a run key: hold Shift to go faster.

    Let's make your hero sprint when you hold Shift. In the Step event, just under those two var move_ lines, add this:

    // Hold Shift to run - 1.5x your normal speed.
    var run_spd = spd;
    if (keyboard_check(vk_shift)) {
        run_spd = spd * 1.5;
    }

    Then change your two movement lines so they use run_spd instead of spd:

    x += move_x * run_spd;
    y += move_y * run_spd;
    The obj_player Step event in GameMaker, showing the run_spd block and the movement lines using run_spd.

    Press Run and hold Shift to dash. It runs at 1.5x whatever speed you picked, so it still works even if you changed spd in the challenge above.

  4. Swap in a different hero, like a knight or a ninja.

    Trade the frog for a different hero from the art pack. First, open obj_player and set its Sprite (the box at the top-left of the object editor) to your new hero's down sprite, like spr_knight_grey_walk_down.

    The obj_player object editor in GameMaker with the Select Sprite window open, choosing a knight sprite from the Heroes folder.

    Then, in the Step event, change the four sprite names in the facing block to match your new hero:

    if (move_x > 0)      sprite_index = spr_knight_grey_walk_right;
    else if (move_x < 0) sprite_index = spr_knight_grey_walk_left;
    else if (move_y > 0) sprite_index = spr_knight_grey_walk_down;
    else if (move_y < 0) sprite_index = spr_knight_grey_walk_up;
    The obj_player Step event in GameMaker, with the facing block updated to use the spr_knight_grey_walk sprites.

    Press Run - your new hero walks with the exact same controls. Snap a screenshot and post it in the classroom!

  5. Extra tricky: lock the hero to four directions.

    Have you noticed your hero moves a little faster diagonally? Pressing two arrows at once slides you sideways and up or down at the same time. Let's lock movement to just up, down, left, and right, like the classic adventure games. This one is a real brain-stretcher!

    First, your hero needs to remember which way it committed to. In the Create event, add one more line:

    last_axis = "";   // which direction we're committed to: "h" or "v"
    The obj_player Create event in GameMaker, with the line last_axis set to an empty string added.

    Then, in the Step event, right after the two var move_ lines (and before the x += lines), add this:

    // 4-directional, first key wins: if both are pressed, keep the axis we were already on.
    if (move_x != 0 && move_y != 0) {
        if (last_axis == "v") move_x = 0;   // committed to vertical first
        else                  move_y = 0;   // otherwise keep horizontal
    }
    
    // Remember this frame's axis, so next frame knows what we committed to.
    if (move_x != 0)      last_axis = "h";
    else if (move_y != 0) last_axis = "v";
    The obj_player Step event in GameMaker, showing the first-key-wins block that locks the hero to four directions.

    Press Run. Now your hero locks to four directions, and whichever arrow you press first wins until you let go, and that sneaky diagonal speed boost is gone too.