Posted June 19, 2022 by drhayes
#events #deep-dive
v.0.15.0:
GameObject
.When the player stomps on a switch or a goblin, or a goblin bonks into another goblin or a bridge, I needed some way to tell the game object, “Hey, something happened to you.”
Originally this was with the GobState
component. It saves state that applies to the game object and writes it into the quicksave and save files (or, at least it will once I start writing to the file system). That way, the bridge stays knocked over and switches stay pushed if they’re marked that way on the map.
This became the way I sort of passed events around between game objects in the game, even momentary ones. And it lead to weird bugs and lots of extra code: set the state to bonked
, but unset it a while later (and why is that going in the save file anyway?). Is that thing bonked
? Lots of weird message subscriptions and stuff, too.
So I scrapped all that and added a message-passing mechanism to GameObject
. It’ll make it out to Squeak.lua pretty soon, as well. Pretty simple: each GameObject
has a sendMessage
that calls onMessage
on all the Component
s. Easy.
Anything with a momentary effect uses the built-in cooldowns component that ships with Squeak. Duh.
As always, this broke lots of stuff. But I think things are better in the end.
And, of course, the game looks basically the same. It just makes it easier for me to add stuff in the future and not worry about breaking everything.