Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- #include <stdio.h>
- #include <stdlib.h>
- // enum ValoresCelula { Vazia = 0, Parede = 1, Premio = 2, Robo = 3 };
- enum ValoresCelula { Vazia, Parede, Premio };
- int corCelula[4];
- void init();
- void deinit();
- struct Tabuleiro {
- int x, y;
- int tamanho_celula;
- int numero_celulas;
- int **celula;
- };
- struct Jogo {
- struct Tabuleiro tab;
- };
- void constroiTabuleiro( struct Tabuleiro* tab, int x, int y ) {
- int i, j;
- tab->x = x;
- tab->y = y;
- tab->tamanho_celula = 50;
- tab->numero_celulas = 8;
- tab->celula = (int **) malloc( tab->numero_celulas * sizeof( int* ) );
- for( i = 0; i < tab->numero_celulas; i++ )
- tab->celula[i] = (int *) malloc( tab->numero_celulas * sizeof( int ) );
- for( i = 0; i < tab->numero_celulas; i++ )
- for( j = 0; j < tab->numero_celulas; j++ )
- tab->celula[i][j] = Vazia;
- //tab->celula[4][5] = Premio;
- //tab->celula[2][2] = Parede;
- //tab->celula[2][2] = Parede;
- //tab->celula[2][3] = Parede;
- //tab->celula[2][4] = Parede;
- //tab->celula[2][5] = Parede;
- }
- void constroiJogo( struct Jogo* j ) {
- constroiTabuleiro( &j->tab, 10, 10);
- }
- void desenhaTabuleiro( BITMAP *bmp, struct Tabuleiro* tab ) {
- int i, j;
- for( i = 0; i <= tab->numero_celulas; i++ )
- line( bmp, tab->x + i * tab->tamanho_celula,
- tab->y,
- tab->x + i * tab->tamanho_celula,
- tab->y + tab->numero_celulas * tab->tamanho_celula,
- makecol( 0, 0, 0 ) );
- for( i = 0; i <= tab->numero_celulas; i++ )
- line( bmp, tab->x,
- tab->y + i * tab->tamanho_celula,
- tab->x + tab->numero_celulas * tab->tamanho_celula,
- tab->y + i * tab->tamanho_celula,
- makecol( 0, 0, 0 ) );
- for( i = 0; i < tab->numero_celulas; i++ )
- for( j = 0; j < tab->numero_celulas; j++ )
- rectfill( bmp, tab->x + i * tab->tamanho_celula + 1,
- tab->y + j * tab->tamanho_celula + 1,
- tab->x + (i+1) * tab->tamanho_celula - 1,
- tab->y + (j+1) * tab->tamanho_celula - 1,
- corCelula[ tab->celula[i][j] ] );
- }
- int main() {
- struct Jogo jogo;
- init();
- constroiJogo( &jogo );
- rectfill( screen, 0, 0, 499, 499, makecol( 23, 43, 72 ) );
- desenhaTabuleiro( screen, &jogo.tab );
- allegro_message("Welcome to tibia");
- while (!key[KEY_ESC])
- {int i;
- int z;
- BITMAP *grama;
- BITMAP *parede;
- parede = load_bitmap("parede.bmp", NULL);
- grama = load_bitmap ("grama.bmp", NULL);
- for (i=0; i<8; i++)
- for (z=0; z<8; z++)
- {
- blit(grama, screen, 0, 0, 11+50*z, 11+50*i, 49, 49);
- }
- for(i = 0 ; i<4 ; i++)
- {
- blit(parede, screen, 0,0, 111, 111+50*i, 49, 49);
- }
- destroy_bitmap (grama);
- destroy_bitmap (parede);
- }
- deinit();
- return 0;
- }
- END_OF_MAIN()
- 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, 500, 500, 0, 0);
- if (res != 0) {
- allegro_message(allegro_error);
- exit(-1);
- }
- install_timer();
- install_keyboard();
- install_mouse();
- /* add other initializations here */
- corCelula[Vazia] = makecol ( 100,100,120);
- //corCelula[Parede] = makecol( 90, 100, 90 );
- //corCelula[Premio] = makecol( 0, 0, 160 );
- }
- void deinit() {
- clear_keybuf();
- /* add other deinitializations here */
- }
Add Comment
Please, Sign In to add comment