Lab 2: Give Your Hero Controls

Learn how POOM reads D-pad and action-button input, then change x and y to move a sprite safely around its 128 by 64 screen.

Make Your Own Game · Step 2 of 5 · Player input

In Lab 1, pixels became a sprite and four frames made our hero appear alive. Now that same hero comes with us. A game becomes interactive when the player can change what happens, so in this lab POOM’s buttons will become messages that tell the hero where to go and which pose to show.

1PixelsComplete
2InputYou are here
3WorldNext
4GoalLater
5FinishLater
Your mission: customize the same four walking frames, add a rising frame and a falling frame, then use the D-pad to move the hero and press A to jump.

What is an input?

An input is a message from the player. Pressing a button does not move a sprite by itself. Your game reads the button, follows a rule, and draws the result.

PRESS → READ THE BUTTON → CHANGE x OR y → DRAW AGAIN

Leftx = x - 1
Rightx = x + 1
Upy = y - 1
Downy = y + 1
Why does up subtract? The POOM screen begins at x 0, y 0 in the top-left corner. x grows toward the right, and y grows toward the bottom. Moving up means choosing a smaller y number.

One button can begin a whole movement

The complete Mystic Balloon game shows that its jump is not one strange action pose. It is a short sequence: frame 4 draws the hero while rising, frame 5 draws the hero while falling or landing, and velocity changes its y position between those drawings. In the original game, B jumps and A creates suction. For this smaller lesson, A starts the jump so we can follow one clear action from button press to landing while B remains our reset button.

FOUR WALK FRAMES + RISE + FALL → PRESS A → UP, DOWN, LAND

Why two jump frames? The screen cannot feel motion; it only draws pictures. While the y number gets smaller, POOM draws the rising frame. After gravity turns the hero around, POOM draws the falling frame. At the original y position, the walking frames return.
Your hero continues through the series. The drawings you make are saved only in this browser. Lab 2 loads your four frames from Lab 1 and adds the two jump frames; later Make Your Own Game labs can load the same hero again.

Try it: make POOM listen

Focus the playground and use your keyboard arrows, or press the virtual POOM buttons. Every direction changes one variable. Hold a direction to keep sending the same input. Press A once to rise, fall, and land. Press B to return the hero to the center. Below the controls, select any of the six frame cards and redraw its pixels.

Loading the input playground…

Enable JavaScript and reload this page to control the hero on the 128×64 POOM screen.

The four movement rules

POOM checks the buttons once during every game frame. When a direction is held, its rule changes the hero’s position by one pixel. Then the screen is cleared and drawn again.

if (!Poom.nextFrame()) return;

if (Poom.pressed(PoomButtonLeft)  && heroX > 0)   heroX -= 1;
if (Poom.pressed(PoomButtonRight) && heroX < 116) heroX += 1;
if (Poom.pressed(PoomButtonUp)    && heroY > 0)   heroY -= 1;
if (Poom.pressed(PoomButtonDown)  && heroY < 48)  heroY += 1;
1

Listen
Poom.pressed(...) asks whether a button is down now.

2

Decide
The boundary check asks whether the next move is safe.

3

Move
+= 1 and -= 1 change the sprite by one pixel.

What A adds to the loop

When A begins the jump, a negative velocity moves the hero upward because smaller y numbers are higher on the screen. Each frame, gravity adds one. The velocity reaches zero at the top, becomes positive on the way down, and the hero stops when it reaches the y position where it began.

if (aPressed && !aWasPressed && !jumping) {
  jumping = true;
  jumpVelocity = -4;
}

jumpOffset += jumpVelocity;
jumpVelocity += 1; // gravity

if (jumpOffset >= 0) {
  jumpOffset = 0;
  jumping = false;
}
1

Start
A gives the hero an upward speed once, rather than every frame it stays held.

2

Arc
Velocity moves the hero. Gravity changes that velocity from up to down.

3

Land
At the starting y, the offset returns to zero and walking can begin again.

Why the hero stops before 127 and 63

A single pixel can reach x 127, y 63, but the hero is a 12×16 group of pixels. Its top-left corner must stop early or the rest of its body would leave the screen.

Horizontal edge128 − 12 = 116

The largest safe hero x is 116.

Vertical edge64 − 16 = 48

The largest safe hero y is 48.

THE INPUT LOOP

Read a button. Change the game. Draw the new result.

The loop happens quickly, so holding a direction looks like smooth movement.

Put the controls on POOM

When all four direction badges are complete, send the input sketch to Web Studio. The generated program includes your four customized 12×16 walk frames, the two original 12×16 jump frames, and the same movement and jump rules you explored above.

Warning — flashing this input sketch will erase and replace the POOM firmware currently installed.

POOM will start directly in this Arduino sketch instead of showing its normal menu and tools. To restore the complete POOM system, use the POOM Web Flasher to install the official firmware again.

Loading POOM Web Studio…

If the editor does not appear, enable JavaScript and reload this page.

Your input challenge

  1. Press all four directions and watch which coordinate changes.
  2. Move all the way left until x = 0, then try one more left input.
  3. Reach the right edge and explain why the hero stops at x = 116.
  4. Edit A Rise and A Fall, press A, and identify the moment when the drawing changes.
  5. Press B to reset the hero’s position.
  6. Send the sketch to Web Studio and find the four Poom.pressed(...) rules.
Stop here. If you can explain how a button changes x or y and why the sprite needs screen boundaries, you finished Lab 2. Continue to Lab 3: Build a Tiny World to add floors, walls, and collision.

The button code in this lesson follows the official Poom Arduino library and its ButtonsDemo example. The two jump drawings and the rise/fall logic come from the complete Mystic Balloon source you supplied: its kidSprite frames 4 and 5, input rules, and player update code.