PhonniX Temat założony przez niniejszego użytkownika  | 
[Allegro] Strzelanka » 2009-05-22 08:58:22 Witam. Właśnie zacząłem robić strzelankę mam problem, pocisk nie leci tylko porusza sie cały czas za kursorem nie wiem jak to naprawić proszę o pomoc. #include <allegro.h>
 
 
  volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
 
  int mx = 0, my = 0, mb = 0; int startx = 100, starty = 100; int ix = 0, iy = 0;
  void myszka() {     if( mx != mouse_x || my != mouse_y || mb != mouse_b )     {         mx = mouse_x;         my = mouse_y;         mb = mouse_b;     } };
  int main() {     allegro_init();     install_keyboard();     set_color_depth( 16 );     set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 );     install_timer();     install_int_ex( increment_speed, BPS_TO_TIMER( 100 ) );          install_mouse();     show_mouse( screen );     unscare_mouse();     BITMAP * bufor = NULL;     BITMAP * x = NULL;     bufor = create_bitmap( 800, 600 );     x = load_bmp( "x.bmp", default_palette );     while( !key[ KEY_ESC ] )     {                  clear_to_color( bufor, makecol( 100, 100, 100 ) );         myszka();         while( speed <= 0 )         {             if( mb == 1 )             {                                                   while( iy != my || ix != mx )                 {                     if( iy < my )                     {                         iy++;                     }                     if( iy > my )                     {                         iy--;                     }                     if( ix > mx )                     {                         ix--;                     }                     if( ix < mx )                     {                         ix++;                     }                                      }                                  textprintf_ex( bufor, font, 200, 200, makecol( 200, 200, 200 ), - 1, "Shot" );                 masked_blit( x, bufor, 0, 0, ix, iy, 200, 200 );             }             textprintf_ex( bufor, font, 20, 20, makecol( 200, 200, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb );             blit( bufor, screen, 0, 0, 0, 0, 800, 600 );             clear_keybuf();                      }         speed -= 2;     }          destroy_bitmap( bufor );     allegro_exit();     return 0; } END_OF_MAIN();
   | 
 | 
DejaVu  | 
» 2009-05-22 09:08:06  | 
 | 
PhonniX Temat założony przez niniejszego użytkownika  | 
» 2009-05-22 14:33:53 Dobra zrobiłem już, że pocisk "leci", ale jakoś krzywo: #include <allegro.h>
 
 
  volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
 
  int mx = 0, my = 0, mb = 0; int ix = 0, iy = 0; int celx = 0, cely = 0;
  void myszka() {     if( mx != mouse_x || my != mouse_y || mb != mouse_b )     {         mx = mouse_x;         my = mouse_y;         mb = mouse_b;     } };
  int main() {     allegro_init();     install_keyboard();     set_color_depth( 16 );     set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 );     install_timer();     install_int_ex( increment_speed, BPS_TO_TIMER( 1000 ) );          install_mouse();     show_mouse( screen );     unscare_mouse();     BITMAP * bufor = NULL;     BITMAP * x = NULL;     bufor = create_bitmap( 800, 600 );     x = load_bmp( "x.bmp", default_palette );     while( !key[ KEY_ESC ] )     {                           clear_to_color( bufor, makecol( 150, 150, 150 ) );         myszka();         masked_blit( x, bufor, 0, 0, ix, iy, 200, 200 );                                             while( speed > 0 )         {                          if( mb == 1 )             {                 celx = mx;                 cely = my;             }             if( iy != cely || ix != celx )             {                 if( iy < cely )                 {                     iy += 1;                 }                 if( iy > cely )                 {                     iy -= 1;                 }                 if( ix > celx )                 {                     ix -= 1;                 }                 if( ix < celx )                 {                     ix += 1;                 }             }                                       speed--;                      }         textprintf_ex( bufor, font, 20, 20, makecol( 200, 200, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb );         blit( bufor, screen, 0, 0, 0, 0, 800, 600 );         clear_keybuf();     }          destroy_bitmap( bufor );     allegro_exit();     return 0;                } END_OF_MAIN();
   | 
 | 
DejaVu  | 
» 2009-05-22 19:46:18 Coś jeszcze w takim razie oczekujesz od nas, czy już wszystko jest si?  | 
 | 
PhonniX Temat założony przez niniejszego użytkownika  | 
» 2009-05-22 20:33:33 Pocisk leci krzywo, nie powinno być tak, nie jest si.  | 
 | 
DejaVu  | 
» 2009-05-22 21:49:20 Zatrzymywanie pocisku już sobie sam dorób. #include <allegro.h> #include <cmath>
 
 
  volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
 
  int mx = 0, my = 0, mb = 0; double ix = 400, iy = 300; int celx = ix, cely = iy;
  void myszka() {     if( mx != mouse_x || my != mouse_y || mb != mouse_b )     {         mx = mouse_x;         my = mouse_y;         mb = mouse_b;     } };
  int main() {     allegro_init();     install_keyboard();     set_color_depth( 16 );     set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 );     install_timer();     install_int_ex( increment_speed, BPS_TO_TIMER( 1000 ) );          install_mouse();     show_mouse( screen );     unscare_mouse();     BITMAP * bufor = NULL;     BITMAP * x = NULL;     bufor = create_bitmap( 800, 600 );     x = load_bmp( "strzal.bmp", default_palette );          double predkosc = 0.5;     double kat;               while( !key[ KEY_ESC ] )     {                           clear_to_color( bufor, makecol( 150, 150, 150 ) );         myszka();         masked_blit( x, bufor, 0, 0,( int ) ix,( int ) iy, 200, 200 );                                             textprintf_ex( bufor, font, 40, 40, makecol( 200, 200, 200 ), - 1, "deltaX = %d, deltaY = %d !",( int ) iy - cely,( int ) ix - celx );         while( speed > 0 )         {                          if( mb == 1 )             {                 celx = mx;                 cely = my;                 double deltaX = ix - celx;                 double deltaY = iy - cely;                                  if(( deltaY ) == 0 )                 {                     kat = 0;                 } else                 {                     kat = atan(( deltaX ) /( deltaY ) );                 }                                   if( deltaY >= 0 )                 {                     kat += M_PI;                 }                               }                                       if( iy != cely || ix != celx )             {                 ix += sin( kat ) * predkosc;                 iy += cos( kat ) * predkosc;             }                                       speed--;                      }         textprintf_ex( bufor, font, 20, 20, makecol( 200, 200, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb );         blit( bufor, screen, 0, 0, 0, 0, 800, 600 );         clear_keybuf();     }          destroy_bitmap( bufor );     allegro_exit();     return 0;                } END_OF_MAIN();
   | 
 | 
PhonniX Temat założony przez niniejszego użytkownika  | 
» 2009-05-22 22:24:36 Chyba coś nie tak, bo wyskakuje błąd aplikacji :/  | 
 | 
DejaVu  | 
» 2009-05-23 03:26:00 Błąd aplikacji jest z tego powodu, że Twój plik z bitmapą inaczej się nazywa niż mój.  | 
 | 
|  « 1 »  2 |