Undo implemented and more costumes! v0.8.1
Wishlist V-Hunter Puzzler Dx!
If you like what you see below, please wishlist V-Hunter Puzzler Dx!
Undo is now in the game!
I’m excited to have Undo added to the game. It’s the feedback I received a few times, and I’ve heard it’s a mandatory addition to puzzle games, so I’ve added it.
I have to say that it was worth the effort. It makes the game more accessible and enjoyable, especially for newer players.
Undo Technical Implementation
I’ll be honest, I was concerned that implementing undo was going to be a gargantuan task. I hadn’t developed my code with undo in mind, so tacking on additional features can sometimes be janky and difficult. However, like with any challenge, it’s helpful to brainstorm solutions and break them down. In order to understand the implementation, I’ll have to explain a little about the turn manager.
Turn Manager
My code has a turn manager that waits for the player to input a move. When the turn manager receives the input, it will iterate through all the enemies and entities on the level and executes a turn tick on each of them. After all enemies and entities have acted, control goes back to the player.
So knowing that as my backdrop, I had two solutions.
Undo Solutions
- In my turn manager, at the start of each turn, copy the state of all entities and store it in a stack.
- Delegate storing state to each entity. Each entity will store the state in a stack at each turn tick.
While solution 1 might be short-term easier, it could definitely get messy, especially since different entities have different properties in their state. For instance, the patrolling enemies have to keep track of where they are in the patrol, while the rat doesn’t have that property.
This led me to pursue solution 2. Each entity has a stack of previous states, which the current state gets appended each turn tick. In addition, each entity has an undo function, which will pop the previous states stack and update the entities state with the values.
Undo Pseudo Code Implementation
TurnManager
func handle_turn():
for entity in get_children():
entity.turn_tick()
func handle_undo():
for entity in get_children():
entity.undo()
Example Entity
func turn_tick():
_save_state()
cur_tick -= 1
if cur_tick == 0:
_do_turn()
func _save_state():
previous_states.append({
"position": position,
"health": self.health,
....
})
func undo():
var state = previous_states.pop()
self.position = state.position
self.health = state.health
....
Undo Complete
This is greatly simplified, but I found a stack and storing state at each entity the easiest and cleanest way to do undo. If you find yourself struggling to make an undo system for your game, I greatly recommend this path. A stack is the perfect data structure for undo!
More Costumes added!
There are a grand total of 7 costumes in the game now! They’re tied to achievements and will give the player some incentive to unlock them. You can see the unlocks in the stat menu from the new tab I added.
TL;DR Features Implemented
- Undo feature implemented
- Normal and Hard mode only now (tick label always visible)
- Tick Label made slightly transparent and lowered position
- Sfx on player attack
- Current Costume selected in the option menu
- Duplicate tick label bug fixed for bosses
- Credits scroll with controller
- Added Cyber, Reaper, Jungle
- Audio Manager Battle theme selector implemented
- Unlock tab added to the stats screen
- fix dynamite tick label bug
Next Steps
Undo wasn’t a planned feature, but I’m really glad to have it added. Now I will just focus on bug fixes, adding music, and other polish to the game. I’ve also been added to Steam Puzzle Fest, so I may be pushing my release earlier if Puzzle Fest is popular enough!
If you like what you’ve read, please wishlist V-Hunter Puzzler Dx and consider following me on Twitter or any of my socials on my Linktree!
Files
V-Hunter Puzzler Dx
Grid turn-based puzzler where you slay monsters and vampires!
More posts
- Hunting Vampires and Writing PostmortemsJun 10, 2023
- V-Hunter Puzzler Dx released on Steam!May 16, 2023
- Alt costumes and Bug bashing! Release v0.7.4Mar 08, 2023
- Level Select, Scene Fades, Steam, and Touch Controls! Release v0.7.2Feb 20, 2023
- All Sagas Completed! Release v0.7.0Feb 04, 2023
- Steam page published!Feb 02, 2023
- More baddies, Saga 4 completed, and controller support in V0.6.0!Dec 24, 2022
- Screen shake, Bullets, and Poison Gas! Saga 3 complete with V0.5.0!Dec 17, 2022
- UI update and Saga 2 complete for v0.4.0!Dec 08, 2022
Leave a comment
Log in with itch.io to leave a comment.