This is the tutorial to save and load individual status for actor with clones
First of all, count the max clone and their status you want to store.
For example you want to store 100 clones, with 5 status (hp,power,coin,PosX,PosY)...since all the status are int, make the master array as int in Global code
Oh yah, first of all make the actor variable for hp,power,coin,PosX,PosY
Global code:
- Code: Select all
#define CloneCount 100
#define StatusCount 5
int Status[CloneCount+1][StatusCount];
The next is just store each status from each clone, for example store the hp value through draw actor :
Actor->Draw Actor:
- Code: Select all
Status[cloneindex][0]=hp; //I think you already know how to set hp :P
Status[cloneindex][1]=power;
Status[cloneindex][2]=coin;
Status[cloneindex][3]=PosX; //or Status[cloneindex][3]=x;
Status[cloneindex][4]=PosY; //or Status[cloneindex][4]=y;
//or something like that
The next is, make the custom load and save function.
Global code:
- Code: Select all
void SaveStatus(char Name[32])
{
FILE *f=fopen(Name,"wb");
int i,j;
for(i=0;i<CloneCount;i++)
{
for(j=0;j<StatusCount;j++)
{
fwrite(Status[i][j],1,sizeof(int),f);
}
}
}
void LoadStatus(char Name[32])
{
FILE *f=fopen(Name,"rb");
int i,j;
for(i=0;i<CloneCount;i++)
{
for(j=0;j<StatusCount;j++)
{
fread(Status[i][j],1,sizeof(int),f);
}
}
}
Now, put the Load and Save function somewhere...usually I Load the status in :
view -> CreateActor:
- Code: Select all
int i,j;
LoadStatus("myfile.sav");
//Now generate the Actor and load all of their status
for(i=0;i<CloneCount;i++)
{
for(j=0;j<StatusCount;j++)
{
if(Status[i][0]>0) //if hp>0
{
CreateActor("Actor","animation","(none)","(none)",0,0,false);
Actor.hp=Status[i][0];
Actor.power=Status[i][1];
Actor.coin=Status[i][2];
Actor.x=Actor.PosX=Status[i][3];
Actor.y=Actor.PosY=Status[i][4];
}
}
}
The last is save the Status...usually I Save the status before load the next level or when pressing save button, well for this one you're free
- Code: Select all
SaveStatus("myfile.sav");
Let me see if you have some trouble