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

  1. In my turn manager, at the start of each turn, copy the state of all entities and store it in a stack.
  2. 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

VHunterPuzzlerDx_html.zip Play in browser
Mar 17, 2023

Leave a comment

Log in with itch.io to leave a comment.