質問: {{"□","□","□","□","■","□","□","□","□","□"}, //ゲーム画面 {"□","□","□","□","■","□","□","□","□","□"}, {"□","□","□","□","■","□","□","□","□","□"}, {"□","□","□","□","■","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}, {"□","□","□","□","□","□","□","□","□","□"}};
回答: ゲームプログラム経験が有るので アドバイスをさせて頂きます。 テトリミノを回転させるプログラムを教えてくださいとのことですが。 だいたいのコードは完成しているとのことですので 何かしらエラーが出てわからない状態と想定させて頂きました。 その場合まずは回転させずに普通にそのまま下に落ちるプログラムを完成させます。 次にそのプログラムとは別に回転させるプログラムを書きます。 ボタンを押すと座標を調べてから回転させるだけですが 少しだけ簡単に説明しますね 以下詳細 ゲームキャラ ■ ● 例えば上のキャラを回転させる時って ●の位置をキャラクター位置座標として回転させます。 テトリスの場合も同じ ●■ クルッ こんな風に おわかり頂けましたね? つまり現在位置を設定して 障害物が無く回転可能なら現在位置はそのままで 描画等を変更すれば解決できるはずです。 テトリスでしたらプログラムがゴロゴロ転がってるはずですので がんばってプログラムしてみてください。 ■描画の基本■ ゲームの描画の基本について説明が足りてなかったので させて頂きます。小話だと思って軽く聞いてください。 ゲームキャラは基本的にどんな物でも”現在位置座標”を持っています それとは別に大きいキャラなどは描画情報も重要です 現在位置● それ以外の描画■ ■ ■ ■ ■ ■ ■ ● ■ ■ こんな風になってる訳ですね 現在位置を動かすだけで 三 ■ ■ ■ 三 ■ ■ ■ 三 ● ■ ■ 動きます(当たり前ですが) 結論を言えば 現在位置とは別に描画設定が存在しているので ボタンを押すと描画設定が変更されるという考え方が一番合理的で まあだいたいのゲームはそんな感じだと思いますよ。 そして描画設定ってどんな感じ?と聞かれれば ●の現在位置に対してx座標に何タイル分y座標に何タイル分描画すると言う事でしょう 座標(0,1) 座標(0,0) ■ ● 座標(0,0) 座標(1,0) ●■ あとは回転のプログラムを考えるだけですが それこそネットに転がってるので説明は省略します。