diff --git a/colisao.c b/colisao.c index f7b7e379b977e9136cd3e044ae2647096e9d53e1..87da04b9bda3140ebc38541d421f5e94b1f65b19 100644 --- a/colisao.c +++ b/colisao.c @@ -21,6 +21,13 @@ char** le_matriz(FILE *fp) return matriz; } +int pode_andar(int i, Pessoa *p) { + if(p[i].freeze <= 0 && p[i].preso <= 0) { + return 1; + } + return 0; +} + int contato_proximo(int i,int j, Pessoa *p) { // I eh o char que tah realizando a acao, J eh o cara que talvez foi atacado / puxado o neon if(p[i].andou_c == 1 || (p[i].andou_b == 0 && p[i].andou_c == 0 && p[i].andou_d == 0 && p[i].andou_e == 0)) { // Olhando pra cima. diff --git a/colisao.h b/colisao.h index 9b6f7bf0907d64329622e27c846e526c9d4af8ff..ab1220b716e0bce4fcc0e872578110ad702cc90a 100644 --- a/colisao.h +++ b/colisao.h @@ -30,10 +30,17 @@ #define MAX_HP 1000 #define MAX_ENERGY 300 #define COMPUTADORES 1 +#define COMANDOS_POR_PERSONAGEM 9 + +/* Defines para magias */ #define ICEBALLS_P_PESSOA 2 #define FIREBALLS_P_PESSOA 2 -#define COMANDOS_POR_PERSONAGEM 8 - +/* Defines para traps */ +#define TRAP_P_PESSOA 3 +#define TRAP_SPRITE_WIDTH 32 +#define TRAP_SPRITE_HEIGHT 32 +#define TRAP_TEMPO_ARMADA 300 +#define TRAP_TEMPO_PRENDENDO 30 /* Defines para flash */ #define FLASH_SPRITE_WIDTH 22 #define FLASH_SPRITE_HEIGHT 22 @@ -50,11 +57,12 @@ typedef struct Pessoa { int comp; int botao_char_int[8],time; int freeze; // Congelado não pode usar magias nem andar. Freeze <= 0 -> não está mais congelado. Freeze > 0, congelado. + int preso; // Preso não pode andar, mas pode usar magias. Preso <= 0, não está preso. Preso > 0, está preso. } Pessoa; typedef struct Magia { int dano, x, y, dist, xsprite, ysprite, xexpl, yexpl, energia, count; - bool ativa, explosao; + bool ativa, explosao, em_acao; ALLEGRO_BITMAP* sprite; int d; /* Direcao == -1 significa que nao foi calculada ainda. * 0 = cima; 1 = direita; 2 = esquerda; 3 = baixo; */ @@ -65,6 +73,7 @@ typedef struct Magias { Magia fireball[PESSOAS][FIREBALLS_P_PESSOA]; Magia iceball[PESSOAS][ICEBALLS_P_PESSOA]; Magia flash[PESSOAS][MAX_FLASH_POSSIVEL]; + Magia trap[PESSOAS][TRAP_P_PESSOA]; } Magias; typedef struct Sprite { @@ -72,7 +81,7 @@ typedef struct Sprite { ALLEGRO_BITMAP **fireballs, *explosion; // Sprite da bola de fogo (cima, dir, esq, baixo) + explosao da fireball. ALLEGRO_BITMAP **iceballs, *gelos; // Sprite da bola de fogo (cima, dir, esq, baixo) + explosao da fireball. ALLEGRO_BITMAP **neons; // Todos os neons (4 cores, na sequencia: amarelo - azul - verde - vermelho) - ALLEGRO_BITMAP *animacao_flash; + ALLEGRO_BITMAP *animacao_flash, *trap; ALLEGRO_BITMAP *bar, *healthbar, *energybar, *frente; ALLEGRO_BITMAP *chars, *dead, *chars_congelados; } Sprite; @@ -136,6 +145,7 @@ private: char** le_matriz(FILE *fp); bool colisao(int,int,char**,int); +int pode_andar(int i, Pessoa *p); int colidiu(char** map,int x,int y,int caso,int eu, Pessoa *p); int colisao_fireball(char** m,int x,int y,int d); int contato_proximo(int i,int j, Pessoa *p); diff --git a/grafico.c b/grafico.c index 690b23531b3c6a180d147551181e91576f9ea148..b95268cce745fe24a30bf9c6361940b0184b4b48 100644 --- a/grafico.c +++ b/grafico.c @@ -151,6 +151,13 @@ Sprite init_sprites(FILE *errext) { exit(1); } + s.trap = al_load_bitmap("Imgs/trap.bmp"); + if(!(s.trap)) { + fprintf(errext,"Falha ao abrir a imagem trap."); + fclose(errext); + exit(1); + } + s.neons[0] = al_load_bitmap("Imgs/neonamarelo.bmp"); if(!s.neons[0]) { fprintf(errext,"Falha ao abrir a imagem s.neons[0]."); @@ -237,6 +244,7 @@ Sprite init_sprites(FILE *errext) { al_convert_mask_to_alpha(s.bar,al_map_rgb(255,0,255)); al_convert_mask_to_alpha(s.dead,al_map_rgb(255,0,255)); + al_convert_mask_to_alpha(s.trap,al_map_rgb(255,0,255)); al_convert_mask_to_alpha(s.tiles,al_map_rgb(255,0,255)); al_convert_mask_to_alpha(s.chars,al_map_rgb(255,0,255)); al_convert_mask_to_alpha(s.explosion,al_map_rgb(255,0,255)); diff --git a/imprime.c b/imprime.c index 55992497f53fc62cb24c398f8288207b8fb3ee2b..827c3398ddcca301b22003de3c6c7210cd67ff91 100644 --- a/imprime.c +++ b/imprime.c @@ -91,7 +91,7 @@ int imprime_4_chars_for(int cont,char** matriz,int *cor,bool *temneon,int njogad if((p[i].andou_b) == 1) { //if(!(colidiu(matriz,p[i].x/4,p[i].y/4,BAIXO,i,p) == 1)) { - if(!(colidiu(matriz,p[i].x/4,p[i].y/4,BAIXO,i,p) == 1) && p[i].freeze <= 0) { + if(!(colidiu(matriz,p[i].x/4,p[i].y/4,BAIXO,i,p) == 1) && pode_andar(i, p)) { p[i].y += 4 * p[i].correr; p[i].yneon += 4 * p[i].correr; } @@ -105,7 +105,7 @@ int imprime_4_chars_for(int cont,char** matriz,int *cor,bool *temneon,int njogad } if((p[i].andou_e) == 1) { // if(!(colidiu(matriz,p[i].x/4,p[i].y/4,ESQ,i,p) == 1)) { // O 1(um) tah ali porque eh o caso de andar pra esquerda. - if(!(colidiu(matriz,p[i].x/4,p[i].y/4,ESQ,i,p) == 1) && p[i].freeze <= 0) { // O 1(um) tah ali porque eh o caso de andar pra esquerda. + if(!(colidiu(matriz,p[i].x/4,p[i].y/4,ESQ,i,p) == 1) && pode_andar(i, p)) { // O 1(um) tah ali porque eh o caso de andar pra esquerda. p[i].x -= 4 * p[i].correr; p[i].xneon -= 4 * p[i].correr; } @@ -119,7 +119,7 @@ int imprime_4_chars_for(int cont,char** matriz,int *cor,bool *temneon,int njogad } if((p[i].andou_d) == 1) { // if(!(colidiu(matriz,p[i].x/4,p[i].y/4,DIR,i,p) == 1)) { // O 3(tres) tah ali porque eh o caso de andar pra direita. - if(!(colidiu(matriz,p[i].x/4,p[i].y/4,DIR,i,p) == 1) && p[i].freeze <= 0) { // O 3(tres) tah ali porque eh o caso de andar pra direita. + if(!(colidiu(matriz,p[i].x/4,p[i].y/4,DIR,i,p) == 1) && pode_andar(i, p)) { // O 3(tres) tah ali porque eh o caso de andar pra direita. p[i].x += 4 * p[i].correr; p[i].xneon += 4 * p[i].correr; } @@ -133,7 +133,7 @@ int imprime_4_chars_for(int cont,char** matriz,int *cor,bool *temneon,int njogad } if((p[i].andou_c) == 1) { // if(!(colidiu(matriz,p[i].x/4,p[i].y/4,CIMA,i,p) == 1)) { // O 2(dois) tah ali porque eh o caso de andar pra cima. - if(!(colidiu(matriz,p[i].x/4,p[i].y/4,CIMA,i,p) == 1) && p[i].freeze <= 0) { // O 2(dois) tah ali porque eh o caso de andar pra cima. + if(!(colidiu(matriz,p[i].x/4,p[i].y/4,CIMA,i,p) == 1) && pode_andar(i, p)) { // O 2(dois) tah ali porque eh o caso de andar pra cima. p[i].y -= 4 * p[i].correr; p[i].yneon -= 4 * p[i].correr; } diff --git a/keys.c b/keys.c index 173dfcccfb7d0c9a9620c1f513297ac4fd9e4be3..cbe171f6b6084eb1eb79b5042f4f0a50fd95a610 100644 --- a/keys.c +++ b/keys.c @@ -1,14 +1,5 @@ #include "keys.h" -#define UP 0 -#define DOWN 1 -#define RIGHT 2 -#define LEFT 3 -#define CORRE 4 -#define PUXAR 5 -#define FLASH 6 -#define ICEBALL 7 - void teclas_iniciais(Pessoa *p) { /* @@ -44,6 +35,7 @@ void teclas_iniciais(Pessoa *p) p[0].botao_char_int[PUXAR] = ALLEGRO_KEY_HOME; p[0].botao_char_int[FLASH] = ALLEGRO_KEY_PGUP; p[0].botao_char_int[ICEBALL] = ALLEGRO_KEY_DELETE; + p[0].botao_char_int[TRAP] = ALLEGRO_KEY_M; p[1].botao_char_int[UP] = ALLEGRO_KEY_I; p[1].botao_char_int[DOWN] = ALLEGRO_KEY_K; diff --git a/keys.h b/keys.h index 5c26ebb4eec8e4cd82fb11934c5ba7f15ad6266d..7c34cd6baa2b8531cf66a37cdd21ab449931edbd 100644 --- a/keys.h +++ b/keys.h @@ -14,6 +14,16 @@ #include <allegro5/allegro_primitives.h> #include <allegro5/allegro_ttf.h> +#define UP 0 +#define DOWN 1 +#define RIGHT 2 +#define LEFT 3 +#define CORRE 4 +#define PUXAR 5 +#define FLASH 6 +#define ICEBALL 7 +#define TRAP 8 + void teclas_iniciais(Pessoa *pessoa); void keyboard_down(int evkeyboardkeycode,bool *puxa,int *flash, Pessoa *p, Magias *m, int njogadores); void keyboard_up(int evkeyboardkeycode,bool *puxa,bool *sair, Pessoa *p, int njogadores); diff --git a/magia.c b/magia.c index 18302ac033b5865fc7d291280bcefa07441d5d20..adfc4d4664bf77edcaa7da945f40dd6a38866789 100644 --- a/magia.c +++ b/magia.c @@ -21,7 +21,7 @@ void init_magias(Magias *m, int njogadores) { */ for(i=0; i<njogadores; ++i) { /* Inicializa iceball. */ - for(j=0; j<2; ++j) { + for(j=0; j<ICEBALLS_P_PESSOA; ++j) { m->iceball[i][j].ativa = false; // Nao foi usada. m->iceball[i][j].dano = 25; // Dano da tecnica. m->iceball[i][j].explosao = false; // Nao colidiu / chegou na distancia limite. @@ -35,6 +35,11 @@ void init_magias(Magias *m, int njogadores) { m->flash[i][j].count = 0; m->flash[i][j].xsprite = 88; } + /* Inicializa trap. */ + for(j=0; j<TRAP_P_PESSOA; ++j) { + m->trap[i][j].ativa = false; // Nao foi usada. + m->trap[i][j].count = 0; // Duração + } } } @@ -249,6 +254,42 @@ void animacao_flash(Pessoa *p, int njogadores, Sprite s, Magias *m) { } } +void usa_trap(Pessoa *p, int njogadores, Sprite s, Magias *m) { + int i, j, k; + for(i=0; i<njogadores; ++i) { + if(p[i].preso > 0) { + --(p[i].preso); + } + for(j=0; j<TRAP_P_PESSOA; ++j) { + if(m->trap[i][j].ativa == true) { // Enquanto xsprite = 88, ele nao imprime a animacao. Quando xprite = 0, ele comeca a animacao. + m->trap[i][j].ativa = false; + m->trap[i][j].count = TRAP_TEMPO_ARMADA; + m->trap[i][j].x = p[i].x; + m->trap[i][j].y = p[i].y; + m->trap[i][j].em_acao = false; + } + if(m->trap[i][j].count > 0) { // Imprime a animação. + al_draw_bitmap_region(s.trap,0,0,TRAP_SPRITE_WIDTH,TRAP_SPRITE_HEIGHT,m->trap[i][j].x,m->trap[i][j].y,0); + --(m->trap[i][j].count); + for(k=0; k<njogadores; ++k) { + if(i == k) + continue; + + // Checa se algum outro jogador pisou na trap + if(p[i].preso <= 0 && m->trap[i][j].em_acao == false && // Confere se o jogador nao pisou em nenhum trap e se a trap nao foi pisada por outro jogador. + p[i].x >= m->trap[i][j].x && p[i].x <= m->trap[i][j].x + 32 && // Colidiu no eixo X + p[i].y >= m->trap[i][j].y && p[i].y <= m->trap[i][j].y + 32) { // Colidiu no eixo Y + p[i].preso = TRAP_TEMPO_PRENDENDO; + m->trap[i][j].count = TRAP_TEMPO_PRENDENDO; + m->trap[i][j].em_acao = true; + } + } + } + + } + } +} + void usa_magias(char **matriz, Pessoa *p, int njogadores, Sprite s, int *flash, Magias *m) { usa_flash(p, flash, matriz, njogadores, m); animacao_flash(p, njogadores, s, m); diff --git a/menu.c b/menu.c index 8682435b198bb0332eebd801fcf73a05dd3f3ac7..873bda135f57df91dabfdb3978de23be2778c332 100644 --- a/menu.c +++ b/menu.c @@ -170,21 +170,21 @@ int selecao_personagem(void *) { botoes[2*i+8].set_button("<", x_inicial[0] + i*x_variacao, 200, team_prev, (void*) param, sizeof(int)) ; botoes[2*i+9].set_button(">", x_inicial[1] + i*x_variacao, 200, team_next, (void*) param, sizeof(int)) ; } - /* Botao para voltar para o menu inicial. */ - param[0] = 1; - botoes[16].set_button("Voltar", 50, 500, return_int, (void*) param, sizeof(int)); /* Botoes para selecionar as teclas que executam os comandos de cada personagem. */ for(i=0; i<PESSOAS; ++i) { for(j=0; j<COMANDOS_POR_PERSONAGEM; ++j) { param[0] = i; param[1] = j; - botoes[17+i*COMANDOS_POR_PERSONAGEM+j].set_button("", 145+250*i, 250+20*j, set_next_key, (void*) param, sizeof(int) * 2); + botoes[16+i*COMANDOS_POR_PERSONAGEM+j].set_button("", 145+250*i, 250+20*j, set_next_key, (void*) param, sizeof(int) * 2); } } + /* Botao para voltar para o menu inicial. */ + param[0] = 1; + botoes[PESSOAS_E_COMANDOS+0].set_button("Voltar", 50, 500, return_int, (void*) param, sizeof(int)); /* Botoes pra selecionar numero de jogadores - se adicionar mais comandos, tem que mudar esses índices! */ - botoes[49].set_button("<", 510, 50, num_jogadores_dec, NULL, 0); - botoes[50].set_button(">", 540, 50, num_jogadores_inc, NULL, 0); - botoes[51].set_button("Salvar", 729, 500, salvar_configs, NULL, 0); + botoes[PESSOAS_E_COMANDOS+1].set_button("<", 510, 50, num_jogadores_dec, NULL, 0); + botoes[PESSOAS_E_COMANDOS+2].set_button(">", 540, 50, num_jogadores_inc, NULL, 0); + botoes[PESSOAS_E_COMANDOS+3].set_button("Salvar", 729, 500, salvar_configs, NULL, 0); set_buttons(botoes); imprime_menu(botoes, BOTOES_SEL_PERSONAGEM_TOTAL, mx, my, -1); diff --git a/menu.h b/menu.h index fc041844597166fe24415e42ee63a831d87d7211..b88b3bd78d84dbcf6223d84f64b08345f2b2e564 100644 --- a/menu.h +++ b/menu.h @@ -22,7 +22,7 @@ int menu_principal(Window win,Pessoa *p,Sprite s,int *num_jogadores, int vencedo #define BOTOES_SEL_N_JOGADORES 2 #define OUTROS_BOTOES 2 // voltar e salvar //#define COMANDOS_POR_PERSONAGEM é definido no colisao.h - +#define PESSOAS_E_COMANDOS BOTOES_SEL_PERSONAGEM + BOTOES_SEL_TIME + COMANDOS_POR_PERSONAGEM * PESSOAS // 16 pra selecionar, 1 pra voltar, 28 teclas (7 pra cada jogador, 4 jogadores), 2 pra selec. nº jogadores -> Total = 47. #define BOTOES_SEL_PERSONAGEM_TOTAL BOTOES_SEL_PERSONAGEM + BOTOES_SEL_TIME + OUTROS_BOTOES + PESSOAS*COMANDOS_POR_PERSONAGEM + BOTOES_SEL_N_JOGADORES diff --git a/neon.c b/neon.c index 150ba2dbe5a3d7bbeaa3373f91930a3c7566e37e..a0667edd88a62ccdf1f835a61296fc1444455749 100644 --- a/neon.c +++ b/neon.c @@ -3,18 +3,6 @@ #include "Fase1.h" #include <math.h> -/* -Problemas: -1- Bola de fogo n�o explode. -2- Barra de HP / Energia - OK. -3- Cor do neon quando parado - Xunxo. -4- Neon se movendo quando colide - OK. -5- Personagens todos iguais. -6- Bola de fogo nao da dano - OK. -7- Nao armazena comandos. -8- Usa fireball quando explosao ta ativa - explosao acompanha a fireball. -*/ - #define CONT 2 #define CONTEXPLO 9 #define TAM 1000 @@ -47,6 +35,7 @@ int main() p[i].selx = 0; p[i].sely = 64; p[i].time = i+1; + p[i].preso = 0; p[i].correr = 1; p[i].andou_b = 0; p[i].andou_c = 0;