fantasy 0.1.13 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -1
- data/.yardopts +4 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +55 -0
- data/README.md +14 -6
- data/docs/Actor.html +2737 -0
- data/docs/Background.html +961 -0
- data/docs/Camera.html +791 -0
- data/docs/Clock.html +753 -0
- data/docs/Color.html +776 -0
- data/docs/Coordinates.html +730 -0
- data/docs/Cursor.html +752 -0
- data/docs/Disk.html +236 -0
- data/docs/Draggable.html +198 -0
- data/docs/Fantasy.html +121 -0
- data/docs/Game.html +904 -0
- data/docs/Global.html +2791 -0
- data/docs/Gravitier.html +179 -0
- data/docs/HudImage.html +979 -0
- data/docs/HudText.html +1151 -0
- data/docs/Image.html +506 -0
- data/docs/Jumper.html +189 -0
- data/docs/Mouse.html +226 -0
- data/docs/MoveByCursor.html +374 -0
- data/docs/MoveByDirection.html +179 -0
- data/docs/Mover.html +305 -0
- data/docs/Music.html +524 -0
- data/docs/Shape.html +1057 -0
- data/docs/Sound.html +374 -0
- data/docs/Tilemap.html +491 -0
- data/docs/Tween.html +186 -0
- data/docs/UserInputs.html +879 -0
- data/docs/Utils.html +345 -0
- data/docs/_index.html +346 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.CHANGELOG.html +121 -0
- data/docs/file.README.html +599 -0
- data/docs/file_list.html +61 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +599 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +1931 -0
- data/docs/top-level-namespace.html +978 -0
- data/lib/fantasy/actor.rb +455 -123
- data/lib/fantasy/background.rb +109 -13
- data/lib/fantasy/base.rb +113 -1
- data/lib/fantasy/camera.rb +95 -11
- data/lib/fantasy/clock.rb +4 -2
- data/lib/fantasy/color.rb +158 -153
- data/lib/fantasy/coordinates.rb +5 -9
- data/lib/fantasy/cursor.rb +2 -1
- data/lib/fantasy/disk.rb +12 -8
- data/lib/fantasy/draggable.rb +22 -1
- data/lib/fantasy/global.rb +59 -31
- data/lib/fantasy/hud_image.rb +5 -3
- data/lib/fantasy/hud_text.rb +6 -2
- data/lib/fantasy/image.rb +12 -4
- data/lib/fantasy/includes/gravitier.rb +2 -0
- data/lib/fantasy/includes/jumper.rb +3 -2
- data/lib/fantasy/includes/log.rb +12 -0
- data/lib/fantasy/includes/move_by_cursors.rb +24 -15
- data/lib/fantasy/includes/move_by_direction.rb +2 -0
- data/lib/fantasy/includes/mover.rb +3 -0
- data/lib/fantasy/includes/user_inputs.rb +6 -0
- data/lib/fantasy/loop.rb +41 -44
- data/lib/fantasy/mouse.rb +2 -0
- data/lib/fantasy/music.rb +4 -2
- data/lib/fantasy/shape.rb +11 -2
- data/lib/fantasy/sound.rb +3 -1
- data/lib/fantasy/tilemap.rb +19 -13
- data/lib/fantasy/tween.rb +3 -1
- data/lib/fantasy/utils.rb +7 -13
- data/lib/fantasy/version.rb +1 -1
- data/lib/fantasy.rb +2 -0
- metadata +90 -4
- data/fantasy.gemspec +0 -40
- data/fonts/VT323-Regular.ttf +0 -0
data/lib/fantasy/global.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "ostruct"
|
2
4
|
|
3
5
|
module Global
|
4
6
|
class << self
|
7
|
+
include Log
|
8
|
+
|
5
9
|
attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :tile_maps, :clocks, :shapes
|
6
10
|
attr_accessor :debug
|
7
11
|
attr_accessor :setup_proc, :loop_proc, :button_proc
|
@@ -17,11 +21,13 @@ module Global
|
|
17
21
|
attr_reader :frame_time # delta_time
|
18
22
|
attr_reader :pixel_fonts
|
19
23
|
attr_reader :references
|
20
|
-
attr_reader :camera
|
21
24
|
attr_reader :game_state
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
attr_reader :screen_width, :screen_height
|
27
|
+
|
28
|
+
# rubocop:disable Metrics/MethodLength
|
29
|
+
def initialize(screen_width, screen_height)
|
30
|
+
log "Global.initialize"
|
25
31
|
@actors = []
|
26
32
|
@hud_texts = []
|
27
33
|
@hud_images = []
|
@@ -32,33 +38,34 @@ module Global
|
|
32
38
|
@last_frame_at = Time.now
|
33
39
|
@debug = false
|
34
40
|
|
35
|
-
@pixel_fonts =
|
36
|
-
@pixel_fonts["small"] = Gosu::Font.new(20, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
37
|
-
@pixel_fonts["medium"] = Gosu::Font.new(40, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
38
|
-
@pixel_fonts["big"] = Gosu::Font.new(60, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
39
|
-
@pixel_fonts["huge"] = Gosu::Font.new(100, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
41
|
+
@pixel_fonts = load_fonts
|
40
42
|
|
41
43
|
@d_key_pressed = false
|
42
44
|
@references = OpenStruct.new
|
43
|
-
@camera = Camera.new(position: Coordinates.zero)
|
44
45
|
@game_state = Global.presentation_proc.nil? ? "game" : "presentation"
|
45
46
|
@scene_started_at = Time.now
|
46
|
-
|
47
47
|
@background = Color.new(r: 0, g: 0, b: 0)
|
48
48
|
|
49
|
+
@frame_time = 0
|
50
|
+
|
51
|
+
@screen_width = screen_width
|
52
|
+
@screen_height = screen_height
|
53
|
+
|
49
54
|
if @presentation_proc.nil?
|
50
|
-
on_presentation { Global.default_on_presentation
|
55
|
+
on_presentation { Global.default_on_presentation }
|
51
56
|
end
|
52
57
|
|
53
58
|
if @game_proc.nil?
|
54
|
-
on_game { Global.default_on_game
|
59
|
+
on_game { Global.default_on_game }
|
55
60
|
end
|
56
61
|
|
57
62
|
if @end_proc.nil?
|
58
|
-
on_end { Global.default_on_end
|
63
|
+
on_end { Global.default_on_end }
|
59
64
|
end
|
60
65
|
end
|
66
|
+
# rubocop:enable Metrics/MethodLength
|
61
67
|
|
68
|
+
# rubocop:disable Style/GuardClause
|
62
69
|
def update
|
63
70
|
@frame_time = Time.now - @last_frame_at
|
64
71
|
@last_frame_at = Time.now
|
@@ -72,6 +79,7 @@ module Global
|
|
72
79
|
@d_key_pressed = false
|
73
80
|
end
|
74
81
|
end
|
82
|
+
# rubocop:enable Style/GuardClause
|
75
83
|
|
76
84
|
def add_reference(name:, object:)
|
77
85
|
@references[name] = object
|
@@ -90,21 +98,21 @@ module Global
|
|
90
98
|
end
|
91
99
|
|
92
100
|
def go_to_presentation
|
93
|
-
|
101
|
+
log "Game stage 'presentation'"
|
94
102
|
|
95
103
|
clear_state_elements
|
96
104
|
@presentation_proc.call
|
97
105
|
end
|
98
106
|
|
99
107
|
def go_to_game
|
100
|
-
|
108
|
+
log "Game stage 'game'"
|
101
109
|
|
102
110
|
clear_state_elements
|
103
111
|
game_proc.call
|
104
112
|
end
|
105
113
|
|
106
114
|
def go_to_end
|
107
|
-
|
115
|
+
log "Game stage 'end'"
|
108
116
|
|
109
117
|
clear_state_elements
|
110
118
|
end_proc.call
|
@@ -112,19 +120,45 @@ module Global
|
|
112
120
|
|
113
121
|
def clear_state_elements
|
114
122
|
@scene_started_at = Time.now
|
123
|
+
|
124
|
+
clear_entities
|
125
|
+
clear_callbacks
|
126
|
+
end
|
127
|
+
|
128
|
+
def mouse_position
|
129
|
+
Coordinates.new(Global.game.mouse_x, Global.game.mouse_y)
|
130
|
+
end
|
131
|
+
|
132
|
+
def setup
|
133
|
+
Sound.preload_sounds
|
134
|
+
Image.preload_images
|
135
|
+
Music.preload_musics
|
136
|
+
end
|
137
|
+
|
138
|
+
def seconds_in_scene
|
139
|
+
Time.now - @scene_started_at
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def clear_entities
|
115
145
|
@actors.clear
|
116
146
|
@hud_texts.clear
|
117
147
|
@hud_images.clear
|
118
148
|
@backgrounds.clear
|
119
149
|
@tile_maps.clear
|
120
150
|
@shapes.clear
|
121
|
-
@camera.position = Coordinates.zero
|
122
151
|
|
123
152
|
@clocks.reject(&:persistent?).each do |clock|
|
124
153
|
clock.stop unless clock.thread == Thread.current # no stop current Thread
|
125
154
|
end
|
126
155
|
|
127
|
-
|
156
|
+
@background = Color.new(r: 0, g: 0, b: 0)
|
157
|
+
|
158
|
+
Camera.reset
|
159
|
+
end
|
160
|
+
|
161
|
+
def clear_callbacks
|
128
162
|
@button_proc = nil
|
129
163
|
@space_bar_proc = nil
|
130
164
|
@cursor_up_proc = nil
|
@@ -133,22 +167,16 @@ module Global
|
|
133
167
|
@cursor_right_proc = nil
|
134
168
|
@mouse_button_left_proc = nil
|
135
169
|
@mouse_button_right_proc = nil
|
136
|
-
|
137
|
-
@background = Color.new(r: 0, g: 0, b: 0)
|
138
|
-
end
|
139
|
-
|
140
|
-
def mouse_position
|
141
|
-
Coordinates.new(Global.game.mouse_x, Global.game.mouse_y)
|
142
170
|
end
|
143
171
|
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
172
|
+
def load_fonts
|
173
|
+
result = {}
|
174
|
+
result["small"] = Gosu::Font.new(20, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" })
|
175
|
+
result["medium"] = Gosu::Font.new(40, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" })
|
176
|
+
result["big"] = Gosu::Font.new(60, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" })
|
177
|
+
result["huge"] = Gosu::Font.new(100, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" })
|
149
178
|
|
150
|
-
|
151
|
-
Time.now - @scene_started_at
|
179
|
+
result
|
152
180
|
end
|
153
181
|
end
|
154
182
|
end
|
data/lib/fantasy/hud_image.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class HudImage
|
2
4
|
include Draggable
|
3
5
|
|
4
6
|
attr_accessor :name, :scale, :color, :visible, :position, :layer
|
5
7
|
|
6
|
-
def initialize(position:, image_name:
|
8
|
+
def initialize(position:, image_name:)
|
7
9
|
@image = Image.new(image_name)
|
8
10
|
@name = image_name
|
9
11
|
@position = position
|
@@ -17,11 +19,11 @@ class HudImage
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def width
|
20
|
-
@image.width
|
22
|
+
@image.width * @scale
|
21
23
|
end
|
22
24
|
|
23
25
|
def height
|
24
|
-
@image.height
|
26
|
+
@image.height * @scale
|
25
27
|
end
|
26
28
|
|
27
29
|
def move
|
data/lib/fantasy/hud_text.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class HudText
|
2
4
|
attr_accessor :text, :size, :color, :background_color, :visible, :layer, :in_world, :position, :alignment
|
3
5
|
|
@@ -17,6 +19,7 @@ class HudText
|
|
17
19
|
|
18
20
|
def move; end
|
19
21
|
|
22
|
+
# rubocop:disable Metrics/AbcSize
|
20
23
|
def draw
|
21
24
|
if visible
|
22
25
|
unless @background_color.nil?
|
@@ -27,12 +30,14 @@ class HudText
|
|
27
30
|
|
28
31
|
draw_debug if Global.debug
|
29
32
|
end
|
33
|
+
# rubocop:enable Metrics/AbcSize
|
30
34
|
|
31
35
|
def font
|
32
36
|
found_font = Global.pixel_fonts[@size]
|
33
37
|
if found_font.nil?
|
34
38
|
raise "HudText.size value not valid '#{@size}'. Valid values: 'small, medium, big, huge'"
|
35
39
|
end
|
40
|
+
|
36
41
|
found_font
|
37
42
|
end
|
38
43
|
|
@@ -44,7 +49,6 @@ class HudText
|
|
44
49
|
font.markup_width(text, 1)
|
45
50
|
end
|
46
51
|
|
47
|
-
|
48
52
|
private
|
49
53
|
|
50
54
|
def position_rel
|
@@ -79,7 +83,7 @@ class HudText
|
|
79
83
|
|
80
84
|
def screen_position
|
81
85
|
if @in_world
|
82
|
-
@position -
|
86
|
+
@position - Camera.main.position
|
83
87
|
else
|
84
88
|
@position
|
85
89
|
end
|
data/lib/fantasy/image.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Image
|
2
4
|
def initialize(image_name)
|
3
5
|
@image = Image.load(image_name)
|
@@ -16,6 +18,8 @@ class Image
|
|
16
18
|
end
|
17
19
|
|
18
20
|
class << self
|
21
|
+
include Log
|
22
|
+
|
19
23
|
@@images = {}
|
20
24
|
|
21
25
|
def load(image_name)
|
@@ -35,19 +39,23 @@ class Image
|
|
35
39
|
def locate_image(image_name)
|
36
40
|
return @@images[image_name] if @@images[image_name]
|
37
41
|
|
38
|
-
|
42
|
+
log "Initialize image: '#{image_name}'"
|
39
43
|
|
40
|
-
file_name = Dir.entries(base_path).find { |e| e =~ /^#{image_name}($|\.)/
|
44
|
+
file_name = Dir.entries(base_path).find { |e| e =~ /^#{image_name}($|\.)/ }
|
41
45
|
|
42
46
|
raise "Image file not found with name '#{image_name}' in #{base_path}" if file_name.nil?
|
43
47
|
|
44
48
|
@@images[image_name] = Gosu::Image.new("#{base_path}/#{file_name}", { retro: true })
|
45
49
|
|
46
|
-
|
50
|
+
@@images[image_name]
|
47
51
|
end
|
48
52
|
|
49
53
|
def base_path
|
50
|
-
"
|
54
|
+
if ENV["environment"] == "test"
|
55
|
+
"#{Dir.pwd}/test/fixtures/images"
|
56
|
+
else
|
57
|
+
"#{Dir.pwd}/images"
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Jumper
|
2
4
|
def jump
|
3
|
-
|
5
|
+
impulse(direction: Coordinates.up, force: @jump_force)
|
4
6
|
@jumping = true
|
5
7
|
@on_floor = false
|
6
|
-
@final_vertical_position = @position.y - @jump_force
|
7
8
|
|
8
9
|
on_jumping_do
|
9
10
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Log
|
2
|
+
def log(message)
|
3
|
+
if ENV["debug"] == "active"
|
4
|
+
full_message = "[#{Time.now.strftime("%T")}]"
|
5
|
+
full_message += " [#{object_id}]"
|
6
|
+
full_message += " [#{@name}]" if defined?(@name)
|
7
|
+
full_message += " : #{message}"
|
8
|
+
|
9
|
+
puts full_message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,4 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MoveByCursor
|
4
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
5
|
+
def move_with_cursors(down: nil, up: nil, left: nil, right: nil, jump: false)
|
6
|
+
if down.nil? && up.nil? && left.nil? && right.nil?
|
7
|
+
down = true
|
8
|
+
up = true
|
9
|
+
left = true
|
10
|
+
right = true
|
11
|
+
end
|
12
|
+
|
13
|
+
@move_with_cursors_down = down || false
|
14
|
+
@move_with_cursors_up = up || false
|
15
|
+
@move_with_cursors_left = left || false
|
16
|
+
@move_with_cursors_right = right || false
|
17
|
+
@move_with_cursors_jump = jump || false
|
18
|
+
end
|
19
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
20
|
+
|
21
|
+
# rubocop:disable
|
22
|
+
|
23
|
+
# @!visibility private
|
2
24
|
def move_by_cursors
|
3
25
|
if Gosu.button_down?(Cursor.down) && @move_with_cursors_down
|
4
26
|
move_by(Coordinates.down)
|
@@ -20,22 +42,9 @@ module MoveByCursor
|
|
20
42
|
jump
|
21
43
|
end
|
22
44
|
end
|
45
|
+
# rubocop:enable
|
23
46
|
|
24
|
-
|
25
|
-
puts "#{@name}: move_with_cursors(down: #{down}, up: #{up}, left: #{left}, right: #{right}), jump: #{jump}"
|
26
|
-
|
27
|
-
if down.nil? and up.nil? and left.nil? and right.nil?
|
28
|
-
down = true
|
29
|
-
up = true
|
30
|
-
left = true
|
31
|
-
right = true
|
32
|
-
end
|
33
|
-
@move_with_cursors_down = down || false
|
34
|
-
@move_with_cursors_up = up || false
|
35
|
-
@move_with_cursors_left = left || false
|
36
|
-
@move_with_cursors_right = right || false
|
37
|
-
@move_with_cursors_jump = jump || false
|
38
|
-
end
|
47
|
+
private
|
39
48
|
|
40
49
|
def move_by(direction)
|
41
50
|
@position += direction * @speed * Global.frame_time
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mover
|
2
4
|
def impulse(direction:, force:)
|
3
5
|
add_force(direction.normalize * force)
|
@@ -13,6 +15,7 @@ module Mover
|
|
13
15
|
@velocity ||= Coordinates.zero
|
14
16
|
|
15
17
|
@velocity += @acceleration
|
18
|
+
|
16
19
|
@velocity.resize(max_speed) if @velocity.length > max_speed
|
17
20
|
|
18
21
|
unless @velocity.length.zero?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module UserInputs
|
2
4
|
# Set callbacks
|
3
5
|
def on_cursor_down(&block)
|
@@ -57,4 +59,8 @@ module UserInputs
|
|
57
59
|
puts "XXX: on_click_do: #{@on_click_callback}"
|
58
60
|
instance_exec(&@on_click_callback) unless @on_click_callback.nil?
|
59
61
|
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
attr_accessor :on_cursor_down_callback, :on_cursor_up_callback, :on_cursor_left_callback, :on_cursor_right_callback, :on_space_bar_callback, :on_mouse_button_left_callback
|
60
66
|
end
|
data/lib/fantasy/loop.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Game < Gosu::Window
|
2
|
-
def initialize
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def initialize(screen_width, screen_height)
|
5
|
+
Camera.initialize
|
6
|
+
Global.initialize(screen_width, screen_height)
|
7
|
+
|
8
|
+
super(Global.screen_width, Global.screen_height)
|
6
9
|
|
7
|
-
Global.presentation_proc.call
|
10
|
+
Global.presentation_proc.call
|
8
11
|
end
|
9
12
|
|
13
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
10
14
|
def button_down(button_id)
|
11
15
|
case button_id
|
12
16
|
when Cursor.down then cursor_down_pressed
|
@@ -18,73 +22,56 @@ class Game < Gosu::Window
|
|
18
22
|
when Mouse.left then mouse_button_left_pressed
|
19
23
|
end
|
20
24
|
|
21
|
-
Global.button_proc
|
25
|
+
Global.button_proc&.call(button_id)
|
22
26
|
|
23
27
|
super
|
24
28
|
end
|
29
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
25
30
|
|
26
31
|
def cursor_down_pressed
|
27
|
-
Global.cursor_down_proc
|
28
|
-
|
32
|
+
Global.cursor_down_proc&.call
|
33
|
+
invoke_input_method_in_entities("on_cursor_down_do")
|
29
34
|
end
|
30
35
|
|
31
36
|
def cursor_up_pressed
|
32
|
-
Global.cursor_up_proc
|
33
|
-
|
37
|
+
Global.cursor_up_proc&.call
|
38
|
+
invoke_input_method_in_entities("on_cursor_up_do")
|
34
39
|
end
|
35
40
|
|
36
41
|
def cursor_left_pressed
|
37
|
-
Global.cursor_left_proc
|
38
|
-
|
42
|
+
Global.cursor_left_proc&.call
|
43
|
+
invoke_input_method_in_entities("on_cursor_left_do")
|
39
44
|
end
|
40
45
|
|
41
46
|
def cursor_right_pressed
|
42
|
-
Global.cursor_right_proc
|
43
|
-
|
47
|
+
Global.cursor_right_proc&.call
|
48
|
+
invoke_input_method_in_entities("on_cursor_right_do")
|
44
49
|
end
|
45
50
|
|
46
51
|
def space_bar_pressed
|
47
|
-
Global.space_bar_proc
|
48
|
-
|
52
|
+
Global.space_bar_proc&.call
|
53
|
+
invoke_input_method_in_entities("on_space_bar_do")
|
49
54
|
end
|
50
55
|
|
51
56
|
def mouse_button_left_pressed
|
52
|
-
Global.mouse_button_left_proc
|
57
|
+
Global.mouse_button_left_proc&.call
|
53
58
|
|
54
59
|
check_click
|
55
60
|
end
|
56
61
|
|
57
|
-
def invoke_input_method(input_method_name)
|
58
|
-
(
|
59
|
-
Global.actors +
|
60
|
-
Global.shapes
|
61
|
-
).sort_by(&:layer).each do |e|
|
62
|
-
e.send(input_method_name)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
62
|
def update
|
67
63
|
Global.update
|
68
64
|
|
69
|
-
Global.actors.each
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
Global.hud_texts.each do |e|
|
74
|
-
e.move
|
75
|
-
end
|
76
|
-
|
77
|
-
Global.hud_images.each do |e|
|
78
|
-
e.move
|
79
|
-
end
|
80
|
-
|
81
|
-
Global.camera.move
|
65
|
+
Global.actors.each(&:move)
|
66
|
+
Global.hud_texts.each(&:move)
|
67
|
+
Global.hud_images.each(&:move)
|
68
|
+
Camera.main.move
|
82
69
|
|
83
|
-
Global.loop_proc
|
70
|
+
Global.loop_proc&.call
|
84
71
|
end
|
85
72
|
|
86
73
|
def draw
|
87
|
-
Gosu.draw_rect(0, 0,
|
74
|
+
Gosu.draw_rect(0, 0, Global.screen_width, Global.screen_height, Global.background)
|
88
75
|
|
89
76
|
(
|
90
77
|
Global.backgrounds +
|
@@ -93,9 +80,7 @@ class Game < Gosu::Window
|
|
93
80
|
Global.hud_texts +
|
94
81
|
Global.hud_images +
|
95
82
|
Global.shapes
|
96
|
-
).sort_by(&:layer).each
|
97
|
-
e.draw
|
98
|
-
end
|
83
|
+
).sort_by(&:layer).each(&:draw)
|
99
84
|
end
|
100
85
|
|
101
86
|
def check_click
|
@@ -106,4 +91,16 @@ class Game < Gosu::Window
|
|
106
91
|
e.on_click_do if Utils.collision_at?(e, mouse_x, mouse_y)
|
107
92
|
end
|
108
93
|
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def invoke_input_method_in_entities(input_method_name)
|
98
|
+
(
|
99
|
+
Global.actors +
|
100
|
+
Global.shapes
|
101
|
+
).sort_by(&:layer).each do |e|
|
102
|
+
e.send(input_method_name)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
109
106
|
end
|
data/lib/fantasy/mouse.rb
CHANGED
data/lib/fantasy/music.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Music
|
2
4
|
class << self
|
3
5
|
@@musics = {}
|
@@ -13,7 +15,7 @@ module Music
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def stop
|
16
|
-
@@actual_song
|
18
|
+
@@actual_song&.stop
|
17
19
|
end
|
18
20
|
|
19
21
|
def volume
|
@@ -35,7 +37,7 @@ module Music
|
|
35
37
|
|
36
38
|
@@musics[music_name] = Gosu::Song.new("#{base_path}/#{file_name}")
|
37
39
|
|
38
|
-
|
40
|
+
@@musics[music_name]
|
39
41
|
end
|
40
42
|
|
41
43
|
def preload_musics
|
data/lib/fantasy/shape.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Shape
|
2
4
|
include UserInputs
|
3
5
|
|
4
6
|
attr_accessor :kind, :position, :width, :height, :stroke, :color, :fill, :stroke_color, :layer
|
5
7
|
|
8
|
+
# rubocop:disable Metrics/ParameterLists
|
6
9
|
def initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil)
|
7
10
|
@kind = kind
|
8
11
|
@position = position
|
@@ -16,9 +19,10 @@ class Shape
|
|
16
19
|
|
17
20
|
Global.shapes << self
|
18
21
|
end
|
22
|
+
# rubocop:enable Metrics/ParameterLists
|
19
23
|
|
20
|
-
def self.rectangle(position:, width:, height:, color: Color.palette.black)
|
21
|
-
Shape.new(kind: "rectangle", position: position, width: width, height: height)
|
24
|
+
def self.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0)
|
25
|
+
Shape.new(kind: "rectangle", position: position, width: width, height: height, color: color)
|
22
26
|
end
|
23
27
|
|
24
28
|
def draw
|
@@ -36,20 +40,25 @@ class Shape
|
|
36
40
|
|
37
41
|
private
|
38
42
|
|
43
|
+
# rubocop:disable Style/GuardClause
|
39
44
|
def draw_rectangle
|
40
45
|
if fill
|
41
46
|
Gosu.draw_rect(@position.x, @position.y, @width, @height, @color)
|
42
47
|
end
|
43
48
|
|
49
|
+
|
44
50
|
unless stroke.zero?
|
45
51
|
draw_frame(@position.x, @position.y, @width, @height, @stroke, @stroke_color || @color)
|
46
52
|
end
|
47
53
|
end
|
54
|
+
# rubocop:enable Style/GuardClause
|
48
55
|
|
56
|
+
# rubocop:disable Metrics/ParameterLists
|
49
57
|
def draw_frame(x, y, width, height, stroke, color)
|
50
58
|
Gosu.draw_rect(x, y, width, stroke, color)
|
51
59
|
Gosu.draw_rect(width - stroke + x, y, stroke, height, color)
|
52
60
|
Gosu.draw_rect(x, height - stroke + y, width, stroke, color)
|
53
61
|
Gosu.draw_rect(x, y, stroke, height, color)
|
54
62
|
end
|
63
|
+
# rubocop:enable Metrics/ParameterLists
|
55
64
|
end
|
data/lib/fantasy/sound.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sound
|
2
4
|
class << self
|
3
5
|
@@sounds = {}
|
@@ -17,7 +19,7 @@ module Sound
|
|
17
19
|
|
18
20
|
@@sounds[sound_name] = Gosu::Sample.new("#{base_path}/#{file_name}")
|
19
21
|
|
20
|
-
|
22
|
+
@@sounds[sound_name]
|
21
23
|
end
|
22
24
|
|
23
25
|
def preload_sounds
|