Build it together

Code-alongs

Small projects you build with your teacher. Download the starter, then in Godot's Project Manager click Import and pick the zip. Every TODO in the code is a step you will write together.

Top-Down Movement

Make a player from nothing and write every line of how it moves, with an expert walking you through it inside Godot. You end with the one line Godot's own template uses, and know what it does.

When you need it

  • Input.is_action_pressed() Check if a key is held down right now.
  • velocity Which way a body is going and how fast, in pixels per second.
  • move_and_slide() Move a body by its velocity, sliding along walls instead of going through.
  • normalized() Make a direction 1 long, so diagonals are not faster.
  • Input.get_vector() Read four keys into a direction in one line.

Checkpoints and the Next Level

A Mario-style level where falling in a pit sends you back to the last flag you touched, and the door at the end loads level 2. In the browser editor, an expert walks you through it. The Starter download has a TODO for each step instead, to practice on your own.

When you need it

  • global_position A node's spot in the level. Store it to come back to it later.
  • body_entered An Area2D noticing something walk into it: a coin, a checkpoint, a goal.
  • is_in_group() Check that the body that walked in is the player.
  • @export_file A file picked in the Inspector, like which level comes next.
  • change_scene_to_file() Swap the whole level for another scene.

Tile Platformer

Paint a platformer level with tiles and make the tiles solid, so the player can run and jump on them with Godot's own movement script. An expert walks you through it inside Godot.

When you need it

  • TileMapLayer A grid you paint tiles onto: the ground, walls and platforms of a level.
  • TileSet The tiles you can paint with, cut out of one picture. Collision is set here, once per tile.
  • is_on_floor() Only jump, or only stop falling, when standing on something.

Make Copies

Drop stones with the mouse. Left click puts a stone in the level, right click puts one on the player, and only one kind stays where you dropped it. An expert walks you through it inside Godot.

When you need it

  • preload() Load a scene once, so you can make copies of it later.
  • instantiate() Make a new copy: a bullet, an enemy, a coin.
  • add_child() Put the copy in the game. Until you do, nobody can see it.
  • get_parent() Reach the node above this one. A bullet goes in the level, not inside the player who fired it.

What Did I Hit?

Shoot crates, balloons and a wall, with an expert walking you through it inside Godot. Every hit shows which signal ran, and only the things in the target group break.

When you need it

  • .connect() Run your function when something happens: a hit, a timer running out, a button pressed.
  • body_entered Something solid touched this area: a wall, a crate, the player.
  • area_entered Another area touched this one: a balloon, a pickup, a hitbox.
  • is_in_group() Ask what kind of thing you hit before doing anything to it.
  • queue_free() Remove something from the game for good: a grabbed coin, a spent bullet, a beaten enemy.

Chase Me

Walk into the circle and a slime chases you. A yellow arrow shows the Vector2 from the slime to you, and how long it is.

When you need it

  • Vector2 Two numbers, x and y. A place (where something is) or an arrow (which way it goes).
  • normalized() Keep the direction, drop the length, so speed alone decides how fast. Chasing, aiming, homing.
  • distance_to() How far apart two things are. Close enough to notice, to grab, to talk to, to open a door?

Coin Count

Coins that announce themselves, and two things that listen: a score in the corner, and a message when every coin is collected. You make the signal file yourself.

When you need it

  • signal Declare news other scripts can hear: a coin collected, an enemy defeated, a door opened.
  • GameEvents One shared file of signals, registered as an autoload, so any script can send or hear them.
  • emit() Send the news. The sender does not know or care who is listening.
  • connect() Listen for the news. Two scripts can listen to the same signal.
  • get_nodes_in_group() Count or find everything in a group, like every coin in the level.
  • show() and hide() Make a node appear or disappear without removing it.

Ouch

Spikes that send ONE signal when they hurt you, and four things that hear it: a counter in the corner, a camera shake, a red flash on the player, and a sound. You make the signal file yourself. An expert walks you through it inside Godot.

When you need it

  • GameEvents One shared file of signals, registered as an autoload, so any script can send or hear them.
  • emit() One event, sent once. The spikes do not know who is listening, or how many.
  • connect() Every script that cares listens for itself. Adding a fifth reaction changes nothing in the spikes.
  • create_tween() Change a value smoothly over time: fade a color back, slide a menu in, grow a pickup.
  • AudioStreamPlayer A node that plays a sound. Put the sound file in its Stream, then call play().

Coin Waves

Coins drop in random spots and colors. Grab them before they vanish. When every coin is gone, a bigger wave drops. An expert walks you through it inside Godot.

When you need it

  • randi_range() A random whole number between two numbers: how many enemies, how much damage.
  • randf_range() A random decimal between two numbers: a spawn spot, a wait time. Godot 3 called it rand_range().
  • randi() % size() Pick one thing from a list at random: a color, a sound, an enemy type.
  • size() How many things are in a list. Add one more and every line using size() keeps working.
  • tree_exiting Hear when something leaves the game, however it left. Count enemies left, then start the next wave.

Guard Patrol

A guard walks a route, waits at every corner, and chases you if you get close. Its label shows the one thing it is doing right now.

When you need it

  • enum State Name the things something can be doing, so it only ever does one: an enemy, a door, a boss fight.
  • match Do something different for each state.
  • PackedVector2Array A list of places: a patrol route, waypoints, the corners of a shape.
  • size() Loop back to the start: (point + 1) % route.size() goes 0, 1, 2, 3, 0, 1...