Skip to content

Functions and Event Handling - Introduction


Learning Goals

When you finish this lesson, you'll be able to do the following:

  • update() You can use functions to write code that runs every frame
  • Sequenceand Func, WaitYou can use it to create repeating actions
  • input() You can use functions to handle keyboard input
  • You can create particle effects by manipulating the vertices of a Mesh

Take a look at the code

Below is the code for a bullet-hell shooter game. Move the player with WASD and press the spacebar to fire bullets!

๐Ÿ“‚ Folder: five_functions / ๐Ÿ“„ File: bullet_hell_functions.py

โšก Don't remember how to run it? (click)
  • Move to terminal: cd .. after cd folder_name
  • Run: python filename.py (autocomplete with the Tab key)
  • Exit: Alt+F4 (Win) / Cmd+Q (Mac)

How to Control It

Most games use the standard control scheme:

  • WASD Or Arrow keys: move
  • Mouse: adjust view / aim
  • Left click: shoot / interact
  • Space: jump (platformer games)
  • Tab: toggle slow motion (slow_motion.py)
  • Escape: quit the game