You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just some thoughts about refactoring the game. I think you should aim to seperate the logic from the presentation as much as possible. Ideally the methods to draw the game screen should be entirely seperated from the methods which update the state of your player, monsters, treasures etc, which in turn should be seperated from the methods to handle player input.
The main game loop should look something like the following. Note that the body of the loop is broken into three sections corresponding to input, processing, and output. Note also that this is basically pseudocode only. The actual implementation if you choose to do this would probably look quite different.
whileTrue:
# INPUT: Process player keystrokes etc.handle_player_input():
# PROCESSING: update the game entities if the player has taken an action.ifaction_taken:
player.update() # move player, get treasure, hit monster etcformonsterinmonsters_on_level:
monster.update() # monster might think, move, attack, die etc.# OUTPUT: Now, only after all of the game logic has taken place,# We can draw the screen in its new state. No 'thinking' should occur.# In reality you could place all of the following code into a method# called "update_screen" or similarbackground.draw()
fortreasure_chestintreasure_chests_on_level:
treasure_chest.draw()
player.draw()
formonsterinmonsters_on_level:
monster.draw()
info_bar.draw()
The text was updated successfully, but these errors were encountered:
I've just read this interesting blog post which talks about the the game loop from a theoretical and philisophical perspective. The author closes the loop with "Model" -- which is what is happening in the players head beetween the feedback (display) and the action (input):
The 'game' aspect of this beast we call a computer game always involves 'loops'.
The player starts with a mental model that prompts them to...
Apply an action to...
The game system and in return...
Receives feedback that...
Updates their mental model and starts the loop all over again. Or kicks off a new loop.
Just some thoughts about refactoring the game. I think you should aim to seperate the logic from the presentation as much as possible. Ideally the methods to draw the game screen should be entirely seperated from the methods which update the state of your player, monsters, treasures etc, which in turn should be seperated from the methods to handle player input.
The main game loop should look something like the following. Note that the body of the loop is broken into three sections corresponding to input, processing, and output. Note also that this is basically pseudocode only. The actual implementation if you choose to do this would probably look quite different.
The text was updated successfully, but these errors were encountered: