Hit a wall

OK, so i'm trying to make a simple game with opengl, i want an inventory on the game to be initialized when i press the key 'I' and after that i want it to disappear when i press the key 'I' again,

So far i thought of doing an if statement, but with that i have the problems of the inventory closing straight away cos of going out of scope. Not entirely sure on how to do this because once its initialized i also want to be able to stop it from the user input.

Anybody input with experience or a good idea on what to do with this would be much appreciated.

Thnx
Buggy
1
2
3
4
5
6
7
void Display ()
{
	Screen Screen;
	
	 Screen.LoadMod();
//here i want to my invetory and possibly others as i go along.. but how i don't know
}
closed account (zb0S216C)
Have you considered handling game states? For example, here's a quick game state handler:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
enum GameState : unsigned int
{
    GameState_Inventory,
    GameState_GamePlay
} CurrentState( GameState_GamePlay );

enum Keys : unsigned char
{
    Key_Null = 'Q',
    Key_I = 'I' // Inventory
} CurrentKey( Key_Null );

while( true )
{
    switch( CurrentState )
    {
        case GameState_GamePlay:
            switch( CurrentKey )
            {
                case Key_I:
                    // Enter inventory
                    break;

                default: break;
            }
            break;

        case GameState_Inventory:
            switch( CurrentKey )
            {
                case Key_I:
                    // exit inventory
                    break;
            }
            break;
    }
}
Last edited on
its something I've never really looked into :P, will have a look now, see if i can find some examples simple enough for my brain :).

Thnx for the reply.
Topic archived. No new replies allowed.