minigl 1.3.2 → 1.3.3
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/README.md +6 -7
- data/lib/minigl/forms.rb +14 -10
- data/lib/minigl/game_object.rb +19 -12
- data/lib/minigl/movement.rb +27 -3
- data/lib/minigl/text.rb +14 -10
- data/test/game.rb +3 -3
- data/test/movement_tests.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6075180b99d1cf18a53a683353828675ed18ca8
|
4
|
+
data.tar.gz: c01f4bd208021a2bff3f2c1aa3f86eac0c7ff093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6981a60cbd32da81a0c96553536dd77b440ccd913cd1a612a23b64292051ec69924e6ed2058df2de72ef75a5db4f5869edec3ded25963d8012b999b17575285a
|
7
|
+
data.tar.gz: 15e2fc67ac2b072da7e3a80b026fe5787b2df7804451aedd28d4e5a0f9e70dfd6ec299be7463b38e354279b87c27a6a9660d4fa00aaae6ae7f32fcad35d534ad
|
data/README.md
CHANGED
@@ -22,12 +22,11 @@ this [working game example](https://github.com/victords/aventura-do-saber).
|
|
22
22
|
* An auxiliary, tutorial-like documentation is under construction
|
23
23
|
[here](https://github.com/victords/minigl/wiki).
|
24
24
|
|
25
|
-
**Version 1.3.
|
25
|
+
**Version 1.3.3**
|
26
26
|
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
* Added `checked` parameter to the constructor of `ToggleButton`.
|
27
|
+
* Added `mass` attribute to the GameObject class and Movement module.
|
28
|
+
* Added readers for the attributes of `Ramp`.
|
29
|
+
* Added z-index support to all drawing functions.
|
31
30
|
|
32
|
-
**WARNING**: this version can generate incompatibility, because
|
33
|
-
|
31
|
+
**WARNING**: this version can generate incompatibility, because the `move`
|
32
|
+
method of `Movement` now requires the calling object to have a `mass` attribute.
|
data/lib/minigl/forms.rb
CHANGED
@@ -173,17 +173,19 @@ module AGL
|
|
173
173
|
# Parameters:
|
174
174
|
# [alpha] The opacity with which the button will be drawn. Allowed values
|
175
175
|
# vary between 0 (fully transparent) and 255 (fully opaque).
|
176
|
-
|
176
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
177
|
+
# will be drawn on top of the ones with smaller z-orders.
|
178
|
+
def draw alpha = 0xff, z_index = 0
|
177
179
|
return unless @visible
|
178
180
|
|
179
181
|
color = (alpha << 24) | 0xffffff
|
180
182
|
text_color = (alpha << 24) | (@enabled ? @text_color : @disabled_text_color)
|
181
|
-
@img[@img_index].draw @x, @y,
|
183
|
+
@img[@img_index].draw @x, @y, z_index, 1, 1, color if @img
|
182
184
|
if @text
|
183
185
|
if @center
|
184
|
-
@font.draw_rel @text, @text_x, @text_y,
|
186
|
+
@font.draw_rel @text, @text_x, @text_y, z_index, 0.5, 0.5, 1, 1, text_color
|
185
187
|
else
|
186
|
-
@font.draw @text, @text_x, @text_y,
|
188
|
+
@font.draw @text, @text_x, @text_y, z_index, 1, 1, text_color
|
187
189
|
end
|
188
190
|
end
|
189
191
|
end
|
@@ -590,32 +592,34 @@ module AGL
|
|
590
592
|
# Parameters:
|
591
593
|
# [alpha] The opacity with which the text field will be drawn. Allowed
|
592
594
|
# values vary between 0 (fully transparent) and 255 (fully opaque).
|
593
|
-
|
595
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
596
|
+
# will be drawn on top of the ones with smaller z-orders.
|
597
|
+
def draw alpha = 0xff, z_index = 0
|
594
598
|
return unless @visible
|
595
599
|
|
596
600
|
color = (alpha << 24) | ((@enabled or @disabled_img) ? 0xffffff : 0x808080)
|
597
601
|
text_color = (alpha << 24) | (@enabled ? @text_color : @disabled_text_color)
|
598
602
|
img = ((@enabled or @disabled_img.nil?) ? @img : @disabled_img)
|
599
|
-
img.draw @x, @y,
|
600
|
-
@font.draw @text, @text_x, @text_y,
|
603
|
+
img.draw @x, @y, z_index, 1, 1, color
|
604
|
+
@font.draw @text, @text_x, @text_y, z_index, 1, 1, text_color
|
601
605
|
|
602
606
|
if @anchor1 and @anchor2
|
603
607
|
selection_color = ((alpha / 2) << 24) | @selection_color
|
604
608
|
Game.window.draw_quad @nodes[@anchor1], @text_y, selection_color,
|
605
609
|
@nodes[@anchor2] + 1, @text_y, selection_color,
|
606
610
|
@nodes[@anchor2] + 1, @text_y + @font.height, selection_color,
|
607
|
-
@nodes[@anchor1], @text_y + @font.height, selection_color,
|
611
|
+
@nodes[@anchor1], @text_y + @font.height, selection_color, z_index
|
608
612
|
end
|
609
613
|
|
610
614
|
if @cursor_visible
|
611
615
|
if @cursor_img
|
612
|
-
@cursor_img.draw @nodes[@cur_node] - @cursor_img.width / 2, @text_y,
|
616
|
+
@cursor_img.draw @nodes[@cur_node] - @cursor_img.width / 2, @text_y, z_index
|
613
617
|
else
|
614
618
|
cursor_color = alpha << 24
|
615
619
|
Game.window.draw_quad @nodes[@cur_node], @text_y, cursor_color,
|
616
620
|
@nodes[@cur_node] + 1, @text_y, cursor_color,
|
617
621
|
@nodes[@cur_node] + 1, @text_y + @font.height, cursor_color,
|
618
|
-
@nodes[@cur_node], @text_y + @font.height, cursor_color,
|
622
|
+
@nodes[@cur_node], @text_y + @font.height, cursor_color, z_index
|
619
623
|
end
|
620
624
|
end
|
621
625
|
end
|
data/lib/minigl/game_object.rb
CHANGED
@@ -83,18 +83,20 @@ module AGL
|
|
83
83
|
# will be darkened, for example.
|
84
84
|
# [angle] A rotation, in degrees, to be applied to the image, relative to
|
85
85
|
# its center.
|
86
|
-
|
86
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
87
|
+
# will be drawn on top of the ones with smaller z-orders.
|
88
|
+
def draw map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0
|
87
89
|
color = (alpha << 24) | color
|
88
90
|
if map
|
89
91
|
if angle
|
90
|
-
@img[@img_index].draw_rot @x.round - map.cam.x, @y.round - map.cam.y,
|
92
|
+
@img[@img_index].draw_rot @x.round - map.cam.x, @y.round - map.cam.y, z_index, angle, 0.5, 0.5, scale_x, scale_y, color
|
91
93
|
else
|
92
|
-
@img[@img_index].draw @x.round - map.cam.x, @y.round - map.cam.y,
|
94
|
+
@img[@img_index].draw @x.round - map.cam.x, @y.round - map.cam.y, z_index, scale_x, scale_y, color
|
93
95
|
end
|
94
96
|
elsif angle
|
95
|
-
@img[@img_index].draw_rot @x.round, @y.round,
|
97
|
+
@img[@img_index].draw_rot @x.round, @y.round, z_index, angle, 0.5, 0.5, scale_x, scale_y, color
|
96
98
|
else
|
97
|
-
@img[@img_index].draw @x.round, @y.round,
|
99
|
+
@img[@img_index].draw @x.round, @y.round, z_index, scale_x, scale_y, color
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
@@ -124,7 +126,9 @@ module AGL
|
|
124
126
|
# image is not a spritesheet.
|
125
127
|
# [sprite_rows] The number of rows in the spritesheet. Use +nil+ if the
|
126
128
|
# image is not a spritesheet.
|
127
|
-
|
129
|
+
# [mass] The mass of the object. Details on how it is used can be found
|
130
|
+
# in the Movement module.
|
131
|
+
def initialize x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, mass = 1.0
|
128
132
|
super x, y, img, sprite_cols, sprite_rows
|
129
133
|
@w = w; @h = h
|
130
134
|
@img_gap =
|
@@ -133,6 +137,7 @@ module AGL
|
|
133
137
|
else
|
134
138
|
img_gap
|
135
139
|
end
|
140
|
+
@mass = mass
|
136
141
|
@speed = Vector.new 0, 0
|
137
142
|
@min_speed = Vector.new 0.01, 0.01
|
138
143
|
@max_speed = Vector.new 15, 15
|
@@ -172,20 +177,22 @@ module AGL
|
|
172
177
|
# will be darkened, for example.
|
173
178
|
# [angle] A rotation, in degrees, to be applied to the image, relative to
|
174
179
|
# its center.
|
175
|
-
|
180
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
181
|
+
# will be drawn on top of the ones with smaller z-orders.
|
182
|
+
def draw map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0
|
176
183
|
color = (alpha << 24) | color
|
177
184
|
if map
|
178
185
|
if angle
|
179
186
|
@img[@img_index].draw_rot @x.round + @img_gap.x - map.cam.x,
|
180
187
|
@y.round + @img_gap.y - map.cam.y,
|
181
|
-
|
188
|
+
z_index, angle, 0.5, 0.5, scale_x, scale_y, color
|
182
189
|
else
|
183
|
-
@img[@img_index].draw @x.round + @img_gap.x - map.cam.x, @y.round + @img_gap.y - map.cam.y,
|
190
|
+
@img[@img_index].draw @x.round + @img_gap.x - map.cam.x, @y.round + @img_gap.y - map.cam.y, z_index, scale_x, scale_y, color
|
184
191
|
end
|
185
192
|
elsif angle
|
186
|
-
@img[@img_index].draw_rot @x.round + @img_gap.x, @y.round + @img_gap.y,
|
193
|
+
@img[@img_index].draw_rot @x.round + @img_gap.x, @y.round + @img_gap.y, z_index, angle, 0.5, 0.5, scale_x, scale_y, color
|
187
194
|
else
|
188
|
-
@img[@img_index].draw @x.round + @img_gap.x, @y.round + @img_gap.y,
|
195
|
+
@img[@img_index].draw @x.round + @img_gap.x, @y.round + @img_gap.y, z_index, scale_x, scale_y, color
|
189
196
|
end
|
190
197
|
end
|
191
198
|
end
|
@@ -245,7 +252,7 @@ module AGL
|
|
245
252
|
end
|
246
253
|
end
|
247
254
|
|
248
|
-
def draw map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil
|
255
|
+
def draw map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0
|
249
256
|
super unless @dead
|
250
257
|
end
|
251
258
|
end
|
data/lib/minigl/movement.rb
CHANGED
@@ -48,6 +48,24 @@ module AGL
|
|
48
48
|
# the y axis. You must provide instances of this class (or derived classes)
|
49
49
|
# to the +ramps+ array parameter of the +move+ method.
|
50
50
|
class Ramp
|
51
|
+
# The x-coordinate of the top left corner of a rectangle that completely
|
52
|
+
# (and precisely) encloses the ramp (thought of as a right triangle).
|
53
|
+
attr_reader :x
|
54
|
+
|
55
|
+
# The y-coordinate of the top left corner of the rectangle described in
|
56
|
+
# the +x+ attribute.
|
57
|
+
attr_reader :y
|
58
|
+
|
59
|
+
# The width of the ramp.
|
60
|
+
attr_reader :w
|
61
|
+
|
62
|
+
# The height of the ramp.
|
63
|
+
attr_reader :h
|
64
|
+
|
65
|
+
# Whether the height of the ramp increases from left to right (decreases
|
66
|
+
# from left to right when +false+).
|
67
|
+
attr_reader :left
|
68
|
+
|
51
69
|
# Creates a new ramp.
|
52
70
|
#
|
53
71
|
# Parameters:
|
@@ -133,6 +151,12 @@ module AGL
|
|
133
151
|
# rectangular bounding boxes), including a method to behave as an elevator,
|
134
152
|
# affecting other objects' positions as it moves.
|
135
153
|
module Movement
|
154
|
+
# The mass of the object, in arbitrary units. The default value for
|
155
|
+
# GameObject instances, for example, is 1. The larger the mass (i.e., the
|
156
|
+
# heavier the object), the more intense the forces applied to the object
|
157
|
+
# have to be in order to move it.
|
158
|
+
attr_reader :mass
|
159
|
+
|
136
160
|
# A Vector with the current speed of the object (x: horizontal component,
|
137
161
|
# y: vertical component).
|
138
162
|
attr_reader :speed
|
@@ -193,12 +217,12 @@ module AGL
|
|
193
217
|
forces.x += Game.gravity.x; forces.y += Game.gravity.y
|
194
218
|
forces.x += @stored_forces.x; forces.y += @stored_forces.y
|
195
219
|
@stored_forces.x = @stored_forces.y = 0
|
196
|
-
|
220
|
+
|
197
221
|
# check_contact obst, ramps
|
198
222
|
forces.x = 0 if (forces.x < 0 and @left) or (forces.x > 0 and @right)
|
199
223
|
forces.y = 0 if (forces.y < 0 and @top) or (forces.y > 0 and @bottom)
|
200
|
-
|
201
|
-
@speed.x += forces.x; @speed.y += forces.y
|
224
|
+
|
225
|
+
@speed.x += forces.x / @mass; @speed.y += forces.y / @mass
|
202
226
|
@speed.x = 0 if @speed.x.abs < @min_speed.x
|
203
227
|
@speed.y = 0 if @speed.y.abs < @min_speed.y
|
204
228
|
@speed.x = (@speed.x <=> 0) * @max_speed.x if @speed.x.abs > @max_speed.x
|
data/lib/minigl/text.rb
CHANGED
@@ -29,7 +29,9 @@ module AGL
|
|
29
29
|
# [color] The color of the text, in hexadecimal RRGGBB format.
|
30
30
|
# [alpha] The opacity of the text. Valid values vary from 0 (fully
|
31
31
|
# transparent) to 255 (fully opaque).
|
32
|
-
|
32
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
33
|
+
# will be drawn on top of the ones with smaller z-orders.
|
34
|
+
def write_line text, x, y, mode = :left, color = 0, alpha = 0xff, z_index = 0
|
33
35
|
color = (alpha << 24) | color
|
34
36
|
rel =
|
35
37
|
case mode
|
@@ -38,7 +40,7 @@ module AGL
|
|
38
40
|
when :right then 1
|
39
41
|
else 0
|
40
42
|
end
|
41
|
-
@font.draw_rel text, x, y,
|
43
|
+
@font.draw_rel text, x, y, z_index, rel, 0, 1, 1, color
|
42
44
|
end
|
43
45
|
|
44
46
|
# Draws text, breaking lines when needed and when explicitly caused by the
|
@@ -58,11 +60,13 @@ module AGL
|
|
58
60
|
# [color] The color of the text, in hexadecimal RRGGBB format.
|
59
61
|
# [alpha] The opacity of the text. Valid values vary from 0 (fully
|
60
62
|
# transparent) to 255 (fully opaque).
|
61
|
-
|
63
|
+
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
64
|
+
# will be drawn on top of the ones with smaller z-orders.
|
65
|
+
def write_breaking text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0
|
62
66
|
color = (alpha << 24) | color
|
63
67
|
text.split("\n").each do |p|
|
64
68
|
if mode == :justified
|
65
|
-
y = write_paragraph_justified p, x, y, width, color
|
69
|
+
y = write_paragraph_justified p, x, y, width, color, z_index
|
66
70
|
else
|
67
71
|
rel =
|
68
72
|
case mode
|
@@ -71,20 +75,20 @@ module AGL
|
|
71
75
|
when :right then 1
|
72
76
|
else 0
|
73
77
|
end
|
74
|
-
y = write_paragraph p, x, y, width, rel, color
|
78
|
+
y = write_paragraph p, x, y, width, rel, color, z_index
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
83
|
private
|
80
84
|
|
81
|
-
def write_paragraph text, x, y, width, rel, color
|
85
|
+
def write_paragraph text, x, y, width, rel, color, z_index
|
82
86
|
line = ""
|
83
87
|
line_width = 0
|
84
88
|
text.split(' ').each do |word|
|
85
89
|
w = @font.text_width word
|
86
90
|
if line_width + w > width
|
87
|
-
@font.draw_rel line.chop, x, y,
|
91
|
+
@font.draw_rel line.chop, x, y, z_index, rel, 0, 1, 1, color
|
88
92
|
line = ""
|
89
93
|
line_width = 0
|
90
94
|
y += @font.height + @line_spacing
|
@@ -92,11 +96,11 @@ module AGL
|
|
92
96
|
line += "#{word} "
|
93
97
|
line_width += @font.text_width "#{word} "
|
94
98
|
end
|
95
|
-
@font.draw_rel line.chop, x, y,
|
99
|
+
@font.draw_rel line.chop, x, y, z_index, rel, 0, 1, 1, color if not line.empty?
|
96
100
|
y + @font.height + @line_spacing
|
97
101
|
end
|
98
102
|
|
99
|
-
def write_paragraph_justified text, x, y, width, color
|
103
|
+
def write_paragraph_justified text, x, y, width, color, z_index
|
100
104
|
space_width = @font.text_width " "
|
101
105
|
spaces = [[]]
|
102
106
|
line_index = 0
|
@@ -127,7 +131,7 @@ module AGL
|
|
127
131
|
spaces.each do |line|
|
128
132
|
new_x = x
|
129
133
|
line.each do |s|
|
130
|
-
@font.draw words[index], new_x, y,
|
134
|
+
@font.draw words[index], new_x, y, z_index, 1, 1, color
|
131
135
|
new_x += @font.text_width(words[index]) + s
|
132
136
|
index += 1
|
133
137
|
end
|
data/test/game.rb
CHANGED
@@ -13,7 +13,7 @@ class MyGame < Gosu::Window
|
|
13
13
|
@writer = TextHelper.new @font, 5
|
14
14
|
@btn = Button.new(10, 560, @font, "Test", :btn, 0x008000, 0x808080, 0, 0, 0, 0, 0, "friends") { |x| puts "hello #{x}" }
|
15
15
|
@btn.enabled = false
|
16
|
-
@chk = ToggleButton.new(
|
16
|
+
@chk = ToggleButton.new(740, 300, @font, "Click me", :check, false, 0xffffff, 0x808080, false, 36, 5, 0, 0, "friends") { |c, x|
|
17
17
|
puts "hello #{x}, checked: #{c}"
|
18
18
|
}
|
19
19
|
@txt = TextField.new(10, 520, @font, :text, nil, nil, 15, 5, 16, false, "", nil, 0, 0, 0x0000ff, "test") { |t, x| puts "field #{x}, text: #{t}" }
|
@@ -49,12 +49,12 @@ class MyGame < Gosu::Window
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def draw
|
52
|
-
@obj1.draw nil, 1, 1,
|
52
|
+
@obj1.draw nil, 1, 1, 255, 0x33ff33, 30, 1
|
53
53
|
@obj2.draw nil, 0.6, 1.4, 0x99
|
54
54
|
@writer.write_breaking "Testing multiple line text.\nThis should draw text "\
|
55
55
|
"across multiple lines, respecting a limit width. "\
|
56
56
|
"Furthermore, the text must be right-aligned.",
|
57
|
-
780, 300, 300, :right,
|
57
|
+
780, 300, 300, :right, 0xff0000, 255, 1
|
58
58
|
|
59
59
|
@btn.draw 0xcc
|
60
60
|
@chk.draw
|
data/test/movement_tests.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minigl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor David Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|