Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » GAME MENU

This thread is locked; no one can reply to it. rss feed Print
 1   2 
GAME MENU
Doctor Cop
Member #16,833
April 2018
avatar

Edgar, What I have used till now is just buttons and labels. I made a calculator with it. I did't do much in it. Yes I used code blocks project, truth to be told It was a college project and I was a beginner, I couldn't compile any other GUI library back then and in search of something I could use I came to liballegro.org and I found your library. Because your Library was available with code blocks project I used it.

I thought of using it more but didn't get the chance to. In future when I make some other mini projects then I will use it. I have also used the code from WidgetZ library because it's minimal, it isn't as large as yours and I found it easy to follow.

GOORE YANNIS
Member #17,073
April 2019

If i want to reset my timer at each level how is that possible i look at stopped_timer and start_timer but he doesn't really work .

Doctor Cop
Member #16,833
April 2018
avatar

Its al_stop_timer() by the way.

Can you show me your code?
I can not tell you anything just by that information.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

GOORE YANNIS
Member #17,073
April 2019

This is my code, and I have a big problem with the al_destroy because i init all objects in the main and i don't know where to destroy them because i have 3 levels and if the player quit in a level i have to destroy the memory of the previous levels so i'm a little bit embarassed if you can help me please I started allegro recently so i have a lot of things i have to improve .

Neil Roy
Member #2,229
April 2002
avatar

Have a separate init function to init the data for each level, you could pass it pointers to the data that level needs and then, when a player quits the level, you should call a function you could create to destroy the data which needs it.

Then, once destroyed, you call your level init function to load in the new data for the new level. If you're programming in C++, this should be fairly simple to do. In C I would store the level data in a struct which contains pointers, then pass that struct to the function to destroy it later on.

You could have separate init functions for initializing things like your display, audio etc... data that has nothing to do with any specific level. I wouldn't do it all in main though. The benefit is that if you need to re-initialize anything, you can call such functions from anywhere else. For example, in my Deluxe Pacman 2 game (link to source in my signature), I have a general init function for graphics and audio used throughout the game. I have a shutdown() function which destroys all data when the game is shutdown. But I also have a separate display_init() specifically for setting up your screen. I separated it because in the game's options you can change certain display properties which requires a reset of the display and this can be done by calling that which only effects the display itself.

It's not terribly difficult, try and plan it out so you can, if needed, call some of these functions from anywhere. I have a game struct which contains certain data, like t he display and other things which need to be destroyed when the game ends. I use that in shutdown() which can then be called from anywhere, like if there is an error that would crash the game, it can still be called and cleanly exit.

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

LEVEL* level = CreateLevelOne();
DestroyLevel(&level);
level = CreateLevelTwo();
DestroyLevel(&level);
/// etc...

Your code has some problems. In main.c you #include "MENU.c" that is a no-no, and causes a redefinition error in affichermenu because the function was defined twice, once in main.c and once in MENU.c.

Second, you are mixing pointers with integers. A pointer is not an integer. A pointer is an address. If you want to change the integer pointed to by an int*, you dereference it first, like so :

/// ex...

int state = STATE_GAME;
int* pstate = &state;

ChangeState(pstate);

void ChangeState(int* p) {
   *p = STATE_QUIT;
}

Third, you are missing break statements at the end of several cases.

Fourth, sometimes you incorrectly use = instead of == (warning, suggest use of parentheses around truth statement is the warning given).

Always compile your code with all warnings enabled. -Wall -Wextra -Wshadow

Fix the warnings first, and then try to run your code. If it crashes, run it through a debugger like gdb.

GOORE YANNIS
Member #17,073
April 2019

Okay thanks you i will fix them.
I try to understand game state but i failed so in my menu function there is the address of the variable p which corresponds to the variable niveau(level in english)in the main and when i want to switch my levels i switch the variable niveau(level)so i have 6 game loops 3 for the solo game and 3 for the 2 players mode.

The only problem with this that's i can't comeback to the menu i don't know how to do do it .

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Levels are a state, and so are screens like the menu. Include the menu screen as a state in your game. If you need to save an old state to return to, like the level, then do so.

Basically you make a decision in your logic and in your drawing on what to draw based on the state.

To change states, set up a tree. Level one can go to level two, level two can go to three. The menu can go to single player or 2P. Then each game has a level.

Represent it like this :

Menu
   Single Player
      Level 1
         Level 2
            Level 3
   Co-op
      Level 1
         Level 2
            Level 3

And each level has a link to the menu, which can then return to the current level if cancelled or another level on loading a game, etc...

 1   2 


Go to: