3. Game Loop

Chapters

            Game loop is heart of game programming every logic must embedded in there e.g. Move player, Fire missile, Collision detect and etc. This chapter will introduce basis of game loop to you.

            Important pass have 3 sections, first is initialize second is update and last is de-initialize by following

            3.1 init, for allocate memory image, sound, movie or etc.

            3.2 update, this is a loop for update game logic

            3.3 deinit, free memory after exit game

            3.4 declare in ARSA Framework, Write before main function

void init()

{

}

void update()

{

}

void deinit()

{

}

            set function pointer to ARSA Framework in main before call arsa_EasyStart

arsa_SetFuncInit(init);

arsa_SetFuncUpdate(update);

arsa_SetFuncDeInit(deinit);

            3.5 Head Up Display (HUD) Drawing must draw over every image always.

void hud()

{

}

Arsa_SetFuncHud(Hud); // write at init function

            3.6 Flow-chart of game loop (Ascii art)

 -------

| start |

 -------

    |

   \|/

 -------

| init  |

 -------            

    |               

   \|/              

 -------            

| update|<--------

 -------         /|\

    |             |

   \|/            |

 -------          |

|  HUD  |         |

 -------          |

    |             |

   \|/            |

 -------     No   |

| Exit? | ------->

 -------

    | Yes

   \|/

 -------

| deinit|

 -------

    |

   \|/

 -------

|  end  |

 -------

Tags: