|
Revision 27314, 1.2 kB
(checked in by isaisstillalive, 4 years ago)
|
|
StarRuby用フレームワーク StarFrame?
画像等をオートロードする部分は蛇足っぽいんで、そこらへんを省いてGoogle Codeからリポジトリを移動。
|
| Line | |
|---|
| 1 | require "starframe/eventable"
|
|---|
| 2 |
|
|---|
| 3 | module StarFrame
|
|---|
| 4 | class Scene
|
|---|
| 5 | include StarFrame::Eventable
|
|---|
| 6 |
|
|---|
| 7 | # StarRuby::Game.run内で呼ぶこと
|
|---|
| 8 | # StarRuby::Game.run外で呼びたい場合はScene.to_procを使うこと
|
|---|
| 9 | def initialize game, *args
|
|---|
| 10 | @game = game
|
|---|
| 11 | @screen = game.screen
|
|---|
| 12 | @running = true
|
|---|
| 13 |
|
|---|
| 14 | call_init *args
|
|---|
| 15 | end
|
|---|
| 16 |
|
|---|
| 17 | def call
|
|---|
| 18 | catch :exit_scene do
|
|---|
| 19 | call_update
|
|---|
| 20 |
|
|---|
| 21 | @screen.clear
|
|---|
| 22 | call_render
|
|---|
| 23 |
|
|---|
| 24 | true
|
|---|
| 25 | end
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 | def start
|
|---|
| 29 | catch :exit_scene do
|
|---|
| 30 | loop do
|
|---|
| 31 | if @game.window_closing?
|
|---|
| 32 | call_quit
|
|---|
| 33 | return nil
|
|---|
| 34 | end
|
|---|
| 35 |
|
|---|
| 36 | @game.wait
|
|---|
| 37 | @game.update_state
|
|---|
| 38 | return @next_scene unless call
|
|---|
| 39 | @game.update_screen
|
|---|
| 40 | end
|
|---|
| 41 | end
|
|---|
| 42 | end
|
|---|
| 43 |
|
|---|
| 44 | private
|
|---|
| 45 | def render_texture *args
|
|---|
| 46 | @screen.render_texture *args
|
|---|
| 47 | end
|
|---|
| 48 |
|
|---|
| 49 | def exit_scene
|
|---|
| 50 | call_quit
|
|---|
| 51 | @next_scene = nil
|
|---|
| 52 | throw :exit_scene, false
|
|---|
| 53 | end
|
|---|
| 54 |
|
|---|
| 55 | def next_scene next_scene
|
|---|
| 56 | call_quit
|
|---|
| 57 | @next_scene = next_scene
|
|---|
| 58 | throw :exit_scene, false
|
|---|
| 59 | end
|
|---|
| 60 | end
|
|---|
| 61 | end
|
|---|