Hi... a keyboard menu simple, but I still do not know to make that with allegro =\
Here are some hints, I'm not going to write it for you.
readkey will read a key press. Similar to getch.
textout_ex will draw text on the screen.
clear_to_color will clear the screen. You'll want to do that when the cursor moves, then redraw your menu.
With those three functions and some boilerplate initialization code, you can make a menu like the one you have there.
This would not be in allegro 4? I'm working with allegro 5
Ok then. Things get a little more complex. You're going to have to learn about events and event queues for keyboard (or any other) input. You'll need to know how to initialize Allegro and at a minimum the font and image addons. Here's a quick example, this may not even compile but it should give you an idea of the function calls you'll need for a menu.
Do ALLEGRO_KEY_UP and ALLEGRO_KEY_DOWN even register an ALLEGRO_EVENT_KEY_CHAR? Don't you want to use the ALLEGRO_EVENT_KEY_DOWN event type instead?
Oo" I'm confuse
Do ALLEGRO_KEY_UP and ALLEGRO_KEY_DOWN even register an ALLEGRO_EVENT_KEY_CHAR? Don't you want to use the ALLEGRO_EVENT_KEY_DOWN event type instead?
For text input you want ALLEGRO_EVENT_KEY_CHAR. But they should have some kind of character, but nothing that is printable.
Using ALLEGRO_EVENT_KEY_CHAR would allow for repeats, and yes it does work with the arrow keys.
Okay then. I just figured that you wouldn't get an ALLEGRO_EVENT_KEY_CHAR for a key that didn't have a printable character. Guess I was wrong. It works better this way though I guess.
I'm doing wrong trying to put the menu this way?
I'm doing wrong trying to put the menu this way?
Somewhat, yes.
Take the ALLEGRO_EVENT_KEY_CHAR check out of your drawing code, and put it in your event loop.
Just ALLEGRO_EVENT_KEY_CHAR or all included if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE).... etc?
All code that deals with events should be inside your event loop. And you're missing some brackets there too. You should only check event.keyboard.keycode if you have received an ALLEGRO_EVENT_KEY_DOWN, ALLEGRO_EVENT_KEY_UP, or an ALLEGRO_EVENT_KEY_CHAR type event.
I don't know if are right but I added after "while (1)" but did not work! I'm revising!
Post your latest code.
here
Change
case SHOWSTART : if (ev.type == ALLEGRO_EVENT_KEY_CHAR) if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) doexit = false; break; if (ev.keyboard.keycode == ALLEGRO_KEY_UP) if (menu_choice > 0) menu_choice--; else if (ev.keyboard.keycode == ALLEGRO_KEY_DOWN) if (menu_choice < NUM_MENU_ITEMS-1) menu_choice++; break;
to
Your code doesn't work because it breaks out of the switch statement every time you check the 'case SHOWSTART'.
I told you to add brackets.
Also, you should set doexit to true when the escape key is pressed, not false.
You should really use consistent indentation in your code. It's much nicer to read that way.
work! Thank you for the explanation and help!