Class: SpaceInvaders::App
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- SpaceInvaders::App
- Defined in:
- lib/space_invaders/app.rb
Constant Summary collapse
- RELATIVE_DEFAULT_FONT =
File.join('..', '..', '..', 'assets', 'fonts', 'unifont.ttf')
- DEFAULT_FONT =
File.(RELATIVE_DEFAULT_FONT,__FILE__)
- STATICS =
:game_status, :button_controller, :images, :sounds, :welcome_screen, :game_over_screen, :next_level_screen
- TRACKERS =
:lives_tracker, :score_tracker
- DYNAMICS =
:ship, :invaders_container, :u_block_container, :red_invader
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
- #draw_dynamics ⇒ Object
- #draw_trackers ⇒ Object
-
#initialize(width = 800, height = 600, fullscreen = false) ⇒ App
constructor
A new instance of App.
- #initialize_dynamics_and_trackers ⇒ Object
- #initialize_statics ⇒ Object
- #update ⇒ Object
- #update_dynamics ⇒ Object
Constructor Details
#initialize(width = 800, height = 600, fullscreen = false) ⇒ App
Returns a new instance of App.
43 44 45 46 47 48 |
# File 'lib/space_invaders/app.rb', line 43 def initialize width=800, height=600, fullscreen=false super self. = "Space Invaders" initialize_statics initialize_dynamics_and_trackers end |
Instance Method Details
#button_down(id) ⇒ Object
50 51 52 |
# File 'lib/space_invaders/app.rb', line 50 def id . id end |
#draw ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/space_invaders/app.rb', line 62 def draw if game_status.hasnt_started? welcome_screen.draw elsif game_status.next_level? next_level_screen.draw elsif game_status.drowned_ship? or game_status.being_played? draw_dynamics draw_trackers elsif game_status.finished? game_over_screen.draw end end |
#draw_dynamics ⇒ Object
83 84 85 |
# File 'lib/space_invaders/app.rb', line 83 def draw_dynamics DYNAMICS.each {|dynamic_element| self.send(dynamic_element).draw} end |
#draw_trackers ⇒ Object
87 88 89 |
# File 'lib/space_invaders/app.rb', line 87 def draw_trackers TRACKERS.each {|tracker_element| self.send(tracker_element).draw} end |
#initialize_dynamics_and_trackers ⇒ Object
79 80 81 |
# File 'lib/space_invaders/app.rb', line 79 def initialize_dynamics_and_trackers define_properties *DYNAMICS, *TRACKERS end |
#initialize_statics ⇒ Object
75 76 77 |
# File 'lib/space_invaders/app.rb', line 75 def initialize_statics define_properties *STATICS end |
#update ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/space_invaders/app.rb', line 54 def update if game_status.drowned_ship? ship.update elsif game_status.being_played? update_dynamics end end |
#update_dynamics ⇒ Object
91 92 93 |
# File 'lib/space_invaders/app.rb', line 91 def update_dynamics DYNAMICS.each {|dynamic_element| self.send(dynamic_element).update} end |