Class: T_BAG::Scene
- Inherits:
-
Object
- Object
- T_BAG::Scene
- Defined in:
- lib/tbag/scene.rb
Overview
Defines a scene and its run behavior.
Instance Method Summary collapse
-
#game_over ⇒ Object
Create a scene change for the game over scene.
-
#initialize(name, title) ⇒ Scene
constructor
A new instance of Scene.
-
#load_game(infile) ⇒ Object
Add a load to the action queue.
-
#main_menu ⇒ Object
Create a scene change for the main menu scene.
-
#pause ⇒ Object
Add a pause to the action queue.
-
#prompt(question, type, error, &block) ⇒ Object
Add a prompt to the action queue.
-
#run ⇒ Object
Define how a scene runs.
-
#save_game(outfile) ⇒ Object
Add a save to the action queue.
-
#scene_change(scene) ⇒ Object
Add a scene change to the action queue.
-
#text(dialog) ⇒ Object
Add a set of text to the action queue.
Constructor Details
#initialize(name, title) ⇒ Scene
Returns a new instance of Scene.
30 31 32 33 34 |
# File 'lib/tbag/scene.rb', line 30 def initialize(name, title) @name = name @title = title @actions = [] end |
Instance Method Details
#game_over ⇒ Object
Create a scene change for the game over scene.
77 78 79 |
# File 'lib/tbag/scene.rb', line 77 def game_over scene_change :endgame end |
#load_game(infile) ⇒ Object
Add a load to the action queue.
72 73 74 |
# File 'lib/tbag/scene.rb', line 72 def load_game(infile) @actions << {type: :load, filename: infile} end |
#main_menu ⇒ Object
Create a scene change for the main menu scene.
82 83 84 |
# File 'lib/tbag/scene.rb', line 82 def scene_change :menu end |
#pause ⇒ Object
Add a pause to the action queue.
37 38 39 |
# File 'lib/tbag/scene.rb', line 37 def pause @actions << {type: :pause} end |
#prompt(question, type, error, &block) ⇒ Object
Add a prompt to the action queue.
58 59 60 61 62 |
# File 'lib/tbag/scene.rb', line 58 def prompt(question, type, error, &block) prompt = T_BAG::Prompt.new(question, type, error) @actions << {type: :prompt, prompt: prompt} Docile.dsl_eval(prompt, &block) end |
#run ⇒ Object
Define how a scene runs.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tbag/scene.rb', line 87 def run @actions.each do |a| case a[:type] when :pause print 'Continue...' gets puts when :scene_change $game.next_scene a[:scene] when :text a[:dialog].bytes.each do |c| putc c sleep(0.05) end putc "\n" when :prompt a[:prompt].run when :save $game.save_game a[:filename] when :load $game.load_game a[:filename] else $stderr.puts '[SCENE] Action not allowed' end end end |
#save_game(outfile) ⇒ Object
Add a save to the action queue.
66 67 68 |
# File 'lib/tbag/scene.rb', line 66 def save_game(outfile) @actions << {type: :save, filename: outfile} end |
#scene_change(scene) ⇒ Object
Add a scene change to the action queue.
43 44 45 |
# File 'lib/tbag/scene.rb', line 43 def scene_change( scene ) @actions << {type: :scene_change, scene: scene} end |
#text(dialog) ⇒ Object
Add a set of text to the action queue.
49 50 51 |
# File 'lib/tbag/scene.rb', line 49 def text(dialog) @actions << {type: :text, dialog: dialog} end |