SoloCodigo

Programación Específica => Programación de Videojuegos => Allegro => Mensaje iniciado por: seov en Miércoles 12 de Abril de 2006, 03:56

Título: Mover Un Bitmap
Publicado por: seov en Miércoles 12 de Abril de 2006, 03:56
Hola a todos!!!! :P

tengo un problemilla.........o mejor una duda ya que no se hacerlo.jijijij :huh:

El problemas es que estoy haciendo un juego en el que hay una tabla, una pelota y unos ladrillo.....se supone que la pelota deberia moverse por la ventana y rebotar con los bordes de la ventana y si choca con la tabla que es la que mueve el jugador podemos dirigir la pelota......el problema me viene cuando quiero animar la pelota.....no se como hacerlo........y no se como hacerlo para que se vea como que rebota........estoy trabajando con detección de colisiones rectangulares si me pueden ayudar a mover la pelota se los agradeceria......aca va lo que yo pensaba que podia mover la pelota :P ....

Código: Text
  1.  
  2. #include <allegro.h>
  3.  
  4. void init();
  5. void deinit();
  6.  
  7. int main()
  8. {
  9.     init();
  10.     BITMAP *pelota;
  11.     BITMAP *bufer;
  12.     PALETTE paleta;
  13.    
  14.     int x_anterior;
  15.     int y_anterior;
  16.     int x,y,sel;
  17.     int guar_x;
  18.     int guar_y;
  19.    
  20.     pelota=load_bitmap("pelota.bmp",paleta);
  21.    
  22.     pelota=load_bitmap("pelota.bmp",paleta);
  23.     set_palette(paleta);
  24.    
  25.      if(pelota==NULL)
  26.         deinit();
  27.      
  28.      bufer=create_bitmap(pelota->w,pelota->h);
  29.      
  30.      clear(bufer);
  31.      
  32.      if(bufer==NULL)
  33.         deinit();
  34.      
  35.      x=SCREEN_W/2;
  36.      y=SCREEN_H/2;
  37.  
  38.      while (!key[KEY_ESC])
  39.      {            
  40.        
  41.        if(x>guar_x)
  42.        {
  43.           guar_x=x;
  44.           x++;
  45.        }
  46.        if(x<guar_x)
  47.        {
  48.           guar_x=x;
  49.           x--;
  50.        }
  51.        if(y<guar_y)
  52.        {
  53.           guar_y=y;
  54.           y--;
  55.        }
  56.        if(y>guar_y)
  57.        {
  58.           guar_y=y;
  59.           y++;
  60.        }
  61.        
  62.        if(x>=SCREEN_W-pelota->w)
  63.           x--;
  64.        else if(x<=0)
  65.           x++;
  66.        else if(y>=SCREEN_H-pelota->h)
  67.           y--;
  68.        else if(y<=0)
  69.           y++;
  70.        else
  71.        {
  72.           x--;
  73.           y++;
  74.       }
  75.      
  76.            
  77.        blit(bufer,screen,0,0,x_anterior,y_anterior,bufer->w,bufer->h);
  78.        blit(screen,bufer,x,y,0,0,bufer->w,bufer->h);
  79.                                        
  80.        draw_sprite(screen,pelota,x,y);
  81.      
  82.        vsync();//espera a que se muestre toda la imagen en pantalla
  83.                      //para escribir la otra
  84.          
  85.      
  86.           x_anterior=x;
  87.           y_anterior=y;
  88.      }
  89.      deinit();
  90.      return 0;
  91. }END_OF_MAIN();
  92.  
  93. void deinit()
  94. {
  95.   clear_keybuf();
  96.   /* añadir otras desintalaciones */
  97.   allegro_exit();
  98. }
  99.  
  100. void init()
  101. {
  102.   int depth, res;
  103.   allegro_init();
  104.   depth = desktop_color_depth();
  105.   if (depth == 0)
  106.         depth = 32;
  107.   set_color_depth(depth);
  108.   res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 400, 0, 0);
  109.   if (res != 0)
  110.     {
  111.     allegro_message(allegro_error);
  112.     exit(-1);
  113.     }
  114.     install_keyboard();
  115. }
  116.  
Título: Re: Mover Un Bitmap
Publicado por: seov en Jueves 13 de Abril de 2006, 20:02
jajajajaja :D

amigos no se preocupen .............ya encontre la forma en que se hacia .........jiiii........es más sencillo de lo que yo me imaginaba........jajajaaja B)
les dejo el codigo por si a alguien le sirve..........chauuuuuuu.....

/*hace rebotar una pelota por una ventana*/



#include <allegro.h>

void init();
void deinit();

int main()
{
    init();
    BITMAP *pelota;
    BITMAP *bufer;
    PALETTE paleta;
   
    int x_anterior;
    int y_anterior;
    int x,y,sel;
    int guar_x;
    int guar_y;
   
    pelota=load_bitmap("pelota.bmp",paleta);
   
    pelota=load_bitmap("pelota.bmp",paleta);
    set_palette(paleta);
   
     if(pelota==NULL)
        deinit();
     
     bufer=create_bitmap(pelota->w,pelota->h);
     
     clear(bufer);
     
     if(bufer==NULL)
        deinit();
     
     x=SCREEN_W/2;
     y=SCREEN_H/2;

     guar_x=SCREEN_W/2-1;
     guar_y=SCREEN_W/2+1;
     while (!key[KEY_ESC])
     {            
       
       if(x>guar_x)
       {
          guar_x=x;
          if(x>=SCREEN_W-pelota->w)
             x--;
          else
             x++;
       }
       if(x<guar_x)
       {
          guar_x=x;
          if(x<=SCREEN_W-SCREEN_W)
             x++;
          else
             x--;
       }
       if(y<guar_y)
       {
          guar_y=y;
          if(y<=0)
             y++;
          else
             y--;
       }
       if(y>guar_y)
       {
          guar_y=y;
          if(y>=SCREEN_H-pelota->h)
             y--;
          else
             y++;
       }
       
       
     
     
           
       blit(bufer,screen,0,0,x_anterior,y_anterior,bufer->w,bufer->h);
       blit(screen,bufer,x,y,0,0,bufer->w,bufer->h);
                                       
       draw_sprite(screen,pelota,x,y);
     
       vsync();//espera a que se muestre toda la imagen en pantalla
                     //para escribir la otra
         
     
          x_anterior=x;
          y_anterior=y;
     }
     deinit();
     return 0;
}END_OF_MAIN();

void deinit()
{
   clear_keybuf();
   /* añadir otras desintalaciones */
   allegro_exit();
}

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_WINDOWED, 320, 400, 0, 0);
   if (res != 0)
    {
      allegro_message(allegro_error);
      exit(-1);
    }
    install_keyboard();
}