Commit 74264705 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Adicionado morte por firefly

parent 1c86ec09
105
\ No newline at end of file
319
\ No newline at end of file
......@@ -22,7 +22,7 @@
10222262w2262262w2220266w2222222w0222621
12622222z2226222z2220200z2222222z0622621
1wwwwwwwwwwwwwwwwwww0wwwwwwwwwwwwwwwwww1
16200022z2222626z2220222z2672262z2222221
1620M022z2222626z2220222z2672262z2222221
12222262w6222222w2270222w0226222w2626621
1700006006000060006000060060600000000001
10220262z6222202z2020220z2020222z2222221
......
......@@ -27,6 +27,7 @@ typedef struct {
typedef struct firefly {
int x, y;
int dir;
int dead;
struct firefly *next;
} firefly;
......
#include "firefly.h"
void updateFirefly(map *m, firefly *first) {
firefly *aux = first;
int i, j;
void updateFirefly(map *m, firefly *first, int *dead, int waittime) {
firefly *aux = first->next;
int i, j, k, l, n, o;
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;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
if (aux->dead) {
for (n = -1; n <= 1; n++) {
for (o = -1; o <= 1; o++) {
if (waittime < 21 && m->grid[i+n][j+o] != '1')
m->grid[i+n][j+o] = 'x';
else if (waittime <= 100 && m->grid[i+n][j+o] != '1')
m->grid[i+n][j+o] = '0';
}
break;
case(4):
if (m->grid[i][j+1] == '0'){
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
}
} else {
i = aux->x;
j = aux->y;
for (k = -1; k <= 1; k++) {
for (l = -1; l <= 1; l++) {
if (m->grid[i+k][j+l] == '5') {
*dead = true;
aux->dead = true;
}
}
break;
case(6):
if (m->grid[i][j-1] == '0'){
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
}
break;
case(2):
if (m->grid[i+1][j] == '0'){
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
}
break;
}
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;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
}
break;
case(4):
if (m->grid[i][j+1] == '0'){
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
}
break;
case(6):
if (m->grid[i][j-1] == '0'){
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
} else if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
}
break;
case(2):
if (m->grid[i+1][j] == '0'){
m->grid[i+1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 6;
aux->x++;
} else if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'M';
m->grid[i][j] = '0';
aux->dir = 2;
aux->y++;
} else if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'M';
m->grid[i][j] = '0';
aux->dir = 4;
aux->x--;
} else if (m->grid[i][j-1] == '0') {
m->grid[i][j-1] = 'M';
m->grid[i][j] = '0';
aux->dir = 8;
aux->y--;
}
break;
}
aux = aux->next;
}
aux = aux->next;
}
}
......@@ -3,6 +3,6 @@
#include "utils.h"
#include "entity.h"
void updateFirefly(map *m, firefly *first);
void updateFirefly(map *m, firefly *first, int *dead, int waittime);
#endif
......@@ -83,6 +83,7 @@ void readFileMap(map *m, int mapn, int pscore) {
lastff->x = j;
lastff->y = i;
lastff->dir = 8;
lastff->dead = false;
lastff->next = NULL;
nff++;
}
......@@ -237,8 +238,6 @@ void updateMap(map *m, int action, int *ismenu) {
void renderMap(map *m, int time) {
int i, j, k, l;
if (nff && !(time % 4))
updateFirefly(m, firstff);
m->grid[3][0] = ((m->diamonds / 10) % 10) + 'A';
m->grid[4][0] = (m->diamonds % 10) + 'A';
......@@ -279,9 +278,12 @@ void renderMap(map *m, int time) {
blink3 = (blink3 % 3) + 4;
}
if (nff && !(time % 6))
updateFirefly(m, firstff, &dead, waittime);
for (i = 0; i < WIDTH; i++) {
for (j = 0; j < HEIGHT; j++) {
updatePhysics(m, m->grid[i][j], i, j, offx, offy, time, waittime, dead);
updatePhysics(m, m->grid[i][j], i, j, offx, offy, time, waittime, &dead);
if (!dead)
waittime = (waittime + 1) % 7;
switch (m->grid[i][j]) {
......@@ -320,7 +322,6 @@ void renderMap(map *m, int time) {
renderChar(ext, i, j, offx, offy, 5);
break;
case('5'):
attron(COLOR_PAIR(6));
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
attron(COLOR_PAIR((k == 0 || k == 1) ? 6 + k : 12));
......
#include "physics.h"
void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time, int waittime, int dead) {
void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time, int waittime, int *dead) {
int k, l;
switch (in) {
case('f'):
......@@ -24,7 +24,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
} else if (m->grid[i][j+1] == '5') {
m->grid[i][j+1] = '0';
m->grid[i][j] = '0';
dead = true;
*dead = true;
} else
m->grid[i][j] = '6';
}
......@@ -44,7 +44,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
} else if (m->grid[i][j+1] == '5') {
m->grid[i][j+1] = 'h';
m->grid[i][j] = '0';
dead = true;
*dead = true;
} else
m->grid[i][j] = '7';
}
......
......@@ -4,6 +4,6 @@
#include "utils.h"
#include "entity.h"
void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time, int waittime, int dead);
void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time, int waittime, int *dead);
#endif
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