softya(ソフト屋) さんが書きました:配列を用意するなら、同じ構造のものを用意したほうが混乱がなく素直に処理できます。
なので、stageと同じ型を用意したほうがシンプルで分かりやすくなります。
playerも構造体にまとめたほうが良いでしょう。
おはようございます。
早速試してみましたが、壁が表示されなくなってしまいました。
コード:
struct StageInfo{
int timerstart; //待機タイマーの開始時刻
int gamestarttime; //ゲームの開始時間
int gametime; //ゲーム開始からの経過ミリ秒
float playerX;
float playerY;
float mapsize_w, mapsize_h; //マップサイズ
Character Wall[MAXMAPCHARA];
Ball Ball[MAXBALLCHARA];
int num_mapchara;
bool isheroleft; //主人公の向き
bool isontheground;
};
//保存用の構造体
struct Retain{
int timerstart; //待機タイマーの開始時刻
int gamestarttime; //ゲームの開始時間
int gametime; //ゲーム開始からの経過ミリ秒
float playerX;
float playerY;
float mapsize_w, mapsize_h; //マップサイズ
Character Wall[MAXMAPCHARA];
Ball Ball[MAXBALLCHARA];
int num_mapchara;
bool isheroleft; //主人公の向き
bool isontheground;
};
コード:
//マップの読み込み
int GameMapLoad(char *filepath){
int f; //ファイルハンドル
char buf[1024]; //テキスト読み込みバッファ
f = FileRead_open(filepath);
if (f == 0) return -1; //読み込みエラー
//マップサイズと主人公初期位置読み込み
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
sscanf_s(buf, "%f, %f, %f, %f", &retain.mapsize_w, &retain.mapsize_h, &retain.playerX, &retain.playerY);
stage.playerX = retain.playerX;
stage.playerY = retain.playerY;
stage.mapsize_w = retain.mapsize_w;
stage.mapsize_h = retain.mapsize_h;
//地形オブジェクト読み込み
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
int imax;
sscanf_s(buf, "%d" , &imax); //行数取得
float wallX, wallY, wallW, wallH, angle;
int id;
for(int i = 0; i < imax; i++){
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
sscanf_s( buf, "%f, %f, %f, %f, %f, %d", &wallX, &wallY, &wallW, &wallH, &angle, &id);
if((int)wallW == 48){
ch.ID = WALL_48;
ch.ID_X = (int)wallX;
ch.ID_Y = (int)wallY;
ch.ID_W = (int)wallW;
ch.ID_H = (int)wallH;
ch.ID_Angle = angle;
}
if((int)wallW == 192){
ch.ID = WALL_192;
ch.ID_X = (int)wallX;
ch.ID_Y = (int)wallY;
ch.ID_W = (int)wallW;
ch.ID_H = (int)wallH;
ch.ID_Angle = angle;
}
if((int)wallW == 284){
ch.ID = WALL_284;
ch.ID_X = (int)wallX;
ch.ID_Y = (int)wallY;
ch.ID_W = (int)wallW;
ch.ID_H = (int)wallH;
ch.ID_Angle = angle;
}
if((int)wallW == 568){
ch.ID = WALL_568;
ch.ID_X = (int)wallX;
ch.ID_Y = (int)wallY;
ch.ID_W = (int)wallW;
ch.ID_H = (int)wallH;
ch.ID_Angle = angle;
}
if(id == 1){
ch.ID = GOAL_FLAG;
ch.ID_X = (int)wallX;
ch.ID_Y = (int)wallY;
ch.ID_W = (int)wallW;
ch.ID_H = (int)wallH;
ch.ID_Angle = angle;
}
ch.used = true;
stage.Wall[stage.num_mapchara] = ch;
retain.Wall[stage.num_mapchara] = stage.Wall[stage.num_mapchara];
stage.num_mapchara++;
retain.num_mapchara = stage.num_mapchara;
}
FileRead_close(f);
return 0;
}
すみません。2つに分けます。