マップを読み込んで表示したいのですが、表示がされません。見ていただけないでしょうか
よろしくお願いします
#include "DxLib.h"
#include "practice.h"
#include "Others.h"
Images img;
StageInfo stage;
//グローバル変数
GameState gamestate = GAME_TITLE;
int ghandle[6];
//時間計測用関数
int g_lasttime = 0; //直前の計測時刻
float g_frametime = 0; //1フレームにかかった時間
float x = 0, y = 0;
int WINAPI WinMain(HINSTANCE h1, HINSTANCE hP, LPSTR lpC, int nC){
//ウィンドウモードにする
ChangeWindowMode(TRUE);
//DXライブラリ初期化
if(DxLib_Init() == -1) return -1;
GameImageLoad();
SetDrawScreen(DX_SCREEN_BACK);
g_lasttime = GetNowCount() & INT_MAX; //現在時刻の記録
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
//1ループにかかった時間を計測
int curtime = GetNowCount() & INT_MAX;
g_frametime = (float)(curtime - g_lasttime) / 1000.0f;
g_lasttime = curtime;
ClsDrawScreen();
//各画面の描画
switch(gamestate){
case GAME_TITLE:
DrawGameTitle();
break;
case GAME_MAIN:
DrawGameMain();
break;
case GAME_CLEAR:
DrawGameClear();
break;
case GAME_OVER:
DrawGameOver();
break;
}
ScreenFlip();
}
//DXライブラリの終了処理
DxLib_End();
return 0;
}
int GameImageLoad(){
//プレーヤー
if(LoadDivGraph("media\\chara_hero_l.png", 6, 6, 1, 46, 96, ghandle) == -1) return -1;
//タイトル画面
img.logo[0] = LoadGraph("media\\titleback.png");
if(img.logo[0] == -1) return -1;
img.logo[1] = LoadGraph("media\\avalanche.png");
if(img.logo[1] == -1) return -1;
//ゲームオーバー
img.logo[2] = LoadGraph("media\\gameover.png");
if(img.logo[2] == -1) return -1;
//壁
img.wall[WALL_568] = LoadGraph("media\\wall_s.png");
if(img.wall[WALL_568] == -1) return -1;
img.wall[WALL_48] = DerivationGraph(0, 0, 48, 48, img.wall[WALL_568]);
img.wall[WALL_192] = DerivationGraph(0, 0, 192, 48, img.wall[WALL_568]);
img.wall[WALL_284] = DerivationGraph(0, 0, 284, 48, img.wall[WALL_568]);
//ゴールの旗
img.wall[GOAL_FLAG] = LoadGraph("media\\goalflag.png");
if(img.wall[GOAL_FLAG] == -1) return -1;
//マップ
if(GameMapLoad("media\\stage01.txt") == -1){
MessageBox(NULL, "マップデータ読み込み失敗", "DXライブラリ", MB_OK);
}
//読み込み成功
return 1;
}
//タイトル画面描画
void GoGameTitle(){
gamestate = GAME_TITLE;
}
void DrawGameTitle(){
int Black = GetColor(0, 0, 0); //黒色の値を取得
//画像表示
DrawGraph(0, 0, img.logo[0], FALSE);
DrawGraph(20, 80, img.logo[1], TRUE);
//テキスト表示
DrawString(100, 340, "Zキーでゲームスタート" , Black); //文字列表示
DrawString(100, 376, "カーソルキーで左右移動" , Black); //文字列表示
int key = GetJoypadInputState(DX_INPUT_KEY_PAD1);
if(IsAKeyTrigger(key) == true) GoGameMain();
}
//ゲーム本編描画
void GoGameMain(){
gamestate = GAME_MAIN;
}
void DrawGameMain(){
int key = GetJoypadInputState( DX_INPUT_KEY_PAD1 );
float mv = 80.0f * g_frametime; //移動量計算
if(key & PAD_INPUT_RIGHT){
x += mv;
stage.isheroleft = false;
}
if(key & PAD_INPUT_LEFT){
x -= mv;
stage.isheroleft = true;
}
if(key == 0){
//プレーヤー
DrawRotaGraph((int)x, (int)y, 1, 0, ghandle[0], TRUE, stage.isheroleft);
}
else {
int animpat = (g_lasttime / (1000 / 12)) % 4;
DrawRotaGraph((int)x, (int)y, 1, 0, ghandle[1 + animpat], TRUE, stage.isheroleft);
}
//Zキーを押すとゲームオーバー画面へ
if(IsAKeyTrigger(key) == true) GoGameOver();
}
//マップの読み込み
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;
float w, h, sx, sy;
sscanf_s(buf, "%f, %f, %f, %f", &w, &h, &sx, &sy);
stage.mapsize_w = w;
stage.mapsize_h = h;
//主人公キャラクター
DrawRotaGraph((int)sx, (int)sy, 1, 0, ghandle[0], TRUE, stage.isheroleft);
//地形オブジェクト読み込み
if(FileRead_gets( buf, 1023, f ) == -1) return -1;
int imax;
sscanf_s(buf, "%d" , &imax); //行数取得
float x, y, 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", &x, &y, &w, &h, &angle, &id);
Character ch;
if((int)w == 48) ch.ID = WALL_48;
if((int)w == 192) ch.ID = WALL_192;
if((int)w == 284) ch.ID = WALL_284;
if((int)w == 568) ch.ID = WALL_568;
if(id == 1) ch.ID = GOAL_FLAG;
ch.used = true;
stage.wall[stage.num_mapchara] = ch;
stage.num_mapchara++;
}
FileRead_close(f);
return 0;
}
//ゲームクリア画面描画
void GoGameClear(){
gamestate = GAME_CLEAR;
}
void DrawGameClear(){
}
//ゲームオーバー画面描画
void GoGameOver(){
gamestate = GAME_OVER;
stage.timerstart = g_lasttime;
}
void DrawGameOver(){
DrawGraph(20, 120, img.logo[2], TRUE);
//5秒経ったらタイトル画面へ
if(g_lasttime - stage.timerstart > 2000) GoGameTitle();
}