← Back to Autumn 2025 Overview

Week 7 β€” Functions, Inputs & Space Invaders

Focus Concept: Functions and game logic
Mini-Projects: Function Challenges β†’ Mini Space Invaders

This week we explored how functions can make our programs cleaner, faster to edit, and easier to reuse.
Participants first created small examples of functions to see how they work, then applied the same ideas in a larger game that used the accelerometer and collisions.


Objectives

  • Understand what a function is and why we use it.
  • Create and call functions to group repeated actions.
  • Use parameters to make a function behave differently.
  • Explore how a function can return a result.
  • Apply loops, variables and conditions inside a larger game.
  • Control sprites using buttons and the accelerometer.

Success Criteria

  • I can explain what a function does and when it runs.
  • I can create my own function that performs a short task.
  • I can add parameters so a function can change what it does.
  • I can describe how functions keep code tidy and reusable.
  • I can reuse my helper function in another project.

Key Vocabulary

  • Function β€” a named group of code that runs together to do one specific job. Programmers use functions to reuse code and keep programs tidy.
  • Call β€” when your program tells a function to run.
  • Parameter β€” information you send into a function so it knows what to do.
  • Return β€” a value a function sends back after it finishes.
  • Variable β€” a labelled box that stores a number or word such as score, speed, or level.
  • Condition β€” a true/false test that decides what happens next.
  • Collision β€” when two sprites touch each other.
  • Accelerometer β€” a sensor inside the micro:bit that detects tilt, movement, and direction.
  • Axis β€” one of the directions used to describe positions on the LED grid (X for left–right, Y for up–down).
  • Coordinate β€” the pair of numbers (X, Y) that tell you exactly where a sprite or LED is on the screen.
  • Threshold β€” a limit or boundary value that triggers an action (like moving only when the tilt is greater than 200).

Part A β€” Function Challenges

What We Explored

  1. Simple Function β€” a short reusable block (e.g. flash an icon, play a tone).
    β†’ Shows how to avoid repeating the same code.

  2. Function with Parameter β€” takes input, such as how many times to flash or which icon to show.
    β†’ Same recipe, flexible results.

  3. Function with Return Value β€” calculates something and gives the answer back (e.g. add two numbers).
    β†’ Lets other parts of the code use the result.

  4. Combining Functions β€” several small helpers can work together, like one that displays a message and another that plays a sound.
    β†’ Builds the habit of modular thinking.

πŸ’‘ Functions are like reusable tools β€” once built, you can use them in any project.

Try These Mini-Challenges

  • Make a function flash(times) that blinks an icon a chosen number of times.
  • Create a function showMessage(text) that scrolls a message.
  • Write a function addNumbers(a, b) that returns their sum and shows it.
  • Combine two functions: one plays a tone, one flashes a light β€” call both together for an alert effect.

Part B β€” Mini Space Invaders

What We Built (Step-by-Step)

  1. Sprites: created a Ship at the bottom and an Alien at the top.
  2. Movement: tilted the micro:bit left/right to move the ship; the alien moved sideways and bounced at the edges.
  3. Shooting: pressing B fired a Laser straight up; if it touched the alien, the alien disappeared, the score increased, and a new one spawned.
  4. Bombs: when the alien lined up with the ship, it dropped a Bomb; if the bomb touched the ship β†’ Game Over.

πŸ”„ This project reused ideas from previous weeks β€” loops, variables, collisions β€” in a completely new style of gameplay.

Try These Mini-Challenges

  • Randomise where the alien respawns (use pick random 0 to 4).
  • Add a β€œlives” variable (e.g. 3 lives before Game Over).
  • Add a short laser sound each time you shoot.
  • Make the alien move faster each time you score 5 points.

Resources

  • MakeCode Editor: makecode.microbit.org
  • Functions in coding Video
  • MakeCode Functions: Video
  • BBC Bitesize – KS2 Algebra and Function Machines: Link
  • Maths function machines (solved examples): Video
  • How Space Invaders Birthed Japanese Games: Video
  • Micro:bit accelerometer: Video
  • Behind the hardware - Acceleromiter on the Microbit: Video
  • Microbit Space Invaders Makecode Code Code

Equipment

  • BBC micro:bits + USB cables (or simulator)
  • Chromebooks / laptops with internet
  • Optional: speakers or headphones for sound effects

Safety & Setup Notes

  • Keep USB cables tidy and test in the simulator first.
  • Work in pairs when debugging β€” one reads code, one tests.
  • Save and name projects clearly before starting the new one.

← Back to Autumn 2025 Overview