Skip to content

Commit

Permalink
fixed save file
Browse files Browse the repository at this point in the history
  • Loading branch information
NotImplementedLife committed Oct 23, 2022
1 parent 454b721 commit e943862
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
25 changes: 3 additions & 22 deletions include/data/mapstats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,10 @@ struct MapData

#define cr_map(mapx, sx, sy, fx, fy) { #mapx, mapx, sx, sy, fx, fy }

#include "intro1.mapdata.h"
#include "intro2.mapdata.h"
#include "intro3.mapdata.h"
extern const MapData MAP_STATS[];

#include "map1.mapdata.h"
#include "map2.mapdata.h"
#include "map3.mapdata.h"
#include "map4.mapdata.h"
#include "map5.mapdata.h"

constexpr MapData MAP_STATS[]
{
MAP_DATA_intro1,
MAP_DATA_intro2,
MAP_DATA_intro3,
MAP_DATA_map1,
MAP_DATA_map2,
MAP_DATA_map3,
MAP_DATA_map4,
MAP_DATA_map5,
};

#define MAP_STATS_COUNT ((int)(sizeof(MAP_STATS)/sizeof(MapData)))
//#define MAP_STATS_COUNT ((int)(sizeof(MAP_STATS)/sizeof(MapData)))
#define MAP_STATS_COUNT 8


const MapData* random_map();
2 changes: 1 addition & 1 deletion include/save_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct SaveData
{
int header;
int language;
int maps_mmss[MAP_STATS_COUNT];
unsigned maps_mmss[MAP_STATS_COUNT];

};

Expand Down
22 changes: 22 additions & 0 deletions source/data/mapstats.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
#include "mapstats.hpp"

#include "intro1.mapdata.h"
#include "intro2.mapdata.h"
#include "intro3.mapdata.h"

#include "map1.mapdata.h"
#include "map2.mapdata.h"
#include "map3.mapdata.h"
#include "map4.mapdata.h"
#include "map5.mapdata.h"

#include <stdlib.h>

const MapData MAP_STATS[]
{
MAP_DATA_intro1,
MAP_DATA_intro2,
MAP_DATA_intro3,
MAP_DATA_map1,
MAP_DATA_map2,
MAP_DATA_map3,
MAP_DATA_map4,
MAP_DATA_map5,
};

const MapData* random_map()
{
return &MAP_STATS[rand()%MAP_STATS_COUNT];
Expand Down
2 changes: 1 addition & 1 deletion source/save_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void SaveFile::load()
data().header = HEADER;
data().language = LANG_EN;
for(int i=0;i<MAP_STATS_COUNT;i++)
data().maps_mmss[i]=0;
data().maps_mmss[i]=0xFFFFFFFF;
save();
return;
}
Expand Down
18 changes: 15 additions & 3 deletions source/scenes/map_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using namespace Astralbrew::Entity;
#include "arrow.h"

#include "ghost.hpp"
#include "save_file.hpp"

#include "qmath.h"

Expand Down Expand Up @@ -69,8 +70,9 @@ void MapScene::load_mapstat(const MapData* md)
}

void MapScene::next_map()
{
int i = mapdata-MAP_STATS;
{
int i = mapdata-MAP_STATS;

if(i==MAP_STATS_COUNT-1)
{
close()->next(nullptr);
Expand Down Expand Up @@ -502,7 +504,17 @@ void MapScene::open_reports(int code)
}
else if(i==5)
{
vwf.put_text(get_message(LMSG_HI_SCORE), Pal4bit, SolidColorBrush(0x4));
int j = (mapdata-MAP_STATS);
unsigned mm_ss = (mm<<16)|ss;
//assert(SAVE_FILE.data().maps_mmss[i]!=0);
if(mm_ss < SAVE_FILE.data().maps_mmss[j])
{
SAVE_FILE.data().maps_mmss[j] = mm_ss;
SAVE_FILE.save();
vwf.put_text(get_message(LMSG_HI_SCORE), Pal4bit, SolidColorBrush(0x4));
}
else
vwf.put_text("\n", Pal4bit, SolidColorBrush(0x4));
digits_moving = false;

vwf.put_text(get_message(LMSG_NEXT_LEVEL_MSG), Pal4bit, SolidColorBrush(0x4));
Expand Down
2 changes: 1 addition & 1 deletion text/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GAME_OVER_PLAYER_FALL = "You fell out of the ice platform.\n"
GAME_OVER_GHOST_ATK = "A ghost attacked you.\n"
LEVEL_COMPLETE = " Well Done!\n"
HI_SCORE = "\n HI SCORE!!!"
GAME_OVER_OPTIONS = "\n A - Restart\n B - Back to title"
GAME_OVER_OPTIONS = "\n A - Restart B - Back to title"
NEXT_LEVEL_MSG = "\n\n A - next level"

[ES]
Expand Down

0 comments on commit e943862

Please sign in to comment.