Commit 68a4e437 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Adicionado highscore, lastscore e esc bugado

parent 1b731de0
123123
586
\ No newline at end of file
0
\ No newline at end of file
......@@ -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,65 +127,87 @@ void setColors() {
init_pair(12, COLOR_RED, COLOR_BLACK);
}
void updateMap(map *m, int action) {
player.dir = action;
if (player.diamonds >= m->diamonds) {
m->score = 15;
done = true;
lightning = hold <= 8;
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);
}
if (!dead) {
if (done && player.x == extx && player.y == exty) {
if (leveltime == 0)
readFileMap(m, mapnumber+1);
void updateMap(map *m, int action, int *ismenu) {
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) {
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);
}
}
......
......@@ -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++)
......
#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,7 +22,7 @@ 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') {
} 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';
......@@ -37,7 +37,7 @@ 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') {
} 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';
......
......@@ -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
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