僕が考えているのは
1.GetPixelで2を捜索する
2
200
002
2
2.もし2が白ならその方向を動けなくして
3.矢印キーが押されたらその方向に動く
4.連続して動かす
5.そしてゴールに触れたならクリア
という流れです
2からできないのでどのような関数を使えばいいのでしょうか?
#include<DxLib.h>
#define px 10
#define X 15
#define Y 11
byte f[Y][X] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,2,1,1,1,1,0,1,1,1,0,1,1,1,0},
{0,1,0,0,0,1,0,1,0,1,0,0,0,1,0},
{0,1,0,1,1,1,0,1,0,1,1,1,1,1,0},
{0,1,0,1,0,0,0,1,0,0,0,0,0,0,0},
{0,1,0,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,1,0},
{0,1,0,1,1,1,0,1,1,1,1,1,1,1,0},
{0,1,0,1,0,1,0,0,0,0,0,0,0,0,0},
{0,1,1,1,0,1,1,1,1,1,1,1,1,3,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
int T[4];
int u, d, l, r;
int R, G, B;
int i = 259, j = 179;
int p = 259, q = 179;
bool w = false;
void P() {
int s = px * 4;
int c = GetColor(255, 212, 0);
for (int y = 0; y < Y; y++) {
for (int x = 0; x < X; x++) {
DrawExtendGraph(i + x * s, j + y * s, i + x * s + s, j + y * s + s, T[f[y][x]], false);
}
}
DrawBox(299, 219, 339, 259, c, true);
}
void UP_move() {
q += 41;
for (j; j < q; j += 4) {
ClearDrawScreen();
P();
ScreenFlip();
WaitTimer(100);
}
}
void DOWN_move() {
q -= 41;
for (j; j > q; j -= 4) {
ClearDrawScreen();
P();
ScreenFlip();
WaitTimer(100);
}
}
void LEFT_move() {
p -= 41;
for (j; j > p; j -= 4) {
ClearDrawScreen();
P();
ScreenFlip();
WaitTimer(100);
}
}
void RIGHT_move() {
p += 41;
for (j; j < p; j += 4) {
ClearDrawScreen();
P();
ScreenFlip();
WaitTimer(100);
}
}
void tick() {
P();
while (1) {
WaitTimer(100);
u = GetPixel(299, 218);
GetColor2(u, &R, &G, &B);
if (R == 255 && G == 255 && B == 255) {
}
else {
if (CheckHitKey(KEY_INPUT_UP)) {
UP_move();
}
}
d = GetPixel(339,260);
GetColor2(d, &R, &G, &B);
if (R == 255 && G == 255 && B == 255) {
}
else {
if (CheckHitKey(KEY_INPUT_DOWN)) {
DOWN_move();
}
}
r = GetPixel(340, 259);
GetColor2(r, &R, &G, &B);
if (R == 255 && G == 255 && B == 255) {
}
else {
if (CheckHitKey(KEY_INPUT_LEFT)) {
LEFT_move();
WaitTimer(1000);
}
}
l = GetPixel(299, 218);
GetColor2(l, &R, &G, &B);
if (R == 255 && G == 255 && B == 255) {
}
else {
if (CheckHitKey(KEY_INPUT_RIGHT)) {
RIGHT_move();
WaitTimer(1000);
}
}
}
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
SetOutApplicationLogValidFlag(false);
SetWindowText("maze");
ChangeWindowMode(true);
SetDrawScreen(DX_SCREEN_BACK);
DxLib_Init();
LoadDivGraph("madia\\a.png", 4, 4, 1, 10, 10, T, false);
while (1) {
tick();
}
WaitKey();
DxLib_End();
return 0;
}