Guest User

Untitled

a guest
Apr 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.22 KB | None | 0 0
  1. #include <allegro.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void init();
  6. void deinit();
  7.  
  8. enum ValoresCelula { Vazia, Parede, Premio };
  9. int corCelula[4];
  10.  
  11. struct Tabuleiro {
  12.   int x, y;
  13.   int tamanho_celula;
  14.   int numero_celulas;
  15.   int **celula;
  16. };
  17.    
  18.     struct Jogo {
  19.   struct Tabuleiro tab;
  20.   }
  21.  
  22. void constroiTabuleiro( struct Tabuleiro* tab, int x, int y ) {
  23.   int i, j;
  24.  
  25.   tab->x = x;
  26.   tab->y = y;
  27.   tab->tamanho_celula = 50;
  28.   tab->numero_celulas = 8;
  29.   tab->celula = (int **) malloc( tab->numero_celulas * sizeof( int* ) );
  30.   for( i = 0; i < tab->numero_celulas; i++ )
  31.     tab->celula[i] = (int *) malloc( tab->numero_celulas * sizeof( int ) );
  32.  
  33.   for( i = 0; i < tab->numero_celulas; i++ )
  34.     for( j = 0; j < tab->numero_celulas; j++ )
  35.       tab->celula[i][j] = Vazia;
  36.      
  37.     }
  38.    
  39.     void constroiJogo( struct Jogo* j ) {
  40.   constroiTabuleiro( &j->tab, 10, 10);
  41. }
  42.    
  43.     void desenhaTabuleiro( BITMAP *bmp, struct Tabuleiro* tab ) {
  44.   int i, j;
  45.  
  46.   for( i = 0; i <= tab->numero_celulas; i++ )
  47.     line( bmp, tab->x + i * tab->tamanho_celula,
  48.               tab->y,
  49.               tab->x + i * tab->tamanho_celula,
  50.               tab->y + tab->numero_celulas * tab->tamanho_celula,
  51.               makecol( 0, 0, 0 ) );
  52.  
  53.   for( i = 0; i <= tab->numero_celulas; i++ )
  54.     line( bmp, tab->x,
  55.               tab->y + i * tab->tamanho_celula,
  56.               tab->x + tab->numero_celulas * tab->tamanho_celula,
  57.               tab->y + i * tab->tamanho_celula,
  58.               makecol( 0, 0, 0 ) );
  59.              
  60.   for( i = 0; i < tab->numero_celulas; i++ )
  61.     for( j = 0; j < tab->numero_celulas; j++ )
  62.       rectfill( bmp, tab->x + i * tab->tamanho_celula + 1,
  63.                     tab->y + j * tab->tamanho_celula + 1,
  64.                     tab->x + (i+1) * tab->tamanho_celula - 1,
  65.                     tab->y + (j+1) * tab->tamanho_celula - 1,
  66.                     corCelula[ tab->celula[i][j] ] );
  67. }
  68.    
  69.  
  70.  
  71.  
  72. int main() {
  73. struct Jogo jogo;
  74.   init();
  75.  
  76.   show_mouse(screen);
  77.   desenhaTabuleiro( screen, &jogo );
  78.  
  79.   rectfill( screen, 0, 0, 499, 499, makecol( 23, 43, 72 ) );
  80.  
  81.   allegro_message("Welcome to tibia");
  82.   while (!key[KEY_ESC]) {
  83.   int i;
  84.   int z;
  85.     BITMAP *grama;
  86.     BITMAP *parede;
  87.        
  88.         parede = load_bitmap("parede.bmp", NULL);
  89.  
  90.        
  91.         grama = load_bitmap ("grama.bmp", NULL);
  92.            for (i=0; i<8; i++)
  93.            for (z=0; z<8; z++)
  94.     {
  95.      blit(grama, screen, 0, 0, 11+50*z, 11+50*i, 49, 49);
  96.     }
  97.      
  98.             for(i = 0 ; i<4 ; i++)
  99.     {
  100.      blit(parede, screen, 0,0, 111, 111+50*i, 49, 49);
  101.     }
  102.      
  103.  destroy_bitmap (grama);
  104.  destroy_bitmap (parede);
  105.     }
  106.   deinit();
  107.   return 0;
  108. }
  109. END_OF_MAIN()
  110.  
  111. void init() {
  112.   int depth, res;
  113.   allegro_init();
  114.   depth = desktop_color_depth();
  115.   if (depth == 0) depth = 32;
  116.   set_color_depth(depth);
  117.   res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 500, 500, 0, 0);
  118.   if (res != 0) {
  119.     allegro_message(allegro_error);
  120.     exit(-1);
  121.   }
  122.  
  123.   install_timer();
  124.   install_keyboard();
  125.   install_mouse();
  126.   /* add other initializations here */
  127.  
  128.   //corCelula[Vazia] = makecol ( 100,100,120);
  129.   //corCelula[Parede] = makecol( 90, 100, 90 );
  130.   //corCelula[Premio] = makecol( 0, 0, 160 );
  131. }
  132.  
  133. void deinit() {
  134.   clear_keybuf();
  135.   /* add other deinitializations here */
  136. }
Add Comment
Please, Sign In to add comment