<loading.h>
#pragma once
#include<DxLib.h>
#define 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.h>
#pragma once
#include"loading.h"
#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}, {1,-3}, {0,-3},
{-1,-2}, {1,-2}, {0,-2},
{-1,-1}, {1,-1}, {0,-1},
{-1,0}, {1,0}, {0,0}
}, { // 1
{-4,1}, {-4,-1}, {-4,0},
{-3,1}, {-3,-1}, {-3,0},
{-2,1}, {-2,-1}, {-2,0},
{-1,1}, {-1,-1}, {-1,0},
{0,1}, {0,-1}, {0,0}
}, { // 2
{-1,4}, {1,4}, {0,4},
{-1,3}, {1,3}, {0,3},
{-1,2}, {1,2}, {0,2},
{-1,1}, {1,1}, {0,1},
{-1,0}, {1,0}, {0,0}
}, { // 3
{4,-1}, {4,1}, {4,0},
{3,-1},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,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,0},
{0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,0},
{0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
{0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
int Px = 1, Py = 1,Pd = 2;
int fov[LOCATION_MAX][DIRECTION_MAX] = {
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1},
{-1,-1,-1,-1}
}; //壁のデータ保存用(3次元)
int fov2[LOCATION_MAX][DIRECTION_MAX]; //グラフィックデータ保存用
<main.cpp>
#include "define.h"
void check_and_paint() {
int data[LOCATION_MAX];
for (int i = 0; i < LOCATION_MAX; i++) {
data[i] = maps[Px + location[Pd][i][0]][Py + location[Pd][i][1]];
}
for (int i = 0; i < LOCATION_MAX; i++) {
for (int j = 0; j < DIRECTION_MAX; j++) {
if (data[i] == 0) {
switch (i) {
case 13:
fov[i][0] = 0;
fov[i][1] = 1;
break;
case 12:
fov[i][0] = 0;
fov[i][3] = 3;
break;
case 5:
case 8:
case 11:
fov[i][0] = 0;
fov[i][1] = 1;
fov[i][2] = 2;
fov[i][3] = 3;
break;
case 4:
case 7:
case 10:
fov[i][0] = 0;
fov[i][1] = 1;
fov[i][2] = 2;
break;
case 3:
case 6:
case 9:
fov[i][0] = 0;
fov[i][2] = 2;
fov[i][3] = 3;
break;
case 0:
case 1:
case 2:
fov[i][2] = 2;
break;
}
}
}
}
for (int i = 0; i < LOCATION_MAX; i++) {
for (int j = 0; j < DIRECTION_MAX; j++) {
if (fov[i][j] == -1) {
continue;
}
else {
fov2[i][j] = aa[i][fov[i][j]];
}
}
}
for (int i = 0; i < LOCATION_MAX; i++) {
for (int j = 0; j < DIRECTION_MAX; j++) {
if (fov2[i][j]) {
DrawGraph(0, 0, fov2[i][j], 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;
}
です。