Class: RedBird::Stage
- Inherits:
-
Object
- Object
- RedBird::Stage
- Defined in:
- lib/red_bird/stage.rb
Overview
A game built with RedBird consists of a succession of Stages. A game has only a single Stage running at a time. Each Stage must have an InputDevice instance and an Array of Entity instances.
This class contains a basic set of functionalities that every stage of a game needs.
Instance Attribute Summary collapse
- #entities ⇒ Array<RedBird::Entity>
-
#input_device ⇒ RedBird::InputDevice
The class that inherits from Stage must defines an variable @input_device containing and instance of InputDevice.
Instance Method Summary collapse
-
#add_entities(entities) ⇒ Object
Add a new entity to this stage.
-
#initialize(global_data) ⇒ Stage
constructor
A new instance of Stage.
-
#post_tick ⇒ Object
Engine calls this method after it ticks entities.
-
#pre_tick ⇒ Object
Engine calls this method before it ticks entities.
Constructor Details
#initialize(global_data) ⇒ Stage
Returns a new instance of Stage.
24 25 26 27 |
# File 'lib/red_bird/stage.rb', line 24 def initialize(global_data) @global_data = global_data @entities = [] end |
Instance Attribute Details
#entities ⇒ Array<RedBird::Entity>
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/red_bird/stage.rb', line 18 class Stage attr_accessor :input_device, :entities # @param global_data [Object] use this to share common data among different # stages. # @author Frederico Linhares def initialize(global_data) @global_data = global_data @entities = [] end # Add a new entity to this stage. This method organizes the entities as # expected by some methods in {RedBird::Engine}. # # @param entities [Entity, Array<Entity>] # @author Frederico Linhares def add_entities(entities) if entities.is_a? Array then @entities.concat entities else @entities << entities end @entities.sort! { |a, b| a.priority <=> b.priority } end # {RedBird::Engine} calls this method before it ticks entities. Overwrite # this to add routines that must run before entities tick. # # @author Frederico Linhares def pre_tick # By default do nothing. end # {RedBird::Engine} calls this method after it ticks entities. Overwrite # this to add routines that must run after entities tick. # # @author Frederico Linhares def post_tick # By default do nothing. end end |
#input_device ⇒ RedBird::InputDevice
Returns the class that inherits from Stage must defines an variable @input_device containing and instance of InputDevice.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/red_bird/stage.rb', line 18 class Stage attr_accessor :input_device, :entities # @param global_data [Object] use this to share common data among different # stages. # @author Frederico Linhares def initialize(global_data) @global_data = global_data @entities = [] end # Add a new entity to this stage. This method organizes the entities as # expected by some methods in {RedBird::Engine}. # # @param entities [Entity, Array<Entity>] # @author Frederico Linhares def add_entities(entities) if entities.is_a? Array then @entities.concat entities else @entities << entities end @entities.sort! { |a, b| a.priority <=> b.priority } end # {RedBird::Engine} calls this method before it ticks entities. Overwrite # this to add routines that must run before entities tick. # # @author Frederico Linhares def pre_tick # By default do nothing. end # {RedBird::Engine} calls this method after it ticks entities. Overwrite # this to add routines that must run after entities tick. # # @author Frederico Linhares def post_tick # By default do nothing. end end |
Instance Method Details
#add_entities(entities) ⇒ Object
Add a new entity to this stage. This method organizes the entities as expected by some methods in Engine.
34 35 36 37 38 39 40 41 42 |
# File 'lib/red_bird/stage.rb', line 34 def add_entities(entities) if entities.is_a? Array then @entities.concat entities else @entities << entities end @entities.sort! { |a, b| a.priority <=> b.priority } end |
#post_tick ⇒ Object
Engine calls this method after it ticks entities. Overwrite this to add routines that must run after entities tick.
56 57 58 |
# File 'lib/red_bird/stage.rb', line 56 def post_tick # By default do nothing. end |
#pre_tick ⇒ Object
Engine calls this method before it ticks entities. Overwrite this to add routines that must run before entities tick.
48 49 50 |
# File 'lib/red_bird/stage.rb', line 48 def pre_tick # By default do nothing. end |