Skip to main content
GameDev.net gamedev.net
🔒 Locked

Game flow concept

Started by wedgeboy Oct 10, 2000 at 6:04 AM 4 replies 600+ views
Original Post
wedgeboy
wedgeboy
hello....i m a newbie in game programming. Recently i m trying to create a game using visual c++ and directx..somehow when come to thinking of the game flow algorithm...i m stuck... I dont understand hows a game able to do so many things ( like detecting collision, updating hi score, updating screen, accpeting user input and go to next game level, etc...) in the same time.. i have been thinking about this for weeks...but i m still stuck. I just cant understand the concept. I been thinking to create a simple side scrolling aircraft shooting game for my college multimedia project and i have been working hard in learning visual c++ and directx. I hope that those who are experts and beginner that better than me can help me in solving this problem...i m really stress out. Thanks.
Dark Star
Dark Star
I''m no expert (as I refer to myself in all my replies,because I really am not) but no game programs ever do things like getting user inputs, doing game AI, moving enemies and player and rendering the scene at the same time because processors can only do one thing at a time unless u have a computer that has more than one processor, so the jobs can be done in parallel with each other. All stuff in your game loop are done so fast that it gives the illusion that they are all happening at the same time but they really are happening one after the other. Look at Windows for example, it''s multi-tasking, it looks like programs are running at the same time but they are not. each program is put in a queue and a small segment of each program is done in a fraction of a second. when that program''s few milli-seconds are over, Windows assigns another few milli-seconds to another. This carries on for as long as programs are running or Windows. This is all done so fast that it makes us think they are running together. Don''t worry about how to make your game look like all stuff are running at the same time, just code it. But be logical, for example you would process all enemy AI before moving the bad guys and of course move all bad guys before rendering the scene which is obvious.

eg.

do loop
Get_user_keys();
Process_AI();
Move_Baddies();
Move_player();
Render_scene();
Update_Screen();
syncronise_to_frames_per_sec();
End loop

all these actions in the example game loop are done one by one, but when it gets to updating the screen all entities like, player,baddies, icons, bullets, etc. are all shown on screen at the same time, when veiwing although they were processed on after the other. Look at Quake for an example. All baddies are processed one by one, but by the time you see them it looks like they have all been processed at the same time. For practice, try your hand at creating a very small game, that processes baddies, get''s user input and renders the scene and then updates the screen, be logical in the order of what jobs are done and you will see that it looks like it''s happening all at once.

Hope this helped.

Dark Star


---------------------------------------------You Only Live Once - Don't be afriad to take chances.
3dModelMan
3dModelMan
I don't want to provide ammunition for every coder and his dog to start arguing over flow control and encapsulation and classes etc etc, I'm just going to try and be helpful and give this guy something to think about.... Well here goes.

For a scrolling shooter there are many things to consider "in the same time" as you put it, so lets put all the important stuff into their own routines..


void MovePlayer()
{
// look for player input and act accordingly..
// moving x,y and shooting missles etc
}
void MoveEnemies()
{
// update the position of the bad guys in here
}
void MoveMissles()
{
// update the position of the players missles
// and see if they hit anything
}
BOOL CollisionDetect()
{
// see if any of the enemies have been destroyed

// See if anything has killed the player
if (player_is_killed) return TRUE;
else return FALSE;
}
void DrawScreen()
{
// write the code here that draws all the graphics to the
// screen
}


I reckon that just about covers the very simplest routines, but we will need to tie them together in the main game loop..


void Game()
{
BOOL playerdead = FALSE;

do
{
MovePlayer();
MoveMissles();
MoveEnemies();
DrawScreen();
playerdead = CollisionDetect();
}while (playerdead == FALSE);
}


So when you call "Game" it will run until the player is flagged as being dead. (I hope you know enough C to understand that ).

You see, all the things in the main game loop do not all happen together, but each one is run in turn. It's a very important part of the game logic to ensure things "appear" to happen together.

Bye

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett

Damn these HTML tags!

Edited by - 3dModelMan on October 10, 2000 3:03:23 PM
wedgeboy
wedgeboy
thanks guys..thanks a lot...i will try to do one simple prototype.
wedgeboy
wedgeboy
thanks for the link!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.