lib/fantasy/loop.rb in fantasy-0.1.9 vs lib/fantasy/loop.rb in fantasy-0.1.11

- old
+ new

@@ -7,24 +7,64 @@ Global.presentation_proc.call() end def button_down(button_id) case button_id - when Gosu::KB_DOWN then Global.cursor_down_proc.call unless Global.cursor_down_proc.nil? - when Gosu::KB_UP then Global.cursor_up_proc.call unless Global.cursor_up_proc.nil? - when Gosu::KB_LEFT then Global.cursor_left_proc.call unless Global.cursor_left_proc.nil? - when Gosu::KB_RIGHT then Global.cursor_right_proc.call unless Global.cursor_right_proc.nil? - when Gosu::MS_LEFT then Global.mouse_button_left_proc.call unless Global.mouse_button_left_proc.nil? - when Gosu::MS_RIGHT then Global.mouse_button_right_proc.call unless Global.mouse_button_right_proc.nil? - when Gosu::KB_SPACE then Global.space_bar_proc.call unless Global.space_bar_proc.nil? + 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.space_bar then space_bar_pressed + + when Mouse.left then mouse_button_left_pressed end Global.button_proc.call(button_id) unless Global.button_proc.nil? super end + def cursor_down_pressed + Global.cursor_down_proc.call unless Global.cursor_down_proc.nil? + invoke_input_method("on_cursor_down_do") + end + + def cursor_up_pressed + Global.cursor_up_proc.call unless Global.cursor_up_proc.nil? + invoke_input_method("on_cursor_up_do") + end + + def cursor_left_pressed + Global.cursor_left_proc.call unless Global.cursor_left_proc.nil? + invoke_input_method("on_cursor_left_do") + end + + def cursor_right_pressed + Global.cursor_right_proc.call unless Global.cursor_right_proc.nil? + invoke_input_method("on_cursor_right_do") + end + + def space_bar_pressed + Global.space_bar_proc.call unless Global.space_bar_proc.nil? + invoke_input_method("on_space_bar_do") + end + + def mouse_button_left_pressed + Global.mouse_button_left_proc.call unless Global.mouse_button_left_proc.nil? + + check_click + end + + def invoke_input_method(input_method_name) + ( + Global.actors + + Global.shapes + ).sort_by(&:layer).each do |e| + e.send(input_method_name) + end + end + def update Global.update Global.actors.each do |e| e.move @@ -49,11 +89,21 @@ ( Global.backgrounds + Global.tile_maps + Global.actors + Global.hud_texts + - Global.hud_images + Global.hud_images + + Global.shapes ).sort_by(&:layer).each do |e| e.draw + end + end + + 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 end