独学で自動生成ダンジョンを作成中なんですが、画像が描写されません。
画面が背景色で指定している黒になってしまいます。
エラーもなく問題なくプログラムは動いているようなのですが、なぜ描写されないのかが分かりません。
OSはWindows7 でコンパイラはVC++2010 でDXライブラリを使っています。
どうかご回答をお願いします。
#include "DxLib.h" //Dxライブラリ ヘッダー
#define Rand( min, max ) GetRand( max ) + min ///乱数の範囲取得(int型)
#define WHITE GetColor( 255, 255, 255 ) ///白色の取得
#define MAX_RECT_COUNT 4 ///区間の最大数
#define MIN_RECT_SIZE 8 ///区間の最小サイズ
#define MIN_ROOM_SIZE 4 ///部屋の最小サイズ
#define MAP_WIDTH 50 ///マップの幅
#define MAP_HEIGHT 50 ///マップの高
int map[ MAP_WIDTH ][ MAP_HEIGHT ]; ///マップ配列
int player, enemy, chip1[3];
int px = 1, py = 1;
typedef struct{
int lx, ly, hx, hy;
} s_room; ///部屋の構造体 定義
typedef struct {
int lx, ly, hx, hy;
s_room room;
} s_rect; ///区間の構造体 定義
int roomCount = 0; ///部屋リスト数
s_room *room_list = NULL; ///部屋リスト
int rectCount = 0; ///区間リスト数
s_rect *rect_list = NULL; ///区間リスト
//関数 メインループ継続のチェック
bool MainLoopCheck( void ){
//裏画面を表画面に反映, メッセージ処理, 画面クリア
return ScreenFlip( ) == 0 && ProcessMessage( ) == 0 && ClearDrawScreen( ) == 0;
}
//部屋リストに追加
void roomList_append(s_room room)
{
roomCount++;
room_list = (s_room *)realloc( room_list, sizeof( s_room ) * roomCount );
room_list[ roomCount - 1 ].lx = room.lx;
room_list[ roomCount - 1 ].ly = room.ly;
room_list[ roomCount - 1 ].hx = room.hx;
room_list[ roomCount - 1 ].hy = room.hy;
}
//部屋の追加
s_room room_add( int lx, int ly, int hx, int hy )
{
s_room room;
room.lx = lx;
room.ly = ly;
room.hx = hx;
room.hy = hy;
roomList_append(room);
return room;
}
//部屋の生成
void room_make( )
{
s_rect rect; ///参照用
int lx, ly, hx, hy; ///結果用
for( int i = 0; i < rectCount; i++ )
{
rect = rect_list[ i ];
hx = Rand( MIN_ROOM_SIZE, rect.hx - 3 );
hy = Rand( MIN_ROOM_SIZE, rect.hy - 3 );
lx = Rand( rect.lx + 2, rect.lx + rect.hx - hx - 1 );
ly = Rand( rect.ly + 2, rect.ly + rect.hy - hy - 1 );
rect_list[ i ].room = room_add( lx, ly, hx, hy );
}
}
//区間リストに追加
void rectList_append(s_rect rect)
{
rectCount++;
rect_list = (s_rect *)realloc( rect_list, sizeof( s_rect ) * rectCount );
rect_list[ rectCount - 1 ].lx = rect.lx;
rect_list[ rectCount - 1 ].ly = rect.ly;
rect_list[ rectCount - 1 ].hx = rect.hx;
rect_list[ rectCount - 1 ].hy = rect.hy;
}
//区間の追加
s_rect rect_add( int lx, int ly, int hx, int hy )
{
s_rect rect;
rect.lx = lx;
rect.ly = ly;
rect.hx = hx;
rect.hy = hy;
rectList_append(rect);
return rect;
}
//区間の生成
void rect_split( s_rect rect_parent )
{
s_rect rect_child;
//生成中止条件
if( ( rect_parent.hy <= MIN_RECT_SIZE * 2 ) || //y軸方向のサイズが最小区間サイズの2倍以下
( rect_parent.hx <= MIN_RECT_SIZE * 2 ) || //x軸方向のサイズが最小区間サイズの2倍以下
rectCount > MAX_RECT_COUNT) //区間データ数が最大数よりおおきい
return;
//区間(子)の生成
rect_child = rect_add( rect_parent.lx, rect_parent.ly, rect_parent.hx, rect_parent.hy );
//分割点
int split_coord;
if( Rand( 0, 2 ) == 0 ){
//縦の分割
split_coord = Rand( rect_parent.ly + MIN_RECT_SIZE, rect_parent.ly + rect_parent.hy - MIN_RECT_SIZE );
rect_parent.hy = split_coord - rect_parent.ly;
rect_child.ly = split_coord;
rect_split( rect_parent );
rect_split( rect_child );
return;
} else{
//横の分割
split_coord = Rand( rect_parent.lx + MIN_RECT_SIZE, rect_parent.lx + rect_parent.hx - MIN_RECT_SIZE );
rect_parent.hx = split_coord - rect_parent.lx;
rect_child.lx = split_coord;
rect_split( rect_parent );
rect_split( rect_child );
return;
}
}
//マップの生成
void mapCreate( void )
{
int i, j, k;
//マップの初期化
for ( j = 0; j < MAP_HEIGHT; j++)
for ( i = 0; i < MAP_WIDTH; i++)
map[ i ][ j ] = -1;
rect_list = NULL;
room_list = NULL;
//区間の生成
rect_split( rect_add( 0, 0, MAP_WIDTH - 1, MAP_HEIGHT - 1 ) );
// rect_add( 0, 0, MAP_WIDTH - 1, MAP_HEIGHT - 1 );
//部屋の生成
room_make( );
s_rect rect;
s_room room;
//描画のための処理
for( k = 0; k < rectCount; k++ ) {
rect = rect_list[ k ];
//「区」の処理
for ( i = rect.lx, j = rect.ly; i <= rect.lx + rect.hx; i++ ) map[ i ][ j ] = -2;
for ( i = rect.lx, j = rect.ly + rect.hy; i <= rect.lx + rect.hx; i++) map[ i ][ j ] = -2;
for ( i = rect.lx, j = rect.ly; j <= rect.ly + rect.hy; j++) map[ i ][ j ] = -2;
for ( i = rect.lx + rect.hx, j = rect.ly; j <= rect.ly + rect.hy; j++) map[ i ][ j ] = -2;
room = rect.room;
//「床」の処理
for ( i = room.lx; i <= room.lx + room.hx; i++ )
for ( j = room.ly; j <= room.ly + room.hy; j++ )
map[ i ][ j ] = 0;
}
}
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int ){
//ゲームの初期化
ChangeWindowMode( TRUE ); //TRUE・・・ウィンドウモード FALSE・・・フルスクリーン
SetGraphMode( 750 , 750, 16 ); //750×750のサイズで解像度16bitに設定
DxLib_Init( ); //DXライブラリ初期化
SetDrawScreen( DX_SCREEN_BACK ); //描画先を裏画面に設定
player = LoadGraph("picture\\player1.png");
int l_fontHandle = LoadDivGraph("picture\\chip1.png", 3, 3, 1, 32, 32, chip1);
while (!ProcessMessage()) {
ClearDrawScreen();
int kx = px, ky = py;
if (CheckHitKey(KEY_INPUT_LEFT)) kx--;
if (CheckHitKey(KEY_INPUT_RIGHT)) kx++;
if (CheckHitKey(KEY_INPUT_UP)) ky--;
if (CheckHitKey(KEY_INPUT_DOWN)) ky++;
if (map[50][50] != 1){
px = kx;
py = ky;
}
}
mapCreate( );
//ゲームの初期化
//メインループ
while( MainLoopCheck( ) ){ ///メインループチェック
for ( int j = 0; j < MAP_HEIGHT; j++)
for ( int i = 0; i < MAP_WIDTH; i++){
if ( map[ i ][ j ] == -1 )
DrawStringToHandle( 15 * i, 15 * j, (TCHAR*)chip1[1] , WHITE,l_fontHandle );
else if ( map[ i ][ j ] == -2 )
DrawStringToHandle( 15 * i, 15 * j, (TCHAR*)chip1[2], WHITE,l_fontHandle );
else if ( map[ i ][ j ] == 0 )
DrawStringToHandle( 15 * i, 15 * j, (TCHAR*)chip1[3], WHITE,l_fontHandle );
}
}
//メインループ
//ゲームの終了処理
DxLib_End( ); //DXライブラリ終了
//ゲームの終了処理
return 0;
}