Is some instruction in c++ or library allegro that if somebody press Esc in function1() or in function2() then he go to important() - because I am doing this now as the example:
1 | int main() |
2 | { |
3 | function1(); |
4 | important(); |
5 | return 0; |
6 | } |
7 | |
8 | |
9 | |
10 | void function1() |
11 | { |
12 | readkey(); |
13 | while (!key[KEY_ESC]&&!key[KEY_ENTER]) |
14 | { |
15 | readkey(); |
16 | } |
17 | function2(); |
18 | } |
19 | |
20 | void function2() |
21 | { |
22 | if(!key[KEY_ESC]) |
23 | { |
24 | ...... |
25 | readkey(); |
26 | } |
27 | |
28 | while(!key[KEY_ENTER]&&(!key[KEY_ESC])) |
29 | { |
30 | readkey(); |
31 | } |
32 | if(!key[KEY_ESC]) |
33 | { |
34 | ............ |
35 | } |
36 | } |
37 | |
38 | |
39 | |
40 | void important() |
41 | { |
42 | } |
Did you compile with -f-important-esc-function in the compiler flags?
Firstly, you don't need to use readkey() to access the key[] array.
And why can't you just use:
if (key[KEY_ESC]) important();
edit:
Steve: Meanie.
I must use readkey() - without that my program wrong run, and I wrote bad example - It should be:
1 | int main() |
2 | { |
3 | important() |
4 | { |
5 | ......... |
6 | } |
7 | |
8 | function1(); |
9 | function3(); |
10 | return 0; |
11 | } |
12 | |
13 | |
14 | |
15 | void function1() |
16 | { |
17 | readkey(); //programme waits on pressing key |
18 | while (!key[KEY_ESC]&&!key[KEY_ENTER]) |
19 | { |
20 | readkey(); //programme waits on pressing GOOD key (ESC or ENTER) |
21 | } |
22 | function2(); |
23 | } |
24 | |
25 | void function2() |
26 | { |
27 | if(!key[KEY_ESC]) //do this only when key wasn't ESC |
28 | { |
29 | ...... |
30 | readkey(); //programme waits on pressing key |
31 | } |
32 | |
33 | while(!key[KEY_ENTER]&&(!key[KEY_ESC])) |
34 | { |
35 | readkey(); //programme waits on pressing key |
36 | } |
37 | if(!key[KEY_ESC]) //do this only when key wasn't ESC |
38 | { |
39 | ............ |
40 | } |
41 | } |
42 | |
43 | |
44 | |
45 | void function3(); |
46 | { |
47 | } |
If somebody press "Esc" - then function1() should will finish and should will go to the start point - important()
I must use readkey() - without that my program wrong run
If you need to use readkey() without checking what it returns, then your program probably isn't written properly. The code you have posted makes very little sense, so it's hard to tell exactly what you're trying to achieve.
But what you probably need in function1() is:
if (key[KEY_ESC]) { esc_was_pressed = 1; return; }
And then in main():
if (esc_was_pressed) important();
Another alternative is just having the following in function1():
if (key[KEY_ESC]) { important(); return; }
Without knowing more about the program flow or what you're trying to achieve, I don't know which would be better.
Albin found: "code of horrors"
if (key[KEY_ESC]) { important(); return; }
after that program go to meni and exit - I think this is fault "return" in above code :/
Then post some REAL code that actually makes sense!!!
And please start using function names that describes what the function does. I have absolutely no idea what the hell it is you are trying to do, which makes it near-impossible to help you.
I can't give you all my code I give you a little part of my code - I had to change names to english because first they were in polish because I am Pole and I deleted 99% my code so maybe something is wrong
:
1 | |
2 | int main() |
3 | { |
4 | inicjalization(); |
5 | if (menu()==0) |
6 | { return 0; } |
7 | |
8 | else |
9 | { |
10 | start_game(); |
11 | end(); |
12 | return 0; |
13 | } |
14 | |
15 | } |
16 | END_OF_MAIN() |
17 | |
18 | |
19 | //int a=50 |
20 | |
21 | int menu() |
22 | { |
23 | while(a!=0) |
24 | { |
25 | clear_to_color(bufer,makecol(255,255,255)); |
26 | blit(meni,bufor,0,0,0,0,meni->w,meni->h); |
27 | |
28 | masked_blit(frame,bufer, 0,0, 80,table[index],frame->w,frame->h); |
29 | |
30 | blit(bufer,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
31 | readkey(); |
32 | |
33 | if (key[KEY_DOWN]&&index!=3) |
34 | { |
35 | |
36 | index++; |
37 | } |
38 | else if (key[KEY_DOWN]&&index==3) |
39 | { |
40 | |
41 | index=0; |
42 | } |
43 | else if (key[KEY_UP]&&index!=0) |
44 | { |
45 | |
46 | index--; |
47 | } |
48 | else if (key[KEY_UP]&&index==0) |
49 | { |
50 | |
51 | index=3; |
52 | } |
53 | else if(key[KEY_ENTER]&&index==3){return 0;} |
54 | else if(key[KEY_ENTER]&&index==0){return 1;} |
55 | else if(key[KEY_ENTER]&&index==1){instructions();} |
56 | else if(key[KEY_ENTER]&&index==2){authors();} |
57 | |
58 | |
59 | } |
60 | } |
61 | |
62 | void start_game() |
63 | { |
64 | |
65 | while (......) |
66 | { |
67 | |
68 | |
69 | readkey(); // oczekuje na wcisniecie klawisza |
70 | if (key[KEY_DOWN]) |
71 | { |
72 | ........ |
73 | function(); |
74 | } |
75 | else if (key[KEY_UP]) |
76 | { |
77 | ............. |
78 | function(); |
79 | } |
80 | else if(key[KEY_ESC]){break;} // but here I want that if somebody press ESC this function |
81 | //finish and we go AGAIN to function menu() - menu of my game |
82 | |
83 | } |
84 | } |
If I was going to implement a menu, I'd first define an enumeration to declare the states the program can be in. eg:
enum { MENU, GAME, INSTRUCTIONS, AUTHORS, EXIT };
Then I'd add a loop that checks the state. eg:
1 | int state = MENU; |
2 | |
3 | while (state != EXIT) { |
4 | |
5 | switch (state) { |
6 | |
7 | case MENU: run_menu(); |
8 | break; |
9 | case GAME: run_game(); |
10 | break; |
11 | case INSTRUCTIONS: show_instructions(); |
12 | break; |
13 | case AUTHORS: show_authors(); |
14 | |
15 | } |
16 | |
17 | } |
Then, in your menu function, I'd change the state depending on what the user selects. eg:
The state will also need to be set to MENU when the run_game(), show_instruction(), and show_authors() functions exit.
not, I want that when somebody press ESC then he go to menu (first player choose option from menu for example "new game", and then he can play, but when he then press ESC he go to menu) and you only change fragment of my code which doing that same thing
I'm not going to write your program for you! That was just an EXAMPLE of another way of doing something that I EXPECTED YOU to be able to modify to your needs.
On that note: I quit. You're on your own.
And I don't want that you write code for me, my code was only example so you can't write for me. You idea is wrong.
You should not mix input from the key[] array and readkey(), they serve different purposes.
Rather than calling readkey() and then checking the key[] array, you should use the return value of readkey(), eg if ((readkey() >> 8) == KEY_ESC). Be sure to check the manual.
this not compile
Count your closing parentheses...
this [...] is better and shorter
It is shorter (but the readkey() version can be written more elegantly) and actually worse, depending on the situation.
Do you want to respond to the player having pressed the key? If yes, use readkey().
Do you want to respond to the key being held down right now? Then use key[].
Do not use readkey() in the second situation and do not use key[] in the first. Somewhere, sometime something will go wrong somehow.
I must use readkey() and key[] because ONLY then program good run. Without readkey at present showed option in menu when I press "->" it jumps over about several of position to lower part and it should about 1 position. And when I have readkey() without key[] - when I pressing another keys than "->" and "<-" postions change and I can't go to game when I am on 1. position in menu and press ENTER (1. position in my menu is "new game"). And when I use readkey() and key[] - EVERYTHING IS PERFECT:
for example - this runs very well because I have readkey() and key[] :
1 | readkey(); |
2 | if (key[KEY_DOWN]&&index!=3) |
3 | { |
4 | |
5 | index++; |
6 | } |
7 | else if (key[KEY_DOWN]&&index==3) |
8 | { |
9 | |
10 | index=0; |
11 | } |
12 | else if (key[KEY_UP]&&index!=0) |
13 | { |
14 | |
15 | index--; |
16 | } |
17 | else if (key[KEY_UP]&&index==0) |
18 | { |
19 | |
20 | index=3; |
21 | } |
22 | else if(key[KEY_ENTER]&&index==3){return 0;} |
23 | else if(key[KEY_ENTER]&&index==0){return 1;} |
24 | else if(key[KEY_ENTER]&&index==1){instructions();} |
25 | else if(key[KEY_ENTER]&&index==2){authors();} |
Did you even bother to read (and try to understand) what I wrote?
I must use readkey() and key[] because ONLY then program good run.
You're doing something wrong then. Post a sample of the code that doesn't run properly.
ok Ever so what is wrong - could you take attachment - then you will see that if I delete readkey() program runs wrong - you can press only KEY_UP, KEY_DOWN or ENTER.
1 | |
2 | #include <iostream> |
3 | #include <ctime> |
4 | #include <allegro.h> |
5 | using namespace std; |
6 | |
7 | BITMAP *game = NULL; |
8 | BITMAP *bufor = NULL; |
9 | BITMAP *menu = NULL; |
10 | BITMAP *autors=NULL; |
11 | BITMAP *instructions = NULL; |
12 | BITMAP *frame = NULL; |
13 | |
14 | |
15 | int go=1; |
16 | int table[4]={215,295,392,550}; |
17 | int index=0; |
18 | |
19 | int meni(); |
20 | void autor(); |
21 | void instruction(); |
22 | void start(); |
23 | void end(); |
24 | |
25 | |
26 | |
27 | int main() |
28 | { |
29 | allegro_init(); |
30 | install_keyboard(); |
31 | set_color_depth(32); |
32 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
33 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
34 | game = load_bitmap("game.bmp",NULL); |
35 | menu = load_bitmap("menu.bmp",NULL); |
36 | autors = load_bitmap("autors.bmp",NULL); |
37 | instructions = load_bitmap("instructions.bmp",NULL); |
38 | frame = load_bitmap("frame.bmp",NULL); |
39 | |
40 | if (meni()==0) |
41 | { return 0; } |
42 | |
43 | |
44 | end(); |
45 | return 0; |
46 | |
47 | |
48 | |
49 | } |
50 | END_OF_MAIN() |
51 | |
52 | |
53 | |
54 | int meni() |
55 | { |
56 | while(go!=0) |
57 | { |
58 | clear_to_color(bufor,makecol(255,255,255)); |
59 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
60 | |
61 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
62 | |
63 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
64 | readkey(); |
65 | |
66 | |
67 | if (key[KEY_DOWN]&&index!=3) |
68 | { |
69 | |
70 | index++; |
71 | } |
72 | else if (key[KEY_DOWN]&&index==3) |
73 | { |
74 | |
75 | index=0; |
76 | } |
77 | else if (key[KEY_UP]&&index!=0) |
78 | { |
79 | |
80 | index--; |
81 | } |
82 | else if (key[KEY_UP]&&index==0) |
83 | { |
84 | |
85 | index=3; |
86 | } |
87 | else if(key[KEY_ENTER]&&index==3){return 0;} |
88 | else if(key[KEY_ENTER]&&index==0){start();} |
89 | else if(key[KEY_ENTER]&&index==1){instruction();} |
90 | else if(key[KEY_ENTER]&&index==2){autor();} |
91 | |
92 | |
93 | } |
94 | } |
95 | |
96 | |
97 | |
98 | void start() |
99 | { |
100 | clear_to_color(bufor,makecol(255,255,255)); |
101 | blit(game,bufor,0,0,0,0,game->w,game->h); |
102 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
103 | readkey(); |
104 | } |
105 | |
106 | |
107 | void instruction() |
108 | { |
109 | clear_to_color(bufor,makecol(255,255,255)); |
110 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
111 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
112 | readkey(); |
113 | } |
114 | |
115 | |
116 | void autor() |
117 | { |
118 | clear_to_color(bufor,makecol(255,255,255)); |
119 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
120 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
121 | readkey(); |
122 | } |
123 | |
124 | |
125 | |
126 | void end() |
127 | { |
128 | destroy_bitmap(game); |
129 | destroy_bitmap(menu); |
130 | destroy_bitmap(frame); |
131 | destroy_bitmap(instructions); |
132 | destroy_bitmap(autors); |
133 | destroy_bitmap(bufor); |
134 | allegro_exit(); |
135 | } |
ok Ever
Evertt
- could you take attachment
No, I can't. I can't open rar archives from this machine.
Make sure that if you do use readkey() instead of key[] you call it only once.
ok - now it is "zip" file
As I say without "readkey()" - everything is wrong.
a b: You are just going to have to trust us when we say is it wrong. Listen to the advice you get instead of trying to fight it.
I want trust you but when I delete readkey() - everything is wrong
I had some trouble with key[] and readkey also with my first project. The point is, you have to use allegro's functions for key input the way they are designed, which is a little different from what you do. Other people here can explain this very much better than I can, but look into do_dialog() and similar functions to make your UI. It has its root somewhere in the parallel existence of a keyboard buffer, which is handled by routines like readkey(), and the key[] array, which allows immediate access to the current key states.
For my needs, I'll do my next game with guichan, which is an excellent GUI library, but still in heavy development (working its way to version 0.6).
I understand but why must I use readkey() and key[] in below code (also in attachment) ? Do somebdoy know ? If I use only readkey() or only key[] program runs wrong:
1 | #include <iostream> |
2 | #include <ctime> |
3 | #include <allegro.h> |
4 | using namespace std; |
5 | |
6 | BITMAP *game = NULL; |
7 | BITMAP *bufor = NULL; |
8 | BITMAP *menu = NULL; |
9 | BITMAP *autors=NULL; |
10 | BITMAP *instructions = NULL; |
11 | BITMAP *frame = NULL; |
12 | |
13 | |
14 | int go=1; |
15 | int table[4]={215,295,392,550}; |
16 | int index=0; |
17 | |
18 | int meni(); |
19 | void autor(); |
20 | void instruction(); |
21 | void start(); |
22 | void end(); |
23 | |
24 | |
25 | |
26 | int main() |
27 | { |
28 | allegro_init(); |
29 | install_keyboard(); |
30 | set_color_depth(32); |
31 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
32 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
33 | game = load_bitmap("game.bmp",NULL); |
34 | menu = load_bitmap("menu.bmp",NULL); |
35 | autors = load_bitmap("autors.bmp",NULL); |
36 | instructions = load_bitmap("instructions.bmp",NULL); |
37 | frame = load_bitmap("frame.bmp",NULL); |
38 | |
39 | if (meni()==0) |
40 | { return 0; } |
41 | |
42 | |
43 | end(); |
44 | return 0; |
45 | |
46 | |
47 | |
48 | } |
49 | END_OF_MAIN() |
50 | |
51 | |
52 | |
53 | int meni() |
54 | { |
55 | while(go!=0) |
56 | { |
57 | clear_to_color(bufor,makecol(255,255,255)); |
58 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
59 | |
60 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
61 | |
62 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
63 | readkey(); |
64 | |
65 | |
66 | if (key[KEY_DOWN]&&index!=3) |
67 | { |
68 | |
69 | index++; |
70 | } |
71 | else if (key[KEY_DOWN]&&index==3) |
72 | { |
73 | |
74 | index=0; |
75 | } |
76 | else if (key[KEY_UP]&&index!=0) |
77 | { |
78 | |
79 | index--; |
80 | } |
81 | else if (key[KEY_UP]&&index==0) |
82 | { |
83 | |
84 | index=3; |
85 | } |
86 | else if(key[KEY_ENTER]&&index==3){return 0;} |
87 | else if(key[KEY_ENTER]&&index==0){start();} |
88 | else if(key[KEY_ENTER]&&index==1){instruction();} |
89 | else if(key[KEY_ENTER]&&index==2){autor();} |
90 | |
91 | |
92 | } |
93 | } |
94 | |
95 | |
96 | |
97 | void start() |
98 | { |
99 | clear_to_color(bufor,makecol(255,255,255)); |
100 | blit(game,bufor,0,0,0,0,game->w,game->h); |
101 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
102 | readkey(); |
103 | } |
104 | |
105 | |
106 | void instruction() |
107 | { |
108 | clear_to_color(bufor,makecol(255,255,255)); |
109 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
110 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
111 | readkey(); |
112 | } |
113 | |
114 | |
115 | void autor() |
116 | { |
117 | clear_to_color(bufor,makecol(255,255,255)); |
118 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
119 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
120 | readkey(); |
121 | } |
122 | |
123 | |
124 | |
125 | void end() |
126 | { |
127 | destroy_bitmap(game); |
128 | destroy_bitmap(menu); |
129 | destroy_bitmap(frame); |
130 | destroy_bitmap(instructions); |
131 | destroy_bitmap(autors); |
132 | destroy_bitmap(bufor); |
133 | allegro_exit(); |
134 | } |
a b, use a boolean value to tell whenever a key has been pressed or not, and when pressing a key check if a key has already been pressed and if, to not execute the action again, i think this is your problem right?
I did not have time to check this, just understand the keyhasbeenpressed part. .
bool keyhasbeenpressed; << this.
int meni()
{
while(go!=0)
{
clear_to_color(bufor,makecol(255,255,255));
blit(menu,bufor,0,0,0,0,menu->w,menu->h);
masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey(); << remove this.
if (key[KEY_DOWN]&&index!=3&&keyhasbeenpressed==false)
{
keyhasbeenpressed=true;
index++;
}
else if (key[KEY_DOWN]&&index==3&&keyhasbeenpressed==false)
{
keyhasbeenpressed=true;
index=0;
}
else if (key[KEY_UP]&&index!=0&&keyhasbeenpressed==false)
{
keyhasbeenpressed=true;
index--;
}
else if (key[KEY_UP]&&index==0&&keyhasbeenpressed==false)
{
keyhasbeenpressed=true;
index=3;
}
else if(key[KEY_ENTER]&&index==3&&keyhasbeenpressed==false)
{return 0;keyhasbeenpressed=true;}
else if(key[KEY_ENTER]&&index==0&&keyhasbeenpressed==false)
{start();keyhasbeenpressed=true;}
else if(key[KEY_ENTER]&&index==1&&keyhasbeenpressed==false)
{instruction();keyhasbeenpressed=true;}
else if(key[KEY_ENTER]&&index==2&&keyhasbeenpressed==false)
{autor();keyhasbeenpressed=true;}
if(!key[KEY_UP]&&!key[KEY_ENTER]&&!key[KEY_DOWN])keyhasbeenpressed=false;
}
}
Use allegro dialogs to do your menu. They have all this UP DOWN stuff already implemented, so you don't need to worry about all that. You also get your callback functions to react on button presses, and you can control your menu with keyboard and mouse. Don't try to re-do all this, it's already contained in allegro.
heheh no
This is my simple menu and frame- when you press KEY_DOWn/UP frame is going down/up, and if you press ENTER you go on another map, but without readkey() it is going strange:
http://img146.imageshack.us/img146/2143/menusx6.png
http://img462.imageshack.us/img462/1453/bvu8.jpg
i can't really tell what's so wrong with the pictures as i don't know whats right... but are you sure that you think what i posted was wrong??
Here's the proper way of doing the code you posted with readkey() alone (which is what you should be using instead of key[]):
int k = readkey()>>8; if (k==KEY_DOWN) { ... } else if (k == KEY_UP]) { ... } else if (k == KEY_ENTER]) { ... }
As others have said, using a DIALOG is probably a better way to do this.
Evert now it is good running - thanks - but why in readkey()>>8; is ">>8" ?
And what is "dialog" - I don't know english very well so mayby I don't understand - in my dictionary dialog=conversation ?
but why in readkey()>>8; is ">>8"
Read the Allegro manual entry for readkey(). Check your favourite C book for information on the bit-shift operators << and >>.
And what is "dialog"
Normally short for "dialog box", the things that pop up on your computer screen where you press "Ok" or "Cancel". In this specific case a dialog object, which is part of Allegro's GUI system. Again, see the manual.
Read the manual for the keyboard section.. please.
nooooooo - your idea with readkey()>>8 is bad I can't declare int k = readkey()>>8; as a global variable because frame wrong moves:
it is also in attachment
I can't write readkey()>>8 in each place in my program because it is going wrong:
Everything is wrong, previously how I wrote readkey() and key[] - everything was okey, it was no problems !! I am angry - sorry, but I am angry.......
Manual don't like me.......
Posted on 12-12-2006 3:17 AM
Guys, this is a lost cause. Just... do something better.
Oh how right he was.
LennyLen if you are so intelligent, say me why readkey()>>8 in two programs UP wrong runs.
Do as Evert (and others) said. READ THE MANUAL.
I readed but it isn't simply when I can't good english........
If you can't understand the english well enough then ok. But if you can, then you don't seem to be trying to understand or think as to why it is not working based on what you read.
edit: nvm
Now I use English translator 3 but it isn't very good.
I gave more parentheses, because I thought that this can their fault
Do it like this:
Etc..
When you call readkey it waits for a key to be pressed, if you call it again it waits for another key to be pressed. So you only want to call it once, then check which key was pressed and deal with all those conditions.
Does that help?
We have in menu:
"new game" index 0
"instructions" index 1
"autor" index 2
"end game" index 3
Richard your idea is also wrong - this see that your idea shoud be good but isn't - very strange
the problem is that I can't do int k = readkey()>>8; global variable
I'm going to recommend that you look at my Game Creation Articles and try to understand how to build a working game. Most of them have more code than English and I think they will help you once you understand them.
Richard but I don't understand why I can't do int k = readkey()>>8; global variable
Think about it..
You can't call a function like that. And even if you could, it would only work ONCE.
yyyy ?? I have this program in attachment .... and I do not know about what already completely it walks
if you put k = readkey() >> 8 outside of any functions, then how are you going to call it? It is not called automatically, and so k will not be correct.
You need to call it each time you want to read 1 new key.
You're asking why you can't you do int k = readkey()>>8;? Seriously? I don't think bad English or the manual are the problems here...
nooooooo - your idea with readkey()>>8 is bad
No, your implementation is. I'm not going to spoon-feed you, but I will give you one more hint (even if Richard already gave the exact same advice above): don't declare it as a global variable; you want to keep calling readkey, don't you?
Think before you type.
Aside, I realise this is probably a reflection of your English not being very good, but I will tell you this: I have been programming for more than fifteen years, and programming in C with Allegro for nine years. I do not take kindly to a novice user getting angry and calling code examples I give "bad" because he fails to implement it properly. I seriously suggest that you invest some time on that attitude.
I readed but it isn't simply when I can't good english........
Feel free to ask any question related to the manual. Feel free todirectly ask the friendly Polish regulars for advice is Polish if you need to.
1. This is a bit uncomfortable declaring in every function this - do you judge ?
2. And when I want that programme will stop as long as I will press ANY(WHATEVER) key then I use only: "readkey()" yes ??
2. I change:
on that:
okay ??
2. I change:
readkey();
while (!key[KEY_ESC]&&!key[KEY_ENTER])
{
readkey();
}
on that:
int k = readkey()>>8;
while (k!=KEY_ESC&&k!=KEY_ENTER)
{
k = readkey()>>8;
}
Please think about what we have said, and what you have read in the manual. That will answer your question.. Ask some polish people here if the english is too difficult.
Another hint: you only need to make a very small change to the readkey() call in your original code.
Oh how right he was.
1. This is a bit uncomfortable declaring in every function this - do you judge ?
I'm not quite sure what you're question is, but technically if you wanted k to be a global variable, you could declare int k; globally and the do k = readkey()>>8; when you need to (albeit I don't see any point in making it into a global variable, and using k as a name for a global variable is a horrible idea).
Evert: "you only need to make a very small change to the readkey() call in your original code." - what do you mean ??
I'm not going to explain more than that. I cannot say more without writing down the actual code, and I want you to do that yourself.
Read what has been written in this thread and try to understand it and think about it.
I'm completely lost now.
If the code you have now works, what is your question?
EDIT: even if your English is not very good, you can explain a bit better what you mean.
If the code you have now works, what is your question?
He's asking you if he changed the right part.
I don't know. Last I knew, he wanted to do something like the pseudo-code I posted here.
Why he would need a while loop at all is beyond me, because I don't think I understand what he's asking for.
Why he would need a while loop at all is beyond me, because I don't think I understand what he's asking for.
It's simple. He has a menu. He wants the UP and DOWN keys to change the current selection, and ENTER to accept it. [I'm assuming] ESC exits the menu.
yes, yes LennyLen
But now I must give question - is it possible because I don't know: Now I have 6 functions, during the game (not in menu but in game) player will press keys many times - and I must write every time when player should press key if this key isn't ESC because if it is ESC then game should exit. Is it possible write as a global that if player press ESC game exit and I can't check it in each place when player should press some key for example: "enter" or "->" or another ??
Is it possible write as a global that if player press ESC game exit and I can't check it in each place when player should press some key for example: "enter" or "->" or another ??
Richard Phipps already answered that question.
Do it like this:
bool gameRunning = true; ... int main() { //Initialization stuff goes here while(gameRunning) { //Main part of your game if(k == KEY_ESC) gameRunning = false; } //De-init stuff goes here return 0; }
That is if you want the game to exit when ESC is pressed.
Kauhiz I made that but when I press ESC - nothing do:
1 | #include <iostream> |
2 | #include <allegro.h> |
3 | using namespace std; |
4 | |
5 | BITMAP *game = NULL; |
6 | BITMAP *bufor = NULL; |
7 | BITMAP *menu = NULL; |
8 | BITMAP *autors=NULL; |
9 | BITMAP *instructions = NULL; |
10 | BITMAP *frame = NULL; |
11 | |
12 | |
13 | int go=1; |
14 | int table[4]={215,295,392,550}; |
15 | int index=0; |
16 | |
17 | void meni(); |
18 | void autor(); |
19 | void instruction(); |
20 | void start(); |
21 | void end(); |
22 | |
23 | |
24 | bool gameRunning = true; |
25 | |
26 | |
27 | |
28 | |
29 | int main() |
30 | { |
31 | allegro_init(); |
32 | install_keyboard(); |
33 | set_color_depth(32); |
34 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
35 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
36 | game = load_bitmap("game.bmp",NULL); |
37 | menu = load_bitmap("menu.bmp",NULL); |
38 | autors = load_bitmap("autors.bmp",NULL); |
39 | instructions = load_bitmap("instructions.bmp",NULL); |
40 | frame = load_bitmap("frame.bmp",NULL); |
41 | |
42 | int k; |
43 | while(gameRunning) |
44 | { |
45 | meni(); |
46 | k = readkey()>>8; |
47 | if(k == KEY_ESC) gameRunning = false; |
48 | } |
49 | |
50 | end(); |
51 | return 0; |
52 | } |
53 | END_OF_MAIN() |
54 | |
55 | |
56 | |
57 | |
58 | void meni() |
59 | { |
60 | int k; |
61 | while(go!=0) |
62 | { |
63 | clear_to_color(bufor,makecol(255,255,255)); |
64 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
65 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
66 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
67 | k= readkey()>>8; |
68 | if ((k==KEY_DOWN)&&index!=3) |
69 | { |
70 | |
71 | index++; |
72 | } |
73 | else if ((k==KEY_DOWN)&&index==3) |
74 | { |
75 | |
76 | index=0; |
77 | } |
78 | else if ((k==KEY_UP)&&index!=0) |
79 | { |
80 | |
81 | index--; |
82 | } |
83 | else if ((k==KEY_UP)&&index==0) |
84 | { |
85 | |
86 | index=3; |
87 | } |
88 | else if((k==KEY_ENTER)&&index==0){start();} |
89 | else if((k==KEY_ENTER)&&index==1){instruction();} |
90 | else if((k==KEY_ENTER)&&index==2){autor();} |
91 | |
92 | } |
93 | } |
94 | |
95 | |
96 | |
97 | void start() |
98 | { |
99 | clear_to_color(bufor,makecol(255,255,255)); |
100 | blit(game,bufor,0,0,0,0,game->w,game->h); |
101 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
102 | readkey(); |
103 | |
104 | } |
105 | |
106 | |
107 | void instruction() |
108 | { |
109 | clear_to_color(bufor,makecol(255,255,255)); |
110 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
111 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
112 | readkey(); |
113 | } |
114 | |
115 | |
116 | void autor() |
117 | { |
118 | clear_to_color(bufor,makecol(255,255,255)); |
119 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
120 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
121 | readkey(); |
122 | } |
123 | |
124 | |
125 | |
126 | void end() |
127 | { |
128 | destroy_bitmap(game); |
129 | destroy_bitmap(menu); |
130 | destroy_bitmap(frame); |
131 | destroy_bitmap(instructions); |
132 | destroy_bitmap(autors); |
133 | destroy_bitmap(bufor); |
134 | allegro_exit(); |
135 | } |
Did you even look at the code you wrote!? Obviously it's not going to quit, because you have while(go!=0) in your meni() function, and go isn't set to anything inside that loop . So you have an infinite loop, and it never gets to the point where it'd check to see if it should quit...
This is basic stuff that has nothing to do with allegro! If you expect to get any help on this forum in the future you have to at least TRY to solve your problems yourself, because otherwise people will get frustrated and just give up! Just like Evert said, you don't need a while-loop there! Do you just hit some random keys on your keyboard and then compile to see if it works?
I try made what you said and I change my code ...... Firstly it was:
1 | #include <iostream> |
2 | #include <allegro.h> |
3 | using namespace std; |
4 | |
5 | BITMAP *game = NULL; |
6 | BITMAP *bufor = NULL; |
7 | BITMAP *menu = NULL; |
8 | BITMAP *autors=NULL; |
9 | BITMAP *instructions = NULL; |
10 | BITMAP *frame = NULL; |
11 | |
12 | |
13 | int go=1; |
14 | int table[4]={215,295,392,550}; |
15 | int index=0; |
16 | |
17 | int meni(); |
18 | void autor(); |
19 | void instruction(); |
20 | void start(); |
21 | void end(); |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | int main() |
30 | { |
31 | allegro_init(); |
32 | install_keyboard(); |
33 | set_color_depth(32); |
34 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
35 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
36 | game = load_bitmap("game.bmp",NULL); |
37 | menu = load_bitmap("menu.bmp",NULL); |
38 | autors = load_bitmap("autors.bmp",NULL); |
39 | instructions = load_bitmap("instructions.bmp",NULL); |
40 | frame = load_bitmap("frame.bmp",NULL); |
41 | if (meni()==0) |
42 | { return 0; } |
43 | |
44 | end(); |
45 | return 0; |
46 | } |
47 | END_OF_MAIN() |
48 | |
49 | |
50 | |
51 | |
52 | int meni() |
53 | { |
54 | int k; |
55 | while(go!=0) |
56 | { |
57 | k = readkey()>>8; |
58 | clear_to_color(bufor,makecol(255,255,255)); |
59 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
60 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
61 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
62 | |
63 | |
64 | if ((k==KEY_DOWN)&&index!=3) |
65 | { |
66 | |
67 | index++; |
68 | } |
69 | else if ((k==KEY_DOWN)&&index==3) |
70 | { |
71 | |
72 | index=0; |
73 | } |
74 | else if ((k==KEY_UP)&&index!=0) |
75 | { |
76 | |
77 | index--; |
78 | } |
79 | else if ((k==KEY_UP)&&index==0) |
80 | { |
81 | |
82 | index=3; |
83 | } |
84 | else if((k==KEY_ENTER)&&index==3){return 0;} |
85 | else if((k==KEY_ENTER)&&index==0){start();} |
86 | else if((k==KEY_ENTER)&&index==1){instruction();} |
87 | else if((k==KEY_ENTER)&&index==2){autor();} |
88 | |
89 | } |
90 | } |
91 | |
92 | |
93 | |
94 | void start() |
95 | { |
96 | clear_to_color(bufor,makecol(255,255,255)); |
97 | blit(game,bufor,0,0,0,0,game->w,game->h); |
98 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
99 | |
100 | while ((k!=KEY_ESC)&&(k!=KEY_ENTER)) |
101 | { |
102 | readkey(); |
103 | } |
104 | SEEING(); // it is define in second code |
105 | } |
106 | |
107 | |
108 | void instruction() |
109 | { |
110 | clear_to_color(bufor,makecol(255,255,255)); |
111 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
112 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
113 | readkey(); |
114 | } |
115 | |
116 | |
117 | void autor() |
118 | { |
119 | clear_to_color(bufor,makecol(255,255,255)); |
120 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
121 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
122 | readkey(); |
123 | } |
124 | |
125 | |
126 | |
127 | void end() |
128 | { |
129 | destroy_bitmap(game); |
130 | destroy_bitmap(menu); |
131 | destroy_bitmap(frame); |
132 | destroy_bitmap(instructions); |
133 | destroy_bitmap(autors); |
134 | destroy_bitmap(bufor); |
135 | allegro_exit(); |
136 | } |
This loop is infinite on purpose. It must be infinite (only when somebody is in index 3 and press enter will be exit and now I want also make that if somebody press ESC program will be exit ) so just therefore I ask is it possible that if somebody press ESC program will exit. This program is also example because I have bigger program and more functions, for example I have function (I will must change there readkey() and key[]):
Just therefore I ask if it possible that that ESC was pressed then the end of programme
Did you read my post? Did you understand it? Do you even understand your own code!? This is why everyone else gave up on you (it seems) and I'm starting to feel I'm wasting my time here too...
This loop is infinite on purpose. It must be infinite
No, wrong! You DO NOT want to have an infinite loop in your code! Secondly, if you can make the program exit when ENTER is pressed, why can't you make it exit when ESC is pressed? There's absolutely no difference!! And BTW, returning when ENTER is pressed isn't even the best way to do that. Replace this:if((k==KEY_ENTER)&&index==3){return 0;} with this:if((k == KEY_ENTER) && index == 3) || k == KEY_ESC) go = 0;
If you can't figure that out by yourself, I quit. I suggest you get a book on C++ and read Phipps' game creation articles, or something. And THINK before you write code (and ask questions)!!
Wow, you guys really are a bunch of incurable masochists, aren't you?
I know, it's bad
It's soo true!
no, no, no - this code is only example, in my real code in main after function "meni()" is another function and if I do as you say function after "meni()" in main will be run - and I don't want this.
I want that during the game after menu if somebody press "ESC" program will be exit.
I quit.
Oh, so you asked a question and didn't bother to post the ACTUAL CODE YOU WERE HAVING PROBLEMS WITH! Great! That's just... great! Why the hell do you even have a function after meni(), if you want to quit straight after meni() anyway?
I have 462 lines of code now, I can't show everything because I have it in POLISH (names and comments are polish), but I now shorten my program and change in this program names and comments to english - for example:
As you see in this program player must press many times the keys (in functions: meni, start, kaukiz) and in each time I must check is key which he press is ESC or not - if the key is ESC some functions won't be make - is it checking in many functions every time when player must press key is necessary ? Can not this simplify ?
And my code has also another wrong thing - if player during the game press ESC in my program (now) he go to menu - I don't want also this - I want that if player press during the game ESC the game will exit. Is it possible do that ?
1 | #include <iostream> |
2 | #include <allegro.h> |
3 | using namespace std; |
4 | |
5 | BITMAP *game = NULL; |
6 | BITMAP *bufor = NULL; |
7 | BITMAP *menu = NULL; |
8 | BITMAP *autors=NULL; |
9 | BITMAP *instructions = NULL; |
10 | BITMAP *frame = NULL; |
11 | |
12 | |
13 | |
14 | |
15 | void meni(); |
16 | void autor(); |
17 | void instruction(); |
18 | void start(); |
19 | void end(); |
20 | void kaukiz(); |
21 | void something(); |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | int main() |
28 | { |
29 | allegro_init(); |
30 | install_keyboard(); |
31 | set_color_depth(32); |
32 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
33 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
34 | game = load_bitmap("game.bmp",NULL); |
35 | menu = load_bitmap("menu.bmp",NULL); |
36 | autors = load_bitmap("autors.bmp",NULL); |
37 | instructions = load_bitmap("instructions.bmp",NULL); |
38 | frame = load_bitmap("frame.bmp",NULL); |
39 | |
40 | |
41 | meni(); |
42 | |
43 | end(); |
44 | return 0; |
45 | } |
46 | END_OF_MAIN() |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | void meni() |
55 | { |
56 | int go=1; |
57 | int table[4]={215,295,392,550}; |
58 | int index=0; |
59 | int k; |
60 | while(go!=0) |
61 | { |
62 | clear_to_color(bufor,makecol(255,255,255)); |
63 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
64 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
65 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
66 | k= readkey()>>8; |
67 | if ((k==KEY_DOWN)&&index!=3) |
68 | { |
69 | |
70 | index++; |
71 | } |
72 | else if ((k==KEY_DOWN)&&index==3) |
73 | { |
74 | |
75 | index=0; |
76 | } |
77 | else if ((k==KEY_UP)&&index!=0) |
78 | { |
79 | |
80 | index--; |
81 | } |
82 | else if ((k==KEY_UP)&&index==0) |
83 | { |
84 | |
85 | index=3; |
86 | } |
87 | else if((k==KEY_ENTER)&&index==0){start();} |
88 | else if((k==KEY_ENTER)&&index==1){instruction();} |
89 | else if((k==KEY_ENTER)&&index==2){autor();} |
90 | else if((k==KEY_ENTER)&&index==3){break;} |
91 | |
92 | } |
93 | } |
94 | |
95 | |
96 | |
97 | void start() |
98 | { |
99 | clear_to_color(bufor,makecol(255,255,255)); |
100 | blit(game,bufor,0,0,0,0,game->w,game->h); |
101 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
102 | readkey(); |
103 | while (!key[KEY_ESC]&&!key[KEY_ENTER]) //pressing keys as long as you press ESC or Enter |
104 | { |
105 | readkey(); |
106 | } |
107 | kaukiz(); // for you kaukiz :) |
108 | |
109 | } |
110 | |
111 | |
112 | |
113 | void kaukiz() |
114 | { |
115 | if(!key[KEY_ESC]) //I must check if somebody don't press ESC in last pressing key |
116 | { |
117 | //here is something |
118 | readkey(); |
119 | something(); |
120 | } |
121 | } |
122 | |
123 | |
124 | void something() |
125 | { |
126 | if(!key[KEY_ESC]) //I must check if somebody don't press ESC in last pressing key |
127 | { |
128 | //here is something |
129 | |
130 | } |
131 | } |
132 | |
133 | |
134 | |
135 | void instruction() |
136 | { |
137 | clear_to_color(bufor,makecol(255,255,255)); |
138 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
139 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
140 | readkey(); |
141 | } |
142 | |
143 | |
144 | void autor() |
145 | { |
146 | clear_to_color(bufor,makecol(255,255,255)); |
147 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
148 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
149 | readkey(); |
150 | } |
151 | |
152 | |
153 | |
154 | void end() |
155 | { |
156 | destroy_bitmap(game); |
157 | destroy_bitmap(menu); |
158 | destroy_bitmap(frame); |
159 | destroy_bitmap(instructions); |
160 | destroy_bitmap(autors); |
161 | destroy_bitmap(bufor); |
162 | allegro_exit(); |
163 | } |
Post the complete code. No matter what language. People that are willing to help would look into that code, regardless of the language. Try to help those people that are willing to help you! Write comments in english if you can, and use english names for functions and variables, if you can.
What you want to do is use states for your game, just like LennyLen told you to do in post #10 of this topic (he even posted code!).
What you want to do is use states for your game, just like LennyLen told you to do in post #10 of this topic (he even posted code!).
I didn't test the code, I just wrote it straight into the reply box, so there's one problem with it. At the moment, it uses if (key[KEY_ENTER])), when it should use readkey() >> 8.
ARRRRRRRRRGGGGGGGGGGGGHHHHHHHHHHH!!!!!!
Don't worry Richard, it'll all be okay. After all...
I know c++ very well
You all realize I'm going to be smug about this all week, right?
You all realize I'm going to be smug about this all week, right?
And how does that differ from any other week?
Don't worry Richard, it'll all be okay. After all...
[quote a b]
I know c++ very well
</quote>Where'd he say that? Are you sure he didn't just forget the [sarcasm] tags or something?
Now I have 1016 lines of code and I can't insert my code here because:
"Your post of 162.82KB is too long. The maximum size is 64K." - eh............. so I can't give all my code - it is only part of my code :/
I have 1016 lines of code - and it is my code (I have this code in 5 files so I insert here everything) - please tell me what should I do if I want that during the game when I press ESC game exit. So could you help me ?
DELETE
Now, that's what I call some ugly code.
When posting alot of files like that, you should atleast put a;
// name_of_file.h/cpp ex:
// klasy_deklaracje.h between every file so that one can see which one it is.
EDIT:
[..]I can't show everything because I have it in POLISH (names and comments are polish)[..]
The only comments I can find in that code are;
int tab1[2][10]={ {272,489,664,882,762,912,682,471,437,211}, // <- "x" {120,175,102,114,262,360,354,421,311,354}, // <- "y" };
and that, IIRC, is not Polish.
You better make a zip-File or rar-File with your (complete) code in it and attach that to a posting here.
No. That does it, I quit. I'm not going to go through 400+ lines of code because you can't bother to think about the advice you are given. You have been given dozens of good answers. But basically, what you do is you copy & paste the code you're given and do zero implementation. And then you expect it to work? Boy, I wonder why your problem hasn't been solved . Please, develop some basic problem solving skills, and the ability of independent thought. Then start programming. You'll find that you'll have less problems and people will be more inclined to help you.
Don't expect anyone to write your code for you. There's hardly a difference between posting your entire source and asking someone to write it from scratch, except that I'd actually prefer writing it from scratch to going through that mess of uncommented code. Why the hell does every variable name have to have like 3 Zs in it? Damn, Polish sucks (well, to be fair, Finnish isn't that much better, but at least we don't get to use our quirky spelling anywhere). IMO, any words that have a C, X and a Z in them should be outlawed.
Kaukiz Wrrrrrrr I alone write this code and copy and paste code from my 5 files here so you have:
#include <iostream> #include <ctime> #include <allegro.h> #include "klasy_deklaracje.h" #include "funkcje_deklaracje.h" using namespace std; ..............
and after that you have:
.................. #include "klasy_deklaracje.h" #include <iostream> #include "funkcje_deklaracje.h" using namespace std;
etc. - because it is code from 5 files - I could this more nicely cut and paste here (in 5 detached code) but I thought that you understood......... eh........ Programme certainly run !!! Kaukiz what this is for you 1000 the line of code hehehehe I add daily about 100 line of code, my game is unceasingly change. In fact anybody does not answer what should I change in the code if I want that after press ESC game will exit.
Neee Neee Neee!!
a b, has anyone ever told you to read http://alleg.sourceforge.net/stabledocs/en/help.html ? It's specifically for when you have a problem with Allegro, but much of the advice given is generally valid, and you routinely breach a lot of it. I very strongly suggest that you read it and try to ask questions based on that.
Evert but in my game haven't mistakes - I only want to know is it better way that if somebody press ESC game will exit - I will be very grateful if you say me mayby on this exmaple - because it is more readable for you - is it better way then in below function: kaukiz() and something() ??
1 | int main() |
2 | { |
3 | allegro_init(); |
4 | install_keyboard(); |
5 | set_color_depth(32); |
6 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
7 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
8 | game = load_bitmap("game.bmp",NULL); |
9 | menu = load_bitmap("menu.bmp",NULL); |
10 | autors = load_bitmap("autors.bmp",NULL); |
11 | instructions = load_bitmap("instructions.bmp",NULL); |
12 | frame = load_bitmap("frame.bmp",NULL); |
13 | |
14 | |
15 | meni(); |
16 | |
17 | end(); |
18 | return 0; |
19 | } |
20 | END_OF_MAIN() |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | void meni() |
29 | { |
30 | int go=1; |
31 | int table[4]={215,295,392,550}; |
32 | int index=0; |
33 | int k; |
34 | while(go!=0) |
35 | { |
36 | clear_to_color(bufor,makecol(255,255,255)); |
37 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
38 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
39 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
40 | k= readkey()>>8; |
41 | if ((k==KEY_DOWN)&&index!=3) |
42 | { |
43 | |
44 | index++; |
45 | } |
46 | else if ((k==KEY_DOWN)&&index==3) |
47 | { |
48 | |
49 | index=0; |
50 | } |
51 | else if ((k==KEY_UP)&&index!=0) |
52 | { |
53 | |
54 | index--; |
55 | } |
56 | else if ((k==KEY_UP)&&index==0) |
57 | { |
58 | |
59 | index=3; |
60 | } |
61 | else if((k==KEY_ENTER)&&index==0){start();} |
62 | else if((k==KEY_ENTER)&&index==1){instruction();} |
63 | else if((k==KEY_ENTER)&&index==2){autor();} |
64 | else if((k==KEY_ENTER)&&index==3){break;} |
65 | |
66 | } |
67 | } |
68 | |
69 | |
70 | |
71 | void start() |
72 | { |
73 | clear_to_color(bufor,makecol(255,255,255)); |
74 | blit(game,bufor,0,0,0,0,game->w,game->h); |
75 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
76 | readkey(); |
77 | while (!key[KEY_ESC]&&!key[KEY_ENTER]) //pressing keys as long as you press ESC or Enter |
78 | { |
79 | readkey(); |
80 | } |
81 | kaukiz(); // for you kaukiz :) |
82 | |
83 | } |
84 | |
85 | |
86 | |
87 | void kaukiz() |
88 | { |
89 | if(!key[KEY_ESC]) //I must check if somebody don't press ESC in last pressing key |
90 | { |
91 | //here is something |
92 | readkey(); |
93 | something(); |
94 | } |
95 | } |
96 | |
97 | |
98 | void something() |
99 | { |
100 | if(!key[KEY_ESC]) //I must check if somebody don't press ESC in last pressing key |
101 | { |
102 | //here is something |
103 | |
104 | } |
105 | } |
106 | |
107 | |
108 | |
109 | void instruction() |
110 | { |
111 | clear_to_color(bufor,makecol(255,255,255)); |
112 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
113 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
114 | readkey(); |
115 | } |
116 | |
117 | |
118 | void autor() |
119 | { |
120 | clear_to_color(bufor,makecol(255,255,255)); |
121 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
122 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
123 | readkey(); |
124 | } |
125 | |
126 | |
127 | |
128 | void end() |
129 | { |
130 | destroy_bitmap(game); |
131 | destroy_bitmap(menu); |
132 | destroy_bitmap(frame); |
133 | destroy_bitmap(instructions); |
134 | destroy_bitmap(autors); |
135 | destroy_bitmap(bufor); |
136 | allegro_exit(); |
137 | } |
This guy is really hopeless. I give up.
I alone write this code and blah blah blah...
I think you missunderstood what I said. What I meant was that people post example code of how to do what you want. And you just throw that into your source, and it doesn't work since it's just an example, and you have to implement it properly.
In fact anybody does not answer what should I change in the code if I want that after press ESC game will exit.
In fact I did. In fact every question you have asked so far has been answered and example code has been supplied. It just seems to me that you think that if you ask the same question again and again, eventually someone's going to write the whole thing for you. Either that or we're getting Punk'd.
Edit: Oh, BTW, kudos on constantly and consistently misspelling my name.
Eh......... I don't want that you write it for me !!!! I now deleting code of my game - and now staying only my examples so you can't write code for me. In function kaukiz() and something() I must check if somebody don't press ESC - could this write better ?
In fact every question you have asked so far has been answered and example code has been supplied.
could this write better ?
Yes, you could write it a lot better. (If that is what you mean)
Honestly, I would suggest you to buy a book regarding C/C++ and read it (and understand it),
before even thinking about game programming.
WHAT THE F*** IS WRONG WITH YOU!?
Seriously, how can a simple program with a really really simple menu take 1016 lines of space? And something even more disturbing: after 99 replies you still haven't learned? listen to people!. you want help but you refuse to listen? that's just stupid. if you don't understand anything that people say then you should not have asked, do you really just want to be a waste of time?.
Please, you almost made me cry, and i haven't cried in years..
if you don't understand anything that people say then you should not have asked
Thing is, I can't work out how much of that is due to his poor English. You can't fault people for not speaking English natively.
So let's try to keep it civil, shall we?
Evert but in my game haven't mistakes
You do, but that wasn't my point.
What you need to take away from that bit of text is mostly from part 5 onward. In particular you should:
1. Make it clear what you're trying to do
2. Make it clear what teh code you have does
3. Make it clear why this is different from what you want it to do
4. Don't expect people to wade through hundreds of lines of source code
5. Think about what people say, ask if you need more help
6. Change your wording if people do not understand your question. Consider posting the question in your own language as well as in your best English; chances are someone will understand it.
I would also strongly recommend that you invest some time in improving your English. Try reading some English texts or books, or watch English movies/television (with subtitles). You'll need a dictionary for reading at first, but I think it's the best way to learn.
it is code which kaukiz suggest:
1 | #include <iostream> |
2 | #include <allegro.h> |
3 | using namespace std; |
4 | |
5 | BITMAP *game = NULL; |
6 | BITMAP *bufor = NULL; |
7 | BITMAP *menu = NULL; |
8 | BITMAP *autors=NULL; |
9 | BITMAP *instructions = NULL; |
10 | BITMAP *frame = NULL; |
11 | |
12 | |
13 | |
14 | |
15 | void meni(); |
16 | void autor(); |
17 | void instruction(); |
18 | void start(); |
19 | void end(); |
20 | void kaukiz(); |
21 | void something(); |
22 | |
23 | |
24 | bool gameRunning = true; |
25 | int k; |
26 | |
27 | int main() |
28 | { |
29 | allegro_init(); |
30 | install_keyboard(); |
31 | set_color_depth(32); |
32 | set_gfx_mode(GFX_AUTODETECT,1024,768,0,0); |
33 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
34 | game = load_bitmap("game.bmp",NULL); |
35 | menu = load_bitmap("menu.bmp",NULL); |
36 | autors = load_bitmap("autors.bmp",NULL); |
37 | instructions = load_bitmap("instructions.bmp",NULL); |
38 | frame = load_bitmap("frame.bmp",NULL); |
39 | |
40 | while(gameRunning) |
41 | { |
42 | meni(); |
43 | if(k == KEY_ESC) gameRunning = false; |
44 | } |
45 | end(); |
46 | return 0; |
47 | } |
48 | END_OF_MAIN() |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | void meni() |
57 | { |
58 | int go=1; |
59 | int table[4]={215,295,392,550}; |
60 | int index=0; |
61 | |
62 | while(go!=0) |
63 | { |
64 | clear_to_color(bufor,makecol(255,255,255)); |
65 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
66 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
67 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
68 | k= readkey()>>8; |
69 | if ((k==KEY_DOWN)&&index!=3) |
70 | { |
71 | |
72 | index++; |
73 | } |
74 | else if ((k==KEY_DOWN)&&index==3) |
75 | { |
76 | |
77 | index=0; |
78 | } |
79 | else if ((k==KEY_UP)&&index!=0) |
80 | { |
81 | |
82 | index--; |
83 | } |
84 | else if ((k==KEY_UP)&&index==0) |
85 | { |
86 | |
87 | index=3; |
88 | } |
89 | else if((k==KEY_ENTER)&&index==0){start();} |
90 | else if((k==KEY_ENTER)&&index==1){instruction();} |
91 | else if((k==KEY_ENTER)&&index==2){autor();} |
92 | else if((k==KEY_ENTER)&&index==3){break;} |
93 | |
94 | } |
95 | } |
96 | |
97 | |
98 | |
99 | void start() |
100 | { |
101 | clear_to_color(bufor,makecol(255,255,255)); |
102 | blit(game,bufor,0,0,0,0,game->w,game->h); |
103 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
104 | k = readkey()>>8; |
105 | while (k!=KEY_ESC&&k!=KEY_ENTER) //pressing keys as long as you press ESC or Enter |
106 | { |
107 | k = readkey()>>8; |
108 | } |
109 | kaukiz(); // for you kaukiz :) |
110 | |
111 | } |
112 | |
113 | |
114 | |
115 | void kaukiz() |
116 | { |
117 | if(k!=KEY_ESC) //I must check if somebody don't press ESC in last pressing key |
118 | { |
119 | //here is something |
120 | k = readkey()>>8; |
121 | something(); |
122 | } |
123 | } |
124 | |
125 | |
126 | void something() |
127 | { |
128 | if(!key[KEY_ESC]) //I must check if somebody don't press ESC in last pressing key |
129 | { |
130 | //here is something |
131 | |
132 | } |
133 | } |
134 | |
135 | |
136 | |
137 | void instruction() |
138 | { |
139 | clear_to_color(bufor,makecol(255,255,255)); |
140 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
141 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
142 | k = readkey()>>8; |
143 | } |
144 | |
145 | |
146 | void autor() |
147 | { |
148 | clear_to_color(bufor,makecol(255,255,255)); |
149 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
150 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
151 | k = readkey()>>8; |
152 | } |
153 | |
154 | |
155 | |
156 | void end() |
157 | { |
158 | destroy_bitmap(game); |
159 | destroy_bitmap(menu); |
160 | destroy_bitmap(frame); |
161 | destroy_bitmap(instructions); |
162 | destroy_bitmap(autors); |
163 | destroy_bitmap(bufor); |
164 | allegro_exit(); |
165 | } |
But it is obvious that this idea kaukiz is bad because if somebody will press ESC program won't exit.
My idea was better in my previous code but it also wasn't perfect.
I think that the best solution will be that in top right corner will "X" - and after click "X" game will exit - but how can I do it ? I know that we must use:
set_gfx_mode(GFX_AUTODETECT_WINDOWED,1024,768,0,0); but if somebody has resolution of monitor: 1024:768 program will wrong run because size window must be smaller than somebody's resolution of monitor - so what should I do if I want that my program runs good in also resolution of monitor 1024:768? And how can I do "X" which exit program.
I cry Punk!
Try using a different word for "bad" when someone's suggestion does not do what you want it to do.
and after click "X" game will exit - but how can I do it ?
http://alleg.sourceforge.net/stabledocs/en/alleg000.html#set_close_button_callback
Note that this is no different in principle from how you should deal with escape exiting the game.
but if somebody has resolution of monitor: 1024:768 program will wrong run because size window must be smaller than somebody's resolution of monitor - so what should I do if I want that my program runs good in also resolution of monitor 1024:768?
Run fullscreen, or make sure the window is smaller. See http://alleg.sourceforge.net/stabledocs/en/alleg000.html#get_desktop_resolution.
Here's another suggestion for your reading list: read through Allegro's manaul to get a rough overview of what's available and where you can find it.
What Evert was thinking ( For the closing part )
1 | #include <allegro.h> |
2 | |
3 | |
4 | |
5 | BITMAP *scrbuf; |
6 | |
7 | |
8 | |
9 | int DONE = 0; /* will take the value 1 if someone wanna exit */ |
10 | |
11 | |
12 | |
13 | void close_callback() |
14 | { |
15 | DONE = 1; /* when set_close_callback is specified, intead of just quitting your program when hitting the cross in windowed mode or when pressing alt-f4 it will call this function*/ |
16 | } |
17 | |
18 | |
19 | int main( int argc, char *argv[] ) |
20 | { |
21 | |
22 | /*system init */ |
23 | allegro_init(); |
24 | install_timer(); |
25 | install_keyboard(); |
26 | install_mouse(); |
27 | |
28 | set_window_title( "Simple ESC test for a b" ); |
29 | |
30 | set_close_button_callback( close_callback ); |
31 | |
32 | /* grafic init */ |
33 | set_color_depth( 32 ); |
34 | set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640 , 480 , 0 , 0 ); |
35 | scrbuf = create_bitmap( SCREEN_W , SCREEN_H ); |
36 | clear( scrbuf ); |
37 | |
38 | while( !DONE && !key[ KEY_ESC ] ) /* Here is the important part: continue game since someone press ESC or push the cross-buton or alt-f4 */ |
39 | { |
40 | |
41 | /* |
42 | Here do some stuf, add things |
43 | */ |
44 | |
45 | clear( scrbuf ); |
46 | circle( scrbuf , mouse_x , mouse_y , 20 , makecol( 255 , 255 , 255 ) ); |
47 | blit( scrbuf , screen , 0 , 0 , 0 , 0 , scrbuf -> w , scrbuf -> h ); |
48 | |
49 | |
50 | } /* while( ... ) */ |
51 | |
52 | destroy_bitmap( scrbuf ); |
53 | |
54 | allegro_exit(); |
55 | |
56 | }END_OF_MAIN() |
What does not work with the ESC key, can you test that attached code, a b ?
Have you really tried what all the others have said ?
Test the attached binary to see if this code do what you want.
Follow Evert's last advisement: there are enough examples and documentation in the allegro library distribution to make you understand how it works (it's commonly the case)
_
What does not work with the ESC key
His program works exactly as it's suppsoed to (from the code's point of view). The problem is with the way it's written.
Have you really tried what all the others have said ?
If by tried you mean "randomly placing the example code you've been given somewhere in your program," then yes.
But it is obvious that this idea kaukiz is bad because if somebody will press ESC program won't exit.
There are so many things wrong with this sentence ...
Firstly: It's not my idea. That's what I do and that's what I told you to do, but it's pretty much standard AFAIK; set a flag that signals the game is running, and run the game as long as the flag is true.
Secondly: like I said, it's standard. That means it does work. You're not an exception in this sense. Programming is logical, the same rules apply everywhere. We're not taking guesses at how to do what you want (although we are guessing what exactly you want), but we're telling you how to do it. We've done it before, the advice given and code posted in this thread is all valid.
Finally, the reason nothing happens when you press ESC is that you have an infinite loop. Any code outside that loop will never be executed, hence the game will never end. You say you can't do what I suggested, since you have another function after meni(). Why? Why do you have a function call you never want to be executed? Please tell me why! If you can't answer that, there's absolutely no helping you.
You can't just call function after function and zip from one procedure to the next. It'll look horrible and it won't work. You have to use states. That is: if your game is in the menu state, call the menu function. No loop inside the menu function, just call it once. If the game is still running, it'll loop over and the function will be called again. Same thing for every state your game can be in. LennyLen already provided basic example code for this. If you do that, all the problems you have addressed so far will pretty much be solved. If you refuse to do this, I refuse to help you.
So you want that my code will be:
1 | #include <iostream> |
2 | #include <allegro.h> |
3 | using namespace std; |
4 | |
5 | BITMAP *game = NULL; |
6 | BITMAP *bufor = NULL; |
7 | BITMAP *menu = NULL; |
8 | BITMAP *autors=NULL; |
9 | BITMAP *instructions = NULL; |
10 | BITMAP *frame = NULL; |
11 | |
12 | |
13 | |
14 | |
15 | void meni(); |
16 | void autor(); |
17 | void instruction(); |
18 | void start(); |
19 | void end(); |
20 | void kaukiz(); |
21 | void something(); |
22 | |
23 | |
24 | bool gameRunning = true; |
25 | int k; |
26 | int go=1; |
27 | |
28 | |
29 | int main() |
30 | { |
31 | allegro_init(); |
32 | install_keyboard(); |
33 | set_color_depth(32); |
34 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,1024,768,0,0); |
35 | bufor=create_bitmap(SCREEN_W,SCREEN_H); |
36 | game = load_bitmap("game.bmp",NULL); |
37 | menu = load_bitmap("menu.bmp",NULL); |
38 | autors = load_bitmap("autors.bmp",NULL); |
39 | instructions = load_bitmap("instructions.bmp",NULL); |
40 | frame = load_bitmap("frame.bmp",NULL); |
41 | |
42 | //yours idea :)))))))))))))))) |
43 | aa: |
44 | meni(); |
45 | |
46 | |
47 | while(!key[ KEY_ESC ]&&go==2) |
48 | { |
49 | start(); |
50 | kaukiz(); |
51 | something(); |
52 | } |
53 | while(!key[ KEY_ESC ]&&go==3) |
54 | { |
55 | autor(); |
56 | go=1; |
57 | goto aa; |
58 | |
59 | } |
60 | while(!key[ KEY_ESC ]&&go==4) |
61 | { |
62 | instruction(); |
63 | go=1; |
64 | goto aa; |
65 | |
66 | } |
67 | end(); |
68 | return 0; |
69 | } |
70 | END_OF_MAIN() |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | void meni() |
79 | { |
80 | |
81 | int table[4]={215,295,392,550}; |
82 | int index=0; |
83 | |
84 | while(go!=0&&go!=2&&go!=3&&go!=4) |
85 | { |
86 | clear_to_color(bufor,makecol(255,255,255)); |
87 | blit(menu,bufor,0,0,0,0,menu->w,menu->h); |
88 | masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); |
89 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
90 | k= readkey()>>8; |
91 | if ((k==KEY_DOWN)&&index!=3) |
92 | { |
93 | |
94 | index++; |
95 | } |
96 | else if ((k==KEY_DOWN)&&index==3) |
97 | { |
98 | |
99 | index=0; |
100 | } |
101 | else if ((k==KEY_UP)&&index!=0) |
102 | { |
103 | |
104 | index--; |
105 | } |
106 | else if ((k==KEY_UP)&&index==0) |
107 | { |
108 | |
109 | index=3; |
110 | } |
111 | else if((k==KEY_ENTER)&&index==0){go=2;} |
112 | else if((k==KEY_ENTER)&&index==1){go=3;} |
113 | else if((k==KEY_ENTER)&&index==2){go=4;} |
114 | else if((k==KEY_ENTER)&&index==3){go=0;} |
115 | else if((k==KEY_ESC)){go=0;} |
116 | |
117 | } |
118 | } |
119 | |
120 | |
121 | |
122 | void start() |
123 | { |
124 | clear_to_color(bufor,makecol(255,255,255)); |
125 | blit(game,bufor,0,0,0,0,game->w,game->h); |
126 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
127 | k = readkey()>>8; |
128 | while (k!=KEY_ESC&&k!=KEY_ENTER) //pressing keys as long as you press ESC or Enter |
129 | { |
130 | k = readkey()>>8; |
131 | } |
132 | if(!key[ KEY_ESC ]){go=1;} |
133 | else {go=0;} |
134 | |
135 | } |
136 | |
137 | |
138 | |
139 | void kaukiz() |
140 | { |
141 | if(key[KEY_ESC]){go=0;} //I must check if somebody don't press ESC in last pressing key |
142 | else |
143 | { |
144 | //here is something |
145 | k = readkey()>>8; |
146 | something(); |
147 | } |
148 | |
149 | } |
150 | |
151 | |
152 | void something() |
153 | { |
154 | if(key[KEY_ESC]){go=0;} //I must check if somebody don't press ESC in last pressing key |
155 | else |
156 | { |
157 | k = readkey()>>8; //here is something |
158 | } |
159 | |
160 | } |
161 | |
162 | |
163 | |
164 | void instruction() |
165 | { |
166 | clear_to_color(bufor,makecol(255,255,255)); |
167 | blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); |
168 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
169 | k = readkey()>>8; |
170 | go=2; |
171 | } |
172 | |
173 | |
174 | void autor() |
175 | { |
176 | clear_to_color(bufor,makecol(255,255,255)); |
177 | blit(autors,bufor,0,0,0,0,autors->w,autors->h); |
178 | blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); |
179 | k = readkey()>>8; |
180 | go=2; |
181 | } |
182 | |
183 | |
184 | |
185 | void end() |
186 | { |
187 | destroy_bitmap(game); |
188 | destroy_bitmap(menu); |
189 | destroy_bitmap(frame); |
190 | destroy_bitmap(instructions); |
191 | destroy_bitmap(autors); |
192 | destroy_bitmap(bufor); |
193 | allegro_exit(); |
194 | } |
now it is more complicated .................
For the love of *(&#*@# stop using key[] already!
If you don't want to block with readkey(), use keypressed() first to check if there's a key in the buffer.
Look up flow control and loops in your favorite C book and get rid of those goto statements.
I would like an option to ignore a thread. For now, I'll just mark it read instead.
Anyway, sometimes it's quite fun to have a peek into this thread here. Never met anybody so impertinent and resistant to advice.
He has no understanding, that's the problem.
I would like an option to ignore a thread
Isn't that what "hide thread" is for?
it "sucks" not knowing English. you will not find the right meaning for words like "sucks" in you translators.
send me your project file zip if your using msvc++6 ill fix for you so you can move on
edit its 2007 why are there no browser to bridge language bearers yet(like star track)
you use too difficult words in english so I can't understand everything and make everything what you say..... I translate my game to english half day but now I translated !! I work over this game all the time...
It is link to this - so can you help me that after ESC game will exit because now I have many loops and when I press ESC game go to menu and no exit :/
........
here is one ways to fix
1 | void start() |
2 | { |
3 | eye = bone(1,3); |
4 | seeall(); |
5 | while (go > 0) |
6 | { |
7 | |
8 | if(check()==1){break;} |
9 | |
10 | gogogo: |
11 | readkey(); |
12 | if (key[KEY_DOWN]) |
13 | { |
14 | index = index - eye; |
15 | if ( index < 0 ) { index = index + 10;} |
16 | go--; |
17 | eye = bone(1,3); |
18 | seeall(); |
19 | } |
20 | else if (key[KEY_UP]) |
21 | { |
22 | index = index + eye; |
23 | if ( index > 9 ) { index = index - 10;} |
24 | go--; |
25 | eye = bone(1,3); |
26 | seeall(); |
27 | } |
28 | else if(key[KEY_ESC]){exitexit();} |
29 | else {goto gogogo; } |
30 | } |
31 | } |
this is what i change
else if(key[KEY_ESC]){break;} //old
to
else if(key[KEY_ESC]){exitexit();} //new
EDit:
sorry i could not compile it because i do not have that compiler.
is that what you wanted it to do
If you want to fix anything you can start by not discarding the return values of readkey().
you use too difficult words in english so I can't understand everything
Use a dictionary (there seem to be several on-line ones, try http://www.dict.pl/ or http://www.polish-dictionary.com/ - I don't know if they're good), babelfish (seems babelfish doesn't do Polish) or ask!
the problem was the trance of the manual. this is how it went down you was looking for things to do keyboard input. so you found readkey(); and key[]. what you did not trance is that they both are tools to do the same thing in 2 different ways. thats why you combined them.
int val; val = readkey(); if ((val >> 8) == KEY_ESC){exitexit();} /* by scancode */
same thing
if(key[KEY_ESC]){exitexit();}
trance?
interpretation
piccolo, those two statements are not the same thing.
readkey() is a blocking function, while the check in the key array returns the state of a key (non-blocking).
http://www.allegro.cc/manual/api/keyboard-routines/readkey
http://www.allegro.cc/manual/api/keyboard-routines/key
quote: they both are tools to do the same thing in 2 different ways.
No, they're not. readkey() and key[] serve completely different purposes. Sure, you can use one to emulate the other (sortof, you'll need keypressed() as well), but that's like using a knife to drive a screw. Or a screwdriver to cut your meat.
What do you mean by same thing?
One waits for a key to be pressed and returns which key it is,
the other one returns the state of a key. That's not the same thing.
they are both tools that can be used to do something based on a key press.i gave examples in my post of them doing the same thing.
In your first example, the program would halt at "val = readkey();", until a key is pressed. The other one would not. Not the same.
It is not the same Piccolo.
Man, I think I've never seen so many crazy people on a thread before!
Man, I think I've never seen so many crazy people on a thread before!
Hey! I mean, who... that is... oh, never mind.
1. so should I change readkey() to keypressed() ?
2. Somebody told that I shouldn't to call out in function function . I read that is good idea ..... so I don't know - should I change that more call function should be in main() ??
3. This:
should be:
?? yes
?
If I understand: http://www.allegro.cc/manual/api/keyboard-routines/readkey thanks ">>8" I can use "key+key" yes ??
1. so should I change readkey() to keypressed() ?
No!
Read the manual on what each of these functions do.
3. This:
[...]
should be:
Yes. Sortof. You should only call readkey() once, not twice at that point. Read the keypressed() manual entry.
thanks ">>8" I can use "key+key" yes ??
I don't understand what you mean.
You didn't answer question 2, Evert.
Somebody told that I shouldn't to call out in function function . I read that is good idea ..... so I don't know - should I change that more call function should be in main() ??
I don't even know what that means.
I'm actually starting to think that a b is, in fact, THE MOST SOPHISTICATED TROLL EVER!
Yeah, like I said, we're getting Punk'd and this guy is having a blast
1.Kaukiz told:
"You can't just call function after function"
Do you agree ??
2. I read manual but it is in english so I don't understand everything - if I want that program stop untill somebody press any key then I must use keypressed() yes ?
3.
int k = readkey()>>8;
k = readkey()>>8;
if(k==KEY_0)
thanks ">>8" I can use for example "ctr+shift" (keyboard shortcuts) yes ??
PS. Jonatan Hedborg I don't like Sweden
if I want that program stop untill somebody press any key then I must use keypressed() yes ?
No.
readkey() will read a key from the buffer and wait if there is no key in the buffer. keypressed() will tell you if there is a key in the buffer. So
val=readkey();
blocks, while
val=0; if (keypressed()) val=readkey();
does not.
thanks ">>8" I can use for example "ctr+shift" (keyboard shortcuts) yes ??
No!
if ((val & 0xff) == 3) /* ctrl+letter */
allegro_message("You pressed Control+C\n");
if (val == (KEY_X << 8)) /* alt+letter */
allegro_message("You pressed Alt+X\n");
EDIT: For shortcuts, check out the key_shifts variable as well.
1.Kaukiz told:
"You can't just call function after function"
Do you agree ??
I assume you mean what I said, and you just simply CAN NOT SPELL! You apparently missed the next part of that statement, which is the more important one. You can call functions after each other, of course. You shouldn't just call the menu function when someone presses a key. There's a HUGE difference there.
2. I read manual but it is in english so I don't understand everything - if I want that program stop untill somebody press any key then I must use keypressed() yes ?
Nope, the exact opposite. If you can't understand a part of the manual, copy the part here and ask.
int k = readkey()>>8;
k = readkey()>>8;
if(k==KEY_0)
That's wrong, you should only call readkey() once. If you knew basic C++, you'd understand why.
PS. Jonatan Hedborg I don't like Germany
WTF?
readkey()>>8
I know bite shift in only theoretical side, I never use it. Bite shift faster some actions. And here what is faster ? Read key is faster ?
PS. Jonatan Hedborg I don't like Sweden
that was random, even for you.
For the record: I don't like you.
Bite shift faster some actions. And here what is faster ? Read key is faster ?
What the HELL!!? Read the goddamn manual!? It doesn't make anything faster, it gets the goddamn scancode for you! Please, please, please tell me you're only joking here!
It's now 140 posts (with this one) to try to resolve this question..
but why in "k = readkey()>>8;" is "8" ?? why bite shift in right is "8" ??
Instead of us answering that, you should try to answer the following questions:
How many bits are there in one byte (on a PC)?
What happens if you have a double-byte word and shift all bits in it from the upper byte to the lower byte?
What does that imply if you use a double byte word to store two one-byte values, one inthe upper and one in the lower byte?
Because >> 8 is one byte and readkey() returns a word (2 bytes):
int readkey();
Returns the next character from the keyboard buffer, in ASCII format. If the buffer is empty, it waits until a key is pressed. You can see if there are queued keypresses with keypressed().
The low byte of the return value contains the ASCII code of the key, and the high byte the scancode.
I.e. xxxxxxxx | xxxxxxxx (8 bits | 8 bits)
Scancode | Asci value
Do you even try to improve your English? People say "bit", you still use "bite". Kauhiz nickname is visible most of the time - is your H-key broke? My god...
Let's just stop this thread right here. Please? I'm working up a brain aneurysm...
[off topic]
I am not going to flame to prove my point.
[/off topic]
from what i understood the problem was that the game went back to the menu when esc was pressed in the started game,and you want it to end the game.
the mods that i made will fix that problem.
when esc was pressed before the mods to the code, a break was issued. This break ends the current loop. when the current loop is ended you are put back to the spot in your code where you entered that loop. That spot is the menu loop.
so what i did to fix this is change that break to the end-game call you made.
But you're still discarding the return value of readkey() which is wrong.
Let's just stop this thread right here.
We're probably making a record here. Almost 150 posts already to solve a trivial problem (which has already been solved many times over)! I think it'll be fun to see how long this thread will go
i just wanted to get the main problem fixed. He has been informed that there are some other design errors in his code. After reviewing his code, i saw that those errors do not harm the game in a drastic way. So these errors can be corrected in a later design faze.(now that he knows of them)
(now that he knows of them)
We could have a whole nother debate on this point...
thanks piccolo for your help
I also will change in code to:
int k=readkey()>>8;
.............
;]
But:
word = 2 bytes ? Thanks I didn't know that.
but if readkey() returns 2 bytes so why readkey()>> can't be "16" ? 2 bytes = 16
You are moving the bits from this [random example]: (you want the bold part) 1011010010011101 to 0000000010110100. It just moves it down to where you can "see" it.
Think about it! readkey()>>16 would be 00000000 00000000!
LennyLen: You were right (the post just after mine)
Evert: You are a model of patience.
and ... no , wait, I can not say that :-p
Spot the mistake:
ENTER or ESC
(k==KEY_ESC&&k==KEY_ENTER)
Spot the mistake:
puts hand up Me sir, me!!!
sorry I shoulded write "AND" hehhe
ok thanks
sorry I shoulded write "AND"
You mean you want them to have to press both keys at the same time?!?!
sorry I shoulded write "AND" hehhe
Richard casts Knights of the Round on a b
You mean you want them to have to press both keys at the same time?!?!
I think he means he shouldn't have written &&.
"and" but I wrong write because in the past I had:
so now it should be:
sorrrrrrrry - little mistake
So you do want the player to press two keys!?
I want that somebody pressing keys while key is diffrent from ESC and diffrent from ENTER
I'm confused..
Actually, his code is right, since NOT(a OR b) = NOT(a) AND NOT(b).
Hurrah!
It might have made more sense to people if you'd expressed it this way:
while (!(k == KEY_ESC || k == KEY_ENTER))
ok thanks
Oh, true. Does this mean that the problem has been solved!?!? The thread is over!
yes.........
Noooo!!
Now, can anybody remember the name of the formula that states NOT(a OR b) = NOT(a) AND NOT(b)? It can also be expressed in set notation as ~(A U B) = ~A ^ ~B. Actually, it's two formulae, with the second one being ~(A ^ B) = ~A U ~B.
De Morgan's laws. Now for the love of all that is unholy, let this topic die. It makes baby Eris cry.
Thanks, that's been bugging me for two hours now. I finally tracked down my Tables and Formulae booklet only to find that it didn't have those formulae anyway!
Now for the love of all that is unholy, let this topic die.
This thread is too unholy to die. It's undead.
And it needs brains to survive!
So do we get credit for helping out?
none needed for me.
all in a days work for KING PICCOLO;D8-)
edit: ill take a chocolate chip if you have any:P
THIS THREAD WILL NEVER DIE! ... or so it seems
I am working and working on my game
Random! Random!
Oh, btw, what kind of game is it?
... please ... lock ... this ... ... threaaaad ! argh
I bet it's a card game.