minigl 1.3.10 → 2.0.0
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 +15 -9
- data/lib/minigl/forms.rb +382 -30
- data/lib/minigl/game_object.rb +35 -10
- data/lib/minigl/global.rb +498 -383
- data/lib/minigl/map.rb +21 -21
- data/lib/minigl/movement.rb +100 -55
- data/lib/minigl/text.rb +37 -9
- data/test/data/img/barbg.png +0 -0
- data/test/data/img/barbg.svg +73 -0
- data/test/data/img/barfg.png +0 -0
- data/test/data/img/barfg.svg +106 -0
- data/test/data/img/barfgl.png +0 -0
- data/test/data/img/barfgl.svg +127 -0
- data/test/data/img/barfgr.png +0 -0
- data/test/data/img/barfgr.svg +135 -0
- data/test/data/img/square.png +0 -0
- data/test/data/img/square.svg +66 -0
- data/test/data/sound/1.wav +0 -0
- data/test/game.rb +49 -17
- data/test/game_object_tests.rb +35 -5
- data/test/iso_game.rb +2 -2
- data/test/map_tests.rb +1 -1
- data/test/mov_game.rb +72 -0
- data/test/movement_tests.rb +2 -3
- data/test/res_tests.rb +17 -3
- data/test/vector_tests.rb +1 -1
- metadata +26 -2
Binary file
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
3
|
+
|
4
|
+
<svg
|
5
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
6
|
+
xmlns:cc="http://creativecommons.org/ns#"
|
7
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
8
|
+
xmlns:svg="http://www.w3.org/2000/svg"
|
9
|
+
xmlns="http://www.w3.org/2000/svg"
|
10
|
+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
11
|
+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
12
|
+
width="50"
|
13
|
+
height="50"
|
14
|
+
id="svg2"
|
15
|
+
version="1.1"
|
16
|
+
inkscape:version="0.48.4 r9939"
|
17
|
+
sodipodi:docname="square.svg"
|
18
|
+
inkscape:export-filename="/home/victor/Projects/TCC/minigl/test/data/img/square.png"
|
19
|
+
inkscape:export-xdpi="90"
|
20
|
+
inkscape:export-ydpi="90">
|
21
|
+
<defs
|
22
|
+
id="defs4" />
|
23
|
+
<sodipodi:namedview
|
24
|
+
id="base"
|
25
|
+
pagecolor="#ffffff"
|
26
|
+
bordercolor="#666666"
|
27
|
+
borderopacity="1.0"
|
28
|
+
inkscape:pageopacity="0.0"
|
29
|
+
inkscape:pageshadow="2"
|
30
|
+
inkscape:zoom="11.68"
|
31
|
+
inkscape:cx="25"
|
32
|
+
inkscape:cy="25"
|
33
|
+
inkscape:document-units="px"
|
34
|
+
inkscape:current-layer="layer1"
|
35
|
+
showgrid="false"
|
36
|
+
inkscape:window-width="1364"
|
37
|
+
inkscape:window-height="718"
|
38
|
+
inkscape:window-x="0"
|
39
|
+
inkscape:window-y="0"
|
40
|
+
inkscape:window-maximized="1" />
|
41
|
+
<metadata
|
42
|
+
id="metadata7">
|
43
|
+
<rdf:RDF>
|
44
|
+
<cc:Work
|
45
|
+
rdf:about="">
|
46
|
+
<dc:format>image/svg+xml</dc:format>
|
47
|
+
<dc:type
|
48
|
+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
49
|
+
<dc:title></dc:title>
|
50
|
+
</cc:Work>
|
51
|
+
</rdf:RDF>
|
52
|
+
</metadata>
|
53
|
+
<g
|
54
|
+
inkscape:label="Layer 1"
|
55
|
+
inkscape:groupmode="layer"
|
56
|
+
id="layer1"
|
57
|
+
transform="translate(0,-1002.3622)">
|
58
|
+
<rect
|
59
|
+
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
60
|
+
id="rect3753"
|
61
|
+
width="50"
|
62
|
+
height="50"
|
63
|
+
x="0"
|
64
|
+
y="1002.3622" />
|
65
|
+
</g>
|
66
|
+
</svg>
|
Binary file
|
data/test/game.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
require_relative '../lib/minigl'
|
2
|
-
include
|
2
|
+
include MiniGL
|
3
3
|
|
4
|
-
class MyGame <
|
4
|
+
class MyGame < GameWindow
|
5
5
|
def initialize
|
6
|
-
super 800, 600, false
|
7
|
-
Game.initialize self, Vector.new(0, 1), 10, 2
|
6
|
+
super 800, 600, false
|
8
7
|
|
9
8
|
@obj1 = GameObject.new 10, 10, 80, 80, :img1, Vector.new(-10, -10)
|
10
9
|
@obj2 = Sprite.new 400, 0, :img1
|
11
10
|
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
11
|
+
@font1 = Res.font :font1, 20
|
12
|
+
@font2 = Res.font :font1, 50
|
13
|
+
@writer1 = TextHelper.new @font1, 5
|
14
|
+
@writer2 = TextHelper.new @font2, 5
|
15
|
+
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true, false, 0, 4, 0, 0, 'friends') { |x| puts "hello #{x}" }
|
15
16
|
@btn.enabled = false
|
16
|
-
@chk =
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
@chk =
|
18
|
+
ToggleButton.new(40, 300, @font1, 'Click me', :check, false, 0xffffff, 0x808080, 0x008000, 0xff9980, false, true, 36, 0, 0, 0, 'friends') { |c, x|
|
19
|
+
puts "hello #{x}, checked: #{c}"
|
20
|
+
}
|
21
|
+
@txt = TextField.new(10, 520, @font1, :text, nil, nil, 15, 5, 16, false, '', nil, 0, 0, 0x0000ff, 'PT-BR')
|
20
22
|
@txt.visible = false
|
23
|
+
|
24
|
+
@pb = ProgressBar.new(5, 240, 200, 20, 0xff0000, 0x00ff00, 3456, 70, 0, 0, @font1, 0xff000080)
|
25
|
+
@ddl = DropDownList.new(5, 270, @font1, nil, nil, ['olá amigos', 'opção 2', 'terceira'], 0, 3, 150, 25, 0, 0x808080, 0xffffff, 0xffff00)
|
26
|
+
|
27
|
+
@eff = Effect.new(100, 100, :check, 2, 4, 10, nil, nil, '1')
|
21
28
|
end
|
22
29
|
|
23
30
|
def needs_cursor?
|
@@ -36,6 +43,20 @@ class MyGame < Gosu::Window
|
|
36
43
|
@chk.enabled = !@chk.enabled if KB.key_pressed? Gosu::KbRightControl
|
37
44
|
@txt.visible = !@txt.visible if KB.key_pressed? Gosu::KbReturn
|
38
45
|
@txt.enabled = !@txt.enabled if KB.key_pressed? Gosu::KbLeftAlt
|
46
|
+
@txt.locale = 'en-us' if KB.key_pressed? Gosu::KbX
|
47
|
+
@txt.locale = 'pt-br' if KB.key_pressed? Gosu::KbC
|
48
|
+
@pb.visible = !@pb.visible if KB.key_pressed? Gosu::KbE
|
49
|
+
@ddl.enabled = !@ddl.enabled if KB.key_pressed? Gosu::KbQ
|
50
|
+
@ddl.visible = !@ddl.visible if KB.key_pressed? Gosu::KbW
|
51
|
+
|
52
|
+
@pb.increase 1 if KB.key_down? Gosu::KbD
|
53
|
+
@pb.decrease 1 if KB.key_down? Gosu::KbA
|
54
|
+
@pb.percentage = 0.5 if KB.key_pressed? Gosu::KbS
|
55
|
+
@pb.value = 10000 if KB.key_pressed? Gosu::KbZ
|
56
|
+
|
57
|
+
@ddl.value = 'olá amigos' if KB.key_pressed? Gosu::Kb1
|
58
|
+
@ddl.value = 'segunda' if KB.key_pressed? Gosu::Kb2
|
59
|
+
@ddl.value = 'terceira' if KB.key_pressed? Gosu::Kb3
|
39
60
|
|
40
61
|
Mouse.update
|
41
62
|
if Mouse.double_click? :left
|
@@ -46,21 +67,32 @@ class MyGame < Gosu::Window
|
|
46
67
|
@btn.update
|
47
68
|
@chk.update
|
48
69
|
@txt.update
|
70
|
+
@ddl.update
|
71
|
+
|
72
|
+
@eff.update
|
49
73
|
end
|
50
74
|
|
51
75
|
def draw
|
76
|
+
clear 0xffabcdef
|
77
|
+
|
52
78
|
@obj1.draw nil, 1, 1, 255, 0x33ff33, 30, 1
|
53
79
|
@obj2.draw nil, 0.6, 1.4, 0x99
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
80
|
+
@writer1.write_line 'Testing effect 1', 400, 260, :center, 0xffffff, :border
|
81
|
+
@writer2.write_line 'Second effect test', 400, 280, :center, 0xffffff, :border, 0xff0000, 2
|
82
|
+
@writer2.write_line 'Text with shadow!!', 400, 340, :center, 0xffff00, :shadow, 0, 2, 0x80
|
83
|
+
@writer1.write_breaking "Testing multiple line text.\nThis should draw text "\
|
84
|
+
'across multiple lines, respecting a limit width. '\
|
85
|
+
'Furthermore, the text must be right-aligned.',
|
86
|
+
780, 450, 300, :right, 0xff0000, 255, 1
|
58
87
|
|
88
|
+
@ddl.draw 0x80, 1
|
59
89
|
@btn.draw 0xcc
|
60
90
|
@chk.draw
|
61
91
|
@txt.draw
|
92
|
+
@pb.draw 0x66
|
93
|
+
|
94
|
+
@eff.draw
|
62
95
|
end
|
63
96
|
end
|
64
97
|
|
65
|
-
|
66
|
-
game.show
|
98
|
+
MyGame.new.show
|
data/test/game_object_tests.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../lib/minigl'
|
3
|
-
include
|
3
|
+
include MiniGL
|
4
4
|
|
5
5
|
class SpriteTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
@window =
|
8
|
-
Game.initialize @window
|
7
|
+
@window = GameWindow.new 800, 600, false
|
9
8
|
Res.prefix = File.expand_path(File.dirname(__FILE__)) + '/data'
|
10
9
|
end
|
11
10
|
|
@@ -27,12 +26,25 @@ class SpriteTest < Test::Unit::TestCase
|
|
27
26
|
5.times { s.animate indices, interval }
|
28
27
|
assert_equal 2, s.img_index
|
29
28
|
end
|
29
|
+
|
30
|
+
def test_sprite_visibility
|
31
|
+
# m = Map.new(1, 1, 800, 600)
|
32
|
+
s = Sprite.new 10, 20, :image, 3, 1 # the sprite will be 1 x 1 pixel
|
33
|
+
assert s.visible?
|
34
|
+
s.x = 800
|
35
|
+
assert(!(s.visible?))
|
36
|
+
s.x = -1
|
37
|
+
assert(!(s.visible?))
|
38
|
+
s.x = 0
|
39
|
+
assert s.visible?
|
40
|
+
s.y = 600
|
41
|
+
assert(!(s.visible?))
|
42
|
+
end
|
30
43
|
end
|
31
44
|
|
32
45
|
class GameObjectTest < Test::Unit::TestCase
|
33
46
|
def setup
|
34
|
-
@window =
|
35
|
-
Game.initialize @window
|
47
|
+
@window = GameWindow.new 800, 600, false
|
36
48
|
Res.prefix = File.expand_path(File.dirname(__FILE__)) + '/data'
|
37
49
|
end
|
38
50
|
|
@@ -60,4 +72,22 @@ class GameObjectTest < Test::Unit::TestCase
|
|
60
72
|
5.times { o.animate indices, interval }
|
61
73
|
assert_equal 1, o.img_index
|
62
74
|
end
|
75
|
+
|
76
|
+
def test_game_object_visibility
|
77
|
+
# m = Map.new(1, 1, 800, 600)
|
78
|
+
o = GameObject.new 10, 20, 30, 30, :square, Vector.new(-10, -10)
|
79
|
+
assert o.visible?
|
80
|
+
o.x = 800
|
81
|
+
assert o.visible?
|
82
|
+
o.x = 810
|
83
|
+
assert(!(o.visible?))
|
84
|
+
o.x = -30
|
85
|
+
assert o.visible?
|
86
|
+
o.y = -50
|
87
|
+
assert(!(o.visible?))
|
88
|
+
o.x = 0; o.y = -30
|
89
|
+
assert o.visible?
|
90
|
+
o.y = 610
|
91
|
+
assert(!(o.visible?))
|
92
|
+
end
|
63
93
|
end
|
data/test/iso_game.rb
CHANGED
data/test/map_tests.rb
CHANGED
data/test/mov_game.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
require_relative '../lib/minigl'
|
3
|
+
include MiniGL
|
4
|
+
|
5
|
+
class MyGame < GameWindow
|
6
|
+
def initialize
|
7
|
+
super 800, 600, false
|
8
|
+
|
9
|
+
@obj = GameObject.new(0, 0, 50, 50, :square)
|
10
|
+
# @obj.max_speed.x = 3
|
11
|
+
@obsts = [
|
12
|
+
Block.new(0, 600, 800, 1, false),
|
13
|
+
Block.new(-1, 0, 1, 600, false),
|
14
|
+
Block.new(800, 0, 1, 600, false),
|
15
|
+
# Block.new(375, 550, 50, 50, true),
|
16
|
+
# Block.new(150, 200, 20, 300, false),
|
17
|
+
# Block.new(220, 300, 100, 20, true),
|
18
|
+
# Block.new(485, 490, 127, 10, false),
|
19
|
+
]
|
20
|
+
@ramps = [
|
21
|
+
# Ramp.new(200, 550, 200, 50, true),
|
22
|
+
Ramp.new(0, 300, 150, 200, false),
|
23
|
+
Ramp.new(150, 500, 150, 100, false),
|
24
|
+
Ramp.new(500, 500, 150, 100, true),
|
25
|
+
Ramp.new(650, 300, 150, 200, true),
|
26
|
+
]
|
27
|
+
|
28
|
+
@cyc_obj = GameObject.new(0, 0, 50, 50, :square)
|
29
|
+
@cycle = [Vector.new(0, 0), Vector.new(430, 107), Vector.new(265, 324)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
KB.update
|
34
|
+
|
35
|
+
forces = Vector.new(0, 0)
|
36
|
+
if @obj.bottom
|
37
|
+
forces.y -= 15 if KB.key_pressed?(Gosu::KbSpace)
|
38
|
+
if KB.key_down?(Gosu::KbLeft)
|
39
|
+
forces.x -= 0.5
|
40
|
+
end
|
41
|
+
if KB.key_down?(Gosu::KbRight)
|
42
|
+
forces.x += 0.5
|
43
|
+
end
|
44
|
+
forces.x -= @obj.speed.x * 0.1
|
45
|
+
else
|
46
|
+
forces.x -= 0.2 if KB.key_down?(Gosu::KbLeft)
|
47
|
+
forces.x += 0.2 if KB.key_down?(Gosu::KbRight)
|
48
|
+
end
|
49
|
+
@obj.move(forces, @obsts, @ramps)
|
50
|
+
# puts @obj.x
|
51
|
+
@cyc_obj.cycle(@cycle, 5, [@obj])
|
52
|
+
# puts @obj.bottom
|
53
|
+
end
|
54
|
+
|
55
|
+
def draw
|
56
|
+
@obj.draw
|
57
|
+
@cyc_obj.draw
|
58
|
+
@obsts.each do |o|
|
59
|
+
draw_quad o.x, o.y, 0xffffffff,
|
60
|
+
o.x + o.w, o.y, 0xffffffff,
|
61
|
+
o.x + o.w, o.y + o.h, 0xffffffff,
|
62
|
+
o.x, o.y + o.h, 0xffffffff, 0
|
63
|
+
end
|
64
|
+
@ramps.each do |r|
|
65
|
+
draw_triangle r.left ? r.x + r.w : r.x, r.y, 0xffffffff,
|
66
|
+
r.x + r.w, r.y + r.h, 0xffffffff,
|
67
|
+
r.x, r.y + r.h, 0xffffffff, 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
MyGame.new.show
|
data/test/movement_tests.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../lib/minigl'
|
3
|
-
include
|
3
|
+
include MiniGL
|
4
4
|
|
5
5
|
class MovingObject
|
6
6
|
include Movement
|
@@ -16,8 +16,7 @@ end
|
|
16
16
|
|
17
17
|
class MovementTest < Test::Unit::TestCase
|
18
18
|
def setup
|
19
|
-
@window =
|
20
|
-
Game.initialize @window
|
19
|
+
@window = GameWindow.new 800, 600, false
|
21
20
|
@obsts = [
|
22
21
|
Block.new(-1, 0, 1, 600, false),
|
23
22
|
Block.new(0, -1, 800, 1, false),
|
data/test/res_tests.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../lib/minigl'
|
3
|
-
include
|
3
|
+
include MiniGL
|
4
4
|
|
5
5
|
class ResTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
@window =
|
8
|
-
Game.initialize @window
|
7
|
+
@window = GameWindow.new 800, 600, false
|
9
8
|
Res.prefix = File.expand_path(File.dirname(__FILE__)) + '/data'
|
10
9
|
end
|
11
10
|
|
@@ -20,4 +19,19 @@ class ResTest < Test::Unit::TestCase
|
|
20
19
|
assert_equal 48, t1[0].width
|
21
20
|
assert_equal 48, t1[0].width
|
22
21
|
end
|
22
|
+
|
23
|
+
def test_dirs_and_separator
|
24
|
+
assert_nothing_raised do
|
25
|
+
img1 = Res.img :img1
|
26
|
+
end
|
27
|
+
Res.img_dir = 'img/sub'
|
28
|
+
assert_nothing_raised do
|
29
|
+
img2 = Res.img :image
|
30
|
+
end
|
31
|
+
Res.img_dir = 'img'
|
32
|
+
Res.separator = '~'
|
33
|
+
assert_nothing_raised do
|
34
|
+
img3 = Res.img 'sub~image'
|
35
|
+
end
|
36
|
+
end
|
23
37
|
end
|
data/test/vector_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:
|
4
|
+
version: 2.0.0
|
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: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -41,10 +41,20 @@ files:
|
|
41
41
|
- lib/minigl/movement.rb
|
42
42
|
- lib/minigl/text.rb
|
43
43
|
- test/data/font/font1.ttf
|
44
|
+
- test/data/img/barbg.png
|
45
|
+
- test/data/img/barbg.svg
|
46
|
+
- test/data/img/barfg.png
|
47
|
+
- test/data/img/barfg.svg
|
48
|
+
- test/data/img/barfgl.png
|
49
|
+
- test/data/img/barfgl.svg
|
50
|
+
- test/data/img/barfgr.png
|
51
|
+
- test/data/img/barfgr.svg
|
44
52
|
- test/data/img/btn.png
|
45
53
|
- test/data/img/check.png
|
46
54
|
- test/data/img/image.png
|
47
55
|
- test/data/img/img1.png
|
56
|
+
- test/data/img/square.png
|
57
|
+
- test/data/img/square.svg
|
48
58
|
- test/data/img/text.png
|
49
59
|
- test/data/img/tile1.png
|
50
60
|
- test/data/img/tile1.svg
|
@@ -52,11 +62,13 @@ files:
|
|
52
62
|
- test/data/img/tile2.png
|
53
63
|
- test/data/img/tile2.svg
|
54
64
|
- test/data/img/tile2b.png
|
65
|
+
- test/data/sound/1.wav
|
55
66
|
- test/data/tileset/tileset1.png
|
56
67
|
- test/game.rb
|
57
68
|
- test/game_object_tests.rb
|
58
69
|
- test/iso_game.rb
|
59
70
|
- test/map_tests.rb
|
71
|
+
- test/mov_game.rb
|
60
72
|
- test/movement_tests.rb
|
61
73
|
- test/res_tests.rb
|
62
74
|
- test/vector_tests.rb
|
@@ -92,16 +104,28 @@ test_files:
|
|
92
104
|
- test/iso_game.rb
|
93
105
|
- test/res_tests.rb
|
94
106
|
- test/game_object_tests.rb
|
107
|
+
- test/mov_game.rb
|
95
108
|
- test/data/tileset/tileset1.png
|
109
|
+
- test/data/img/barfg.png
|
96
110
|
- test/data/img/tile2b.png
|
111
|
+
- test/data/img/barfgr.svg
|
112
|
+
- test/data/img/barfgl.svg
|
97
113
|
- test/data/img/tile1.png
|
114
|
+
- test/data/img/barfgl.png
|
98
115
|
- test/data/img/btn.png
|
116
|
+
- test/data/img/barfgr.png
|
117
|
+
- test/data/img/square.png
|
99
118
|
- test/data/img/tile1b.png
|
100
119
|
- test/data/img/text.png
|
101
120
|
- test/data/img/img1.png
|
121
|
+
- test/data/img/square.svg
|
122
|
+
- test/data/img/barbg.svg
|
102
123
|
- test/data/img/tile1.svg
|
103
124
|
- test/data/img/image.png
|
104
125
|
- test/data/img/check.png
|
105
126
|
- test/data/img/tile2.svg
|
127
|
+
- test/data/img/barfg.svg
|
128
|
+
- test/data/img/barbg.png
|
106
129
|
- test/data/img/tile2.png
|
130
|
+
- test/data/sound/1.wav
|
107
131
|
- test/data/font/font1.ttf
|