• Content count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About Celeborn09

  • Rank
  1. Main game loop design

    Thanks! This is all really helpful information to get me started. I'll take a look through all these articles and give all this a try here soon.
  2. Main game loop design

    Ok, thanks! This helps a lot. So just a few last questions to clarify for myself:[list] [*]what would you have HandleInput() do within an individual Object::Update? [*]what are some examples of what m_Events.Update() might include? [*]If opjects are being moved one at a time, where would collisions be handled? Would that be within m_ObjectManager.Update after all the individual Object::Update methods have been called? [/list]
  3. So far, I've made a few small simple games in the past using visual c++ and Windows GDI. More recently in the past year, I've been wanting to develop more complex games and have learned through books and online tutorials about AI techniques and I have a decent understanding of how to use DirectX. My problem is I don't know how to structure my main game loop. Essentially, I want to create my own simple game engine. I know there are plenty of game engines out there, but I want to do this as a learning experience more than anything. Here are the three main things I know that I need in my loop.[list=1] [*][u]Graphics update[/u] -- runs more or less as fast as it can [*][u]Physics update[/u] -- from what I understand, this should run every predetermined set period of time to limit the number of odd physics related bugs that I see. [*][u]AI update[/u] -- this takes care of computer "strategy", pathfinding, etc, and should only be run much less often when compared with the graphics or physics updates. [/list] Based on what I've ready, the sudo code way of how I imagine this going looks like this: [CODE] #define PHYSICS_DELAY 30 #define AI_DELAY 500 . . . while(!exit) { if (time_since_last_physics_update > PHYSICS_DELAY) run_physics_update(); if (time_since_last_ai_update > AI_DELAY) run_ai_update(); run_graphics_update(); } [/CODE] However, this means that the time required to make it through a single loop is highly variable. It might just run the graphics update (hopefully not because from what I read, the physics should be updating about twice as fast as the graphics) or it might run all three updates. I'm sure I'm missing something because this doesn't seem right to me at all. Could someone please explain to me how a game loop should work? Everything I've seen up to this point that tries to explain it leaves out one part or another.
  4. Ray and Rectangle Collision

    I am currently making a basic 2D game and need to determine when a ray (your sprite's laser) collides with a rectangle (the enemy). I also need it to determine which rectangle the ray collides with first and have it return to me the point where the ray and the edge of the rectangle intersect. I would like to know if there is a simple method to calculate this and what the process is for checking this single type of collision as in my game, no other collisions are taken into account. Thanks in advance for your help.