Class: Conjuration::Scene
- Inherits:
-
Object
- Object
- Conjuration::Scene
- Includes:
- Attributes
- Defined in:
- lib/conjuration/scene.rb
Overview
Keeps track of game objects and manages their updates, draws, mouse, and keyboard events.
Instance Attribute Summary collapse
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #add_object(game_object) ⇒ Object
- #button_down(context, key) ⇒ Object
- #button_up(context, key) ⇒ Object
- #draw(context) ⇒ Object
-
#initialize(window, options = {}) ⇒ Scene
constructor
A new instance of Scene.
- #set_background(asset_path) ⇒ Object
-
#update(context) ⇒ Object
Abstract Methods ==========.
Methods included from Attributes
Constructor Details
#initialize(window, options = {}) ⇒ Scene
Returns a new instance of Scene.
10 11 12 13 14 15 16 |
# File 'lib/conjuration/scene.rb', line 10 def initialize(window, = {}) super @window = window @game_objects = [] @asset_manager = AssetManager.new end |
Instance Attribute Details
#window ⇒ Object (readonly)
Returns the value of attribute window.
8 9 10 |
# File 'lib/conjuration/scene.rb', line 8 def window @window end |
Instance Method Details
#add_object(game_object) ⇒ Object
18 19 20 |
# File 'lib/conjuration/scene.rb', line 18 def add_object(game_object) @game_objects << game_object end |
#button_down(context, key) ⇒ Object
40 41 42 |
# File 'lib/conjuration/scene.rb', line 40 def (context, key) @game_objects.each { |game_object| game_object.mouse_down(self, key) } end |
#button_up(context, key) ⇒ Object
44 45 46 |
# File 'lib/conjuration/scene.rb', line 44 def (context, key) @game_objects.each { |game_object| game_object.mouse_up(self, key) } end |
#draw(context) ⇒ Object
34 35 36 37 38 |
# File 'lib/conjuration/scene.rb', line 34 def draw(context) @background_image&.draw(0, 0, 0, context.width.to_f / @background_image.width, context.height.to_f / @background_image.height) @game_objects.each { |game_object| game_object.draw(context, self) } end |
#set_background(asset_path) ⇒ Object
22 23 24 |
# File 'lib/conjuration/scene.rb', line 22 def set_background(asset_path) @background_image = AssetManager.load_image(asset_path) end |
#update(context) ⇒ Object
Abstract Methods
30 31 32 |
# File 'lib/conjuration/scene.rb', line 30 def update(context) @game_objects.each { |game_object| game_object.mouse_position(context) } end |