Class: Game
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Game
- Defined in:
- lib/fantasy/loop.rb
Instance Method Summary collapse
-
#button_down(button_id) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #check_click ⇒ Object
-
#cursor_down_pressed ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
- #cursor_left_pressed ⇒ Object
- #cursor_right_pressed ⇒ Object
- #cursor_up_pressed ⇒ Object
- #draw ⇒ Object
-
#initialize(screen_width, screen_height) ⇒ Game
constructor
A new instance of Game.
- #mouse_button_left_pressed ⇒ Object
- #space_bar_pressed ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(screen_width, screen_height) ⇒ Game
Returns a new instance of Game.
4 5 6 7 8 9 10 11 |
# File 'lib/fantasy/loop.rb', line 4 def initialize(screen_width, screen_height) Camera.initialize Global.initialize(screen_width, screen_height) super(Global.screen_width, Global.screen_height) Global.presentation_proc.call end |
Instance Method Details
#button_down(button_id) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fantasy/loop.rb', line 14 def () case when Cursor.down then cursor_down_pressed when Cursor.up then cursor_up_pressed when Cursor.left then cursor_left_pressed when Cursor.right then cursor_right_pressed when Cursor. then when Mouse.left then end Global.&.call() super end |
#check_click ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/fantasy/loop.rb', line 86 def check_click ( Global.actors + Global.shapes ).sort_by(&:layer).each do |e| e.on_click_do if Utils.collision_at?(e, mouse_x, mouse_y) end end |
#cursor_down_pressed ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
31 32 33 34 |
# File 'lib/fantasy/loop.rb', line 31 def cursor_down_pressed Global.cursor_down_proc&.call invoke_input_method_in_entities("on_cursor_down_do") end |
#cursor_left_pressed ⇒ Object
41 42 43 44 |
# File 'lib/fantasy/loop.rb', line 41 def cursor_left_pressed Global.cursor_left_proc&.call invoke_input_method_in_entities("on_cursor_left_do") end |
#cursor_right_pressed ⇒ Object
46 47 48 49 |
# File 'lib/fantasy/loop.rb', line 46 def cursor_right_pressed Global.cursor_right_proc&.call invoke_input_method_in_entities("on_cursor_right_do") end |
#cursor_up_pressed ⇒ Object
36 37 38 39 |
# File 'lib/fantasy/loop.rb', line 36 def cursor_up_pressed Global.cursor_up_proc&.call invoke_input_method_in_entities("on_cursor_up_do") end |
#draw ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fantasy/loop.rb', line 73 def draw Gosu.draw_rect(0, 0, Global.screen_width, Global.screen_height, Global.background) ( Global.backgrounds + Global.tile_maps + Global.actors + Global.hud_texts + Global.hud_images + Global.shapes ).sort_by(&:layer).each(&:draw) end |
#mouse_button_left_pressed ⇒ Object
56 57 58 59 60 |
# File 'lib/fantasy/loop.rb', line 56 def Global.&.call check_click end |
#space_bar_pressed ⇒ Object
51 52 53 54 |
# File 'lib/fantasy/loop.rb', line 51 def Global.&.call invoke_input_method_in_entities("on_space_bar_do") end |