いつもお世話になっております。
今回はゲームを作っているのですが、初めにタイトル画面を表示して、次にゲーム画面にかえてゲームをプレイします。ゲームオーバーになったときに、タイトル画面に戻すようにしたいのですが、どのようにするのが簡単でしょうか。
ひとつ考えたのが、ゲームオーバーになったときに、タイトル画面のファイルをrequireして、タイトル画面に戻すというものでしたが、これだと、ゲーム中の画面が残ったままになってしまいました。
これがタイトル画面ですクリックされることでゲーム画面に行くようにしています。
ruby
1#main.rb 2#!ruby -Ks 3require "./window.rb" 4require "./kuizu.rb" 5 6 7while true do 8window = Window.new 9window.drawBack 10window.gamestart 11window.refresh 12 13 14 while event = SDL::Event2.poll do 15 case event 16 when SDL::Event2::Quit 17 exit 18 when SDL::Event2::MouseButtonDown 19 x = event.x 20 y = event.y 21 if window.kuizuclicked?(x,y) 22 hajime 23 window.refresh 24 end 25 if window.zairyoclicked?(x,y) 26 require "./aaa.rb" 27 end 28 end 29 end 30 31end 32
これは、ゲーム画面のタイトルです。
ruby
1#aaa.rb 2#!ruby -Ks 3require "sdl" 4require "./window2.rb" 5require "./color" 6window = Window.new 7 8 window.drawBack 9 window.start 10 window.refresh 11while true do 12 while event = SDL::Event2.poll 13 case event 14 when SDL::Event2::Quit 15 exit 16 when SDL::Event2::KeyDown 17 if event.sym == SDL::Key::SPACE then 18 require "./zairyo.rb" 19 end 20 end 21 end 22 end 23 24
これがゲーム画面です。
gameOverで戻るようにしたいです。
ruby
1#!ruby -Ks 2require "./window2" 3require "./syujinko" 4require "./item" 5require "sdl" 6 7def hit?(syujinko,baikin) 8 diffx = syujinko.centerX - baikin.centerX 9 diffy = syujinko.centerY - baikin.centerY 10 if (diffx > -30) and (diffx < 50) and (diffy > -20) and (diffy < 50) 11 return true 12 else 13 return false 14 end 15end 16def clicked?(x,y,baikin) 17 diffx = x - baikin.centerX 18 diffy = y - baikin.centerY 19 if (diffx > -20) and (diffx < 20) and (diffy > -20) and (diffy < 20) 20 return true 21 else 22 return false 23 end 24end 25 26def gameOver(window,syujinko) 27 window.drawEndBack 28 syujinko.draw 29 window.refresh 30 sleep 5 31 exit 32 # require "./main.rb" #ここで、戻そうとしています 33end 34 35def checkScore 36 if @score <= 0 37 @score = 0 38 end 39 return @score 40end 41 42window = Window.new #(save_data.high_score) 43 44while true do 45 46 time = window.getTime 47 while event = SDL::Event2.poll do 48 case event 49 when SDL::Event2::Quit 50 exit 51 when SDL::Event2::MouseButtonDown 52 x = event.x 53 y = event.y 54 55 end 56 end 57 58 SDL::Key.scan 59 if SDL::Key.press?(SDL::Key::A) 60 syujinko.moveLeft 61 end 62 if SDL::Key.press?(SDL::Key::F) 63 syujinko.moveRight 64 end 65 66 67 if time < 0 68 gameOver(window,syujinko) 69 end 70##文が長いので繰り返しの部分を省略しました。
皆さんお忙しいとは思いますが、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/03 05:25
2016/08/03 12:22
2016/08/08 00:45