• 0 Posts
  • 69 Comments
Joined 6 months ago
cake
Cake day: August 25th, 2024

help-circle















  • Complexity being added at updating also feels wrong to me. Let me pseudo code some rust (just the language I know best off the top of my head right now) at you, cause it feels like maybe I’m just not understanding something that’s making this seem easier than it is.

    Enum Game_State
        Paused
        Paused_Saved
        Running
        Loading
        Exit
     
    ///Technically you could make Menu() part of the enum but I'd probably leave it elsewhere
    
    Match Game_State
        Paused => Menu()
        Paused_Saved => Menu()
        Running => Main_Loop()
        Exit => Exit()
    

    And then your other functions always return a game_state. You’re right that adding that return would be a huge undertaking if it’s not handled in the initial building of the game, but it’s a QoL for the user that’s easily maintainable and is therefore worth doing IMO. But these two things, defining the possible game states and then always routing decisions through that game state, makes this kind of feature relatively doable


  • I think we write our code in different enough ways that we’re not seeing eye to eye.

    Tracking the state of the game being paused, when the menu is open and when the game is saved can all be a single match statement on a current “game state” variable which just holds “running/paused/paused and saved/exit” and when it becomes exit, it checks the save time. Only 2 lines of code and adding an enumerated state to the variable to add this functionality. Since the variable is enumerated, it’s really difficult to mess it up when refactoring because if you can’t pass the wrong code or else your game doesn’t save or close