DXライブラリを使用したゲームに近いものを作っていますが、分割したマップ画像が表示されない(シーン変更ボタンを押しても切り替わらない)という事態になっています。
色々とおかしなところだらけですが、根本的に間違っている所があると思いますので、そこを指摘して頂ければありがたいです。
ソースコードとヘッダーは以下の通りです。
#include"map.h"
_MAP _map;
_MAP_LIST _maplist;
int LoadListFile(const char*name, char list[][STR_MAX], int max);
//ファイルのパス読み込み
bool LoadMapList(){
if ((_maplist.num = LoadListFile(MAP_LIST, _maplist.list, MAP_LIST_MAX)) == -1){
return false;
}
return true;
}
bool LoadMapData(){
int fh = 0;
char pass[STR_MAX] = { NULL };
char str[STR_MAX] = { NULL };
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_DATA);
if ((fh = FileRead_open(pass)) == 0){
return false;
}
FileRead_gets(str, STR_MAX, fh);
_map._data.size_x = atoi(str);
_map._data.size_y = atoi(str);
_map._data.chipsize_x = atoi(str);
_map._data.chipsize_y = atoi(str);
if (FileRead_close(fh) == -1){
return false;
}
return true;
}
bool LoadMapFieldData(){
int fh = 0;
char pass[STR_MAX] = { NULL };
char buf[10];
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_IMAGE);
if ((fh = FileRead_open(pass)) == 0){
return false;
}
for (int i = 0; i < _map._data.size_y; i++){
for (int j = 0; j < _map._data.size_x; j++){
_map._field.mapdata[i][j] = (int)(buf[i] - '0');
}
}
if (FileRead_close(fh) == -1){
return false;
}
return true;
}
bool LoadMapGraph(){
char pass[STR_MAX] = { NULL };
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_GRAPH);
LoadDivGraph(pass, 192, 16, 12, _map._data.chipsize_x, _map._data.chipsize_y, _map._field.mapchip[0], false);
if (_map._field.mapchip==false)return false;
return true;
}
void DrawMap(){
for (int i = 0; i <(_map._data.size_y/_map._data.chipsize_y); i++){
for (int j = 0; j <( _map._data.size_x/_map._data.chipsize_x); j++){
DrawGraph((i + _map._data.chipsize_x), (j + _map._data.chipsize_y), _map._field.mapdata[i][j],false);
}
}
}
void GameMap(){
DrawMap();
}
#include"map.h"
_MAP _map;
_MAP_LIST _maplist;
int LoadListFile(const char*name, char list[][STR_MAX], int max);
//ファイルのパス読み込み
bool LoadMapList(){
if ((_maplist.num = LoadListFile(MAP_LIST, _maplist.list, MAP_LIST_MAX)) == -1){
return false;
}
return true;
}
bool LoadMapData(){
int fh = 0;
char pass[STR_MAX] = { NULL };
char str[STR_MAX] = { NULL };
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_DATA);
if ((fh = FileRead_open(pass)) == 0){
return false;
}
FileRead_gets(str, STR_MAX, fh);
_map._data.size_x = atoi(str);
_map._data.size_y = atoi(str);
_map._data.chipsize_x = atoi(str);
_map._data.chipsize_y = atoi(str);
if (FileRead_close(fh) == -1){
return false;
}
return true;
}
bool LoadMapFieldData(){
int fh = 0;
char pass[STR_MAX] = { NULL };
char buf[10];
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_IMAGE);
if ((fh = FileRead_open(pass)) == 0){
return false;
}
for (int i = 0; i < _map._data.size_y; i++){
for (int j = 0; j < _map._data.size_x; j++){
_map._field.mapdata[i][j] = (int)(buf[i] - '0');
}
}
if (FileRead_close(fh) == -1){
return false;
}
return true;
}
bool LoadMapGraph(){
char pass[STR_MAX] = { NULL };
sprintf_s(pass, "%s%s%s", MAP_ROOT, _maplist.list[_maplist.map_id], MAP_GRAPH);
LoadDivGraph(pass, 192, 16, 12, _map._data.chipsize_x, _map._data.chipsize_y, _map._field.mapchip[0], false);
if (_map._field.mapchip==false)return false;
return true;
}
void DrawMap(){
for (int i = 0; i <(_map._data.size_y/_map._data.chipsize_y); i++){
for (int j = 0; j <( _map._data.size_x/_map._data.chipsize_x); j++){
DrawGraph((i + _map._data.chipsize_x), (j + _map._data.chipsize_y), _map._field.mapdata[i][j],false);
}
}
}
void GameMap(){
DrawMap();
}
#include"title.h"
char key[256];
void GameTitle(){
DrawBox(0, 0, 640, 480, GetColor(255, 255, 255), true);
DrawGraph(0, 0, g_titleimg, false);
if (key[KEY_INPUT_Z] == 1){
g_gamestate = GAME_MAP;
}
}
#ifndef __MAP_H__
#define __MAP_H__
#include<DxLib.h>
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
#define MAP_LIST "Map\\map.txt"
#define MAP_ROOT "Map\\"
#define MAP_DATA "\\data.txt"
#define MAP_IMAGE "\\image.txt"
#define MAP_GRAPH "\\chip.png"
#define MAP_LIST_MAX 10
#define MAP_CHIP_NUM_X 20
#define MAP_CHIP_NUM_Y 15
#define MAP_CHIP_X_MAX 192
#define MAP_CHIP_Y_MAX 192
#define MAP_RAYER 4
#define STR_MAX 256
#define SCROLL_MAX_X 40
#define SCROLL_MAX_Y 30
struct MapData{
int size_x;//マップのサイズX
int size_y;//マップのサイズY
int chipsize_x;
int chipsize_y;
};
struct MapField{
int back;
int graphic;
int chipset[32];
int mapchip[5][192];
int mapdata[MAP_CHIP_Y_MAX][MAP_CHIP_X_MAX];
};
struct MapObject{
int field;
int wall;
int obg;
int item;
};
struct _MAP{
MapData _data;
MapField _field;
MapObject _object;
};
struct _MAP_LIST{
char list[MAP_LIST_MAX][STR_MAX];
int num;
int map_id;
};
extern _MAP_LIST _maplist;
bool LoadMapList();
bool LoasMapData();
bool LoadMapFieldData();
bool LoadMapGraph();
void DrawMap();
void GameMap();
#endif
#ifndef __MAIN_H__
#define __MAIN_H__
#include<DxLib.h>
#include"file.h"
#include"title.h"
#include"map.h"
#define STR_MAX 256
//グローバール
extern int g_lasttime;
extern int g_frametime;
enum GameState{
GAME_TITLE, GAME_MAP, GAME_END, GAME_OVER
};
extern GameState g_gamestate;
extern int g_titleimg;
extern float g_hx;
extern float g_hy;
extern char key[256];
void DrawGameTitle();
void DrawGameMap();
void DrawGameEnd();
void DrawGameOver();
#endif