DEV Community

Selfish Dev
Selfish Dev

Posted on

Finite State Machine #1 (What)

Before You Read

I know, I know—I haven’t finished my VS Code extensions series yet! But here’s the thing: I’ve joined the Code For Cause jam, so the final part of that series will be delayed for a bit.

Also, I’ve decided that from now on, I’ll complete a series on my blog first before continuing it on YouTube.

Alright, enough talking—let’s get started.

What We’ll Cover in This Series

A state machine is a powerful concept in computer science, widely used in areas that require controlled or random behavior. In this series, we’ll explore state machines specifically in the context of game development.

We’ll start by understanding what a state machine is, then move on to implementing it in different game engines. Some of the engines we’ll cover include:

  • Godot
  • LÖVE 2D
  • Mini Micro
  • Pygame

What is State machine

As i told you state machine are used in computer science when we want something to show random behaviour
Example

  • Traffic Light (While real traffic lights may not always use state machines, this is just for understanding.)

Breaking Down a Finite State Machine (FSM)

An FSM consists of three key components:

  • States – Different possible conditions of a system.
  • Transitions – The change from one state to another
  • State Factors – Conditions that trigger state transitions.

Now, let’s apply this to a traffic light:

  • A traffic light has three states: RED, YELLOW, and GREEN.

  • It transitions from RED → GREEN → YELLOW → RED in a cycle.

  • The state factor controlling these transitions is time—after a set duration, the light changes.

NEXT PART : State machine in game boss

Top comments (0)