【解決済み】倉庫番のようなゲームで岩を複数同時に動かしたい
Posted: 2022年6月18日(土) 10:24
プレイヤーや、ほかのイベントが岩に触れた時に動かして、岩がつながったときは一緒に動かせるようにしたいです
https://www.youtube.com/watch?v=ei6o_RO ... e=youtu.be
上記の動画のようにしたいのですが、複数重なったときに挙動が変になってしまいます
//スイッチID41がオンの時に処理を行う
let switchIndex = 41;
//イベントID4-7が岩のID、イベント1と接触したときに移動する
if($gameSwitches.value(switchIndex)){
for(let i = 4 ; i<= 7 ; i++){
if( $gameMap.event(1).isMoving() ){
let x_d = $gameMap.event(1)._x - $gameMap.event(i)._x;
let y_d = $gameMap.event(1)._y - $gameMap.event(i)._y;
//イベント1と岩の距離の半径が0.5以下の時に、条件をみたす
if(Math.sqrt(x_d ** 2 + y_d **2)<0.5){
let dire = $gameMap.event(1).direction();
$gameMap.event(i).moveStraight(dire);
}
}
}
}
//岩が複数並んでいた時の処理
if($gameSwitches.value(switchIndex)){
for(let j = 4 ; j<=7 ; j++){
for(let i = 4 ; i<= 7 ; i++){
if( i !== j && $gameMap.event(j).isMoving() ){
let x_d = $gameMap.event(j)._x - $gameMap.event(i)._x;
let y_d = $gameMap.event(j)._y - $gameMap.event(i)._y;
if(Math.sqrt(Math.pow(x_d,2) + Math.pow(y_d,2))<0.5){
let dire = $gameMap.event(1).direction();
$gameMap.event(i).moveStraight(dire);
}
}
}
}
}
スイッチ41がオンの時に、並列処理でいろいろと試してみたのですがうまくいきませんでした。
スクリプトが見づらくて申し訳ないですが、何か知恵を頂けたら幸いです。
https://www.youtube.com/watch?v=ei6o_RO ... e=youtu.be
上記の動画のようにしたいのですが、複数重なったときに挙動が変になってしまいます
//スイッチID41がオンの時に処理を行う
let switchIndex = 41;
//イベントID4-7が岩のID、イベント1と接触したときに移動する
if($gameSwitches.value(switchIndex)){
for(let i = 4 ; i<= 7 ; i++){
if( $gameMap.event(1).isMoving() ){
let x_d = $gameMap.event(1)._x - $gameMap.event(i)._x;
let y_d = $gameMap.event(1)._y - $gameMap.event(i)._y;
//イベント1と岩の距離の半径が0.5以下の時に、条件をみたす
if(Math.sqrt(x_d ** 2 + y_d **2)<0.5){
let dire = $gameMap.event(1).direction();
$gameMap.event(i).moveStraight(dire);
}
}
}
}
//岩が複数並んでいた時の処理
if($gameSwitches.value(switchIndex)){
for(let j = 4 ; j<=7 ; j++){
for(let i = 4 ; i<= 7 ; i++){
if( i !== j && $gameMap.event(j).isMoving() ){
let x_d = $gameMap.event(j)._x - $gameMap.event(i)._x;
let y_d = $gameMap.event(j)._y - $gameMap.event(i)._y;
if(Math.sqrt(Math.pow(x_d,2) + Math.pow(y_d,2))<0.5){
let dire = $gameMap.event(1).direction();
$gameMap.event(i).moveStraight(dire);
}
}
}
}
}
スイッチ41がオンの時に、並列処理でいろいろと試してみたのですがうまくいきませんでした。
スクリプトが見づらくて申し訳ないですが、何か知恵を頂けたら幸いです。