私の手元のプログラムは『迷路について2』の頃にFFGXさんがアップしたプログラムをファイルを
分けずに一つのプログラムになっていますが、基本的にFFGXさんのプログラムの
check_and_paint の中身を変えただけとなっています
#include<DxLib.h>
enum {
LOCATION_F4_L, // 0:前4左
LOCATION_F4_R, // 1:前4右
LOCATION_F4, // 2:前4
LOCATION_F3_L, // 3:前3左
LOCATION_F3_R, // 4:前3右
LOCATION_F3, // 5:前3
LOCATION_F2_L, // 6:前2左
LOCATION_F2_R, // 7:前2右
LOCATION_F2, // 8:前2
LOCATION_F1_L, // 9:前1左
LOCATION_F1_R, // 10:前1右
LOCATION_F1, // 11:前1
LOCATION_L, // 12:左
LOCATION_R, // 13:右
LOCATION_C, // 14:現在地
LOCATION_MAX // 15
};
int gr[LOCATION_MAX][4];
int aa[LOCATION_MAX][4];
void loading() {
gr[0][2] = LoadGraph("madia\\0_2.png", true);
gr[1][2] = LoadGraph("madia\\1_2.png", true);
gr[2][2] = LoadGraph("madia\\2_2.png", true);
gr[3][2] = LoadGraph("madia\\3_2.png", true);
gr[3][3] = LoadGraph("madia\\3_3.png", true);
gr[4][1] = LoadGraph("madia\\4_1.png", true);
gr[4][2] = LoadGraph("madia\\4_2.png", true);
gr[5][2] = LoadGraph("madia\\5_2.png", true);
gr[6][2] = LoadGraph("madia\\6_2.png", true);
gr[6][3] = LoadGraph("madia\\6_3.png", true);
gr[7][1] = LoadGraph("madia\\7_1.png", true);
gr[7][2] = LoadGraph("madia\\7_2.png", true);
gr[8][2] = LoadGraph("madia\\8_2.png", true);
gr[9][2] = LoadGraph("madia\\9_2.png", true);
gr[9][3] = LoadGraph("madia\\9_3.png", true);
gr[10][1] = LoadGraph("madia\\10_1.png", true);
gr[10][2] = LoadGraph("madia\\10_2.png", true);
gr[11][2] = LoadGraph("madia\\11_2.png", true);
gr[12][3] = LoadGraph("madia\\12_3.png", true);
gr[13][1] = LoadGraph("madia\\13_1.png", true);
aa[0][0] = NULL;
aa[0][1] = NULL;
aa[0][2] = gr[0][2];
aa[0][3] = NULL;
aa[1][0] = NULL;
aa[1][1] = NULL;
aa[1][2] = gr[1][2];
aa[1][3] = NULL;
aa[2][0] = NULL;
aa[2][1] = NULL;
aa[2][2] = gr[2][2];
aa[2][3] = NULL;
aa[3][0] = gr[0][2];
aa[3][1] = NULL;
aa[3][2] = gr[3][2];
aa[3][3] = gr[3][3];
aa[4][0] = gr[1][2];
aa[4][1] = gr[4][1];
aa[4][2] = gr[4][2];
aa[4][3] = NULL;
aa[5][0] = gr[2][2];
aa[5][1] = gr[3][3];
aa[5][2] = gr[5][2];
aa[5][3] = gr[4][1];
aa[6][0] = gr[3][2];
aa[6][1] = NULL;
aa[6][2] = gr[6][2];
aa[6][3] = gr[6][3];
aa[7][0] = gr[4][2];
aa[7][1] = gr[7][1];
aa[7][2] = gr[7][2];
aa[7][3] = NULL;
aa[8][0] = gr[5][2];
aa[8][1] = gr[6][3];
aa[8][2] = gr[8][2];
aa[8][3] = gr[7][1];
aa[9][0] = gr[6][2];
aa[9][1] = NULL;
aa[9][2] = gr[9][2];
aa[9][3] = gr[9][3];
aa[10][0] = gr[7][2];
aa[10][1] = gr[10][1];
aa[10][2] = gr[10][2];
aa[10][3] = NULL;
aa[11][0] = gr[8][2];
aa[11][1] = gr[9][3];
aa[11][2] = gr[11][2];
aa[11][3] = gr[10][1];
aa[12][0] = gr[9][2];
aa[12][1] = NULL;
aa[12][2] = NULL;
aa[12][3] = gr[12][3];
aa[13][0] = gr[10][2];
aa[13][1] = gr[13][1];
aa[13][2] = NULL;
aa[13][3] = NULL;
aa[14][0] = gr[11][2];
aa[14][1] = gr[12][3];
aa[14][3] = gr[13][1];
}
#define ONE 41
int maphierarchy = 1;
enum {
DIRECTION_N,
DIRECTION_W,
DIRECTION_S,
DIRECTION_E,
DIRECTION_MAX
};
enum {
WALL_NONE,
WALL_WALL,
WALL_MAX
};
int location[DIRECTION_MAX][LOCATION_MAX][2] = {
{ // 0
{-1,-4}, {1,-4}, {0,-4},
{-1,-3},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1,-1,-1},
{-1,-1,-1,-1}
}; //壁のデータ保存用(3次元)
int fov2[LOCATION_MAX][DIRECTION_MAX]; //グラフィックデータ保存用
void check_and_paint() {
int data[LOCATION_MAX];
for (int i = 0; i < LOCATION_MAX; i++) {
data[i] = maps[Py + location[Pd][i][1]][Px + location[Pd][i][0]];
}
if (data[LOCATION_F4_L] == 0 &&
data[LOCATION_F3_L] == 1 &&
data[LOCATION_F3] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[0][2], true);
}
if (data[LOCATION_F4_R] == 0 &&
data[LOCATION_F3_R] == 1 &&
data[LOCATION_F3] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[1][2], true);
}
if (data[LOCATION_F4] == 0 &&
data[LOCATION_F3] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[2][2], true);
}
if (data[LOCATION_F3_L] == 0 &&
data[LOCATION_F2_L] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[3][2], true);
}
if (data[LOCATION_F3_L] == 0 &&
data[LOCATION_F3] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[3][3], true);
}
if (data[LOCATION_F3_R] == 0 &&
data[LOCATION_F3] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[4][1], true);
}
if (data[LOCATION_F3_R] == 0 &&
data[LOCATION_F2_R] == 1 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[4][2], true);
}
if (data[LOCATION_F3] == 0 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[5][2], true);
}
if (data[LOCATION_F2_L] == 0 &&
data[LOCATION_F1_L] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[6][2], true);
}
if (data[LOCATION_F2_L] == 0 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[6][3], true);
}
if (data[LOCATION_F2_R] == 0 &&
data[LOCATION_F2] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[7][1], true);
}
if (data[LOCATION_F2_L] == 0 &&
data[LOCATION_F1] == 1 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[7][2], true);
}
if (data[LOCATION_F2] == 0 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[8][2], true);
}
if (data[LOCATION_F1_L] == 0 &&
data[LOCATION_L] == 1)
{
DrawGraph(0, 0, gr[9][2], true);
}
if (data[LOCATION_F1_L] == 0 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[9][3], true);
}
if (data[LOCATION_F1_R] == 0 &&
data[LOCATION_F1] == 1)
{
DrawGraph(0, 0, gr[10][1], true);
}
if (data[LOCATION_F1_R] == 0 &&
data[LOCATION_R] == 1)
{
DrawGraph(0, 0, gr[10][2], true);
}
if (data[LOCATION_F1] == 0)
{
DrawGraph(0, 0, gr[11][2], true);
}
if (data[LOCATION_L] == 0)
{
DrawGraph(0, 0, gr[12][3], true);
}
if (data[LOCATION_R] == 0)
{
DrawGraph(0, 0, gr[13][1], true);
}
}
void mapPaint() {
check_and_paint();
DrawBox(480, 0, 640, 480,GetColor(0, 0, 0), true);
}
void mainloop() {
ClearDrawScreen();
mapPaint();
ScreenFlip();
if (CheckHitKey(KEY_INPUT_UP)) {
if (Pd==0) {
}
WaitTimer(200);
}
if (CheckHitKey(KEY_INPUT_DOWN)) {
Pd += 2;
if (Pd == 4)
Pd = 0;
if (Pd == 5)
Pd = 1;
WaitTimer(200);
}
if (CheckHitKey(KEY_INPUT_RIGHT)) {
Pd--;
if (Pd == -1)
Pd = 3;
WaitTimer(200);
}
if (CheckHitKey(KEY_INPUT_LEFT)) {
Pd++;
if (Pd == 4)
Pd = 0;
WaitTimer(200);
}
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
SetOutApplicationLogValidFlag(false);
SetWindowText("maze");
ChangeWindowMode(true);
SetBackgroundColor(255, 255, 255);
DxLib_Init();
SetDrawScreen(DX_SCREEN_BACK);
loading();// 読み込み
while (1) {
mainloop();
if (ProcessMessage() != 0)
break;
if (CheckHitKey(KEY_INPUT_ESCAPE))
break;
}
DxLib_End();
return 0;
}