State Machine demo!

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

State Machine demo!

Post by milon »

Hey all,

I've been playing with states and overlays (not sure if that's the right term). I finally hammered out a decent state machine with less-elegant overlays (mini-states that can be stacked up arbitrarily). It was mostly a learning process for me, and it qualifies as a creation, so I'm positing it here. Everything is CC0, so use it however you like.

It features Fail, Load, Menu, Play, and Quit states with some fun effects tossed in. Try to spot which bits are overlays! :)

Post your questions, tweaks, etc.

Enjoy!
Attachments
state.love
State machine demo
(14.05 KiB) Downloaded 389 times
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
Gunroar:Cannon()
Party member
Posts: 1141
Joined: Thu Dec 10, 2020 1:57 am

Re: State Machine demo!

Post by Gunroar:Cannon() »

Nice, this reminds me of the state machine I used in this project, though mine was more behavior based and also had stateless AI, and was less flexible(?). :)
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: State Machine demo!

Post by togFox »

I really need to get into the whole state machine thing. I think it is "next level" for my coding development. I've always been hesitant because it's not essential to use a state machine but, of course, there are many ways to do things and this might be better so I'll jump into it and learn it.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: State Machine demo!

Post by milon »

Awesome! I felt like that too, originally. It's only made me a better (and more organized!) coder! :D

The simple way to look at it is we're just using some well-organized tables in a very specific way. The current state is the key value used to look up other values, and those happen to be functions particular to a given state. It's also a very elegant way to avoid massive IF..ESLEIF.. blocks.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
Gunroar:Cannon()
Party member
Posts: 1141
Joined: Thu Dec 10, 2020 1:57 am

Re: State Machine demo!

Post by Gunroar:Cannon() »

Wait, which kind of state machine is this? The AI kind or the screen manager kind?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: State Machine demo!

Post by milon »

Screen manager - sorry that was unclear!
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests