| 自動で動かしたときのキャラの向き |
| キャラを動かしたときのキャラの向きを変更 |

let index = 0;
//ひよこの歩く判定のため追加
const aryX=[150,100,100,150,150,150,100,100, 50, 50, 0, 0, 0, 50, 50, 0];
const aryY=[ 0, 0, 50, 50,100,150,150,100,100,150,150,100, 50, 50, 0, 0];
//ひよこの初期位置
moveChick();
const b1 = document.getElementById("btn1");
b1.addEventListener("click", () =>
{
//ひよこを進める
walkChick();
});
const b2 = document.getElementById("btn2");
b2.addEventListener("click", () =>
{
//リセット
chickReset();
});
function walkChick()
{
const intervalId = setInterval(() =>
{
// 止める条件
if (index >= aryX.length)
{
clearInterval(intervalId);
judgeEnd();
return;
}
index++;
moveChick();
}, 1000);
}
function judgeEnd()
{
//ボタンを非表示にします。
const b1 = document.getElementById("btn1");
b1.style.visibility="hidden";
//ゴールのメッセージを表示します。
alert("ゴールしました。");
}
//ひよこの場所変更
function moveChick()
{
//ひよこ
const obj = document.getElementById("hiyoko");
obj.style.left = aryX[index] +'px';
obj.style.top = aryY[index] +'px';
const img = document.getElementById("img");
img.src = chickDirection();
}
//パスを返す処理
function chickDirection()
{
let path = "";//パスを指定してください ex.) img/
let up = "nawmin_sample10.png";
let left = "nawmin_sample6.png";
let right = "nawmin_sample9.png";
if(index==0)
{
return path + up;
}
if(aryX[index] < aryX[index-1])
{
return path + left;
}
else if(aryX[index] > aryX[index-1])
{
return path + right;
}
else
{
return path + up;
}
}
//リセット
function chickReset()
{
index = 0;
//ひよこの歩く判定のため追加
moveChick();
const b1 = document.getElementById("btn1");
b1.style.visibility="visible";
}
| 方向 | 判定方法 |
| 左 | aryXの座標が小さいケース (例) if(aryX[index] < aryX[index - 1]) |
| 右 | aryXの座標が小さいケース (例) if(aryX[index] > aryX[index - 1]) |
| 上下 | else |
| [URL]イラスト:農民イラスト | |
| URL[https://nawmin.stores.jp][クリックすると開きます]) |
| Character direction when moving automatically |
| Change the character's orientation when moving the character |

let index = 0;
//Added for chick walking detection
const aryX=[150,100,100,150,150,150,100,100, 50, 50, 0, 0, 0, 50, 50, 0];
const aryY=[ 0, 0, 50, 50,100,150,150,100,100,150,150,100, 50, 50, 0, 0];
//Chick's initial position
moveChick();
const b1 = document.getElementById("btn1");
b1.addEventListener("click", () =>
{
//Advance the chick
walkChick();
});
const b2 = document.getElementById("btn2");
b2.addEventListener("click", () =>
{
//reset
chickReset();
});
function walkChick()
{
const intervalId = setInterval(() =>
{
//Stop conditions
if (index >= aryX.length)
{
clearInterval(intervalId);
judgeEnd(lang);
return;
}
index++;
moveChick();
}, 1000);
}
function judgeEnd(lng)
{
//Hide the button.
const b1 = document.getElementById("btn1");
b1.style.visibility="hidden";
//Displays the goal message.
alert("reached the goal.");
}
//Change chick location
function moveChick()
{
//chick
const obj = document.getElementById("hiyoko");
obj.style.left = aryX[index] +'px';
obj.style.top = aryY[index] +'px';
const img = document.getElementById("img");
img.src = chickDirection();
}
//Returning the path
function chickDirection()
{
let path = "";//Please specify the path ex.) img/
let up = "nawmin_sample10.png";
let left = "nawmin_sample6.png";
let right = "nawmin_sample9.png";
if(index==0)
{
return path + up;
}
if(aryX[index] < aryX[index-1])
{
return path + left;
}
else if(aryX[index] > aryX[index-1])
{
return path + right;
}
else
{
return path + up;
}
}
//reset
function chickReset()
{
index = 0;
//Added for chick walking detection
moveChick();
const b1 = document.getElementById("btn1");
b1.style.visibility="visible";
}
| Direction | Determination method |
| Left | When aryX coordinates are small (Example) if(aryX[index] < aryX[index - 1]) |
| Right | When aryX coordinates are small (Example) if(aryX[index] > aryX[index - 1]) |
| up and down | else |
| [URL]illustration by nawmin.com | |
| URL[https://nawmin.stores.jp][click to open the homepage]) |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |