Advertisement Jump to content
Sign in to follow this  

Game logic, application and view seperation

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to have an architecture similar to the engine in Game Coding Complete. I like how the game view is separate from the game logic, so that it's easier to add multiplayer. The thing I'm trying to figure out though, is how to get the game view system to play nice with my component based entity system. I'm going to have character animation, and the game I'm making will have melee combat. Should the animation be updated in the game logic as a component? Or should the character control component send events to control the animations? I can't figure out how I would detect sword hits without knowing bone positions. Basically I want to do a Zelda like combat system. How is the sword collision handled in those kind of games? A hit circle? A delayed reaction while the animation plays and the character is pulling back his arm?

Share this post

Link to post
Share on other sites
You may likely get differences of opinions but if it were me I wouldn't try to separate things just yet. I think there is merit in pushing forward and adding the features you want so long as you're happy with the design. If you find you need to refactor code, then do so; however, don't refactor just to try and build your engine at this stage. It will only delay what you want to accomplish in the end.

Specific to your question about animation, yes animation is handled as a component in a component-based entity approach. In general terms, most game logic in a component-based entity approach is implemented in some form of a component that is associated to your entities because the entity framework is the glue that ties the game logic back to the engine systems and extended systems (such as weapons system, etc.). Now what drives the change in animation is entirely up to your design but typically animations are a response or effect based upon a cause.

There are two ways you can handle animation triggers.

The first is that you allow the player controller to dictate what animation to play. The reason behind this approach is that the controller knows the present state such as whether the character is flying, swimming, on the ground, in walk/run mode, or maybe is mounted on a horse or in a vehicle. Because it has the state knowledge, it's in the best position to dictate what animation should be played and all the animation system does is listen for play/stop requests on that entity for certain animations. I've also seen where the animation system listens for "move" events and then inspects the state of the controller and determines the animation to play. My personal preference is the first approach because there simply seems to be no reason to tie the animation system to anything beyond what its meant to do, play animations. The controller component has to maintain so much state information as is, it's logically the right keeper of what needs to happen and when.

From a combat perspective, there are a number of ways. You could use collision bodies to determine whether a hit was successful, and if so, emit particles for effects, play sounds, etc. Another way is to simply determine that the player is close enough to attack the target and based on an algorithm that you calculate when the player starts to attack, you determine whether they can actually "hit" the target and if so, how much was the damage. If damage was caused, you emit particles, sound effects. This can easily happen after the attack animation has finished or right before it finishes. For example, animation takes 1 second. You calculate the hit/damage/prepare particles at 0.75 seconds. Then .25 seconds later when the animation is wrapping up, you have blood splatter happening and sound emitted :P. In short, it becomes a sequence of timed events based on a cause :).

Share this post

Link to post
Share on other sites
Example code for you with comments explaining why things are where they are. (Python)

This is normally how I set up my main game loops, using the MVC architecture you are working with.

# Main game loop

While True:
controller.process_events() # Processes user input to manipulate game and/or view values (Such as the player's position / Which animation is playing).
game.update() # Updates game values that aren't controlled by the user (Such as physics and collision)
view.update()# Updates resource specific objects (Such as the timer/frame progression for an animation)
view.draw() # Draw the game.

Hope this helps,


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!