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.

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.

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. 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 Waves

Coins drop in random spots and colors. Grab them before they vanish. When every coin is gone, a bigger wave drops.

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...