我的代碼長這樣,請指教一下。另外我最近在用RM做俄羅斯方塊,遇到一些困難,有沒有甚麼思路和建議?
function findLine(root) { let line = []; line.push(root); findNear(root); function findNear(event) { let name = event.characterName(); let index = event.characterIndex(); let direction = event.direction(); check(event.x + 1, event.y); check(event.x - 1, event.y); check(event.x, event.y + 1); check(event.x, event.y - 1); check(event.x + 1, event.y + 1); check(event.x - 1, event.y - 1); check(event.x + 1, event.y - 1); check(event.x - 1, event.y + 1); function check(x, y) { let event2 = $gameMap.eventsXy(x, y)[0]; if (event2) { let name2 = event2.characterName(); let index2 = event2.characterIndex(); let direction2 = event2.direction(); if (name2 === name && index2 === index && direction2 === direction) { if (line.indexOf(event2) === -1) { line.push(event2); findNear(event2); } } } } } return line; }
function findLine(root) {
let line = [];
line.push(root);
findNear(root);
function findNear(event) {
let name = event.characterName();
let index = event.characterIndex();
let direction = event.direction();
check(event.x + 1, event.y);
check(event.x - 1, event.y);
check(event.x, event.y + 1);
check(event.x, event.y - 1);
check(event.x + 1, event.y + 1);
check(event.x - 1, event.y - 1);
check(event.x + 1, event.y - 1);
check(event.x - 1, event.y + 1);
function check(x, y) {
let event2 = $gameMap.eventsXy(x, y)[0];
if (event2) {
let name2 = event2.characterName();
let index2 = event2.characterIndex();
let direction2 = event2.direction();
if (name2 === name && index2 === index && direction2 === direction) {
if (line.indexOf(event2) === -1) {
line.push(event2);
findNear(event2);
}
}
}
}
}
return line;
}
|