Ok I managed to install and configure A5 on MSVS 2010...
Using allegro-5.0.3-monolith-mt-debug.dll for debug and allegro-5.0.3-monolith-mt.dll for release.
First question: Are these the good dll's I should be using if I want to distribute my game to other PCs ?
Second question: I see A5 brings a console window with it every time I run the project, in debug and even in release. How can I remove the window in release only ?
Third question:
this is my A4 menu:
how would this work in A5 ? I read about the events stuff but I can't seem to grasp the concept for single key presses like menu navigation.
Oww and how can I get input from the user? I now use:
This is to get the player's name and store in in a class... I really don't think it will work in A5...
4'th Question:
This is how my game loop works in A4:
so the question is... the same principle applies in A5 ? logic check then drawing stuff?
That would be all , thanks in advance for your help
First off, please use consistent indentation - don't have code on the same line after an opening brace, line up code blocks, and indent every time you enter a new block. It makes it so much more pleasant to read (and help fix your problems).
First question: Are these the good dll's I should be using if I want to distribute my game to other PCs ?
If you're linking to the libraries that came with them, then yes those are the dll's you want to distribute with your program.
Second question: I see A5 brings a console window with it every time I run the project, in debug and even in release. How can I remove the window in release only ?
There should be a setting in MSVC that allows you to change whether the program is compiled as a console program or a graphical program. Look for subsystem::windowed or something like that in your settings.
If you want to know whether a key is up or down, there are two ways to detect this in Allegro 5.
1) Use ALLEGRO_EVENT_KEY_DOWN and ALLEGRO_EVENT_KEY_UP to track when the keys are pressed and released (and therefore, when they are up or down).
2) Use al_get_keyboard_state and al_key_down. The problem with these is that they will never contain the substates of the keys between checks to al_get_keyboard_state. If you use method 1, you will never have this problem.
Oww and how can I get input from the user? I now use:
...
This is to get the player's name and store in in a class... I really don't think it will work in A5...
Use al_wait_for_event and check the event type for equivalence to ALLEGRO_EVENT_KEY_CHAR. It will work in A5 just fine...
4'th Question:
This is how my game loop works in A4:
...Code...
so the question is... the same principle applies in A5 ? logic check then drawing stuff?
Yes, in A5 you process events until there aren't any, and for each tick of the timer you process your logic and set a redraw flag. Then when you're done with all the events, you check your redraw flag and draw if necessary.
That would be all , thanks in advance for your help
You'll probably want to look at several things from the manual :
1) Events
2) Keyboard
You should also take a look at the tutorials for A5 on the wiki, and the Porting guide from A4 to A5 on the wiki.
Thanks for the response !
I got the release version working without the console !
If other MSVS users: Project Properties->Linker->System->Windows
But I still can't figure out how to do the menu navigation...
I mean I know how to check if a key was pressed and released but I tried thinking about implementing it into making a menu and still can't figure out how to make a simple menu with multiple submenus. Am I broken ? even in A4 I did some stupid loops inside more loops waiting for a keypress... Any concept ideas on how to make such a menu ?
"Use al_wait_for_event and check the event type for equivalence to ALLEGRO_EVENT_KEY_CHAR."
in my example, should I use al_wait_for_event instead of while (keypressed()) ?
and what do to about
int newkey = readkey();
?
and
switch(scancode) 30 { case KEY_DEL: //....
That should give you a basic idea of a setup for a menu. You'll have to implement hit checks and drawing yourself.
"Use al_wait_for_event and check the event type for equivalence to ALLEGRO_EVENT_KEY_CHAR."
in my example, should I use al_wait_for_event instead of while (keypressed()) ?
Yes, you can use al_is_event_queue_empty to check if there are any events in the queue. When you get a KEY_CHAR event, send the keycode and the unichar field to your input object to be processed. Check the keycode first to process things like left/right/backspace/delete and if the keycode wasn't used then check the unichar field.
I'm not totally sure how unicode works, but I think you can get away with checking to see if the value is greater than or equal to 32 then I think it will be a printable character. You'll want to take a look at the ALLEGRO_USTR type.
EDIT: Code above works quite well !
new question:
Error 1 error C2664: 'al_stop_sample' : cannot convert parameter 1 from 'ALLEGRO_SAMPLE *' to 'ALLEGRO_SAMPLE_ID *' c:\users\alexaroth\documents\visual studio 2010\projects\homeless bloodbath a5\homeless bloodbath a5\sound.cpp
why ?
You need to send an ALLEGRO_SAMPLE_ID, not just an ALLEGRO_SAMPLE.
When you play a sample using
al_play_sample(ALLEGRO_SAMPLE *spl, float gain, float pan, float speed, ALLEGRO_PLAYMODE loop, ALLEGRO_SAMPLE_ID *ret_id)
you need to set an ALLEGRO_SAMPLE_ID.
ALLEGRO_SAMPLE_ID * id; al_play_sample(spl, 1, 0, 1, 1, id); al_stop_sample(id);
The reason is that you can call al_play_sample() many times on the same sample, so the id distinguishes those.
Technically there's some misnomers with the function names, but I think they are easier to understand misnamed.
another question: why can't I draw text onto a bitmap anymore ? how could I do that ?
and: how can I pass arguments ?
like
al_draw_text( font, l_map_rgb(255,255,255), 210,-1,ALLEGRO_ALIGN_LEFT,"You are now level %d",level); }
and a bonus one: is masked_blit gone ? like, the concept of it
also what does al_clear_to_color clear ? the screen ? how can I make it clear a specified bitmap ? //done
note that I have read the A5 tutorials but they don't provide any info on this
EDIT: got the set target function.. but why complicate things ? anyway
See al_draw_textf().
The alpha component with the default blender automatically gives you masked_blits. So all you need to do is load a PNG file and those pixels with alpha=0 will be skipped.
A convenience method is provided al_convert_mask_to_alpha() that converts the old pink style bitmaps to an alpha-ready bitmap.
The al_set_target_bitmap() affects the drawing operations.
so if I have a bmp with pink background it will automatically see the pink as transparent ?
and how exactly would I use al_convert_mask_to_alpha() ?
does it edit the picture file or the one loaded in the memory ?
and I still don't get key presses
I would have
while (!key[KEY_ESC]) {do stuff}
how is that in A5 again ? don't tell me I have to use events here too
al_convert_mask_to_alpha(bmp, al_map_rgb(255,0,255));
If bmp was an old A4 magic-pink bitmap, it is now an A5 ready alpha bitmap.
how is that in A5 again ? don't tell me I have to use events here too
Read the manual section that talks about al_get_keyboard_state().
al_get_keyboard_state(&kbdstate); if (al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE))
got it thanks !
Although it feels kinda complicated and seems impossible to implement as I wish without adding another loop around the original loop ...
Allegro 5 is not as simple for quick & dirty implementations. But it allows you to do more, so the complications are not for nothing. If you really want an old key style function, just do:
bool is_key_pressed(int key) { ALLEGRO_KEYBOARD_STATE s; al_get_keyboard_state(&s); return al_key_down(&s, key); } while (!is_key_pressed(ALLEGRO_KEY_ESCAPE)) { }
Yea hopefully timers will work better in A5... I'll probably have some questions for those too
thanks for the help so far !
its past midnight here so might stop coding and start reading more tutorials tomorrow.
PS isn't it
while (!is_key_pressed(ALLEGRO_KEY_ESCAPE))
Fixed.
still can't find a work around for the menu... It's not the escape while in a fight type of menu , but more like a simple out of the game menu.
Let's say I have several options, that can be triggered by key presses like: load, options, play, shop etc.
You press let's say "4" to visit the shop (which is a separate function, with it's own .cpp file), then you have multiple sub-menus like buy/sell/back. buy has some other sub-menus and so on.
What would the basic structure of such a menu be ? It seems simple I know but I couldn't figure out a simple structure without multiple loops inside other loops and function re-calling just go back to a sub-menu ....
Let's say I have several options, that can be triggered by key presses like: load, options, play, shop etc.
You press let's say "4" to visit the shop (which is a separate function, with it's own .cpp file), then you have multiple sub-menus like buy/sell/back. buy has some other sub-menus and so on.
The first thing I came up with is a switchboard. Use a function pointer to store the current menu that you're in, and do stuff based on the return value of the current menu. For the simplest kind of menus (selecting a state), this will work perfectly. For more complicated menus that change settings interactively it should still work as long as you can change the settings inside the menu function. You can easily separate each menu into it's own file if you like, as long as you include the function's declaration in your main source file.