Your first game
Goal: a red ball you drive around the screen with the arrow keys. About five minutes, right in your browser - nothing to install. If you can read a dozen lines of Python, you can do this.
1. Write it, press Try it
Section titled “1. Write it, press Try it”Here is the whole game, about a dozen lines. Press Try it to run it live in your browser, then drive the ball with the arrow keys.
import picogame as pgimport picogame_game # one-call setupimport picogame_input # buttonsimport picogame_clock # frame timingimport picogame_shapes as shapes # make simple bitmaps in code
# Take over the screen and get a scene to draw into.scene, _, _ = picogame_game.setup(background=pg.rgb565(20, 24, 40))buttons = picogame_input.Buttons()clock = picogame_clock.Clock(30) # aim for 30 frames per second
# A red ball — a 24px circle drawn in code, so we need no art yet.ball = pg.Sprite(shapes.circle(24, pg.rgb565(230, 80, 80)), 150, 110)scene.add(ball)
# The game loop: read input, move, redraw — forever.while True: buttons.poll() ball.x += (buttons.is_pressed(buttons.RIGHT) - buttons.is_pressed(buttons.LEFT)) * 3 ball.y += (buttons.is_pressed(buttons.DOWN) - buttons.is_pressed(buttons.UP)) * 3 scene.refresh() clock.tick()That is the picogame engine (the native C module, compiled to WASM) running in your browser. Edit the code, press Run, and your change shows instantly. When you want more room to tinker, open it in the Playground.
2. What the code does
Section titled “2. What the code does”Only four ideas carry the whole game; the rest is detail you’ll meet later:
| Line | Idea |
|---|---|
picogame_game.setup(...) |
Returns the scene you draw into (plus two helper buffers you don’t need yet, the _, _ in scene, _, _). This one call hides all the display setup and clears the screen. |
pg.Sprite(shapes.circle(...), x, y) |
A sprite is a movable picture. Here the picture is a circle we generated in code; later it’ll be your own art. |
scene.add(ball) |
Put the sprite in the scene so it gets drawn. |
the while loop |
The game loop: every frame, read input, change things, then scene.refresh(). The engine redraws only what moved. |
3. Take it further
Section titled “3. Take it further”- Build on your PC. Want a faster local loop, or to work with your own art files? Run the same
game in the desktop simulator: one
git clone, thenpython3 sim/run.py. - Learn step by step. The tutorials build a Breakout, then a shooter, then an RPG, one new idea per step.
- Get the mental model. How picogame works explains the engine in five minutes, so the next things you build make sense.
- Put it on a device. When you’re ready for hardware, see Run on hardware.