エラー対策などはしっかり調べて、しっかり対処しました。したつもりです。
Mapping.cpp
#pragma once
#include "fmfmap.h"
extern CFmfMap MapObj;
extern int MapBitCount;
extern int MapGraph;
//マップチップサイズ
const int MAP_CELL = 16;
#include "Main.h"
#include "Player.h"
#include "Stage.h"
#include "Mapping.h"
CGameMain Main;
//ステージデータのクラスを生成する。
CStage *Stage;
CFmfMap MapObj;
int CGameMain::MapLoad(const char* file_name, int stage_num) {
MapBitCount = MapObj.GetLayerBitCount() == 8 ? 16 : 256;
if (!MapObj.Open(file_name)) {
return -1;
}
BYTE* layer = (BYTE*)MapObj.GetLayerCount();
if (layer == NULL) {
return -1;
}
return 0;
}
int CGameMain::Init() {
ChangeWindowMode(TRUE), SetGraphMode(320, 240, 32);
//DXライブラリの初期化エラーが発生したときに終了。
if (DxLib_Init() == -1) { return -1; }
Time = GetNowCount();
SetDrawScreen(DX_SCREEN_BACK);
SetWaitVSyncFlag(FALSE);
MapLoad("テスト用.fmf", 0);
LoadDivGraph("マップチップ.bmp", 2, 2, 1, 16, 16, MapGraph, FALSE);
int InitX = 0.0F, InitY = 0.0F;
Player = new CPlayer(InitX,InitY);
Player->Init();
return 0;
}
void CGameMain::Main() {
Time = GetNowCount();
//1/60秒立つまで待つ
while(GetNowCount()-Time<1000/60){}
Player->Update();
Stage->DrawStage();
Player->Draw();
}
void CGameMain::Fin() {
Player->Fin();
delete Player;
DxLib_End();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
Main.Init();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
Main.Main();
}
Main.Fin();
return 0;
}
class CGameMain {
int Time;
CPlayer *Player;
public:
int MapGraph[2];
int StageIndex;
int GameMap;
int MapLoad(const char* file_name, int stage_num);
int Init();
void Main();
void Fin();
};
#pragma once
class CStage {
public:
int MapGraph[2];
float ScrollX, ScrollY;
const char* Name;
int Score, Time;
CStage(const char* name) : Name(name) {}
virtual void Init() {}
virtual void Destroy() {}
virtual bool Move() { return true; }
virtual void Draw() {};
void DrawStage();
};
#include "Stage.h"
#include "Mover.h"
#include "Player.h"
void CStage::DrawStage() {
DWORD cwidth = MapObj.GetChipWidth();
DWORD cheight = MapObj.GetChipHeight();
int index, src_x, src_y;
for (int y = 0; y < 15; y++) {
for (int x = 0; x < 20; x++) {
index = MapObj.GetValue(0, x, y);
src_x = (index % MapBitCount) * cwidth;
src_y = (index / MapBitCount)*cheight;
DrawRectGraph((int)(x*MAP_CELL), (int)(y*MAP_CELL), src_x, src_y, MAP_CELL, MAP_CELL, MapGraph[index], TRUE, FALSE); //ここで例外が起こっている。
}
}
}
エラーコードは以下のとおりです。