<RGSS>
class Scene_stg #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main #フレームレート変更(1秒間に60回のペースで画面を書き換えます) Graphics.frame_rate = 60 @shot = Array.new #自機の弾を格納 @shot_interval = 4 #弾の発射間隔(フレーム) @shot_count = 0 @enemy = Array.new #敵を格納 @enemyshot = Array.new #敵の弾を格納 Graphics.frame_count = 0 #フレームカウントの初期化 #自機表示 @player = Stg_player.new #メインループ loop do #自機の操作 @player.move #自機の低速グラフィック変更 player_slow() #自機の弾を発射 player_shot() #敵キャラの作成 make_enemy() #敵と弾の接触判定 enemy_crash() #敵のショット enemy_shot() #敵の弾と自機の接触処理 player_crash() #各種更新 Input.update Graphics.update end end #-------------------------------------------------------------------------- # ● 自機のショット #-------------------------------------------------------------------------- def player_shot if Input.press?(Input::A) @shot_count += 1 if @shot_count == @shot_interval @shot_count = 0 @shot.push Stg_bullet.new(@player.x,@player.y - 37) end end #弾の移動&削除 @shot.reject!{|i|i.move} end #-------------------------------------------------------------------------- # ● 敵キャラの生成 #-------------------------------------------------------------------------- def make_enemy if Graphics.frame_count % 100 == 0 @enemy.push Stg_enemy.new(rand(640),60,1) end if Graphics.frame_count % 250 == 0 @enemy.push Stg_enemy.new(rand(640),60,2) end if Graphics.frame_count % 550 == 0 @enemy.push Stg_enemy.new(rand(430)+210,60,3) end @enemy.reject!{|i|i.move} end #-------------------------------------------------------------------------- # ● 弾と敵の接触処理 #-------------------------------------------------------------------------- def enemy_crash @shot.each{|i| @enemy.each{|j| if crash?(i,j) i.dispose j.dispose @enemy.delete(j) break end } } @shot.reject!{|i|i.disposed?} end #-------------------------------------------------------------------------- # ● 当たり判定 #-------------------------------------------------------------------------- def crash?(obj1, obj2) if (obj1.x - obj2.x).abs < obj1.dx + obj2.dx and (obj1.y - obj2.y).abs < obj1.dy + obj2.dy return true else return false end end #-------------------------------------------------------------------------- # ● 敵のショット ■更新■ #-------------------------------------------------------------------------- def enemy_shot @enemy.each{|i| type = i.attack case type when 2 @enemyshot.push Stg_bullet.new(i.x, i.y, 2,@player.x, @player.y) when 3 @enemyshot.push Stg_bullet.new(i.x, i.y, 3, @player.x, @player.y, -0.1) @enemyshot.push Stg_bullet.new(i.x, i.y, 3, @player.x, @player.y, 0) @enemyshot.push Stg_bullet.new(i.x, i.y, 3, @player.x, @player.y, 0.1) when 4 for rot in 0..11 @enemyshot.push Stg_bullet.new(i.x, i.y, 4, 0,0,0,rot*30) end end } @enemyshot.reject!{|i|i.move} end #-------------------------------------------------------------------------- # ● 敵の弾と自機の接触処理 #-------------------------------------------------------------------------- def player_crash @enemyshot.each{|i| if crash?(i, @player) i.dispose @player.flash(Color.new(255, 255, 255, 255), 5) end } @enemyshot.reject!{|i|i.disposed?} @player.update end #-------------------------------------------------------------------------- # ● 低速時の自機グラフィック変更設定 #-------------------------------------------------------------------------- def player_slow if Input.press?(Input::B) @player.yukkuri else @player.normal end end end
<RGSS2>