Log in

View Full Version : Interface and game itself



ki
15-08-2003, 07:36 AM
I'm new on this forum and I've been learning directx for 6months now..
How should I split up my code so that MenuInterface has its own functions and the actual game its own. I dont want to have a lot of flags that tell which function to call.. Is there a good way of doing this?
and I hope my english is readable.

Paulius
15-08-2003, 11:04 AM
Simply make variable procedures or functions and when shifting the games state to menu or game mode make them point to whatever you need. For example:

var
DoProcess:procedure;

procedure SwitchState(const newstate:cardinal);
begin
case newstate of
0: DoProcess:=@ProcMenu;
1: DoProcess:=@ProcGame;
end;//ProcMenu and ProcGame are simple procedures
end;

Alimonster
15-08-2003, 11:54 AM
I have an article on how to separate out the states: http://www.alistairkeys.co.uk/states.shtml. I've refined the method a bit for my own projects but the article is about right. The only addition I'd make to the article is to allow states to be killed immediately after changing states, e.g. for a one-time intro, instead of being caught in the finalization. This can save you from having a few states sitting around unnecessarily. That's just a boolean per state and a couple of lines of code to change or thereabouts.