if somebody press Esc he go to another function
a b

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:

1int main()
2{
3function1();
4important();
5return 0;
6}
7 
8 
9 
10void function1()
11{
12readkey();
13 while (!key[KEY_ESC]&&!key[KEY_ENTER])
14 {
15 readkey();
16 }
17 function2();
18}
19 
20void function2()
21{
22if(!key[KEY_ESC])
23{
24......
25readkey();
26}
27 
28while(!key[KEY_ENTER]&&(!key[KEY_ESC]))
29 {
30 readkey();
31 }
32if(!key[KEY_ESC])
33{
34............
35}
36}
37
38 
39 
40void important()
41{
42}

Steve Terry

Did you compile with -f-important-esc-function in the compiler flags?

LennyLen

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. :P

a b

I must use readkey() - without that my program wrong run, and I wrote bad example - It should be:

1int main()
2{
3important()
4{
5.........
6}
7 
8function1();
9function3();
10return 0;
11}
12 
13 
14 
15void function1()
16{
17readkey(); //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 
25void function2()
26{
27if(!key[KEY_ESC]) //do this only when key wasn't ESC
28{
29......
30readkey(); //programme waits on pressing key
31}
32 
33while(!key[KEY_ENTER]&&(!key[KEY_ESC]))
34 {
35 readkey(); //programme waits on pressing key
36 }
37if(!key[KEY_ESC]) //do this only when key wasn't ESC
38{
39............
40}
41}
42
43 
44 
45void function3();
46{
47}

If somebody press "Esc" - then function1() should will finish and should will go to the start point - important()

LennyLen
Quote:

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 Engström

Albin found: "code of horrors"

a b
if (key[KEY_ESC]) {
    important();
    return;
}

after that program go to meni and exit - I think this is fault "return" in above code :/

LennyLen

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.

a b

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 
2int main()
3{
4 inicjalization();
5 if (menu()==0)
6 { return 0; }
7
8else
9{
10 start_game();
11 end();
12 return 0;
13}
14
15}
16END_OF_MAIN()
17 
18 
19//int a=50
20 
21int menu()
22{
23while(a!=0)
24{
25clear_to_color(bufer,makecol(255,255,255));
26blit(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 
62void 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}

LennyLen

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:

1int state = MENU;
2 
3while (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:

1[if (key[KEY_ENTER]) {
2 
3 switch (index) {
4
5 case 0: state = GAME;
6 break;
7 case 1: state = INSTRUCTIONS;
8 break;
9 case 2: state = AUTHORS;
10 break;
11 case 3: state = EXIT;
12 
13 }
14 
15 return;
16 
17}


The state will also need to be set to MENU when the run_game(), show_instruction(), and show_authors() functions exit.

a b

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

LennyLen

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.

a b

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.

Evert

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.

a b

hm........... and everywhere: if ((readkey() >> 8)== KEY_ENTER)&&index!=3) this not compile and it is longer - this : if (key[KEY_DOWN]&&index!=3) is better and shorter

Evert
Quote:

this not compile

Count your closing parentheses...

Quote:

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.

a b

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();}

Evert

Did you even bother to read (and try to understand) what I wrote?

Quote:

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.

a b

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>
5using namespace std;
6 
7BITMAP *game = NULL;
8BITMAP *bufor = NULL;
9BITMAP *menu = NULL;
10BITMAP *autors=NULL;
11BITMAP *instructions = NULL;
12BITMAP *frame = NULL;
13 
14 
15int go=1;
16int table[4]={215,295,392,550};
17int index=0;
18 
19int meni();
20void autor();
21void instruction();
22void start();
23void end();
24 
25 
26 
27int main()
28{
29allegro_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}
50END_OF_MAIN()
51 
52 
53 
54int meni()
55{
56 while(go!=0)
57{
58clear_to_color(bufor,makecol(255,255,255));
59blit(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 
98void 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 
107void 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 
116void 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}

Evert
Quote:

ok Ever

Evertt

Quote:

- 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.

a b

ok - now it is "zip" file :)

As I say without "readkey()" - everything is wrong.

Richard Phipps

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. :)

a b

I want trust you but when I delete readkey() - everything is wrong :)

tobing

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).

a b

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>
4using namespace std;
5 
6BITMAP *game = NULL;
7BITMAP *bufor = NULL;
8BITMAP *menu = NULL;
9BITMAP *autors=NULL;
10BITMAP *instructions = NULL;
11BITMAP *frame = NULL;
12 
13 
14int go=1;
15int table[4]={215,295,392,550};
16int index=0;
17 
18int meni();
19void autor();
20void instruction();
21void start();
22void end();
23 
24 
25 
26int main()
27{
28allegro_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}
49END_OF_MAIN()
50 
51 
52 
53int meni()
54{
55 while(go!=0)
56{
57clear_to_color(bufor,makecol(255,255,255));
58blit(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 
97void 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 
106void 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 
115void 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}

Albin Engström

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;
}
}

tobing

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.

a b

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

Albin Engström

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??

Evert

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.

a b

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 ?

Evert
Quote:

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 >>.

Quote:

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.

a b

If I good remember:
a= b >> 3

a 0000 1111
b 0000 0001

but "readkey()>>8" - is strange........

and how can we good write this:

readkey();
        while (!key[KEY_ESC]&&!key[KEY_ENTER])
        {
          readkey();
        }

???

Richard Phipps

Read the manual for the keyboard section.. please.

a b

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

#SelectExpand
1#include <iostream> 2#include <allegro.h> 3using namespace std; 4 5BITMAP *game = NULL; 6BITMAP *bufor = NULL; 7BITMAP *menu = NULL; 8BITMAP *autors=NULL; 9BITMAP *instructions = NULL; 10BITMAP *frame = NULL; 11 12 13int go=1; 14int table[4]={215,295,392,550}; 15int index=0; 16 17int meni(); 18void autor(); 19void instruction(); 20void start(); 21void end(); 22 23int k = readkey()>>8; // <------ global variable 24 25 26 27 28 29int main() 30{ 31allegro_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); 41if (meni()==0) 42 { return 0; } 43 44end(); 45return 0; 46} 47END_OF_MAIN() 48 49 50 51 52int meni() 53{ 54 while(go!=0) 55{ 56clear_to_color(bufor,makecol(255,255,255)); 57blit(menu,bufor,0,0,0,0,menu->w,menu->h); 58masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); 59blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 60 61 if ((k==KEY_DOWN)&&index!=3) 62 { 63 64 index++; 65 } 66 else if ((k==KEY_DOWN)&&index==3) 67 { 68 69 index=0; 70 } 71 else if ((k==KEY_UP)&&index!=0) 72 { 73 74 index--; 75 } 76 else if ((k==KEY_UP)&&index==0) 77 { 78 79 index=3; 80 } 81 else if((k==KEY_ENTER)&&index==3){return 0;} 82 else if((k==KEY_ENTER)&&index==0){start();} 83 else if((k==KEY_ENTER)&&index==1){instruction();} 84 else if((k==KEY_ENTER)&&index==2){autor();} 85 86} 87} 88 89 90 91void start() 92{ 93 clear_to_color(bufor,makecol(255,255,255)); 94 blit(game,bufor,0,0,0,0,game->w,game->h); 95 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 96 97 while ((k!=KEY_ESC)&&(k!=KEY_ENTER)) 98 { 99 readkey(); 100 } 101} 102 103 104void instruction() 105{ 106 clear_to_color(bufor,makecol(255,255,255)); 107 blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); 108 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 109 readkey(); 110} 111 112 113void autor() 114{ 115 clear_to_color(bufor,makecol(255,255,255)); 116 blit(autors,bufor,0,0,0,0,autors->w,autors->h); 117 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 118 readkey(); 119} 120 121 122 123 void end() 124{ 125 destroy_bitmap(game); 126 destroy_bitmap(menu); 127 destroy_bitmap(frame); 128 destroy_bitmap(instructions); 129 destroy_bitmap(autors); 130 destroy_bitmap(bufor); 131 allegro_exit(); 132}

I can't write readkey()>>8 in each place in my program because it is going wrong:

#SelectExpand
1#include <iostream> 2#include <allegro.h> 3using namespace std; 4 5BITMAP *game = NULL; 6BITMAP *bufor = NULL; 7BITMAP *menu = NULL; 8BITMAP *autors=NULL; 9BITMAP *instructions = NULL; 10BITMAP *frame = NULL; 11 12 13int go=1; 14int table[4]={215,295,392,550}; 15int index=0; 16 17int meni(); 18void autor(); 19void instruction(); 20void start(); 21void end(); 22 23 24 25 26 27 28 29int main() 30{ 31allegro_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); 41if (meni()==0) 42 { return 0; } 43 44end(); 45return 0; 46} 47END_OF_MAIN() 48 49 50 51 52int meni() 53{ 54 while(go!=0) 55{ 56clear_to_color(bufor,makecol(255,255,255)); 57blit(menu,bufor,0,0,0,0,menu->w,menu->h); 58masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h); 59blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 60 61 if (((readkey()>>8)==KEY_DOWN)&&index!=3) 62 { 63 64 index++; 65 } 66 else if (((readkey()>>8)==KEY_DOWN)&&index==3) 67 { 68 69 index=0; 70 } 71 else if (((readkey()>>8)==KEY_UP)&&index!=0) 72 { 73 74 index--; 75 } 76 else if (((readkey()>>8)==KEY_UP)&&index==0) 77 { 78 79 index=3; 80 } 81 else if(((readkey()>>8)==KEY_ENTER)&&index==3){return 0;} 82 else if(((readkey()>>8)==KEY_ENTER)&&index==0){start();} 83 else if(((readkey()>>8)==KEY_ENTER)&&index==1){instruction();} 84 else if(((readkey()>>8)==KEY_ENTER)&&index==2){autor();} 85 86} 87} 88 89 90 91void start() 92{ 93 clear_to_color(bufor,makecol(255,255,255)); 94 blit(game,bufor,0,0,0,0,game->w,game->h); 95 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 96 97 while ((readkey()>>8!=KEY_ESC)&&(readkey()>>8!=KEY_ENTER)) 98 { 99 readkey(); 100 } 101} 102 103 104void instruction() 105{ 106 clear_to_color(bufor,makecol(255,255,255)); 107 blit(instructions,bufor,0,0,0,0,instructions->w,instructions->h); 108 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 109 readkey(); 110} 111 112 113void autor() 114{ 115 clear_to_color(bufor,makecol(255,255,255)); 116 blit(autors,bufor,0,0,0,0,autors->w,autors->h); 117 blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H); 118 readkey(); 119} 120 121 122 123 void end() 124{ 125 destroy_bitmap(game); 126 destroy_bitmap(menu); 127 destroy_bitmap(frame); 128 destroy_bitmap(instructions); 129 destroy_bitmap(autors); 130 destroy_bitmap(bufor); 131 allegro_exit(); 132}

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.......

LennyLen
X-G said:

Posted on 12-12-2006 3:17 AM

Guys, this is a lost cause. Just... do something better.

Oh how right he was.

a b

LennyLen if you are so intelligent, say me why readkey()>>8 in two programs UP wrong runs.

tobing

Do as Evert (and others) said. READ THE MANUAL.

a b

I readed but it isn't simply when I can't good english........

Richard Phipps

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.

Kauhiz

edit: nvm

a b

Now I use English translator 3 but it isn't very good.

I gave more parentheses, because I thought that this can their fault :)

Richard Phipps

Do it like this:

k = readkey() >> 8;

if ((k == KEY_DOWN) && index!=3)
         {
               
               index++;         
         } 
if ((k == KEY_DOWN) && index == 3)
         {
               
               index=0;         
         }

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?

a b

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

Richard Phipps

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.

http://www.reflectedgames.com/create.html

a b

Richard but I don't understand why I can't do int k = readkey()>>8; global variable

Richard Phipps

Think about it..

You can't call a function like that. And even if you could, it would only work ONCE.

a b

yyyy ????? I have this program in attachment .... and I do not know about what already completely it walks

Richard Phipps

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.

Kauhiz

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...

Evert
Quote:

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.

Quote:

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.

a b

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:

  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; 
        }

okay ??

Richard Phipps

Quote:

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.

Evert

Another hint: you only need to make a very small change to the readkey() call in your original code.

X-G
Quote:

Oh how right he was.

Kauhiz
Quote:

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).

a b

Evert: "you only need to make a very small change to the readkey() call in your original code." - what do you mean ??

Evert

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.

a b
int k = readkey()>>8;
while (k!=KEY_ESC&&k!=KEY_ENTER)
{
k = readkey()>>8;
}

this code runs very very well - so....... ? ? ?

Evert

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.

LennyLen
Quote:

If the code you have now works, what is your question?

He's asking you if he changed the right part.

Evert

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.

LennyLen
Quote:

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.

a b

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 ??

LennyLen
Quote:

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.

Kauhiz

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.

a b

Kauhiz I made that but when I press ESC - nothing do:

1#include <iostream>
2#include <allegro.h>
3using namespace std;
4 
5BITMAP *game = NULL;
6BITMAP *bufor = NULL;
7BITMAP *menu = NULL;
8BITMAP *autors=NULL;
9BITMAP *instructions = NULL;
10BITMAP *frame = NULL;
11 
12 
13int go=1;
14int table[4]={215,295,392,550};
15int index=0;
16 
17void meni();
18void autor();
19void instruction();
20void start();
21void end();
22 
23 
24bool gameRunning = true;
25 
26 
27 
28 
29int main()
30{
31allegro_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 
42int k;
43while(gameRunning)
44{
45meni();
46k = readkey()>>8;
47if(k == KEY_ESC) gameRunning = false;
48}
49
50end();
51return 0;
52}
53END_OF_MAIN()
54 
55 
56 
57 
58void meni()
59{
60int k;
61 while(go!=0)
62{
63clear_to_color(bufor,makecol(255,255,255));
64blit(menu,bufor,0,0,0,0,menu->w,menu->h);
65masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
66blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
67k= 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 
97void 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 
107void 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 
116void 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}

Kauhiz

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?

a b

I try made what you said and I change my code ...... Firstly it was:

1#include <iostream>
2#include <allegro.h>
3using namespace std;
4 
5BITMAP *game = NULL;
6BITMAP *bufor = NULL;
7BITMAP *menu = NULL;
8BITMAP *autors=NULL;
9BITMAP *instructions = NULL;
10BITMAP *frame = NULL;
11 
12 
13int go=1;
14int table[4]={215,295,392,550};
15int index=0;
16 
17int meni();
18void autor();
19void instruction();
20void start();
21void end();
22 
23 
24 
25 
26 
27 
28 
29int main()
30{
31allegro_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);
41if (meni()==0)
42 { return 0; }
43
44end();
45return 0;
46}
47END_OF_MAIN()
48 
49 
50 
51 
52int meni()
53{
54int k;
55 while(go!=0)
56{
57k = readkey()>>8;
58clear_to_color(bufor,makecol(255,255,255));
59blit(menu,bufor,0,0,0,0,menu->w,menu->h);
60masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
61blit(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 
94void 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 }
104SEEING(); // it is define in second code
105}
106 
107 
108void 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 
117void 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[]):

1void SEEING()
2{
3.....................................
4 readkey();
5 while (!key[KEY_ENTER]&&!key[KEY_ESC])
6 {
7 readkey();
8 }
9 something();
10
11}
12 
13 
14void something()
15{
16 if(!key[KEY_ESC])
17 {
18
19 .........................................
20 readkey();
21 }
22}

Just therefore I ask if it possible that that ESC was pressed then the end of programme

Kauhiz

:o 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...

Quote:

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)!!

X-G

Wow, you guys really are a bunch of incurable masochists, aren't you?

Kauhiz

I know, it's bad :(

Richard Phipps

It's soo true! :'(

a b

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.

Richard Phipps

I quit.

Kauhiz

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? >:(

a b

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>
3using namespace std;
4 
5BITMAP *game = NULL;
6BITMAP *bufor = NULL;
7BITMAP *menu = NULL;
8BITMAP *autors=NULL;
9BITMAP *instructions = NULL;
10BITMAP *frame = NULL;
11 
12 
13 
14 
15void meni();
16void autor();
17void instruction();
18void start();
19void end();
20void kaukiz();
21void something();
22 
23 
24 
25 
26 
27int main()
28{
29allegro_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
41meni();
42 
43end();
44return 0;
45}
46END_OF_MAIN()
47 
48 
49 
50 
51 
52 
53 
54void meni()
55{
56int go=1;
57int table[4]={215,295,392,550};
58int index=0;
59int k;
60 while(go!=0)
61{
62clear_to_color(bufor,makecol(255,255,255));
63blit(menu,bufor,0,0,0,0,menu->w,menu->h);
64masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
65blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
66k= 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 
97void 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 
113void kaukiz()
114{
115if(!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 
124void something()
125{
126if(!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 
135void 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 
144void 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}

tobing

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.

Kauhiz

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!).

LennyLen
Quote:

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.

Richard Phipps

ARRRRRRRRRGGGGGGGGGGGGHHHHHHHHHHH!!!!!!

LennyLen

Don't worry Richard, it'll all be okay. After all...

a b said:

I know c++ very well

X-G

You all realize I'm going to be smug about this all week, right?

LennyLen
Quote:

You all realize I'm going to be smug about this all week, right?

And how does that differ from any other week? :P

Kauhiz
LennyLen said:

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?

Evert
a b

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 ;D;D;D;D

hexagon

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:

Quote:

[..]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.

tobing

You better make a zip-File or rar-File with your (complete) code in it and attach that to a posting here.

Kauhiz

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 :P (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.

a b

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.

Richard Phipps

Neee Neee Neee!!

Evert

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.

a b

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() ??

1int main()
2{
3allegro_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
15meni();
16 
17end();
18return 0;
19}
20END_OF_MAIN()
21 
22 
23 
24 
25 
26 
27 
28void meni()
29{
30int go=1;
31int table[4]={215,295,392,550};
32int index=0;
33int k;
34 while(go!=0)
35{
36clear_to_color(bufor,makecol(255,255,255));
37blit(menu,bufor,0,0,0,0,menu->w,menu->h);
38masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
39blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
40k= 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 
71void 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 
87void kaukiz()
88{
89if(!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 
98void something()
99{
100if(!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 
109void 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 
118void 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}

tobing

This guy is really hopeless. I give up.

Kauhiz
Quote:

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.

Quote:

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.

X-G
a b

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 ?

Kauhiz
I said:

In fact every question you have asked so far has been answered and example code has been supplied.

hexagon
Quote:

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.

Albin Engström

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..

Evert
Quote:

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? :)

Quote:

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.

a b

it is code which kaukiz suggest:

1#include <iostream>
2#include <allegro.h>
3using namespace std;
4 
5BITMAP *game = NULL;
6BITMAP *bufor = NULL;
7BITMAP *menu = NULL;
8BITMAP *autors=NULL;
9BITMAP *instructions = NULL;
10BITMAP *frame = NULL;
11 
12 
13 
14 
15void meni();
16void autor();
17void instruction();
18void start();
19void end();
20void kaukiz();
21void something();
22 
23 
24bool gameRunning = true;
25int k;
26 
27int main()
28{
29allegro_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 
40while(gameRunning)
41{
42meni();
43if(k == KEY_ESC) gameRunning = false;
44}
45end();
46return 0;
47}
48END_OF_MAIN()
49 
50 
51 
52 
53 
54 
55 
56void meni()
57{
58int go=1;
59int table[4]={215,295,392,550};
60int index=0;
61
62 while(go!=0)
63{
64clear_to_color(bufor,makecol(255,255,255));
65blit(menu,bufor,0,0,0,0,menu->w,menu->h);
66masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
67blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
68k= 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 
99void 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 
115void kaukiz()
116{
117if(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 
126void something()
127{
128if(!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 
137void 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 
146void 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.

Richard Phipps

I cry Punk!

Evert

Try using a different word for "bad" when someone's suggestion does not do what you want it to do.

Quote:

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.

Quote:

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.

GullRaDriel

What Evert was thinking ( For the closing part )

1#include <allegro.h>
2 
3 
4 
5BITMAP *scrbuf;
6 
7 
8 
9int DONE = 0; /* will take the value 1 if someone wanna exit */
10 
11 
12 
13void 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 
19int 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)

_

LennyLen
Quote:

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.

Quote:

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.

Kauhiz
Quote:

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 :-X...
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.

a b

So you want that my code will be:

1#include <iostream>
2#include <allegro.h>
3using namespace std;
4 
5BITMAP *game = NULL;
6BITMAP *bufor = NULL;
7BITMAP *menu = NULL;
8BITMAP *autors=NULL;
9BITMAP *instructions = NULL;
10BITMAP *frame = NULL;
11 
12 
13 
14 
15void meni();
16void autor();
17void instruction();
18void start();
19void end();
20void kaukiz();
21void something();
22 
23 
24bool gameRunning = true;
25int k;
26int go=1;
27 
28 
29int main()
30{
31allegro_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 :))))))))))))))))
43aa:
44meni();
45 
46 
47while(!key[ KEY_ESC ]&&go==2)
48{
49start();
50kaukiz();
51something();
52}
53while(!key[ KEY_ESC ]&&go==3)
54{
55autor();
56go=1;
57goto aa;
58
59}
60while(!key[ KEY_ESC ]&&go==4)
61{
62instruction();
63go=1;
64goto aa;
65
66}
67end();
68return 0;
69}
70END_OF_MAIN()
71 
72 
73 
74 
75 
76 
77 
78void meni()
79{
80 
81int table[4]={215,295,392,550};
82int index=0;
83
84 while(go!=0&&go!=2&&go!=3&&go!=4)
85{
86clear_to_color(bufor,makecol(255,255,255));
87blit(menu,bufor,0,0,0,0,menu->w,menu->h);
88masked_blit(frame,bufor, 0,0, 80,table[index],frame->w,frame->h);
89blit(bufor,screen,0,0,0,0,SCREEN_W,SCREEN_H);
90k= 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 
122void 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 
139void kaukiz()
140{
141if(key[KEY_ESC]){go=0;} //I must check if somebody don't press ESC in last pressing key
142else
143{
144 //here is something
145 k = readkey()>>8;
146 something();
147}
148
149}
150 
151 
152void something()
153{
154if(key[KEY_ESC]){go=0;} //I must check if somebody don't press ESC in last pressing key
155else
156{
157k = readkey()>>8; //here is something
158}
159
160}
161 
162 
163 
164void 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 
174void 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 .................

Evert

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.

tobing

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.

Richard Phipps

He has no understanding, that's the problem.

Evert
Quote:

I would like an option to ignore a thread

Isn't that what "hide thread" is for?

piccolo

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)

a b

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 :/

........

piccolo

here is one ways to fix

1void 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

Evert

If you want to fix anything you can start by not discarding the return values of readkey().

Quote:

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!

piccolo

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();}

Kauhiz

trance?

piccolo

interpretation

hexagon

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

piccolo

quote: they both are tools to do the same thing in 2 different ways.

Evert

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.

hexagon

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.

piccolo

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.

Jonatan Hedborg

In your first example, the program would halt at "val = readkey();", until a key is pressed. The other one would not. Not the same.

Richard Phipps

It is not the same Piccolo.

Michael Faerber

Man, I think I've never seen so many crazy people on a thread before! :o

LennyLen
Quote:

Man, I think I've never seen so many crazy people on a thread before!

Hey! I mean, who... that is... oh, never mind.

a b

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:

readkey();
if(key[KEY_0])

should be:

int k = readkey()>>8;
 k = readkey()>>8;
if(k==KEY_0)

???????? yes ??????????
If I understand: http://www.allegro.cc/manual/api/keyboard-routines/readkey thanks ">>8" I can use "key+key" yes ??

Evert
Quote:

1. so should I change readkey() to keypressed() ?

No!
Read the manual on what each of these functions do.

Quote:

3. This:
[...]
should be:

Yes. Sortof. You should only call readkey() once, not twice at that point. Read the keypressed() manual entry.

Quote:

thanks ">>8" I can use "key+key" yes ??

I don't understand what you mean.

LennyLen

You didn't answer question 2, Evert. :-*

Jonatan Hedborg
Quote:

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!

Kauhiz

Yeah, like I said, we're getting Punk'd and this guy is having a blast :-/

a b

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 :D

Evert
Quote:

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.

Quote:

thanks ">>8" I can use for example "ctr+shift" (keyboard shortcuts) yes ??

No!

TFM said:

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.

Kauhiz
Quote:

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.

Quote:

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.

Quote:

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.

Quote:

PS. Jonatan Hedborg I don't like Germany :D

WTF?

a b

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 ?

Jonatan Hedborg
Quote:

PS. Jonatan Hedborg I don't like Sweden :D

that was random, even for you.

For the record: I don't like you.

Kauhiz
Quote:

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!

Richard Phipps

It's now 140 posts (with this one) to try to resolve this question.. :)

a b

but why in "k = readkey()>>8;" is "8" ?? why bite shift in right is "8" ??

Evert

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?

Richard Phipps

Because >> 8 is one byte and readkey() returns a word (2 bytes):

Quote:

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

Jonatan Hedborg

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...

piccolo

[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.

Kauhiz

But you're still discarding the return value of readkey() which is wrong.

Quote:

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 :)

piccolo

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)

Kauhiz
Quote:

(now that he knows of them)

We could have a whole nother debate on this point...

a b

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

Kikaru

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. :)

Kauhiz

Think about it! readkey()>>16 would be 00000000 00000000!

GullRaDriel

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

a b

ok thanks :)

And if I want that game will stop untill somebody press ENTER or ESC can I write that ???

 int k; 
         k= readkey()>>8; 
        
        while (k==KEY_ESC&&k==KEY_ENTER)
        {
          k= readkey()>>8;
        }
................

Evert

Spot the mistake:

Quote:

ENTER or ESC

Quote:

(k==KEY_ESC&&k==KEY_ENTER)

LennyLen
Quote:

Spot the mistake:

puts hand up Me sir, me!!!

a b

sorry I shoulded write "AND" :) hehhe
ok thanks :)

LennyLen
Quote:

sorry I shoulded write "AND"

You mean you want them to have to press both keys at the same time?!?!

Richard Phipps

Quote:

sorry I shoulded write "AND" :) hehhe

Richard casts Knights of the Round on a b

Kauhiz
Quote:

You mean you want them to have to press both keys at the same time?!?!

I think he means he shouldn't have written &&.

a b

"and" but I wrong write because in the past I had:

readkey();
        while (!key[KEY_ESC]&&!key[KEY_ENTER])
        {
          readkey();
        }

so now it should be:

   int k; 
         k= readkey()>>8; 
        
        while (k!=KEY_ESC&&k!=KEY_ENTER)  //previous I had wrong write: //k==KEY_ESC&&k==KEY_ENTER :)
        {
          k= readkey()>>8;
        }

sorrrrrrrry - little mistake :)

Kauhiz

So you do want the player to press two keys!?

a b

I want that somebody pressing keys while key is diffrent from ESC and diffrent from ENTER

Richard Phipps

I'm confused..

LennyLen

Actually, his code is right, since NOT(a OR b) = NOT(a) AND NOT(b).

Richard Phipps

Hurrah!

a b

:)

LennyLen

It might have made more sense to people if you'd expressed it this way:

while (!(k == KEY_ESC || k == KEY_ENTER))

a b

ok thanks :)

Kauhiz

Oh, true. Does this mean that the problem has been solved!?!? The thread is over! :o

a b

yes.........

Richard Phipps

Noooo!! :-*

LennyLen

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.

X-G

De Morgan's laws. Now for the love of all that is unholy, let this topic die. It makes baby Eris cry.

LennyLen

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!

Quote:

Now for the love of all that is unholy, let this topic die.

This thread is too unholy to die. It's undead.

Richard Phipps

And it needs brains to survive!

Evert

So do we get credit for helping out?

piccolo

none needed for me.
all in a days work for KING PICCOLO;D8-)

edit: ill take a chocolate chip if you have any:P

Kauhiz

THIS THREAD WILL NEVER DIE! ... or so it seems

a b

I am working and working on my game :) :) :)

Kauhiz

Random! Random!

Oh, btw, what kind of game is it?

GullRaDriel

... please ... lock ... this ... ... threaaaad ! argh

James Stanley

I bet it's a card game.

Thread #589465. Printed from Allegro.cc