ブロック(といっても中心辺り限定)をクリックするとそこにキャラが移動する。
ソースコードはこんな感じ。
import dxlib;
int map[5][5] = [
[1,1,1,1,1],
[1,0,1,0,1],
[1,0,1,0,1],
[1,0,1,0,1],
[1,1,1,1,1],
];
bool canRun(){
return
CheckHitKey(KEY_INPUT_ESCAPE) == 0 &&
ProcessMessage() != -1;
}
bool isHitCircle(int pX, int pY, int cX, int cY, int R){
return
(pX - cX)*(pX - cX) + (pY - cY)*(pY - cY) <= R*R;
}
void main(){
ChangeWindowMode(TRUE);
if(DxLib_Init() == -1) return;
scope(exit) DxLib_End();
int handle[2];
LoadDivGraph("map2.png", 2, 1, 2, 38, 19, handle.ptr);
int graph_w, graph_h;
GetGraphSize(handle[0], &graph_w, &graph_h);
int ch_handle[12];
LoadDivGraph("chara.png", 12, 3, 4, 32, 48, ch_handle.ptr);
int mouse_x=0, mouse_y=0;
int before_x, before_y;
int slip_x=100, slip_y=100;
int select_x=0, select_y=0;
int ch_x=0, ch_y=0;
int ch_w, ch_h;
GetGraphSize(ch_handle[0], &ch_w, &ch_h);
SetDrawScreen(DX_SCREEN_BACK);
while(canRun()){
ClearDrawScreen();
before_x = mouse_x;
before_y = mouse_y;
GetMousePoint(&mouse_x, &mouse_y);
if((GetMouseInput() & MOUSE_INPUT_RIGHT) != 0){
slip_x += mouse_x - before_x;
slip_y += mouse_y - before_y;
}
for(int i=0; i<map.length; i++){
for(int j=0; j<map[i].length; j++){
if(map[i][j] == 1){
int x = (graph_w / 2) * (j + i) + slip_x;
int y = (graph_h / 2) * (j - i) + slip_y;
int cir_x = x + graph_h;
int cir_y = y + graph_w/4;
int num = (isHitCircle(mouse_x, mouse_y, cir_x, cir_y, graph_h/2)) ? 1 : 0;
if((GetMouseInput() & MOUSE_INPUT_LEFT) != 0 && num == 1){
select_x = j;
select_y = i;
ch_x = j;
ch_y = i;
}
DrawGraph(x, y, handle[num], TRUE);
}
}
}
{
int x = (graph_w / 2) * (ch_x + ch_y) + slip_x;
int y = (graph_h / 2) * (ch_x - ch_y) + slip_y - ch_h + graph_h/2 + 5;
DrawGraph(x, y, ch_handle[1], TRUE);
}
ScreenFlip();
}
}
しかしそれってつまり、A*探索アルゴリズムとかそういうアレを導入する必要があるわけで…時間かかりそうだなあ。
ソートとか探索とかのアルゴリズムは苦手なのよね…。