Class: T_BAG::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/tbag/scene.rb

Overview

Defines a scene and its run behavior.

Direct Known Subclasses

Game_Over, Main_Menu

Instance Method Summary collapse

Constructor Details

#initialize(name, title) ⇒ Scene

Returns a new instance of Scene.

Parameters:

  • name (String)

    the name of the scene

  • title (String)

    the title of the 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_overObject

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.

Parameters:

  • infile (String)

    the name of the file to load from



72
73
74
# File 'lib/tbag/scene.rb', line 72

def load_game(infile)
  @actions << {type: :load, filename: infile}
end

Create a scene change for the main menu scene.



82
83
84
# File 'lib/tbag/scene.rb', line 82

def main_menu
  scene_change :menu
end

#pauseObject

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.

Parameters:

  • question (String)

    the prompt for the User

  • type (ANY)

    the type of the expected User input

  • error (String)

    the error to display if User input is invalid

  • block (Block)


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

#runObject

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.

Parameters:

  • outfile (String)

    the name of the file to save to



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.

Parameters:

  • scene (Symbol)

    a scene



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.

Parameters:

  • dialog (String)

    the text to be output to the User



49
50
51
# File 'lib/tbag/scene.rb', line 49

def text(dialog)
  @actions << {type: :text, dialog: dialog}
end