Post

Swivle!

A game where you pivot letters around to make words! (Come on - the name is just perfect, right?)

I was inspired by the surge in quick and short word games in the past number of years: Wordle, Wordscapes, crosswords on NYT, as well as games with really tiny game loops like Flappy Bird or 0h h1. I’m definitely not the first person to come up with this idea, but I just wanted to make a short game with some appealing art to it. And out of the brain fuzz came the idea of swapping letters around a central pivot. There are a maximum of six letters, and you select two letters to pivot them around (including any and all letters in between as well), three or more to submit a valid word. You have a limited amount of moves that is returned scaled with the length of the word. Letters have individual scores that add up to a sum for your score.

Github repository here! At the time of writing this there are still updates to come - read about it below.

It’s just something simple I wanted to make. The project took only a few hours to code up, and the art takes way way longer. I knew where to take this game, but I did not know what kind of theme I wanted. I ended up going for a coffee shop/cozy pixel art vibe in the end - the logo above is the result.

This project made me realize just how powerful Godot signals are. The core principle is to “Code down, signal up”. Every node should work when run on its own. If you call “up”, call get_parent(), then you risk getting your code broken because the node (when run on its own) does not have a parent to reference. Instead, you would have the node emit a signal. The parent (at runtime) will connect the node’s signal to a callable function, where it will do whatever it needs to do for the node (a child of the parent).

For example: the Hand controls the Keys. The Hand wants to know which Keys are selected, and the Key contains code that triggers when it is selected, but it does not know it is part of a collection - the Hand. So when a new Key is generated, the Hand connects the new Key’s signal (objects can have a signal with the same name, but every signal is unique to that object) to its own code. The new Key’s signal also contains an identifier for itself to differentiate among other Keys. When a Key is selected, it sends out a signal to let anyone connected to it know that it is selected. The Hand listens, and keeps track of its identifier (which was emitted along with the signal) to know which Keys were selected.

Let’s say now the Hand wants to do something with the selected Key. The Hand wants to turn any Keys that were selected into a different color. The Hand uses the identifiers that it kept track of, to access those specific Keys from all the Keys it knows. Since the Hand keeps references to all Keys, the Hand can find those specific keys from the identifiers and access their functions to turn it into a different colour.

Of course, there are situations where get_parent() is just overall easier, but if you instantiate new objects on the fly, connecting to a signal and applying “Call down, signal up” is the best way to go.

Here’s the high level structure of the code:

Each node contains a reference to its child node and their functions and handles any signals from them. The node “Main” will be the overall game, handling all past scores and settings. The Main Menu node has not been created yet, but it will be a sibling to the Game node. I’ve written responsibilities next to each node.

At the time of writing this, the playable version has a move counter, but no game over screen so you can just keep playing forever. I’m implementing a score system (scrabble points for each letter), a game over screen and main menu, and I’m also updating the background, key, and letter colors and sprites to match the the logo. Also a pivot/submit button and clearer player input instructions. The link to the repository is here and the link to the release is here.

This post is licensed under CC BY 4.0 by the author.