minigl 2.3.2 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ac508ba7f8437fc38fe8fbb4f0bd9b82e95fcaecb629cd5fa9ed5e38f34058e
4
- data.tar.gz: c6feadf293623b39817281093e9cb0f92fe72935d698ff7b0bc24b8a8e3881e0
3
+ metadata.gz: db8b9de89a3372e81cfdef102808b9bbaec3fbd88a930c95cd5af2f946cb744d
4
+ data.tar.gz: d4fd66ee8e177e80fcbbe14808e4a8518a526fc6cec47d41adfc032da881750c
5
5
  SHA512:
6
- metadata.gz: 1f54a8f402998aae0f9db1cb40266d8a165a69b2d637ddd36b2190e66319a73fe49dcc20b88757abcfb68fd9c86a3f91889020634c71cd998836013bcb842ee9
7
- data.tar.gz: bdc777463aa6681d0cbd1e18dd2e02af34d84e4d59daf0ce51f71d9b7fe6cd97b671c1db7420274c436ff74a83fc3244c650ed984947ff0a4925842e6ad62211
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.2
32
+ ## Version 2.3.6
33
33
 
34
- * Added the `ignore_collision` option to `Movement#move_carrying`.
34
+ * Added inverted ramps (for sloped ceilings, still has some issues).
35
35
 
36
36
  ## Contributing
37
37
 
@@ -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
- def initialize(x, y, w, h, left)
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 && obj.y > get_y(obj) && obj.y <= @y + @h - obj.h
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
- if @can_collide and intersect? obj
125
- counter = @left && obj.prev_speed.x > 0 || !@left && obj.prev_speed.x < 0
126
- if obj.prev_speed.y > 0 && counter
127
- dx = get_x(obj) - obj.x
128
- s = (obj.prev_speed.y.to_f / obj.prev_speed.x).abs
129
- dx /= s + @ratio
130
- obj.x += dx
131
- end
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
- return @x + (1.0 * (@y + @h - obj.y - obj.h) * @w / @h) - obj.w if @left
143
- return obj.x if obj.x < @x
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 - obj.h if @left && obj.x + obj.w > @x + @w
149
- return @y + (1.0 * (@x + @w - obj.x - obj.w) * @h / @w) - obj.h if @left
150
- return @y - obj.h if obj.x < @x
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
@@ -513,6 +517,8 @@ module MiniGL
513
517
  unless @cycle_setup
514
518
  @cur_point = 0 if @cur_point.nil?
515
519
  if obstacles
520
+ obst_obstacles = [] if obst_obstacles.nil?
521
+ obst_ramps = [] if obst_ramps.nil?
516
522
  move_carrying points[@cur_point], speed, obstacles, obst_obstacles, obst_ramps
517
523
  else
518
524
  move_free points[@cur_point], speed
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, 50, 50),
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,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minigl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
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: 2020-08-08 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.11'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.11'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  description: A minimal 2D Game Library built on top of the Gosu gem.
28
34
  email: victordavidsantos@gmail.com
29
35
  executables: []
@@ -84,7 +90,7 @@ require_paths:
84
90
  - lib
85
91
  required_ruby_version: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - "~>"
93
+ - - ">="
88
94
  - !ruby/object:Gem::Version
89
95
  version: '2.0'
90
96
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -93,42 +99,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
99
  - !ruby/object:Gem::Version
94
100
  version: '0'
95
101
  requirements: []
96
- rubygems_version: 3.1.2
102
+ rubygems_version: 3.2.15
97
103
  signing_key:
98
104
  specification_version: 4
99
105
  summary: MiniGL
100
106
  test_files:
101
- - test/vector_tests.rb
102
- - test/res_tests.rb
107
+ - test/game.rb
108
+ - test/game_object_tests.rb
109
+ - test/iso_game.rb
110
+ - test/map_tests.rb
103
111
  - test/mov_game.rb
104
112
  - test/movement_tests.rb
105
- - test/map_tests.rb
106
- - test/iso_game.rb
107
- - test/game_object_tests.rb
108
- - test/game.rb
113
+ - test/res_tests.rb
114
+ - test/vector_tests.rb
109
115
  - test/test.png
110
- - test/data/tileset/tileset1.png
111
116
  - test/data/font/font1.ttf
112
- - test/data/sound/1.wav
113
- - test/data/img/check.png
114
- - test/data/img/square.svg
115
- - test/data/img/tile2.svg
117
+ - test/data/img/barbg.png
118
+ - test/data/img/barbg.svg
116
119
  - test/data/img/barfg.png
117
- - test/data/img/tile2.png
118
- - test/data/img/tile1.svg
119
- - test/data/img/square3.svg
120
- - test/data/img/text.png
121
- - test/data/img/square2.svg
120
+ - test/data/img/barfg.svg
121
+ - test/data/img/btn.png
122
+ - test/data/img/check.png
122
123
  - test/data/img/image.png
123
124
  - test/data/img/img1.png
124
- - test/data/img/square2.png
125
- - test/data/img/barbg.svg
126
- - test/data/img/barfg.svg
127
- - test/data/img/tile1b.png
128
- - test/data/img/barbg.png
129
125
  - test/data/img/square.png
130
- - test/data/img/btn.png
126
+ - test/data/img/square.svg
127
+ - test/data/img/square2.png
128
+ - test/data/img/square2.svg
131
129
  - test/data/img/square3.png
132
- - test/data/img/tile2b.png
130
+ - test/data/img/square3.svg
131
+ - test/data/img/text.png
133
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
134
140
  - test/data/img/sub/image.png