save the upgrade to a file, the best way is the following:
write a struct that can hold all the data that you want to save, for example:
struct SAVEDATA
{
unsigned int points
TYPE upgrade; //this can be a struct or enum or int or whatever, up to you
//or just do it like
unsigned int speed;
unsigned int armor;
//etc, add whatever you want
};
and then to save do this:
1- create an instance of the data:
2- fill the data
save.speed = speed;
save.points = points;
///whatever..
3- write it to a file:
fstream file;
file.open ( "FILEPATH.MYFORMAT", ios::out | ios::binary );
if ( !file.is_open ( ) )
{
//failed to open the file, handle the error..
}
file.write ( (char*)&save, sizeof SAVEDATA );
file.close ( );
that's it, info saved, and for loading, same thing but reversed:
1- open the file with
ios::in
fstream file;
file.open ( "MYFILEPATH.MYFORMAT", ios::in | ios::binary );
if ( !file.is_open ( ) )
{
//failed to open file (might not be found), handle the error
}
2- read data
SAVEDATA savedData;
file.read ( (char*)&savedData, sizeof SAVEDATA );
//and ofc, close the file which we opened earlier
file.close ( );
3- fill in your game variables using the read data:
speed = savedData.speed;
points = savedData.points;
//etc..
a few things to notice:
1- you need to #include <iostream> and #include <fstream>
2- you need to add "using std::fstream;" and "using std::ios;", or simply just "using namedspace std;"
3-MYFILEPATH.MYFORMAT, can be something like "data\\info.ASD", or whatever, first part (before ".") is the path, and after "." is the format (or extension)