Module: Global

Extended by:
Log
Defined in:
lib/fantasy/global.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Log

log

Class Attribute Details

.actorsObject

Returns the value of attribute actors.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def actors
  @actors
end

.backgroundObject

Returns the value of attribute background.



18
19
20
# File 'lib/fantasy/global.rb', line 18

def background
  @background
end

.backgroundsObject

Returns the value of attribute backgrounds.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def backgrounds
  @backgrounds
end

.button_procObject

Returns the value of attribute button_proc.



11
12
13
# File 'lib/fantasy/global.rb', line 11

def button_proc
  @button_proc
end

.clocksObject

Returns the value of attribute clocks.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def clocks
  @clocks
end

.cursor_down_procObject

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_procObject

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_procObject

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_procObject

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

.debugObject

Returns the value of attribute debug.



10
11
12
# File 'lib/fantasy/global.rb', line 10

def debug
  @debug
end

.end_procObject

Returns the value of attribute end_proc.



12
13
14
# File 'lib/fantasy/global.rb', line 12

def end_proc
  @end_proc
end

.frame_timeObject (readonly)

delta_time



21
22
23
# File 'lib/fantasy/global.rb', line 21

def frame_time
  @frame_time
end

.gameObject

Returns the value of attribute game.



20
21
22
# File 'lib/fantasy/global.rb', line 20

def game
  @game
end

.game_procObject

Returns the value of attribute game_proc.



12
13
14
# File 'lib/fantasy/global.rb', line 12

def game_proc
  @game_proc
end

.game_stateObject (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_imagesObject

Returns the value of attribute hud_images.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def hud_images
  @hud_images
end

.hud_textsObject

Returns the value of attribute hud_texts.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def hud_texts
  @hud_texts
end

.loop_procObject

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_procObject

Returns the value of attribute mouse_button_left_proc.



16
17
18
# File 'lib/fantasy/global.rb', line 16

def mouse_button_left_proc
  @mouse_button_left_proc
end

.mouse_button_right_procObject

Returns the value of attribute mouse_button_right_proc.



16
17
18
# File 'lib/fantasy/global.rb', line 16

def mouse_button_right_proc
  @mouse_button_right_proc
end

.pixel_fontsObject (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_procObject

Returns the value of attribute presentation_proc.



12
13
14
# File 'lib/fantasy/global.rb', line 12

def presentation_proc
  @presentation_proc
end

.referencesObject (readonly)

Returns the value of attribute references.



23
24
25
# File 'lib/fantasy/global.rb', line 23

def references
  @references
end

.screen_heightObject (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_widthObject (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_procObject

Returns the value of attribute setup_proc.



11
12
13
# File 'lib/fantasy/global.rb', line 11

def setup_proc
  @setup_proc
end

.shapesObject

Returns the value of attribute shapes.



9
10
11
# File 'lib/fantasy/global.rb', line 9

def shapes
  @shapes
end

.space_bar_procObject

Returns the value of attribute space_bar_proc.



14
15
16
# File 'lib/fantasy/global.rb', line 14

def space_bar_proc
  @space_bar_proc
end

.tile_mapsObject

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_elementsObject



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_endObject



96
97
98
# File 'lib/fantasy/global.rb', line 96

def default_on_end
  Global.go_to_presentation
end

.default_on_gameObject



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_presentationObject



88
89
90
# File 'lib/fantasy/global.rb', line 88

def default_on_presentation
  Global.go_to_game
end

.go_to_endObject



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_gameObject



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_presentationObject



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_positionObject



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_sceneObject



138
139
140
# File 'lib/fantasy/global.rb', line 138

def seconds_in_scene
  Time.now - @scene_started_at
end

.setupObject



132
133
134
135
136
# File 'lib/fantasy/global.rb', line 132

def setup
  Sound.preload_sounds
  Image.preload_images
  Music.preload_musics
end

.updateObject

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.button_down?(Gosu::KB_D) && !@d_key_pressed
    @debug = !@debug
    @d_key_pressed = true
  end

  if !Gosu.button_down?(Gosu::KB_D) && @d_key_pressed
    @d_key_pressed = false
  end
end