minigl 2.3.5 → 2.3.6
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 +2 -2
- data/lib/minigl/movement.rb +33 -29
- data/test/mov_game.rb +10 -4
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8b9de89a3372e81cfdef102808b9bbaec3fbd88a930c95cd5af2f946cb744d
|
4
|
+
data.tar.gz: d4fd66ee8e177e80fcbbe14808e4a8518a526fc6cec47d41adfc032da881750c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c966227f4b6a7d020c5e07c601fc18d8ea6603f07f6d661bc92127ae1335b02118e71ed997c2f25fd1c9089ae0e4730d61d0395a82ef0c2e495025b25fd019c3
|
7
|
+
data.tar.gz: e603e887d2c595c61e16bdeee8fd1b928414cf895caa7f98dd69b2aed0cf7bf2eb2dd0d115a460b07797d19ce3dccfeafc825151935012c62bc94671fdd90f2d
|
data/README.md
CHANGED
@@ -29,9 +29,9 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
29
29
|
* The [wiki](https://github.com/victords/minigl/wiki) is a work in progress with tutorials and examples.
|
30
30
|
* Test package and examples aren't complete!
|
31
31
|
|
32
|
-
## Version 2.3.
|
32
|
+
## Version 2.3.6
|
33
33
|
|
34
|
-
*
|
34
|
+
* Added inverted ramps (for sloped ceilings, still has some issues).
|
35
35
|
|
36
36
|
## Contributing
|
37
37
|
|
data/lib/minigl/movement.rb
CHANGED
@@ -66,6 +66,10 @@ module MiniGL
|
|
66
66
|
# from left to right when +false+).
|
67
67
|
attr_reader :left
|
68
68
|
|
69
|
+
# Whether the ramp is vertically inverted, i.e., the face that is parallel
|
70
|
+
# to the x-axis faces up and the sloped face faces down.
|
71
|
+
attr_reader :inverted
|
72
|
+
|
69
73
|
attr_reader :ratio # :nodoc:
|
70
74
|
attr_reader :factor # :nodoc:
|
71
75
|
|
@@ -85,12 +89,16 @@ module MiniGL
|
|
85
89
|
# highest).
|
86
90
|
# [left] Whether the height of the ramp increases from left to right. Use
|
87
91
|
# +false+ for a ramp that goes down from left to right.
|
88
|
-
|
92
|
+
# [inverted] Whether the ramp is vertically inverted, i.e., the face that
|
93
|
+
# is parallel to the x-axis faces up and the sloped face faces
|
94
|
+
# down.
|
95
|
+
def initialize(x, y, w, h, left, inverted = false)
|
89
96
|
@x = x
|
90
97
|
@y = y
|
91
98
|
@w = w
|
92
99
|
@h = h
|
93
100
|
@left = left
|
101
|
+
@inverted = inverted
|
94
102
|
@ratio = @h.to_f / @w
|
95
103
|
@factor = @w / Math.sqrt(@w**2 + @h**2)
|
96
104
|
end
|
@@ -101,6 +109,7 @@ module MiniGL
|
|
101
109
|
# [obj] The object to check contact with. It must have the +x+, +y+, +w+
|
102
110
|
# and +h+ accessible attributes determining its bounding box.
|
103
111
|
def contact?(obj)
|
112
|
+
return false if @inverted
|
104
113
|
obj.x + obj.w > @x && obj.x < @x + @w && obj.x.round(6) == get_x(obj).round(6) && obj.y.round(6) == get_y(obj).round(6)
|
105
114
|
end
|
106
115
|
|
@@ -111,44 +120,44 @@ module MiniGL
|
|
111
120
|
# [obj] The object to check intersection with. It must have the +x+, +y+,
|
112
121
|
# +w+ and +h+ accessible attributes determining its bounding box.
|
113
122
|
def intersect?(obj)
|
114
|
-
obj.x + obj.w > @x && obj.x < @x + @w &&
|
123
|
+
obj.x + obj.w > @x && obj.x < @x + @w &&
|
124
|
+
(@inverted ? obj.y < get_y(obj) && obj.y + obj.h > @y : obj.y > get_y(obj) && obj.y < @y + @h)
|
115
125
|
end
|
116
126
|
|
117
127
|
# :nodoc:
|
118
128
|
def check_can_collide(m)
|
119
|
-
y = get_y(m) + m.h
|
129
|
+
y = get_y(m) + (@inverted ? 0 : m.h)
|
120
130
|
@can_collide = m.x + m.w > @x && @x + @w > m.x && m.y < y && m.y + m.h > y
|
121
131
|
end
|
122
132
|
|
123
133
|
def check_intersection(obj)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
obj.y = get_y obj
|
133
|
-
if counter && obj.bottom != self
|
134
|
-
obj.speed.x *= @factor
|
135
|
-
end
|
136
|
-
obj.speed.y = 0
|
134
|
+
return unless @can_collide && intersect?(obj)
|
135
|
+
|
136
|
+
counter = @left && obj.prev_speed.x > 0 || !@left && obj.prev_speed.x < 0
|
137
|
+
if counter && (@inverted ? obj.prev_speed.y < 0 : obj.prev_speed.y > 0)
|
138
|
+
dx = get_x(obj) - obj.x
|
139
|
+
s = (obj.prev_speed.y.to_f / obj.prev_speed.x).abs
|
140
|
+
dx /= s + @ratio
|
141
|
+
obj.x += dx
|
137
142
|
end
|
143
|
+
if counter && obj.bottom != self
|
144
|
+
obj.speed.x *= @factor
|
145
|
+
end
|
146
|
+
|
147
|
+
obj.speed.y = 0
|
148
|
+
obj.y = get_y(obj)
|
138
149
|
end
|
139
150
|
|
140
151
|
def get_x(obj)
|
141
|
-
return obj.x if @left && obj.x + obj.w > @x + @w
|
142
|
-
|
143
|
-
|
144
|
-
@x + (1.0 * (obj.y + obj.h - @y) * @w / @h)
|
152
|
+
return obj.x if @left && obj.x + obj.w > @x + @w || !@left && obj.x < @x
|
153
|
+
offset = (@inverted ? obj.y - @y : @y + @h - obj.y - obj.h).to_f * @w / @h
|
154
|
+
@left ? @x + offset - obj.w : @x + @w - offset
|
145
155
|
end
|
146
156
|
|
147
157
|
def get_y(obj)
|
148
|
-
return @y -
|
149
|
-
|
150
|
-
|
151
|
-
@y + (1.0 * (obj.x - @x) * @h / @w) - obj.h
|
158
|
+
return @y + (@inverted ? @h : -obj.h) if @left && obj.x + obj.w > @x + @w || !@left && obj.x < @x
|
159
|
+
offset = (@left ? @x + @w - obj.x - obj.w : obj.x - @x).to_f * @h / @w
|
160
|
+
@inverted ? @y + @h - offset : @y + offset - obj.h
|
152
161
|
end
|
153
162
|
end
|
154
163
|
|
@@ -340,11 +349,6 @@ module MiniGL
|
|
340
349
|
@x += @speed.x
|
341
350
|
@y += @speed.y
|
342
351
|
|
343
|
-
# Keeping contact with ramp
|
344
|
-
# if @speed.y == 0 and @speed.x.abs <= G.ramp_contact_threshold and @bottom.is_a? Ramp
|
345
|
-
# @y = @bottom.get_y(self)
|
346
|
-
# puts 'aqui'
|
347
|
-
# end
|
348
352
|
ramps.each do |r|
|
349
353
|
r.check_intersection self
|
350
354
|
end
|
data/test/mov_game.rb
CHANGED
@@ -13,7 +13,7 @@ class MyGame < GameWindow
|
|
13
13
|
Block.new(0, 600, 800, 1, false),
|
14
14
|
Block.new(-1, 0, 1, 600, false),
|
15
15
|
Block.new(800, 0, 1, 600, false),
|
16
|
-
Block.new(300, 430,
|
16
|
+
Block.new(300, 430, 250, 50),
|
17
17
|
# Block.new(375, 550, 50, 50, true),
|
18
18
|
# Block.new(150, 200, 20, 300, false),
|
19
19
|
# Block.new(220, 300, 100, 20, true),
|
@@ -26,6 +26,12 @@ class MyGame < GameWindow
|
|
26
26
|
Ramp.new(500, 500, 150, 100, true),
|
27
27
|
Ramp.new(650, 300, 150, 200, true),
|
28
28
|
Ramp.new(650, 500, 150, 100, true),
|
29
|
+
Ramp.new(0, 100, 100, 100, false, true),
|
30
|
+
Ramp.new(100, 0, 150, 100, false, true),
|
31
|
+
Ramp.new(700, 100, 100, 100, true, true),
|
32
|
+
Ramp.new(550, 0, 150, 100, true, true),
|
33
|
+
# Ramp.new(250, 250, 75, 75, false, true),
|
34
|
+
Ramp.new(525, 250, 75, 200, true, true),
|
29
35
|
]
|
30
36
|
|
31
37
|
# @cycle = [Vector.new(100, 530), Vector.new(650, 500)]
|
@@ -67,9 +73,9 @@ class MyGame < GameWindow
|
|
67
73
|
o.x, o.y + o.h, 0xffffffff, 0
|
68
74
|
end
|
69
75
|
@ramps.each do |r|
|
70
|
-
draw_triangle r.left ? r.x + r.w : r.x, r.y, 0xffffffff,
|
71
|
-
r.x + r.w, r.y + r.h, 0xffffffff,
|
72
|
-
r.x, r.y + r.h, 0xffffffff, 0
|
76
|
+
draw_triangle r.left ? r.x + r.w : r.x, r.inverted ? r.y + r.h : r.y, 0xffffffff,
|
77
|
+
r.x + r.w, r.inverted ? r.y : r.y + r.h, 0xffffffff,
|
78
|
+
r.x, r.inverted ? r.y : r.y + r.h, 0xffffffff, 0
|
73
79
|
end
|
74
80
|
end
|
75
81
|
end
|
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: 2.3.
|
4
|
+
version: 2.3.6
|
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: 2021-02
|
11
|
+
date: 2021-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -99,42 +99,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.2.15
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: MiniGL
|
106
106
|
test_files:
|
107
|
-
- test/
|
108
|
-
- test/
|
107
|
+
- test/game.rb
|
108
|
+
- test/game_object_tests.rb
|
109
|
+
- test/iso_game.rb
|
110
|
+
- test/map_tests.rb
|
109
111
|
- test/mov_game.rb
|
110
112
|
- test/movement_tests.rb
|
111
|
-
- test/
|
112
|
-
- test/
|
113
|
-
- test/game_object_tests.rb
|
114
|
-
- test/game.rb
|
113
|
+
- test/res_tests.rb
|
114
|
+
- test/vector_tests.rb
|
115
115
|
- test/test.png
|
116
|
-
- test/data/tileset/tileset1.png
|
117
116
|
- test/data/font/font1.ttf
|
118
|
-
- test/data/
|
119
|
-
- test/data/img/
|
120
|
-
- test/data/img/square.svg
|
121
|
-
- test/data/img/tile2.svg
|
117
|
+
- test/data/img/barbg.png
|
118
|
+
- test/data/img/barbg.svg
|
122
119
|
- test/data/img/barfg.png
|
123
|
-
- test/data/img/
|
124
|
-
- test/data/img/
|
125
|
-
- test/data/img/
|
126
|
-
- test/data/img/text.png
|
127
|
-
- test/data/img/square2.svg
|
120
|
+
- test/data/img/barfg.svg
|
121
|
+
- test/data/img/btn.png
|
122
|
+
- test/data/img/check.png
|
128
123
|
- test/data/img/image.png
|
129
124
|
- test/data/img/img1.png
|
130
|
-
- test/data/img/square2.png
|
131
|
-
- test/data/img/barbg.svg
|
132
|
-
- test/data/img/barfg.svg
|
133
|
-
- test/data/img/tile1b.png
|
134
|
-
- test/data/img/barbg.png
|
135
125
|
- test/data/img/square.png
|
136
|
-
- test/data/img/
|
126
|
+
- test/data/img/square.svg
|
127
|
+
- test/data/img/square2.png
|
128
|
+
- test/data/img/square2.svg
|
137
129
|
- test/data/img/square3.png
|
138
|
-
- test/data/img/
|
130
|
+
- test/data/img/square3.svg
|
131
|
+
- test/data/img/text.png
|
139
132
|
- test/data/img/tile1.png
|
133
|
+
- test/data/img/tile1.svg
|
134
|
+
- test/data/img/tile1b.png
|
135
|
+
- test/data/img/tile2.png
|
136
|
+
- test/data/img/tile2.svg
|
137
|
+
- test/data/img/tile2b.png
|
138
|
+
- test/data/sound/1.wav
|
139
|
+
- test/data/tileset/tileset1.png
|
140
140
|
- test/data/img/sub/image.png
|