Guest User

Untitled

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