Commit 33cd918d authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Adicionado fireflies

parent f0f3d3ee
343 260
\ No newline at end of file
24 15 150 75 05 150
912 728 636 1000 724 1000
0 0 0 0 0 0
324 244 0
1000 988 0
512 328 236
412 228 136 412 228 136
712 528 436 1000 988 0
620 324 660
420 124 460
620 324 660
1000 1000 1000 1000 1000 1000
0000000000000000000000000000000000000000 0000000000000000000000000000000000000000
1111111111111111111111111111111111111111 1111111111111111111111111111111111111111
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
17667w00000000000z7777676z00000000000z71 17667w00000000000z7777676z00000000000z71
16777z00000000000w7667276w00000000000w71 16777z00000000000w7667276w00000000000w71
16666w00000000000z7667766z00000000000z61 16666w00000000000z7667766z00000000000z61
17677z00000000000w2676676w00000000000w61 17677z00000000000wzwzwzwzw00000000000w61
17677w00000000000zwzwzwzwz00000000000z61 17677w0000000000000000000000000000000z61
16667z0000000000000000000000000000000w61 16667z00000000000z2676676w00000000000w61
16667w00000000000w7726767z00000000000z61 16667w00000000000w7726767z00000000000z61
17733z00000000000z6667677w00000000000w61 17766z00000000000z6667677w00000000000w61
17722wzwzwzwzwzwzw7666777zwzwzwzwzwzwz71 17722wzwzwzwzwzwzw7666777zwzwzwzwzwzwz71
1111111111111111111111111111111111111111 1111111111111111111111111111111111111111
...@@ -24,4 +24,10 @@ typedef struct { ...@@ -24,4 +24,10 @@ typedef struct {
int last; int last;
} menu; } menu;
typedef struct firefly {
int x, y;
int dir;
struct firefly *next;
} firefly;
#endif #endif
#include "firefly.h"
void updateFirefly(map *m, firefly *first) {
firefly *aux = first;
int i, j;
while (aux != NULL) {
i = aux->x;
j = aux->y;
switch (aux->dir) {
case(8):
if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
}
break;
case(4):
if (m->grid[i][j+1] == '0'){
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
}
break;
case(6):
if (m->grid[i][j-1] == '0'){
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
}
break;
case(2):
if (m->grid[i+1][j] == '0'){
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
}
break;
}
aux = aux->next;
}
}
#ifndef _FIREFLY_H
#define _FIREFLY_H
#include "utils.h"
#include "entity.h"
void updateFirefly(map *m, firefly *first);
#endif
...@@ -24,6 +24,7 @@ int colors[8][3]; ...@@ -24,6 +24,7 @@ int colors[8][3];
char input[WIDTH]; char input[WIDTH];
rockford player; rockford player;
firefly *firstff, *auxff;
int alter; int alter;
int dead; int dead;
int offy, offx; int offy, offx;
...@@ -36,6 +37,7 @@ int extx, exty; ...@@ -36,6 +37,7 @@ int extx, exty;
int pushdelay; int pushdelay;
int highscore; int highscore;
int fireflyblink; int fireflyblink;
int nff;
FILE *lastscorefile; FILE *lastscorefile;
FILE *highscorefile; FILE *highscorefile;
...@@ -66,6 +68,19 @@ void readFileMap(map *m, int mapn, int pscore) { ...@@ -66,6 +68,19 @@ void readFileMap(map *m, int mapn, int pscore) {
} else if (input[j] == '4') { } else if (input[j] == '4') {
extx = i; extx = i;
exty = j; exty = j;
} else if (input[j] == 'M') {
if (!nff) {
firstff = (firefly*) malloc(sizeof(firefly));
firstff->x = j;
firstff->y = i;
auxff = firstff;
} else {
auxff->next = (firefly*) malloc(sizeof(firefly));
auxff->next->x = j;
auxff->next->y = i;
auxff = auxff->next;
}
nff++;
} }
m->grid[j][i] = input[j]; m->grid[j][i] = input[j];
} }
...@@ -214,6 +229,8 @@ void updateMap(map *m, int action, int *ismenu) { ...@@ -214,6 +229,8 @@ void updateMap(map *m, int action, int *ismenu) {
void renderMap(map *m, int time) { void renderMap(map *m, int time) {
int i, j, k, l; int i, j, k, l;
if (!(time % 4))
updateFirefly(m, firstff);
m->grid[3][0] = ((m->diamonds / 10) % 10) + 'A'; m->grid[3][0] = ((m->diamonds / 10) % 10) + 'A';
m->grid[4][0] = (m->diamonds % 10) + 'A'; m->grid[4][0] = (m->diamonds % 10) + 'A';
...@@ -248,6 +265,8 @@ void renderMap(map *m, int time) { ...@@ -248,6 +265,8 @@ void renderMap(map *m, int time) {
if (lightning) if (lightning)
hold++; hold++;
if (!(time % 2))
fireflyblink = (fireflyblink + 1) % 3;
for (i = 0; i < WIDTH; i++) { for (i = 0; i < WIDTH; i++) {
for (j = 0; j < HEIGHT; j++) { for (j = 0; j < HEIGHT; j++) {
...@@ -313,13 +332,16 @@ void renderMap(map *m, int time) { ...@@ -313,13 +332,16 @@ void renderMap(map *m, int time) {
} }
break; break;
case('6'): case('6'):
if (m->grid[i][j+1] == '0' || m->grid[i][j+1] == '7') if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7')
m->grid[i][j] = 'f'; && m->grid[i+1][j] == '0' && m->grid[i+1][j+1] == '0')
if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7') && m->grid[i+1][j] == '0' && m->grid[i+1][j+1] == '0')
m->grid[i][j] = 'r'; m->grid[i][j] = 'r';
if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7') && m->grid[i-1][j] == '0' && m->grid[i-1][j+1] == '0') else if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7')
&& m->grid[i-1][j] == '0' && m->grid[i-1][j+1] == '0')
m->grid[i][j] = 'l'; m->grid[i][j] = 'l';
if (m->grid[i][j+1] == '0')
m->grid[i][j] = 'f';
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) for (l = 0; l < 6; l++)
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) { if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
...@@ -335,12 +357,16 @@ void renderMap(map *m, int time) { ...@@ -335,12 +357,16 @@ void renderMap(map *m, int time) {
} }
break; break;
case('7'): case('7'):
if (m->grid[i][j+1] == '0' || m->grid[i][j+1] == '7') if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7')
m->grid[i][j] = 'F'; && m->grid[i-1][j] == '0' && m->grid[i-1][j+1] == '0')
if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7') && m->grid[i+1][j] == '0' && m->grid[i+1][j+1] == '0')
m->grid[i][j] = 'R';
if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7') && m->grid[i-1][j] == '0' && m->grid[i-1][j+1] == '0')
m->grid[i][j] = 'L'; m->grid[i][j] = 'L';
else if ((m->grid[i][j+1] == '6' || m->grid[i][j+1] == 'w' || m->grid[i][j+1] == 'z' || m->grid[i][j+1] == '7')
&& m->grid[i+1][j] == '0' && m->grid[i+1][j+1] == '0')
m->grid[i][j] = 'R';
if (m->grid[i][j+1] == '0')
m->grid[i][j] = 'h';
attron(COLOR_PAIR(7)); attron(COLOR_PAIR(7));
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) for (l = 0; l < 6; l++)
...@@ -374,14 +400,14 @@ void renderMap(map *m, int time) { ...@@ -374,14 +400,14 @@ void renderMap(map *m, int time) {
m->grid[i][j+1] = 'f'; m->grid[i][j+1] = 'f';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
} else if (m->grid[i][j+1] == '5') { } else if (m->grid[i][j+1] == '5') {
m->grid[i][j+1] = 'f'; m->grid[i][j+1] = '0';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
dead = true; dead = true;
} else } else
m->grid[i][j] = '6'; m->grid[i][j] = '6';
} }
break; break;
case('F'): case('h'):
attron(COLOR_PAIR(7)); attron(COLOR_PAIR(7));
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) for (l = 0; l < 6; l++)
...@@ -395,10 +421,10 @@ void renderMap(map *m, int time) { ...@@ -395,10 +421,10 @@ void renderMap(map *m, int time) {
if (waittime == 6) { if (waittime == 6) {
if (m->grid[i][j+1] == '0') { if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'F'; m->grid[i][j+1] = 'h';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
} else if (m->grid[i][j+1] == '5') { } else if (m->grid[i][j+1] == '5') {
m->grid[i][j+1] = 'F'; m->grid[i][j+1] = 'h';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
dead = true; dead = true;
} else } else
...@@ -445,15 +471,22 @@ void renderMap(map *m, int time) { ...@@ -445,15 +471,22 @@ void renderMap(map *m, int time) {
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) { if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) { if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8)); attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", diamond[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8)); attroff(COLOR_PAIR(8));
} else { } else {
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", diamond[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3)); attroff(COLOR_PAIR(3));
} }
} }
} }
if (waittime == 6) {
if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'f';
m->grid[i][j] = '0';
}
}
break;
case('R'): case('R'):
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) { for (l = 0; l < 6; l++) {
...@@ -468,12 +501,11 @@ void renderMap(map *m, int time) { ...@@ -468,12 +501,11 @@ void renderMap(map *m, int time) {
else else
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", diamond3[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", diamond3[k][l]);
attroff(COLOR_PAIR(7)); attroff(COLOR_PAIR(7));
} }
}
} }
if (waittime == 6) { if (waittime == 6) {
if (m->grid[i+1][j] == '0') { if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'F'; m->grid[i+1][j] = 'h';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
} }
} }
...@@ -496,7 +528,7 @@ void renderMap(map *m, int time) { ...@@ -496,7 +528,7 @@ void renderMap(map *m, int time) {
} }
if (waittime == 6) { if (waittime == 6) {
if (m->grid[i-1][j] == '0') { if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'F'; m->grid[i-1][j] = 'h';
m->grid[i][j] = '0'; m->grid[i][j] = '0';
} }
} }
...@@ -565,9 +597,21 @@ void renderMap(map *m, int time) { ...@@ -565,9 +597,21 @@ void renderMap(map *m, int time) {
renderChar(symbol, i, j, offx, offy, 11); renderChar(symbol, i, j, offx, offy, 11);
break; break;
case('M'): case('M'):
/*if (!(time % 4)) {
if (!(time % 5)) if (m->grid[i-1][j] == '0') {
fireflyblink = (fireflyblink + 1) % 3; m->grid[i-1][j] = '<';
m->grid[i][j] = '0';
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = '>';
m->grid[i][j] = '0';
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'v';
m->grid[i][j] = '0';
}
}*/
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) { for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) { if (k == 0 || k == 2 || l == 0 || l == 5) {
...@@ -575,17 +619,116 @@ void renderMap(map *m, int time) { ...@@ -575,17 +619,116 @@ void renderMap(map *m, int time) {
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(4 + fireflyblink)); attroff(COLOR_PAIR(4 + fireflyblink));
} else if (k == 1 && (l == 2 || l == 3)) { } else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(5 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(5 + fireflyblink));
} else {
attron(COLOR_PAIR(6 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(6 + fireflyblink));
}
}
break;
/*case('<'):
if (!(time % 4)) {
if (m->grid[i][j+1] == '0'){
m->grid[i][j+1] = 'v';
m->grid[i][j] = '0';
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = '<';
m->grid[i][j] = '0';
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = '>';
m->grid[i][j] = '0';
}
}
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) {
attron(COLOR_PAIR(4 + fireflyblink)); attron(COLOR_PAIR(4 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(4 + fireflyblink)); attroff(COLOR_PAIR(4 + fireflyblink));
} else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(5 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(5 + fireflyblink));
} else { } else {
attron(COLOR_PAIR(6 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(6 + fireflyblink));
}
}
break;
case('>'):
if (!(time % 4)) {
if (m->grid[i][j-1] == '0'){
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = '>';
m->grid[i][j] = '0';
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'v';
m->grid[i][j] = '0';
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = '<';
m->grid[i][j] = '0';
}
}
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) {
attron(COLOR_PAIR(4 + fireflyblink)); attron(COLOR_PAIR(4 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]); mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(4 + fireflyblink)); attroff(COLOR_PAIR(4 + fireflyblink));
} else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(5 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(5 + fireflyblink));
} else {
attron(COLOR_PAIR(6 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(6 + fireflyblink));
} }
} }
break; break;
case('v'):
if (!(time % 4)) {
if (m->grid[i+1][j] == '0'){
m->grid[i+1][j] = '>';
m->grid[i][j] = '0';
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'v';
m->grid[i][j] = '0';
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = '<';
m->grid[i][j] = '0';
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
}
}
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) {
attron(COLOR_PAIR(4 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(4 + fireflyblink));
} else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(5 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(5 + fireflyblink));
} else {
attron(COLOR_PAIR(6 + fireflyblink));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(6 + fireflyblink));
}
}
break;*/
} }
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "utils.h" #include "utils.h"
#include "entity.h" #include "entity.h"
#include "rockford.h" #include "rockford.h"
#include "firefly.h"
void readFileMap(map *m, int mapn, int pscore); void readFileMap(map *m, int mapn, int pscore);
void setColors(); void setColors();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment