Advertisement
tapette101

Allegro swap animation with crash guaranteed !

Jun 22nd, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <allegro.h>
  4.  
  5.  
  6. echanger_gauche_droite(char tab,int i,int j,BITMAP* sprite1,BITMAP* sprite2,BITMAP* buffer){
  7.     double pos_x, pos_y;
  8.     double pos_x_bis, pos_y_bis;
  9.     pos_x = 95+i*36; pos_y = 95+j*36; pos_x_bis = 95+(i+1)*36; pos_y_bis = 95+j*36;
  10.     clear_bitmap(buffer);
  11.  
  12.     while(pos_x <= pos_x+36){
  13.         while(pos_x_bis >= pos_x-36){
  14.             pos_x += 0.5;
  15.             pos_x_bis -= 0.5;
  16.             clear_bitmap(buffer);
  17.             draw_sprite(buffer,sprite1,pos_x,pos_y);
  18.             draw_sprite(buffer,sprite2,pos_x_bis,pos_y_bis);
  19.             blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
  20.         }
  21.     }
  22. }END_OF_FUNCTION();
  23.  
  24. echanger_haut_bas(char tab,int i,int j,BITMAP* sprite1,BITMAP* sprite2,BITMAP* buffer){
  25.     double pos_x, pos_y;
  26.     double pos_x_bis, pos_y_bis;
  27.     pos_x = 95+i*36; pos_y = 95+j*36; pos_x_bis = 95+i*36; pos_y_bis = 95+(j+1)*36;
  28.     clear_bitmap(buffer);
  29.  
  30.     while(pos_y <= pos_y+36){
  31.         while(pos_y_bis >= pos_y-36){
  32.             pos_y += 0.5;
  33.             pos_y_bis -= 0.5;
  34.             clear_bitmap(buffer);
  35.             draw_sprite(buffer,sprite1,pos_x,pos_y);
  36.             draw_sprite(buffer,sprite2,pos_x_bis,pos_y_bis);
  37.             blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
  38.         }
  39.     }
  40. }END_OF_FUNCTION();
  41.  
  42.  
  43.  
  44. //fonction qui permute deux fruits de droite a gauche
  45. int main()
  46. {
  47.     allegro_init();
  48.     install_keyboard();
  49.     install_mouse();
  50.     set_color_depth(desktop_color_depth());
  51.     set_gfx_mode(GFX_AUTODETECT_WINDOWED,1024,768,0,0);
  52.  
  53.     int i=0,j=0;
  54.     char tab;
  55.     BITMAP* buffer = NULL;
  56.     BITMAP* apple = NULL;
  57.     BITMAP* onion = NULL;
  58.     BITMAP* orange = NULL;
  59.     BITMAP* fraise = NULL;
  60.     BITMAP* sun = NULL;
  61.     apple = load_bitmap("Apple.bmp",NULL);
  62.     fraise = load_bitmap("Fraise.bmp",NULL);
  63.     onion = load_bitmap("Onion.bmp",NULL);
  64.     sun = load_bitmap("Sun.bmp",NULL);
  65.     orange = load_bitmap("Orange.bmp",NULL);
  66.     buffer = create_bitmap(SCREEN_W,SCREEN_H);
  67.  
  68.     while(!key[KEY_ESC]){
  69.         clear_bitmap(buffer);
  70.         draw_sprite(buffer,apple,95,95);
  71.         draw_sprite(buffer,fraise,95,95+36);
  72.         blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
  73.         while(key[KEY_ENTER]){
  74.         echanger_haut_bas(tab,i,j,apple,fraise,buffer);
  75.         }
  76.     }
  77. }END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement