Module: Global
- Extended by:
- Log
- Defined in:
- lib/fantasy/global.rb
Class Attribute Summary collapse
-
.actors ⇒ Object
Returns the value of attribute actors.
-
.background ⇒ Object
Returns the value of attribute background.
-
.backgrounds ⇒ Object
Returns the value of attribute backgrounds.
-
.button_proc ⇒ Object
Returns the value of attribute button_proc.
-
.clocks ⇒ Object
Returns the value of attribute clocks.
-
.cursor_down_proc ⇒ Object
Returns the value of attribute cursor_down_proc.
-
.cursor_left_proc ⇒ Object
Returns the value of attribute cursor_left_proc.
-
.cursor_right_proc ⇒ Object
Returns the value of attribute cursor_right_proc.
-
.cursor_up_proc ⇒ Object
Returns the value of attribute cursor_up_proc.
-
.debug ⇒ Object
Returns the value of attribute debug.
-
.end_proc ⇒ Object
Returns the value of attribute end_proc.
-
.frame_time ⇒ Object
readonly
delta_time.
-
.game ⇒ Object
Returns the value of attribute game.
-
.game_proc ⇒ Object
Returns the value of attribute game_proc.
-
.game_state ⇒ Object
readonly
Returns the value of attribute game_state.
-
.hud_images ⇒ Object
Returns the value of attribute hud_images.
-
.hud_texts ⇒ Object
Returns the value of attribute hud_texts.
-
.loop_proc ⇒ Object
Returns the value of attribute loop_proc.
-
.mouse_button_left_proc ⇒ Object
Returns the value of attribute mouse_button_left_proc.
-
.mouse_button_right_proc ⇒ Object
Returns the value of attribute mouse_button_right_proc.
-
.pixel_fonts ⇒ Object
readonly
Returns the value of attribute pixel_fonts.
-
.presentation_proc ⇒ Object
Returns the value of attribute presentation_proc.
-
.references ⇒ Object
readonly
Returns the value of attribute references.
-
.screen_height ⇒ Object
readonly
Returns the value of attribute screen_height.
-
.screen_width ⇒ Object
readonly
Returns the value of attribute screen_width.
-
.setup_proc ⇒ Object
Returns the value of attribute setup_proc.
-
.shapes ⇒ Object
Returns the value of attribute shapes.
-
.space_bar_proc ⇒ Object
Returns the value of attribute space_bar_proc.
-
.tile_maps ⇒ Object
Returns the value of attribute tile_maps.
Class Method Summary collapse
-
.add_reference(name:, object:) ⇒ Object
rubocop:enable Style/GuardClause.
- .clear_state_elements ⇒ Object
- .default_on_end ⇒ Object
- .default_on_game ⇒ Object
- .default_on_presentation ⇒ Object
- .go_to_end ⇒ Object
- .go_to_game ⇒ Object
- .go_to_presentation ⇒ Object
-
.initialize(screen_width, screen_height) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .mouse_position ⇒ Object
- .seconds_in_scene ⇒ Object
- .setup ⇒ Object
-
.update ⇒ Object
rubocop:disable Style/GuardClause.
Methods included from Log
Class Attribute Details
.actors ⇒ Object
Returns the value of attribute actors.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def actors @actors end |
.background ⇒ Object
Returns the value of attribute background.
18 19 20 |
# File 'lib/fantasy/global.rb', line 18 def background @background end |
.backgrounds ⇒ Object
Returns the value of attribute backgrounds.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def backgrounds @backgrounds end |
.button_proc ⇒ Object
Returns the value of attribute button_proc.
11 12 13 |
# File 'lib/fantasy/global.rb', line 11 def @button_proc end |
.clocks ⇒ Object
Returns the value of attribute clocks.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def clocks @clocks end |
.cursor_down_proc ⇒ Object
Returns the value of attribute cursor_down_proc.
15 16 17 |
# File 'lib/fantasy/global.rb', line 15 def cursor_down_proc @cursor_down_proc end |
.cursor_left_proc ⇒ Object
Returns the value of attribute cursor_left_proc.
15 16 17 |
# File 'lib/fantasy/global.rb', line 15 def cursor_left_proc @cursor_left_proc end |
.cursor_right_proc ⇒ Object
Returns the value of attribute cursor_right_proc.
15 16 17 |
# File 'lib/fantasy/global.rb', line 15 def cursor_right_proc @cursor_right_proc end |
.cursor_up_proc ⇒ Object
Returns the value of attribute cursor_up_proc.
15 16 17 |
# File 'lib/fantasy/global.rb', line 15 def cursor_up_proc @cursor_up_proc end |
.debug ⇒ Object
Returns the value of attribute debug.
10 11 12 |
# File 'lib/fantasy/global.rb', line 10 def debug @debug end |
.end_proc ⇒ Object
Returns the value of attribute end_proc.
12 13 14 |
# File 'lib/fantasy/global.rb', line 12 def end_proc @end_proc end |
.frame_time ⇒ Object (readonly)
delta_time
21 22 23 |
# File 'lib/fantasy/global.rb', line 21 def frame_time @frame_time end |
.game ⇒ Object
Returns the value of attribute game.
20 21 22 |
# File 'lib/fantasy/global.rb', line 20 def game @game end |
.game_proc ⇒ Object
Returns the value of attribute game_proc.
12 13 14 |
# File 'lib/fantasy/global.rb', line 12 def game_proc @game_proc end |
.game_state ⇒ Object (readonly)
Returns the value of attribute game_state.
24 25 26 |
# File 'lib/fantasy/global.rb', line 24 def game_state @game_state end |
.hud_images ⇒ Object
Returns the value of attribute hud_images.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def hud_images @hud_images end |
.hud_texts ⇒ Object
Returns the value of attribute hud_texts.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def hud_texts @hud_texts end |
.loop_proc ⇒ Object
Returns the value of attribute loop_proc.
11 12 13 |
# File 'lib/fantasy/global.rb', line 11 def loop_proc @loop_proc end |
.mouse_button_left_proc ⇒ Object
Returns the value of attribute mouse_button_left_proc.
16 17 18 |
# File 'lib/fantasy/global.rb', line 16 def @mouse_button_left_proc end |
.mouse_button_right_proc ⇒ Object
Returns the value of attribute mouse_button_right_proc.
16 17 18 |
# File 'lib/fantasy/global.rb', line 16 def @mouse_button_right_proc end |
.pixel_fonts ⇒ Object (readonly)
Returns the value of attribute pixel_fonts.
22 23 24 |
# File 'lib/fantasy/global.rb', line 22 def pixel_fonts @pixel_fonts end |
.presentation_proc ⇒ Object
Returns the value of attribute presentation_proc.
12 13 14 |
# File 'lib/fantasy/global.rb', line 12 def presentation_proc @presentation_proc end |
.references ⇒ Object (readonly)
Returns the value of attribute references.
23 24 25 |
# File 'lib/fantasy/global.rb', line 23 def references @references end |
.screen_height ⇒ Object (readonly)
Returns the value of attribute screen_height.
26 27 28 |
# File 'lib/fantasy/global.rb', line 26 def screen_height @screen_height end |
.screen_width ⇒ Object (readonly)
Returns the value of attribute screen_width.
26 27 28 |
# File 'lib/fantasy/global.rb', line 26 def screen_width @screen_width end |
.setup_proc ⇒ Object
Returns the value of attribute setup_proc.
11 12 13 |
# File 'lib/fantasy/global.rb', line 11 def setup_proc @setup_proc end |
.shapes ⇒ Object
Returns the value of attribute shapes.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def shapes @shapes end |
.space_bar_proc ⇒ Object
Returns the value of attribute space_bar_proc.
14 15 16 |
# File 'lib/fantasy/global.rb', line 14 def @space_bar_proc end |
.tile_maps ⇒ Object
Returns the value of attribute tile_maps.
9 10 11 |
# File 'lib/fantasy/global.rb', line 9 def tile_maps @tile_maps end |
Class Method Details
.add_reference(name:, object:) ⇒ Object
rubocop:enable Style/GuardClause
84 85 86 |
# File 'lib/fantasy/global.rb', line 84 def add_reference(name:, object:) @references[name] = object end |
.clear_state_elements ⇒ Object
121 122 123 124 125 126 |
# File 'lib/fantasy/global.rb', line 121 def clear_state_elements @scene_started_at = Time.now clear_entities clear_callbacks end |
.default_on_end ⇒ Object
96 97 98 |
# File 'lib/fantasy/global.rb', line 96 def default_on_end Global.go_to_presentation end |
.default_on_game ⇒ Object
92 93 94 |
# File 'lib/fantasy/global.rb', line 92 def default_on_game raise "You have to define a 'on_game' block" end |
.default_on_presentation ⇒ Object
88 89 90 |
# File 'lib/fantasy/global.rb', line 88 def default_on_presentation Global.go_to_game end |
.go_to_end ⇒ Object
114 115 116 117 118 119 |
# File 'lib/fantasy/global.rb', line 114 def go_to_end log "Game stage 'end'" clear_state_elements end_proc.call end |
.go_to_game ⇒ Object
107 108 109 110 111 112 |
# File 'lib/fantasy/global.rb', line 107 def go_to_game log "Game stage 'game'" clear_state_elements game_proc.call end |
.go_to_presentation ⇒ Object
100 101 102 103 104 105 |
# File 'lib/fantasy/global.rb', line 100 def go_to_presentation log "Game stage 'presentation'" clear_state_elements @presentation_proc.call end |
.initialize(screen_width, screen_height) ⇒ Object
rubocop:disable Metrics/MethodLength
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 60 61 62 63 64 65 |
# File 'lib/fantasy/global.rb', line 29 def initialize(screen_width, screen_height) log "Global.initialize" @actors = [] @hud_texts = [] @hud_images = [] @backgrounds = [] @tile_maps = [] @clocks = [] @shapes = [] @last_frame_at = Time.now @debug = false @pixel_fonts = load_fonts @d_key_pressed = false @references = OpenStruct.new @game_state = Global.presentation_proc.nil? ? "game" : "presentation" @scene_started_at = Time.now @background = Color.new(r: 0, g: 0, b: 0) @frame_time = 0 @screen_width = screen_width @screen_height = screen_height if @presentation_proc.nil? on_presentation { Global.default_on_presentation } end if @game_proc.nil? on_game { Global.default_on_game } end if @end_proc.nil? on_end { Global.default_on_end } end end |
.mouse_position ⇒ Object
128 129 130 |
# File 'lib/fantasy/global.rb', line 128 def mouse_position Coordinates.new(Global.game.mouse_x, Global.game.mouse_y) end |
.seconds_in_scene ⇒ Object
138 139 140 |
# File 'lib/fantasy/global.rb', line 138 def seconds_in_scene Time.now - @scene_started_at end |
.setup ⇒ Object
132 133 134 135 136 |
# File 'lib/fantasy/global.rb', line 132 def setup Sound.preload_sounds Image.preload_images Music.preload_musics end |
.update ⇒ Object
rubocop:disable Style/GuardClause
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fantasy/global.rb', line 69 def update @frame_time = Time.now - @last_frame_at @last_frame_at = Time.now if Gosu.(Gosu::KB_D) && !@d_key_pressed @debug = !@debug @d_key_pressed = true end if !Gosu.(Gosu::KB_D) && @d_key_pressed @d_key_pressed = false end end |