DEV Community

Selfish Dev
Selfish Dev

Posted on

2

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️