Con Allegro se me ve raro

Tratamos sobre el manejo de APIs frecuentemente utilizadas en el desarrollo de videojuegos, como SDL, pygame o SFML.

Con Allegro se me ve raro

Notapor Demenus » Jue Ene 08, 2009 4:10 am

Muy buenas a todos, estoy recien empezando y este es mi primer post ademas.
El caso es que ando haciendo un Space Invaders con allegro y C pero noto que al mover la nave que en mitad del movimiento se ve y no se ve a la vez, se pone en modo fantasmagorico
Hice ya uno con Python y Pygame y no vi nunca ese efecto, y sin embargo ahora...
Ando usando doble buffering y la verdad no se otra manera mejor de implementar eso que estoy buscando para que no parpadee
En fin, os dejo el code a ver si algún erudito me ilumina

Código: Seleccionar todo
#include<allegro.h>
#include<stdio.h>

void iniciar()
   {
   allegro_init();
   
   set_color_depth(16);
   if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0)<0)
      {
      printf("Error al iniciar el modo grafico");
      allegro_exit();
      }
   install_keyboard();
   
   }
   
void terminar()
   {
   allegro_exit();
   }
   

void realizar_juego()
{

   
    /*Declaracion de variables*/
    BITMAP *nave,*fondo,*laser;
    PALETTE paleta;
    int x,y, x_anterior, y_anterior, lasery, laserx, chivato;
    BITMAP *buffer,*buffer2;
   
    /*Carga de imagenes*/
    fondo=load_bitmap("/home/demenus/Escritorio/background.bmp",paleta);
    nave=load_bitmap("/home/demenus/Escritorio/xwing.bmp", paleta);
    laser=load_bitmap("/home/demenus/Escritorio/rebel_laser.bmp",paleta);
    set_palette(paleta);
    buffer=create_bitmap(800,600);
   
   
    /*Verificaciones*/
    if (nave==NULL) terminar();
    if (fondo==NULL) terminar();
    if (laser==NULL) terminar();
    if (buffer==NULL) terminar();

    x=SCREEN_W/2;
    y=SCREEN_H/2;
   
   
   
    /*main loop*/
    while (!key[KEY_ESC])
    {   
   
/*Controles*/
        if (key[KEY_UP])
            y=y-3;
        if (key[KEY_DOWN])
            y=y+3;
        if (key[KEY_LEFT])
            x=x-3;
        if (key[KEY_RIGHT])
            x=x+3;       
        if (x<0) x=x_anterior;
        if (x>SCREEN_W-nave->w)    x=x_anterior;
        if (y<0) y=y_anterior;
        if (y>SCREEN_H-nave->h) y=y_anterior;
       
        if (key[KEY_SPACE] && chivato==0)
            {    
            lasery=y-nave->h/2;
            laserx=x+nave->w/2;
            draw_sprite(buffer,laser,laserx,lasery);
            chivato=1;
            }
/*Controles*/           
        {   
            blit(fondo,buffer,0,0,0,0,fondo->w,fondo->h);
            draw_sprite(buffer,nave,x,y);
            if (chivato=1)
               {
               draw_sprite(buffer,laser,laserx,lasery);
               lasery=lasery-3;
               if (laser->h+lasery<=0) chivato=0;
               }
            blit(buffer,screen,0,0,0,0,800,600);
            clear_bitmap(buffer);


        }
        x_anterior=x;
        y_anterior=y;
        }
       
   destroy_bitmap(fondo);
   destroy_bitmap(laser);
   destroy_bitmap(nave);
}

   
int main()
   {
   iniciar();
   realizar_juego();
   
   readkey();

   allegro_exit();
   return 0;
   }
END_OF_MAIN();
   



Espero ir bien en todo esto k ando haciendo =____=
Avatar de Usuario
Demenus
 
Mensajes: 2
Registrado: Jue Ene 08, 2009 3:49 am

Volver a Sobre las bibliotecas multimedia

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 1 invitado