minigl 2.4.0 → 2.4.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 +9 -4
- data/lib/minigl/forms.rb +18 -4
- data/lib/minigl/game_object.rb +18 -7
- data/lib/minigl/movement.rb +85 -38
- data/test/collision.rb +49 -0
- data/test/game.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46eaeb260b03c9bcfbac716d7568b01c081d66760d71dc540ca9046050f7d89d
|
4
|
+
data.tar.gz: 3de3cd79bd21324af047f1705d641374e92c986ec0f02badf0a5fd9206f228e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33675d555bd833c359f548bff9c16ef95da819ecc084ecbc657c60016d5e3d18255cd19da03252b212e53bb8600a5a0c4c9f4ab4893261377a7f4f20a03d991b
|
7
|
+
data.tar.gz: 3f9ed35d874c81bca4544a42c7f6106c0f3b26ba69bf5bfcba59f201297588be32aa6a2f697f2ea4ffde846e8f46fd2d42c5bc68142ec925cf9f8cd6bc5542cf
|
data/README.md
CHANGED
@@ -16,9 +16,14 @@ to victordavidsantos@gmail.com.
|
|
16
16
|
|
17
17
|
## Made with MiniGL
|
18
18
|
|
19
|
-
Below are
|
19
|
+
Below are some games built with MiniGL, all available for free download and also open source.
|
20
20
|
* [Super Bombinhas](https://github.com/victords/super-bombinhas)
|
21
21
|
* [ConnecMan](https://github.com/victords/connecman)
|
22
|
+
* [SokoAdventure](https://github.com/victords/sokoadventure)
|
23
|
+
* [Spheres](https://github.com/victords/spheres)
|
24
|
+
* [Willy the droid](https://github.com/gavr-games/willy_the_droid)
|
25
|
+
|
26
|
+
Download Super Bombinhas, ConnecMan, SokoAdventure and Spheres in my [itch.io page](https://victords.itch.io).
|
22
27
|
|
23
28
|
If you create a project using MiniGL, feel free to open a PR to include it in this list.
|
24
29
|
|
@@ -37,11 +42,11 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
37
42
|
* The [wiki](https://github.com/victords/minigl/wiki) is a work in progress with tutorials and examples.
|
38
43
|
* Test package and examples aren't complete!
|
39
44
|
|
40
|
-
## Version 2.4.
|
45
|
+
## Version 2.4.3
|
41
46
|
|
42
|
-
*
|
47
|
+
* Fixed a collision checking bug in `Movement#move`.
|
43
48
|
|
44
49
|
## Contributing
|
45
50
|
|
46
51
|
Contributions are very welcome. Feel free to fork and send pull requests.
|
47
|
-
Also, you can support my work by
|
52
|
+
Also, you can support my work by purchasing any of my games on [itch.io](https://victords.itch.io) or [Super Bombinhas on Steam](https://store.steampowered.com/app/1553840).
|
data/lib/minigl/forms.rb
CHANGED
@@ -365,7 +365,7 @@ module MiniGL
|
|
365
365
|
elsif mouse_rel
|
366
366
|
@img_index = 1
|
367
367
|
@state = :over
|
368
|
-
|
368
|
+
enqueue_action
|
369
369
|
else
|
370
370
|
@img_index = 2
|
371
371
|
end
|
@@ -444,6 +444,10 @@ module MiniGL
|
|
444
444
|
|
445
445
|
private
|
446
446
|
|
447
|
+
def enqueue_action
|
448
|
+
Mouse.add_click(@z_index || 0, method(:perform_action))
|
449
|
+
end
|
450
|
+
|
447
451
|
def perform_action
|
448
452
|
@action.call(@params) if @action
|
449
453
|
end
|
@@ -524,7 +528,7 @@ module MiniGL
|
|
524
528
|
|
525
529
|
super
|
526
530
|
@img_index *= 2
|
527
|
-
@img_index += 1 if @checked
|
531
|
+
@img_index += 1 if @checked && !@toggling || !@checked && @toggling
|
528
532
|
end
|
529
533
|
|
530
534
|
# Sets the state of the button to the value given.
|
@@ -544,8 +548,14 @@ module MiniGL
|
|
544
548
|
|
545
549
|
private
|
546
550
|
|
551
|
+
def enqueue_action
|
552
|
+
super
|
553
|
+
@toggling = true
|
554
|
+
end
|
555
|
+
|
547
556
|
def perform_action
|
548
557
|
@checked = !@checked
|
558
|
+
@toggling = false
|
549
559
|
@action.call(@checked, @params) if @action
|
550
560
|
end
|
551
561
|
end
|
@@ -720,7 +730,7 @@ module MiniGL
|
|
720
730
|
end
|
721
731
|
set_cursor_visible
|
722
732
|
elsif Mouse.button_pressed? :left
|
723
|
-
Mouse.add_click(@z_index || 0, method(:
|
733
|
+
Mouse.add_click(@z_index || 0, method(:focus_and_set_anchor))
|
724
734
|
elsif Mouse.button_down? :left
|
725
735
|
if @anchor1 and not @double_clicked
|
726
736
|
set_node_by_mouse
|
@@ -912,7 +922,6 @@ module MiniGL
|
|
912
922
|
def focus
|
913
923
|
@focused = true
|
914
924
|
set_node_by_mouse
|
915
|
-
@anchor1 = @cur_node
|
916
925
|
@anchor2 = nil
|
917
926
|
@double_clicked = false
|
918
927
|
set_cursor_visible
|
@@ -996,6 +1005,11 @@ module MiniGL
|
|
996
1005
|
|
997
1006
|
private
|
998
1007
|
|
1008
|
+
def focus_and_set_anchor
|
1009
|
+
focus
|
1010
|
+
@anchor1 = @cur_node
|
1011
|
+
end
|
1012
|
+
|
999
1013
|
def set_cursor_visible
|
1000
1014
|
@cursor_visible = true
|
1001
1015
|
@cursor_timer = 0
|
data/lib/minigl/game_object.rb
CHANGED
@@ -3,6 +3,9 @@ require_relative 'movement'
|
|
3
3
|
module MiniGL
|
4
4
|
# This class represents an (optionally animated) image inside the game screen.
|
5
5
|
class Sprite
|
6
|
+
# The list of images of this sprite (i.e. the spritesheet).
|
7
|
+
attr_reader :img
|
8
|
+
|
6
9
|
# The index of the current sprite in the spritesheet being drawn.
|
7
10
|
attr_reader :img_index
|
8
11
|
|
@@ -268,18 +271,20 @@ module MiniGL
|
|
268
271
|
end
|
269
272
|
|
270
273
|
color = (alpha << 24) | color
|
274
|
+
img_gap_scale_x = scale_image_gap? ? scale_x : 1
|
275
|
+
img_gap_scale_y = scale_image_gap? ? scale_y : 1
|
271
276
|
if angle
|
272
277
|
center_x = @x + @w * 0.5
|
273
278
|
center_y = @y + @h * 0.5
|
274
|
-
o_x = center_x - @x - @img_gap.x
|
275
|
-
o_y = center_y - @y - @img_gap.y
|
276
|
-
@img[@img_index].draw_rot @x + (flip == :horiz ? -1 : 1) * (@img_gap.x + o_x) - (map ? map.cam.x : 0),
|
277
|
-
@y + (flip == :vert ? -1 : 1) * (@img_gap.y + o_y) - (map ? map.cam.y : 0),
|
279
|
+
o_x = center_x - @x - @img_gap.x * img_gap_scale_x
|
280
|
+
o_y = center_y - @y - @img_gap.y * img_gap_scale_y
|
281
|
+
@img[@img_index].draw_rot @x + (flip == :horiz ? -1 : 1) * (@img_gap.x * img_gap_scale_x + o_x) - (map ? map.cam.x : 0),
|
282
|
+
@y + (flip == :vert ? -1 : 1) * (@img_gap.y * img_gap_scale_y + o_y) - (map ? map.cam.y : 0),
|
278
283
|
z_index, angle, o_x.to_f / (@img[0].width * scale_x), o_y.to_f / (@img[0].height * scale_y),
|
279
284
|
(flip == :horiz ? -scale_x : scale_x), (flip == :vert ? -scale_y : scale_y), color
|
280
285
|
else
|
281
|
-
x = @x + (flip == :horiz ? -1 : 1) * @img_gap.x - (map ? map.cam.x : 0) + (flip == :horiz ? @w : 0)
|
282
|
-
y = @y + (flip == :vert ? -1 : 1) * @img_gap.y - (map ? map.cam.y : 0) + (flip == :vert ? @h : 0)
|
286
|
+
x = @x + (flip == :horiz ? -1 : 1) * @img_gap.x * img_gap_scale_x - (map ? map.cam.x : 0) + (flip == :horiz ? @w : 0)
|
287
|
+
y = @y + (flip == :vert ? -1 : 1) * @img_gap.y * img_gap_scale_y - (map ? map.cam.y : 0) + (flip == :vert ? @h : 0)
|
283
288
|
@img[@img_index].draw (round ? x.round : x), (round ? y.round : y),
|
284
289
|
z_index, (flip == :horiz ? -scale_x : scale_x),
|
285
290
|
(flip == :vert ? -scale_y : scale_y), color
|
@@ -294,6 +299,12 @@ module MiniGL
|
|
294
299
|
return Rectangle.new(0, 0, G.window.width, G.window.height).intersect? r if map.nil?
|
295
300
|
map.cam.intersect? r
|
296
301
|
end
|
302
|
+
|
303
|
+
# override this if you don't want the image_gap to be scaled when drawing
|
304
|
+
# the object scaled.
|
305
|
+
def scale_image_gap?
|
306
|
+
true
|
307
|
+
end
|
297
308
|
end
|
298
309
|
|
299
310
|
# Represents a visual effect, i.e., a graphic - usually animated - that shows
|
@@ -384,7 +395,7 @@ module MiniGL
|
|
384
395
|
@dead = true if @elapsed_time == @lifetime
|
385
396
|
end
|
386
397
|
|
387
|
-
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0)
|
398
|
+
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0, round = false)
|
388
399
|
super unless @dead
|
389
400
|
end
|
390
401
|
|
data/lib/minigl/movement.rb
CHANGED
@@ -40,6 +40,10 @@ module MiniGL
|
|
40
40
|
def bounds
|
41
41
|
Rectangle.new @x, @y, @w, @h
|
42
42
|
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
"Block(#{@x}, #{@y}, #{@w}, #{@h}#{@passable ? ", passable" : ''})"
|
46
|
+
end
|
43
47
|
end
|
44
48
|
|
45
49
|
# Represents a ramp, i.e., an inclined structure which allows walking over
|
@@ -301,48 +305,28 @@ module MiniGL
|
|
301
305
|
end
|
302
306
|
else
|
303
307
|
# Diagonal
|
304
|
-
x_aim = @x + @speed.x + (rt ? @w : 0); x_lim_def = x_aim
|
305
|
-
y_aim = @y + @speed.y + (dn ? @h : 0); y_lim_def = y_aim
|
308
|
+
x_aim = @x + @speed.x + (rt ? @w : 0); x_lim_def = [x_aim, nil]
|
309
|
+
y_aim = @y + @speed.y + (dn ? @h : 0); y_lim_def = [y_aim, nil]
|
306
310
|
coll_list.each do |c|
|
307
|
-
|
308
|
-
|
309
|
-
else; x_lim = c.x + c.w
|
310
|
-
end
|
311
|
-
if dn; y_lim = c.y
|
312
|
-
elsif c.passable; y_lim = y_aim
|
313
|
-
else; y_lim = c.y + c.h
|
314
|
-
end
|
311
|
+
find_limits(c, x_aim, y_aim, x_lim_def, y_lim_def, up, rt, dn, lf)
|
312
|
+
end
|
315
313
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
x_lim_def = x_lim if (rt && x_lim < x_lim_def) || (lf && x_lim > x_lim_def)
|
314
|
+
if x_lim_def[0] != x_aim && y_lim_def[0] != y_aim
|
315
|
+
x_time = (x_lim_def[0] - @x - (lf ? 0 : @w)).to_f / @speed.x
|
316
|
+
y_time = (y_lim_def[0] - @y - (up ? 0 : @h)).to_f / @speed.y
|
317
|
+
if x_time < y_time
|
318
|
+
stop_at_x(x_lim_def[0], lf)
|
319
|
+
move_bounds = Rectangle.new(@x, up ? @y + @speed.y : @y, @w, @h + @speed.y.abs)
|
320
|
+
stop_at_y(y_lim_def[0], up) if move_bounds.intersect?(y_lim_def[1].bounds)
|
324
321
|
else
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
# Will limit by x
|
329
|
-
x_lim_def = x_lim if (rt && x_lim < x_lim_def) || (lf && x_lim > x_lim_def)
|
330
|
-
elsif (dn && y_lim < y_lim_def) || (up && y_lim > y_lim_def)
|
331
|
-
y_lim_def = y_lim
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
if x_lim_def != x_aim
|
336
|
-
@speed.x = 0
|
337
|
-
if lf; @x = x_lim_def
|
338
|
-
else; @x = x_lim_def - @w
|
339
|
-
end
|
340
|
-
end
|
341
|
-
if y_lim_def != y_aim
|
342
|
-
@speed.y = 0
|
343
|
-
if up; @y = y_lim_def
|
344
|
-
else; @y = y_lim_def - @h
|
322
|
+
stop_at_y(y_lim_def[0], up)
|
323
|
+
move_bounds = Rectangle.new(lf ? @x + @speed.x : @x, @y, @w + @speed.x.abs, @h)
|
324
|
+
stop_at_x(x_lim_def[0], lf) if move_bounds.intersect?(x_lim_def[1].bounds)
|
345
325
|
end
|
326
|
+
elsif x_lim_def[0] != x_aim
|
327
|
+
stop_at_x(x_lim_def[0], lf)
|
328
|
+
elsif y_lim_def[0] != y_aim
|
329
|
+
stop_at_y(y_lim_def[0], up)
|
346
330
|
end
|
347
331
|
end
|
348
332
|
end
|
@@ -606,5 +590,68 @@ module MiniGL
|
|
606
590
|
end
|
607
591
|
limit
|
608
592
|
end
|
593
|
+
|
594
|
+
def find_limits(obj, x_aim, y_aim, x_lim_def, y_lim_def, up, rt, dn, lf)
|
595
|
+
x_lim =
|
596
|
+
if obj.passable
|
597
|
+
x_aim
|
598
|
+
elsif rt
|
599
|
+
obj.x
|
600
|
+
else
|
601
|
+
obj.x + obj.w
|
602
|
+
end
|
603
|
+
|
604
|
+
y_lim =
|
605
|
+
if dn
|
606
|
+
obj.y
|
607
|
+
elsif obj.passable
|
608
|
+
y_aim
|
609
|
+
else
|
610
|
+
obj.y + obj.h
|
611
|
+
end
|
612
|
+
|
613
|
+
x_v = x_lim_def[0]; y_v = y_lim_def[0]
|
614
|
+
if obj.passable
|
615
|
+
if dn && @y + @h <= y_lim && y_lim < y_v
|
616
|
+
y_lim_def[0] = y_lim
|
617
|
+
y_lim_def[1] = obj
|
618
|
+
end
|
619
|
+
elsif (rt && @x + @w > x_lim) || (lf && @x < x_lim)
|
620
|
+
# Can't limit by x, will limit by y
|
621
|
+
if (dn && y_lim < y_v) || (up && y_lim > y_v)
|
622
|
+
y_lim_def[0] = y_lim
|
623
|
+
y_lim_def[1] = obj
|
624
|
+
end
|
625
|
+
elsif (dn && @y + @h > y_lim) || (up && @y < y_lim)
|
626
|
+
# Can't limit by y, will limit by x
|
627
|
+
if (rt && x_lim < x_v) || (lf && x_lim > x_v)
|
628
|
+
x_lim_def[0] = x_lim
|
629
|
+
x_lim_def[1] = obj
|
630
|
+
end
|
631
|
+
else
|
632
|
+
x_time = (x_lim - @x - (lf ? 0 : @w)).to_f / @speed.x
|
633
|
+
y_time = (y_lim - @y - (up ? 0 : @h)).to_f / @speed.y
|
634
|
+
if x_time > y_time
|
635
|
+
# Will limit by x
|
636
|
+
if (rt && x_lim < x_v) || (lf && x_lim > x_v)
|
637
|
+
x_lim_def[0] = x_lim
|
638
|
+
x_lim_def[1] = obj
|
639
|
+
end
|
640
|
+
elsif (dn && y_lim < y_v) || (up && y_lim > y_v)
|
641
|
+
y_lim_def[0] = y_lim
|
642
|
+
y_lim_def[1] = obj
|
643
|
+
end
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
def stop_at_x(x, moving_left)
|
648
|
+
@speed.x = 0
|
649
|
+
@x = moving_left ? x : x - @w
|
650
|
+
end
|
651
|
+
|
652
|
+
def stop_at_y(y, moving_up)
|
653
|
+
@speed.y = 0
|
654
|
+
@y = moving_up ? y : y - @h
|
655
|
+
end
|
609
656
|
end
|
610
657
|
end
|
data/test/collision.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../lib/minigl'
|
2
|
+
|
3
|
+
include MiniGL
|
4
|
+
|
5
|
+
class CollisionTest < GameWindow
|
6
|
+
def initialize
|
7
|
+
super(300, 300, false)
|
8
|
+
|
9
|
+
@object = GameObject.new(0, 150, 50, 50, :img1)
|
10
|
+
@object.max_speed.x = @object.max_speed.y = 1000
|
11
|
+
@blocks = [
|
12
|
+
Block.new(0, 0, 100, 100),
|
13
|
+
Block.new(100, 0, 100, 100),
|
14
|
+
Block.new(200, 100, 100, 100),
|
15
|
+
Block.new(200, 200, 100, 100),
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
KB.update
|
21
|
+
|
22
|
+
forces = Vector.new
|
23
|
+
if KB.key_pressed?(Gosu::KB_Z)
|
24
|
+
@object.x = 0
|
25
|
+
@object.y = 150
|
26
|
+
end
|
27
|
+
forces = Vector.new(60, -100) if KB.key_pressed?(Gosu::KB_X)
|
28
|
+
if KB.key_pressed?(Gosu::KB_C)
|
29
|
+
@object.x = 100
|
30
|
+
@object.y = 250
|
31
|
+
end
|
32
|
+
forces = Vector.new(100, -60) if KB.key_pressed?(Gosu::KB_V)
|
33
|
+
if KB.key_pressed?(Gosu::KB_B)
|
34
|
+
@object.x = 100
|
35
|
+
@object.y = 150
|
36
|
+
end
|
37
|
+
|
38
|
+
@object.move(forces, @blocks, [], true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def draw
|
42
|
+
@blocks.each_with_index do |block, i|
|
43
|
+
draw_rect(block.x, block.y, block.w, block.h, i.even? ? 0xffffffff : 0xffcccccc)
|
44
|
+
end
|
45
|
+
draw_rect(@object.x, @object.y, @object.w, @object.h, 0xffffffff)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
CollisionTest.new.show
|
data/test/game.rb
CHANGED
@@ -6,7 +6,7 @@ class MyGame < GameWindow
|
|
6
6
|
super 800, 600, false
|
7
7
|
|
8
8
|
# @img = Res.img :img1
|
9
|
-
@obj1 = GameObject.new 75, 75,
|
9
|
+
@obj1 = GameObject.new 75, 75, 40, 40, :square3, Vector.new(-50, -50)
|
10
10
|
@obj2 = Sprite.new 400, 0, :img1
|
11
11
|
@obj3 = GameObject.new 4, 50, 24, 24, :check, Vector.new(-4, -4), 2, 4
|
12
12
|
@obj3.set_animation 1
|
@@ -137,7 +137,7 @@ class MyGame < GameWindow
|
|
137
137
|
clear 0xabcdef
|
138
138
|
|
139
139
|
# @img.draw_rot 400, 100, 0, @angle, 1, 1
|
140
|
-
@obj1.draw color: 0x33ff33, angle: (@angle == 0 ? nil : @angle), scale_x: 1.5
|
140
|
+
@obj1.draw color: 0x33ff33, angle: (@angle == 0 ? nil : @angle), scale_x: 1.5
|
141
141
|
@obj2.draw angle: (@angle == 0 ? nil : @angle), scale_x: 0.5, scale_y: 1.4
|
142
142
|
@obj3.draw flip: @flip
|
143
143
|
@obj4.draw round: true
|
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.4.
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/minigl/map.rb
|
48
48
|
- lib/minigl/movement.rb
|
49
49
|
- lib/minigl/text.rb
|
50
|
+
- test/collision.rb
|
50
51
|
- test/data/font/font1.ttf
|
51
52
|
- test/data/img/barbg.png
|
52
53
|
- test/data/img/barbg.svg
|
@@ -108,6 +109,7 @@ signing_key:
|
|
108
109
|
specification_version: 4
|
109
110
|
summary: MiniGL
|
110
111
|
test_files:
|
112
|
+
- test/collision.rb
|
111
113
|
- test/game.rb
|
112
114
|
- test/game_object_tests.rb
|
113
115
|
- test/iso_game.rb
|