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

Organizado

parent e15b7771
#include "entity.h"
void renderDirt(int i, int j, int offx, int offy) {
int k, l;
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++)
if ((k == 0 && (l == 2 || l == 4)) ||
(k == 1 && (l == 3 || l == 5)) ||
(k == 2 && (l == 0 || l == 4))) {
attron(COLOR_PAIR(13));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", dirt[k][l]);
attroff(COLOR_PAIR(13));
} else {
attron(COLOR_PAIR(1));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", dirt[k][l]);
attroff(COLOR_PAIR(1));
}
}
void renderBould(int i, int j, int offx, int offy) {
int k, l;
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++)
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8));
} else {
attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3));
}
}
}
void renderDiamonds(int i, int j, int offx, int offy, int time) {
if (time < 10)
renderChar(diamond, i, j, offx, offy, 7);
else if (time < 20)
renderChar(diamond2, i, j, offx, offy, 7);
else
renderChar(diamond3, i, j, offx, offy, 7);
}
#ifndef _ENTITY_H
#define _ENTITY_H
#include "utils.h"
typedef struct {
int x, y;
int dir;
......@@ -31,4 +33,8 @@ typedef struct firefly {
struct firefly *next;
} firefly;
void renderDirt(int i, int j, int offx, int offy);
void renderBould(int i, int j, int offx, int offy);
void renderDiamonds(int i, int j, int offx, int offy, int time);
#endif
......@@ -116,3 +116,23 @@ void updateFirefly(map *m, firefly *first, int *dead, int done) {
aux = aux->next;
}
}
void renderFirefly(int i, int j, int offx, int offy, int b1, int b2, int b3) {
int k, l;
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) {
attron(COLOR_PAIR(b1));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(b1));
} else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(b2));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(b2));
} else {
attron(COLOR_PAIR(b3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(b3));
}
}
}
......@@ -4,5 +4,6 @@
#include "entity.h"
void updateFirefly(map *m, firefly *first, int *dead, int done);
void renderFirefly(int i, int j, int offx, int offy, int b1, int b2, int b3);
#endif
#include "maps.h"
#include "physics.h"
char input[WIDTH];
char mapfile[8][100] = {"./sprites/map1.txt", "./sprites/map2.txt", "./sprites/map3.txt",
"./sprites/map4.txt", "./sprites/map5.txt", "./sprites/map6.txt",
"./sprites/map7.txt", "./sprites/congrats.txt"};
int colors[8][3];
char input[WIDTH];
rockford player;
firefly *firstff, *lastff;
int colors[8][3];
int alter;
int dead;
int offy, offx;
......@@ -40,15 +39,15 @@ void readFileMap(map *m, int mapn, int pscore) {
falltime = 0;
m->sprite = fopen(mapfile[mapnumber], "r");
firstff = (firefly*) malloc(sizeof(firefly));
lastff = firstff;
lastff->next = NULL;
fscanf(m->sprite, "%d %d %d", &m->diamonds, &m->score, &leveltime);
for (i = 0; i < 8; i++)
for (j = 0; j < 3; j++)
fscanf(m->sprite, "%d", &colors[i][j]);
firstff = (firefly*) malloc(sizeof(firefly));
lastff = firstff;
lastff->next = NULL;
for (i = 0; i < HEIGHT; i++) {
fscanf(m->sprite, "%s", input);
for (j = 0; j < WIDTH; j++) {
......@@ -153,6 +152,7 @@ void updateMap(map *m, int action, int *ismenu, int *loadMenu) {
getmaxyx(stdscr, row, col);
offy = (row / 2) - (12 * 3);
offx = (col / 2) - (20 * 6);
if (action == 9) {
saveScore();
*ismenu = true;
......@@ -195,7 +195,7 @@ void updateMap(map *m, int action, int *ismenu, int *loadMenu) {
}
void renderMap(map *m, int time) {
int i, j, k, l;
int i, j;
if (mapnumber == 7) {
m->grid[21][20] = ((player.score / 100000) % 10) + 'A';
......@@ -253,8 +253,11 @@ void renderMap(map *m, int time) {
updatePhysics(m, m->grid[i][j], i, j, offx, offy, time, falltime, waittime, &dead);
falltime = (falltime + 1) % 7;
if (mapnumber == 7 && ((m->grid[i][j] >= 'a' && m->grid[i][j] <= 'z') || m->grid[i][j] == '@' || m->grid[i][j] == '#' || m->grid[i][j] == '!'))
if (mapnumber == 7 && ((m->grid[i][j] >= 'a' && m->grid[i][j] <= 'z') ||
m->grid[i][j] == '@' || m->grid[i][j] == '#' || m->grid[i][j] == '!'))
renderLetter(m->grid[i][j], i, j, offx, offy);
if (m->grid[i][j] >= 'A' && m->grid[i][j] <= 'K')
renderHUB(m->grid[i][j], i, j, offx, offy);
switch (m->grid[i][j]) {
case('0'):
......@@ -264,17 +267,7 @@ void renderMap(map *m, int time) {
renderChar((j == 1 || j == 22) ? steel : steel2, i, j, offx, offy, 5);
break;
case('2'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++)
if ((k == 0 && (l == 2 || l == 4)) || (k == 1 && (l == 3 || l == 5)) || (k == 2 && (l == 0 || l == 4))) {
attron(COLOR_PAIR(13));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", dirt[k][l]);
attroff(COLOR_PAIR(13));
} else {
attron(COLOR_PAIR(1));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", dirt[k][l]);
attroff(COLOR_PAIR(1));
}
renderDirt(i, j, offx, offy);
break;
case('z'):
renderChar(wall, i, j, offx, offy, 4);
......@@ -284,124 +277,46 @@ void renderMap(map *m, int time) {
break;
case('4'):
if (done) {
if (time < 15)
renderChar(ext, i, j, offx, offy, 5);
else
renderChar(empty, i, j, offx, offy, 4);
if (time < 15) renderChar(ext, i, j, offx, offy, 5);
else renderChar(empty, i, j, offx, offy, 4);
} else
renderChar(ext, i, j, offx, offy, 5);
break;
case('5'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
attron(COLOR_PAIR((k == 0 || k == 1) ? 6 + k : 12));
if (player.dir == 0 || player.dir == 5)
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", rockf[k][l]);
else if (player.dir == 6 || player.dir == 8)
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", rockfr[k][l]);
else if (player.dir == 4 || player.dir == 2)
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", rockfl[k][l]);
attroff(COLOR_PAIR((k == 0 || k == 1) ? 6 + k : 12));
}
renderRockford(&player, i, j, offx, offy);
break;
case('6'):
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')
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';
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')
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';
if (m->grid[i][j+1] == '0')
m->grid[i][j] = 'f';
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++)
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8));
} else {
attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3));
}
}
renderBould(i, j, offx, offy);
break;
case('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-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] = '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')
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';
if (time < 10)
renderChar(diamond, i, j, offx, offy, 7);
else if (time < 20)
renderChar(diamond2, i, j, offx, offy, 7);
else
renderChar(diamond3, i, j, offx, offy, 7);
break;
case('8'):
renderChar(butterfly, i, j, offx, offy, 5);
break;
case('A'):
renderChar(zero, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('B'):
renderChar(one, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('C'):
renderChar(two, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('D'):
renderChar(three, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('E'):
renderChar(four, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('F'):
renderChar(five, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('G'):
renderChar(six, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('H'):
renderChar(seven, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('I'):
renderChar(eight, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('J'):
renderChar(nine, i, j, offx, offy, (i == 3 || i == 4 || i == 12 || i == 13) ? 2 : 11);
break;
case('K'):
renderChar(symbol, i, j, offx, offy, 11);
renderDiamonds(i, j, offx, offy, time);
break;
case('M'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (k == 0 || k == 2 || l == 0 || l == 5) {
attron(COLOR_PAIR(blink1));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(blink1));
} else if (k == 1 && (l == 2 || l == 3)) {
attron(COLOR_PAIR(blink2));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(blink2));
} else {
attron(COLOR_PAIR(blink3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", empty[k][l]);
attroff(COLOR_PAIR(blink3));
}
}
renderFirefly(i, j, offx, offy, blink1, blink2, blink3);
break;
}
......
......@@ -5,6 +5,7 @@
#include "entity.h"
#include "rockford.h"
#include "firefly.h"
#include "physics.h"
void readFileMap(map *m, int mapn, int pscore);
void setColors();
......
......@@ -47,7 +47,12 @@ void setMenuColors() {
int updateMenu(menu *menu, int action, int *loadMenu) {
buffer = -1;
if (*loadMenu) {
setMenuColors();
menu->highscore = fopen("./data/highscore.txt", "r");
fscanf(menu->highscore, "%d", &menu->high);
menu->lastscore = fopen("./data/lastscore.txt", "r");
fscanf(menu->lastscore, "%d", &menu->last);
setMenuColors();
*loadMenu = false;
}
switch(action){
......@@ -87,112 +92,7 @@ void renderMenu(menu *menu){
menu->grid[25][21] = ((menu->last / 10) % 10) + '0';
menu->grid[26][21] = (menu->last % 10) + '0';
for (i = 0; i < WIDTH; i++) {
for (j = 0; j < HEIGHT; j++) {
for (i = 0; i < WIDTH; i++)
for (j = 0; j < HEIGHT; j++)
renderLetter(menu->grid[i][j], i, j, offmenux, offmenuy);
/*switch (menu->grid[i][j]) {
case('@'):
renderChar(empty, i, j, offmenux, offmenuy, 1);
break;
case('!'):
renderChar(empty, i, j, offmenux, offmenuy, 4);
break;
case('#'):
renderChar(empty, i, j, offmenux, offmenuy, 3);
break;
case('<'):
renderChar(SL, i, j, offmenux, offmenuy, 2);
break;
case('>'):
renderChar(SR, i, j, offmenux, offmenuy, 2);
break;
case(':'):
renderChar(DOTS, i, j, offmenux, offmenuy, 2);
break;
case('a'):
renderChar(A, i, j, offmenux, offmenuy, 2);
break;
case('b'):
renderChar(B, i, j, offmenux, offmenuy, 2);
break;
case('c'):
renderChar(C, i, j, offmenux, offmenuy, 2);
break;
case('d'):
renderChar(D, i, j, offmenux, offmenuy, 2);
break;
case('e'):
renderChar(E, i, j, offmenux, offmenuy, 2);
break;
case('f'):
renderChar(F, i, j, offmenux, offmenuy, 2);
break;
case('g'):
renderChar(G, i, j, offmenux, offmenuy, 2);
break;
case('h'):
renderChar(H, i, j, offmenux, offmenuy, 2);
break;
case('i'):
renderChar(I, i, j, offmenux, offmenuy, 2);
break;
case('j'):
renderChar(J, i, j, offmenux, offmenuy, 2);
break;
case('l'):
renderChar(L, i, j, offmenux, offmenuy, 2);
break;
case('n'):
renderChar(N, i, j, offmenux, offmenuy, 2);
break;
case('o'):
renderChar(zero, i, j, offmenux, offmenuy, 2);
break;
case('r'):
renderChar(R, i, j, offmenux, offmenuy, 2);
break;
case('s'):
renderChar(S, i, j, offmenux, offmenuy, 2);
break;
case('t'):
renderChar(T, i, j, offmenux, offmenuy, 2);
break;
case('u'):
renderChar(U, i, j, offmenux, offmenuy, 2);
break;
case('v'):
renderChar(V, i, j, offmenux, offmenuy, 2);
break;
case('1'):
renderChar(one, i, j, offmenux, offmenuy, 2);
break;
case('2'):
renderChar(two, i, j, offmenux, offmenuy, 2);
break;
case('3'):
renderChar(three, i, j, offmenux, offmenuy, 2);
break;
case('4'):
renderChar(four, i, j, offmenux, offmenuy, 2);
break;
case('5'):
renderChar(five, i, j, offmenux, offmenuy, 2);
break;
case('6'):
renderChar(six, i, j, offmenux, offmenuy, 2);
break;
case('7'):
renderChar(seven, i, j, offmenux, offmenuy, 2);
break;
case('8'):
renderChar(eight, i, j, offmenux, offmenuy, 2);
break;
case('9'):
renderChar(nine, i, j, offmenux, offmenuy, 2);
break;
case('0'):
renderChar(zero, i, j, offmenux, offmenuy, 2);
break;*/
}
}
}
#include "physics.h"
void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time, int falltime, int waittime, int *dead) {
int k, l;
switch (in) {
case('f'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++)
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8));
} else {
attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3));
}
}
renderBould(i, j, offx, offy);
if (falltime == 6) {
if (m->grid[i][j+1] == '0') {
m->grid[i][j+1] = 'f';
......@@ -30,12 +17,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
}
break;
case('h'):
if (time < 10)
renderChar(diamond, i, j, offx, offy, 7);
else if (time < 20)
renderChar(diamond2, i, j, offx, offy, 7);
else
renderChar(diamond3, i, j, offx, offy, 7);
renderDiamonds(i, j, offx, offy, time);
if (falltime == 6) {
if (m->grid[i][j+1] == '0') {
......@@ -58,20 +40,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
renderChar(explosion3, i, j, offx, offy, 9);
break;
case('r'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8));
} else {
attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3));
}
}
}
renderBould(i, j, offx, offy);
if (falltime == 6) {
if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'f';
......@@ -80,20 +49,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
}
break;
case('l'):
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
if (!((k == 0 || k == 2) && (l == 0 || l == 5))) {
if (k == 0 && (l == 3 || l == 4)) {
attron(COLOR_PAIR(8));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(8));
} else {
attron(COLOR_PAIR(3));
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", bould[k][l]);
attroff(COLOR_PAIR(3));
}
}
}
renderBould(i, j, offx, offy);
if (falltime == 6) {
if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'f';
......@@ -102,13 +58,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
}
break;
case('R'):
if (time < 10)
renderChar(diamond, i, j, offx, offy, 7);
else if (time < 20)
renderChar(diamond2, i, j, offx, offy, 7);
else
renderChar(diamond3, i, j, offx, offy, 7);
renderDiamonds(i, j, offx, offy, time);
if (falltime == 6) {
if (m->grid[i+1][j] == '0') {
m->grid[i+1][j] = 'h';
......@@ -117,13 +67,7 @@ void updatePhysics(map *m, char in, int i, int j, int offx, int offy, int time,
}
break;
case('L'):
if (time < 10)
renderChar(diamond, i, j, offx, offy, 7);
else if (time < 20)
renderChar(diamond2, i, j, offx, offy, 7);
else
renderChar(diamond3, i, j, offx, offy, 7);
renderDiamonds(i, j, offx, offy, time);
if (falltime == 6) {
if (m->grid[i-1][j] == '0') {
m->grid[i-1][j] = 'h';
......
......@@ -56,6 +56,19 @@ void updateRockford(rockford *player, map *m, int action, int done, int delay) {
}
}
void renderRockford(rockford *player) {
void renderRockford(rockford *player, int i, int j, int offx, int offy) {
int k, l;
for (k = 0; k < 3; k++)
for (l = 0; l < 6; l++) {
attron(COLOR_PAIR((k == 0 || k == 1) ? 6 + k : 12));
if (player->dir == 0 || player->dir == 5)
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", rockf[k][l]);
else if (player->dir == 6 || player->dir == 8)
mvprintw(3*j+k+offy, 6*i+l+offx, "%c", rockfr[k][l]);
else if (player->dir == 4 || player->dir == 2)