Archived

This topic is now archived and is closed to further replies.

flags arent working right, please help, thx

This topic is 5966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, for some reason...the menus for my game keep drawing over the mouse...and i do not see why. here is the code, thanks for any help =) void drawInterface(void) { flag.f1 = true; //main menu flag.f2 = false; //p1 menu flag.f3 = false; //p2 menu flag.f4 = false; //credits flag.f5 = false; //exit if(flag.f1 == true) { flag.ff1 = true; flag.ff2 = false; flag.ff3 = false; flag.ff4 = false; flag.ff5 = false; scare_mouse(); clear(buffer); text_mode(-1); draw_sprite(buffer, menubg, 0, 0); textout_centre(buffer, font, "1 Player", 320, 150, makecol(0, 0, 255) ); textout_centre(buffer, font, "2 Player", 320, 170, makecol(0, 0, 255) ); textout_centre(buffer, font, "Credits", 320, 190, makecol(0, 0, 255) ); textout_centre(buffer, font, "Exit", 320, 210, makecol(0, 0, 255) ); blit(buffer, screen, 0, 0, 0, 0, 640, 480); unscare_mouse(); flag.f1 = false; } if(flag.f2 == true) { flag.ff1 = false; flag.ff2 = true; flag.ff3 = false; flag.ff4 = false; flag.ff5 = false; scare_mouse(); clear(buffer); text_mode(-1); draw_sprite(buffer, menubg, 0, 0); textout_centre(buffer, font, "1 Player Mode:", 320, 150, makecol(0, 0, 255) ); textout_centre(buffer, font, "Build Car", 320, 170, makecol(0, 0, 255) ); textout_centre(buffer, font, "Select PreBuilt Car", 320, 190, makecol(0, 0, 255) ); textout_centre(buffer, font, "Back", 320, 210, makecol(0, 0, 255) ); blit(buffer, screen, 0, 0, 0, 0, 640, 480); unscare_mouse(); flag.f2 = false; } if(flag.f3 == true) { flag.ff1 = false; flag.ff2 = false; flag.ff3 = true; flag.ff4 = false; flag.ff5 = false; scare_mouse(); clear(buffer); text_mode(-1); draw_sprite(buffer, menubg, 0, 0); textout_centre(buffer, font, "2 Player Mode:", 320, 150, makecol(0, 0, 255) ); textout_centre(buffer, font, "Player 1 - Build Car", 320, 170, makecol(0, 0, 255) ); textout_centre(buffer, font, "Player 1 - Select PreBuilt Car", 320, 190, makecol(0, 0, 255) ); textout_centre(buffer, font, "Player 2 - Build Car", 320, 210, makecol(0, 0, 255) ); textout_centre(buffer, font, "Player 2 - Select PreBuilt Car", 320, 230, makecol(0, 0, 255) ); textout_centre(buffer, font, "Back", 320, 250, makecol(0, 0, 255) ); blit(buffer, screen, 0, 0, 0, 0, 640, 480); unscare_mouse(); flag.f3 = false; } if(flag.f4 == true) { flag.ff1 = false; flag.ff2 = false; flag.ff3 = false; flag.ff4 = true; flag.ff5 = false; scare_mouse(); clear(buffer); text_mode(-1); draw_sprite(buffer, menubg, 0, 0); textout_centre(buffer, font, "Extream Racing Credits:", 320, 150, makecol(0, 0, 255) ); textout_centre(buffer, font, "Programmers - blyind", 320, 170, makecol(0, 0, 255) ); textout_centre(buffer, font, "Ideas - blyind", 320, 190, makecol(0, 0, 255) ); textout_centre(buffer, font, "Graphics - blyind", 320, 210, makecol(0, 0, 255) ); textout_centre(buffer, font, "Tile Engine - Andrew Deren, I modified it to fit my needs", 320, 230, makecol(0, 0, 255) ); textout_centre(buffer, font, "Contact - my(blyind) icq is 66154327, my aim is blyind4, and my email is blyind@hotmail.com", 320, 250, makecol(0, 0, 255) ); textout_centre(buffer, font, "Back", 320, 250, makecol(0, 0, 255) ); blit(buffer, screen, 0, 0, 0, 0, 640, 480); unscare_mouse(); flag.f4 = false; } if(flag.f5 == true) { flag.ff1 = false; flag.ff2 = false; flag.ff3 = false; flag.ff4 = false; flag.ff5 = true; scare_mouse(); clear(buffer); text_mode(-1); draw_sprite(buffer, menubg, 0, 0); textout_centre(buffer, font, "Bye", 320, 250, makecol(0, 0, 255) ); blit(buffer, screen, 0, 0, 0, 0, 640, 480); allegro_exit(); cout << "Thanks For Playing Extream Racing!" << endl; flag.f5 = false; } // now this is the part where i use another set of flags to enable the mouse clicking on the menus if( flag.ff1 == true ) { if( ( mouse_x < 300 ) && ( mouse_x > 340 ) && ( mouse_y > 140 ) && ( mouse_y < 160 ) ) { if(mouse_b & 1) { flag.f1 = false; flag.f2 = true; flag.f3 = false; flag.f4 = false; flag.f5 = false; } } if( ( mouse_x < 300 ) && ( mouse_x > 340 ) && ( mouse_y > 160 ) && ( mouse_y < 180 ) ) { if(mouse_b & 1) { flag.f1 = false; flag.f2 = false; flag.f3 = true; flag.f4 = false; flag.f5 = false; } } if( ( mouse_x < 300 ) && ( mouse_x > 340 ) && ( mouse_y > 180 ) && ( mouse_y < 200 ) ) { if(mouse_b & 1) { flag.f1 = false; flag.f2 = false; flag.f3 = false; flag.f4 = true; flag.f5 = false; } } if( ( mouse_x < 300 ) && ( mouse_x > 340 ) && ( mouse_y > 200 ) && ( mouse_y < 220 ) ) { if(mouse_b & 1) { flag.f1 = false; flag.f2 = false; flag.f3 = false; flag.f4 = false; flag.f5 = true; } } } }

Share this post


Link to post
Share on other sites
Thanks for the spaghetti, but I just ate.

Your states are all mutually exclusive, no reason to put them into a bitmapped struct (or whatever it is flags is). Replace them with an enumeration, then replace the if statements with a switch. I think after doing that the code will be easier to digest and the bug easier to find.

Share this post


Link to post
Share on other sites