Rabbcio Temat założony przez niniejszego użytkownika |
<Allegro> Myszka-Chodzenie » 2009-10-15 00:15:40 Myślałem nad chodzeniem za pomocą myszki... I napisałem pewien kod.... #include <allegro.h>
void init(); volatile long TimerV = 0; void Timer() { TimerV++; } int speed = 1; int frame = 0; int msx; int msy; int mx = 0, my = 0, mb = 0; int Postac_x = 320, Postac_y = 240; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } }; bool click() { }
int main() { init(); BITMAP * Bufor = NULL; BITMAP * Postac = load_bitmap( "Postac.bmp", default_palette );; Bufor = create_bitmap( 640, 480 ); while( !key[ KEY_ESC ] ) { if( TimerV > 0 ) { if( mb == 1 ) { frame++; if( frame == 1 ) { msx = mx; msy = my; while( Postac_x != msx || Postac_y != msy ) { if( Postac_x > msx ) Postac_x = Postac_x - speed; if( Postac_x < msx ) Postac_x = Postac_x + speed; if( Postac_y > msy ) Postac_y = Postac_y - speed; if( Postac_y < msy ) Postac_y = Postac_y + speed; } } } else if( mb = 1 ) frame = 0; TimerV--; } clear_to_color( Bufor, makecol( 100, 100, 100 ) ); myszka(); masked_blit( Postac, Bufor, 0, 0, Postac_x, Postac_y, 32, 32 ); textprintf_ex( Bufor, font, 20, 20, makecol( 200, 200, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb ); textprintf_ex( Bufor, font, 20, 40, makecol( 200, 200, 200 ), - 1, "Kliknieta x = %d, y = %d, klawisz = %d !", msx, msy ); blit( Bufor, screen, 0, 0, 0, 0, 800, 600 ); clear_keybuf(); } readkey(); } END_OF_MAIN();
void init() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ); install_timer(); install_int_ex( Timer, BPS_TO_TIMER( 100 ) ); install_mouse(); show_mouse( screen ); unscare_mouse(); }
No i niby wszystko działa, ale.. Postać zamiast iść to się "teleportuje"... I nie wiem właśnie czemu... Więc może wy wiecie??Xd |