Jump to content
  • Advertisement
Sign in to follow this  
gabzuka

Game loop/flow design

This topic is 2995 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

Hi guys,

I've been coding a game for a few weeks now and ran into a design issue, I've tried several things but none seem to feel right.

I have a number of enemies on the screen and a team of three characters that are controlled by the player. The player moves only one of these characters, the other two follow it.

I have an Enemy class and a TeamMember class which both inherit from a Character. These classes have the position of the character, its speed and direction of movement.

Now, the game loop goes first to the AI code which updates the speed and direction of movement of the characters (not the position). After this is done, the "collision/movement" code is started which again goes through each character making sure that the new position calculated with the new speed and direction does not collide with anything else, if it doesn't the position is effectively updated, otherwise it leaves the character where it is. After everyone is at its position the rendering code is executed which again goes through the characters and depending on the angle (its a sprite game), state, etc selects what to render.

Now the problem is that I don't know how to structure all this. It seems wrong to have all this code in the Game class and I believe it shouldn't be in the Character/Enemy/TeamMember either as I would need access everything else on the map (for the collisions and AI), I would need access to the sprites and the rendering system for rendering.

How do you guys structure this in your games. I seem to be blocked in little details and I am not looking at the big picture.

Cheers

Share this post


Link to post
Share on other sites
Advertisement
This article, suggest what I was saying of not having that logic in the game loop:
http://www.andyjdesign.com/game-programming/common-pitfalls-in-your-game-loop/

I still feel that having it inside the Character class goes against the modularity of the design.

Share this post


Link to post
Share on other sites
Hi, there, I really want to answer your question, but which is really a huge topic, maybe you can visit the website of my game engine:http://www.3d-trump.com/G-force/index.htm, and goto the 'more info' page, I think there will be a lot of informations which you will glad to see.

Share this post


Link to post
Share on other sites
Quote:
Original post by gabzuka
I think this helps a lot: link


I did not read it fully, but he seems to do the update and render in the same step. The technique is good, but you should separate the update and render code. This allows you to run multiple logical frame per render frame if you need to and it ensures your objects have all been updated before rendering. If some of them rely on each other(like a tracking beam), they may not be at the correct position when rendering depending on their update order.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!