Commit 9ac45b6c authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Organização

parents adaec8af e0b9835f
123123
901
\ No newline at end of file
324
\ No newline at end of file
24 15 150
912 728 636
0 0 0
324 244 0
1000 988 0
512 328 236
412 228 136
712 528 436
1000 1000 1000
0000000000000000000000000000000000000000
1111111111111111111111111111111111111111
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222000222220002222200022222000222221
1222222000222220002222200022222000222221
1222222070222220702222207022222070222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1222222222222222222222222222222222222221
1111111111111111111111111111111111111111
......@@ -18,6 +18,7 @@ typedef struct {
typedef struct {
FILE *sprite;
FILE *highscore;
FILE *lastscore;
char grid[WIDTH][HEIGHT];
int high;
int last;
......
......@@ -11,6 +11,11 @@ void run(int ismenu, int running) {
me.highscore = fopen("./data/highscore.txt", "r");
fscanf(me.highscore, "%d", &me.high);
me.lastscore = fopen("./data/lastscore.txt", "r");
fscanf(me.lastscore, "%d", &me.last);
fclose(me.highscore);
fclose(me.lastscore);
last_time = getTime() / NANO;
readFileMenu(&me);
......@@ -23,7 +28,7 @@ void run(int ismenu, int running) {
renderMenu(&me);
else {
if (load) {
readFileMap(&level, menuaction);
readFileMap(&level, menuaction, 0);
load = false;
}
render(s);
......@@ -54,6 +59,8 @@ int getInput() {
return 4;
case 10:
return 1;
case 27:
return 9;
default:
return 0;
}
......@@ -67,8 +74,10 @@ void update(int action, int *ismenu) {
if (menuaction != -1) {
load = true;
*ismenu = false;
me.last = 0;
}
} else updateMap(&level, action);
} else
updateMap(&level, action, ismenu);
}
void render(int time) {
......
......@@ -33,11 +33,16 @@ int mapnumber;
int done, lightning;
int hold;
int extx, exty;
int pushdelay;
int highscore;
FILE *lastscorefile;
FILE *highscorefile;
void readFileMap(map *m, int mapn) {
void readFileMap(map *m, int mapn, int pscore) {
int i, j;
done = lightning = false;
hold = 0;
pushdelay = 0;
mapnumber = mapn;
waittime = 0;
m->sprite = fopen(mapfile[mapnumber], "r");
......@@ -55,7 +60,7 @@ void readFileMap(map *m, int mapn) {
player.y = j;
player.dir = 5;
player.diamonds = 0;
player.score = 0;
player.score = pscore;
dead = false;
} else if (input[j] == '4') {
extx = i;
......@@ -122,51 +127,91 @@ void setColors() {
init_pair(12, COLOR_RED, COLOR_BLACK);
}
void updateMap(map *m, int action) {
void saveScore() {
lastscorefile = fopen("./data/lastscore.txt", "w+");
highscorefile = fopen("./data/highscore.txt", "r");
fprintf(lastscorefile, "%d", player.score);
fscanf(highscorefile, "%d", &highscore);
fclose(highscorefile);
if (highscore < player.score) {
highscorefile = fopen("./data/highscore.txt", "w+");
fprintf(highscorefile, "%d", player.score);
fclose(highscorefile);
}
fclose(lastscorefile);
}
void updateMap(map *m, int action, int *ismenu) {
getmaxyx(stdscr, row, col);
offy = (row / 2) - (12 * 3);
offx = (col / 2) - (20 * 6);
player.dir = action;
if (player.diamonds >= m->diamonds) {
m->score = 15;
done = true;
lightning = hold <= 8;
}
if (!dead) {
if (done && player.x == extx && player.y == exty) {
if (leveltime == 0)
readFileMap(m, mapnumber+1);
if (action == 9) {
saveScore();
*ismenu = true;
} else {
player.dir = action;
pushdelay = (pushdelay + 1) % 30;
if (player.diamonds >= m->diamonds) {
m->score = 15;
done = true;
lightning = hold <= 8;
}
if (!dead) {
if (done && player.x == extx && player.y == exty) {
if (leveltime == 0) {
saveScore();
readFileMap(m, mapnumber+1, player.score);
}
} else {
updateRockford(&player, m, action, done, pushdelay);
if (leveltime == 0)
dead = true;
}
} else {
updateRockford(&player, m, action, done);
if (leveltime == 0)
dead = true;
waittime++;
if (waittime < 21) {
if(m->grid[player.y-1][player.x-1] != '1')
m->grid[player.y-1][player.x-1] = 'x';
if(m->grid[player.y][player.x-1] != '1')
m->grid[player.y][player.x-1] = 'x';
if(m->grid[player.y+1][player.x-1] != '1')
m->grid[player.y+1][player.x-1] = 'x';
if(m->grid[player.y-1][player.x] != '1')
m->grid[player.y-1][player.x] = 'x';
if(m->grid[player.y][player.x] != '1')
m->grid[player.y][player.x] = 'x';
if(m->grid[player.y+1][player.x] != '1')
m->grid[player.y+1][player.x] = 'x';
if(m->grid[player.y-1][player.x+1] != '1')
m->grid[player.y-1][player.x+1] = 'x';
if(m->grid[player.y][player.x+1] != '1')
m->grid[player.y][player.x+1] = 'x';
if(m->grid[player.y+1][player.x+1] != '1')
m->grid[player.y+1][player.x+1] = 'x';
} else if (waittime <= 100) {
if(m->grid[player.y-1][player.x-1] != '1')
m->grid[player.y-1][player.x-1] = '0';
if(m->grid[player.y][player.x-1] != '1')
m->grid[player.y][player.x-1] = '0';
if(m->grid[player.y+1][player.x-1] != '1')
m->grid[player.y+1][player.x-1] = '0';
if(m->grid[player.y-1][player.x] != '1')
m->grid[player.y-1][player.x] = '0';
if(m->grid[player.y][player.x] != '1')
m->grid[player.y][player.x] = '0';
if(m->grid[player.y+1][player.x] != '1')
m->grid[player.y+1][player.x] = '0';
if(m->grid[player.y-1][player.x+1] != '1')
m->grid[player.y-1][player.x+1] = '0';
if(m->grid[player.y][player.x+1] != '1')
m->grid[player.y][player.x+1] = '0';
if(m->grid[player.y+1][player.x+1] != '1')
m->grid[player.y+1][player.x+1] = '0';
} else if (waittime > 100)
readFileMap(m, mapnumber, player.score);
}
} else {
waittime++;
if (waittime < 21) {
m->grid[player.y-1][player.x-1] = 'x';
m->grid[player.y][player.x-1] = 'x';
m->grid[player.y+1][player.x-1] = 'x';
m->grid[player.y-1][player.x] = 'x';
m->grid[player.y][player.x] = 'x';
m->grid[player.y+1][player.x] = 'x';
m->grid[player.y-1][player.x+1] = 'x';
m->grid[player.y][player.x+1] = 'x';
m->grid[player.y+1][player.x+1] = 'x';
} else if (waittime <= 100) {
m->grid[player.y-1][player.x-1] = '0';
m->grid[player.y][player.x-1] = '0';
m->grid[player.y+1][player.x-1] = '0';
m->grid[player.y-1][player.x] = '0';
m->grid[player.y][player.x] = '0';
m->grid[player.y+1][player.x] = '0';
m->grid[player.y-1][player.x+1] = '0';
m->grid[player.y][player.x+1] = '0';
m->grid[player.y+1][player.x+1] = '0';
} else if (waittime > 100)
readFileMap(m, mapnumber);
}
}
......@@ -247,6 +292,7 @@ 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));
......@@ -264,9 +310,9 @@ void renderMap(map *m, int time) {
case('6'):
if (m->grid[i][j+1] == '0')
m->grid[i][j] = 'f';
if (m->grid[i][j+1] == '6' && 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+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-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-1][j] == '0' && m->grid[i-1][j+1] == '0')
m->grid[i][j] = 'l';
for (k = 0; k < 3; k++)
......
......@@ -5,9 +5,10 @@
#include "entity.h"
#include "rockford.h"
void readFileMap(map *m, int mapn);
void readFileMap(map *m, int mapn, int pscore);
void setColors();
void updateMap(map *m, int action);
void saveScore();
void updateMap(map *m, int action, int *ismenu);
void renderMap(map *m, int time);
#endif
......@@ -11,6 +11,7 @@ int buffer = -1;
void readFileMenu(menu *menu) {
int i, j;
menu->sprite = fopen("./sprites/menu.txt", "r");
buffer = -1;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
......@@ -23,10 +24,6 @@ void readFileMenu(menu *menu) {
}
fclose(menu->sprite);
setMenuColors();
getmaxyx(stdscr, row, col);
offmenuy = (row / 2) - (12 * 3);
offmenux = (col / 2) - (20 * 6);
}
void setMenuColors() {
......@@ -48,6 +45,7 @@ void setMenuColors() {
}
int updateMenu(menu *menu, int action) {
switch(action){
case 6:
currmap = (currmap + 1) % 5;
......@@ -69,6 +67,9 @@ int updateMenu(menu *menu, int action) {
void renderMenu(menu *menu){
int i, j;
getmaxyx(stdscr, row, col);
offmenuy = (row / 2) - (12 * 3);
offmenux = (col / 2) - (20 * 6);
menu->grid[21][20] = ((menu->high / 100000) % 10) + '0';
menu->grid[22][20] = ((menu->high / 10000) % 10) + '0';
......
#include "rockford.h"
void updateRockford(rockford *player, map *m, int action, int done) {
void updateRockford(rockford *player, map *m, int action, int done, int delay) {
if (action == 8) {
char up = m->grid[player->y][player->x-1];
if (up == '0' || up == '2' || (done && up == '4')) {
......@@ -22,6 +22,10 @@ void updateRockford(rockford *player, map *m, int action, int done) {
m->grid[player->y][player->x] = '5';
player->diamonds++;
player->score += m->score;
} else if (right == '6' && m->grid[player->y+2][player->x] == '0' && !(delay % 10)) {
m->grid[player->y++][player->x] = '0';
m->grid[player->y][player->x] = '5';
m->grid[player->y+1][player->x] = '6';
}
} else if (action == 4) {
char left = m->grid[player->y-1][player->x];
......@@ -33,6 +37,10 @@ void updateRockford(rockford *player, map *m, int action, int done) {
m->grid[player->y][player->x] = '5';
player->diamonds++;
player->score += m->score;
} else if (left == '6' && m->grid[player->y-2][player->x] == '0' && !(delay % 10)) {
m->grid[player->y--][player->x] = '0';
m->grid[player->y][player->x] = '5';
m->grid[player->y-1][player->x] = '6';
}
} else if (action == 2) {
char down = m->grid[player->y][player->x+1];
......
......@@ -3,7 +3,7 @@
#include "utils.h"
#include "entity.h"
void updateRockford(rockford *player, map *m, int action, int done);
void updateRockford(rockford *player, map *m, int action, int done, int delay);
void renderRockford(rockford *player);
#endif
......@@ -13,7 +13,7 @@ char nine[3][6] = {" __ ", " [__] ", " _/ "};
char zero[3][6] = {" __ ", " | | ", " |__| "};
char symbol[3][6] = {" ", " /##\\ ", " \\##/ "};
char A[3][6] = {" __ ", " |__| ", " | | "};
char B[3][6] = {" __ ", " | ) ", " |__) "};
char B[3][6] = {" __ ", " |__) ", " |__) "};
char C[3][6] = {" __ ", " | ", " |__ "};
char D[3][6] = {" __ ", " | \\ ", " |__/ "};
char E[3][6] = {" __ ", " |__ ", " |__ "};
......
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