Commit 09e78bba authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Adicionado suporte a multiplos mapas

parents 4764ac71 550dd390
1000 1000 1000
0 0 0
0 0 1000
000000000000000000000000000000000000000
011111111111111111111111111111111111110
012222222222222222222222222222222222210
012111122111121222211122211112111222210
012122212122121222212212212222122122210
012122212122121222212221211122121222210
012122122122121222212221211122112222210
012122212122121222212212212222121222210
012111122111121111211122211112122122210
012222222222222222222222222222222222210
012222222222211122222122211111212221210
012222222222212212221212212222212221210
012222222222212221212221211111211111210
012222222222212221211111222221211111210
012222222222212212212221222221212221210
012222222222211122212221211111212221210
012222222222222222222222222222222222210
011111111111111111111111111111111111110
000000000000000000000000000000000000000
00000000high0score:00000000000000000000
00000000last000000:00000000000000000000
0000<0>00000000cave00000000000000000000
000000000000000000000000000000000enter0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@
@!###################################!@
@!#!!!!##!!!!#!####!!!###!!!!#!!!####!@
@!#!###!#!##!#!####!##!##!####!##!###!@
@!#!###!#!##!#!####!###!#!!!##!#!####!@
@!#!##!##!##!#!####!###!#!!!##!!#####!@
@!#!###!#!##!#!####!##!##!####!#!####!@
@!#!!!!##!!!!#!!!!#!!!###!!!!#!##!###!@
@!###################################!@
@!###########!!!#####!###!!!!!#!###!#!@
@!###########!##!###!#!##!#####!###!#!@
@!###########!###!#!###!#!!!!!#!!!!!#!@
@!###########!###!#!!!!!#####!#!!!!!#!@
@!###########!##!##!###!#####!#!###!#!@
@!###########!!!###!###!#!!!!!#!###!#!@
@!###################################!@
@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@high@score:@@@@@@@@@@@@@@@@@@@@
@@@@@@@@last@@@@@@:@@@@@@@@@@@@@@@@@@@@
@@@@<@>@@@@@@@@cave@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@enter@
......@@ -20,6 +20,7 @@ typedef struct {
FILE *highscore;
char grid[WIDTH][HEIGHT];
int high;
int last;
} menu;
#endif
......@@ -3,6 +3,7 @@
map level;
menu me;
int menuaction;
int load = false;
void run(int ismenu, int running) {
double last_time, current_time, delta = FPS;
......@@ -10,17 +11,23 @@ void run(int ismenu, int running) {
me.highscore = fopen("./data/highscore.txt", "r");
fscanf(me.highscore, "%d", &me.high);
last_time = getTime() / NANO;
readFileMap(&level);
readFileMenu(&me);
while (running) {
current_time = getTime() / NANO;
if (current_time >= last_time) {
last_time += delta;
if (ismenu)
renderMenu(&me);
else
else {
if (load) {
readFileMap(&level, menuaction);
load = false;
}
render(s);
}
update(action, &ismenu);
action = getInput();
s = (s + 1) % 30;
......@@ -45,7 +52,7 @@ int getInput() {
return 6;
case KEY_LEFT:
return 4;
case KEY_ENTER:
case 10:
return 1;
default:
return 0;
......@@ -57,8 +64,10 @@ int getInput() {
void update(int action, int *ismenu) {
if (*ismenu) {
menuaction = updateMenu(&me, action);
if (menuaction == 1)
if (menuaction != -1) {
load = true;
*ismenu = false;
}
} else updateMap(&level, action);
}
......
......@@ -18,6 +18,7 @@ char butterfly[3][6] = {"\\\\ //", " (__) ", "// \\\\"};
char explosion[3][6] = {" ", " ## ", " "};
char explosion2[3][6] = {"\\\\||//", "--##--", "//||\\\\"};
char explosion3[3][6] = {"#%$@%@", "#@ ##", "&@*@*#"};
char mapfile[2][100] = {"./sprites/map1.txt", "./sprites/map2.txt"};
int colors[7][3];
......@@ -28,14 +29,16 @@ int dead;
int offy, offx;
int row, col;
int leveltime, waittime;
int mapnumber;
void readFileMap(map *m) {
void readFileMap(map *m, int mapn) {
int i, j;
mapnumber = mapn;
leveltime = 150;
waittime = 0;
m->score = 10;
m->diamonds = 12;
m->sprite = fopen("./sprites/map1.txt", "r");
m->sprite = fopen(mapfile[mapnumber], "r");
for (i = 0; i < 7; i++)
for (j = 0; j < 3; j++)
......@@ -136,7 +139,7 @@ void updateMap(map *m, int action) {
m->grid[player.y][player.x+1] = '0';
m->grid[player.y+1][player.x+1] = '0';
} else if (waittime > 100)
readFileMap(m);
readFileMap(m, mapnumber);
}
}
......
......@@ -5,7 +5,7 @@
#include "entity.h"
#include "rockford.h"
void readFileMap(map *m);
void readFileMap(map *m, int mapn);
void setColors();
void updateMap(map *m, int action);
void renderMap(map *m, int time);
......
......@@ -4,6 +4,9 @@ int menuColors[3][3];
char input[WIDTH];
int offmenuy, offmenux;
int row, col;
char mps[5] = {'a', 'b', 'c', 'd', 'e'};
int currmap = 0;
int buffer = -1;
void readFileMenu(menu *menu) {
int i, j;
......@@ -45,28 +48,53 @@ void setMenuColors() {
}
int updateMenu(menu *menu, int action) {
return 0;
switch(action){
case 6:
currmap = (currmap + 1) % 5;
menu->grid[21][21] = mps[currmap];
break;
case 4:
currmap = currmap == 0 ? 4 : currmap - 1;
menu->grid[21][21] = mps[currmap];
break;
case 1:
buffer = currmap;
break;
default:
menu->grid[21][21] = mps[currmap];
break;
}
return buffer;
}
void renderMenu(menu *menu){
int i, j;
/*menu->grid[31][0] = ((menu->high / 100000) % 10) + 'A';
menu->grid[32][0] = ((menu->high / 10000) % 10) + 'A';
menu->grid[33][0] = ((menu->high / 1000) % 10) + 'A';
menu->grid[34][0] = ((menu->high / 100) % 10) + 'A';
menu->grid[35][0] = ((menu->high / 10) % 10) + 'A';
menu->grid[36][0] = (menu->high % 10) + 'A';*/
for (i = 0; i < WIDTH; i++) {
menu->grid[21][19] = ((menu->high / 100000) % 10) + '0';
menu->grid[22][19] = ((menu->high / 10000) % 10) + '0';
menu->grid[23][19] = ((menu->high / 1000) % 10) + '0';
menu->grid[24][19] = ((menu->high / 100) % 10) + '0';
menu->grid[25][19] = ((menu->high / 10) % 10) + '0';
menu->grid[26][19] = (menu->high % 10) + '0';
menu->grid[21][20] = ((menu->last / 100000) % 10) + '0';
menu->grid[22][20] = ((menu->last / 10000) % 10) + '0';
menu->grid[23][20] = ((menu->last / 1000) % 10) + '0';
menu->grid[24][20] = ((menu->last / 100) % 10) + '0';
menu->grid[25][20] = ((menu->last / 10) % 10) + '0';
menu->grid[26][20] = (menu->last % 10) + '0';
for (i = 0; i < WIDTH; i++) {
for (j = 0; j < HEIGHT; j++) {
switch (menu->grid[i][j]) {
case('0'):
case('@'):
renderChar(empty, i, j, offmenux, offmenuy, 1);
break;
case('1'):
case('!'):
renderChar(empty, i, j, offmenux, offmenuy, 4);
break;
case('2'):
case('#'):
renderChar(empty, i, j, offmenux, offmenuy, 3);
break;
case('h'):
......@@ -96,6 +124,12 @@ void renderMenu(menu *menu){
case('a'):
renderChar(A, i, j, offmenux, offmenuy, 2);
break;
case('b'):
renderChar(B, i, j, offmenux, offmenuy, 2);
break;
case('d'):
renderChar(D, i, j, offmenux, offmenuy, 2);
break;
case('t'):
renderChar(T, i, j, offmenux, offmenuy, 2);
break;
......@@ -113,6 +147,39 @@ void renderMenu(menu *menu){
break;
case('n'):
renderChar(N, i, j, offmenux, offmenuy, 2);
break;
case(':'):
renderChar(DOTS, 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;
}
}
......
......@@ -28,7 +28,7 @@ char T[3][6] = {" ___ ", " | ", " | "};
char V[3][6] = {" ", " \\ / ", " \\/ "};
char SL[3][6] = {" ", " /___ ", " \\ "};
char SR[3][6] = {" ", " ___\\ ", " / "};
char DOTS[3][6] = {" ", " . ", " . "};
void renderChar(char mat[3][6], int i, int j, int offx, int offy, int color) {
int k, l;
......
......@@ -41,6 +41,7 @@ char T[3][6];
char V[3][6];
char SL[3][6];
char SR[3][6];
char DOTS[3][6];
void renderChar(char mat[3][6], int i, int j, int offx, int offy, int color);
......
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