hello!
I am working on my project and making checkers game.Uptill now i have just uploaded checkers board image and interface mouse.The problem is that how could i select a particular position(x,y coordinates) through mouse.I need just a little help and i will go for it.Here is my code.
Code:#include <allegro.h> int x = 50; int y = 680; void init(); void deinit(); BITMAP* buffer; int cursor_x = 20; int cursor_y = 20; int getMouseInfo(){ if((mouse_b & 2) &&(mouse_b & 1) && (mouse_b & 3)) { cursor_x = mouse_x; cursor_y = mouse_y; return 1; } return 0; } void updateScreen(){ show_mouse(screen); circlefill ( buffer, cursor_x, cursor_y, 5, makecol( 0, 0, 0)); draw_sprite( screen, buffer, 0, 0); } int main() { init(); while (!key[KEY_ESC]) { getMouseInfo(); updateScreen(); clear_keybuf(); acquire_screen(); textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 0, 0, 0) ); textout_ex( screen, font, "Your time", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) ); release_screen(); rest(50); } deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); BITMAP *my_pic = NULL; //Declare a BITMAP called my_pic, setting it to NULL my_pic = load_bitmap("checkers.bmp", NULL); // Load our picture blit(my_pic, screen, 0,0,180,120,2000,2000);//Draw the whole bitmap to the screen at ( buffer = create_bitmap( 1024, 768); show_mouse(screen); while( !key[KEY_ESC]) { int switcher=1; while(getMouseInfo()) { updateScreen(); if(getMouseInfo()==0) switcher=0; } if(switcher==0) show_mouse(screen); } } void deinit() { clear_keybuf(); /* add other deinitializations here */ }



LinkBack URL
About LinkBacks


