minigl 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/minigl/game_object.rb +24 -10
- data/test/data/img/square3.png +0 -0
- data/test/data/img/square3.svg +76 -0
- data/test/game.rb +9 -7
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 545d2e46bcc97bb95ef2ef8a9b150cf5492a4ca6
|
4
|
+
data.tar.gz: f35a2fc0ad36a5b640d11b5001521db050b04c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c7cf269750dd3dea9f6bd4f09b17216974dc3cfa4a28cd212d72f6e9210dfecd3a02256a8d0e2b3bf5b21d94011eeb4f703821f694d44d9c0e700ea593f16d4
|
7
|
+
data.tar.gz: 3a786d3aa449653647f112ca35e839817f8a74ba5d9712121d78c4d2673bfd9735678be24943a00d481244670cdd64fc7f539b3adb0e1ed8fa16827bfefebf85
|
data/README.md
CHANGED
@@ -25,10 +25,11 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
25
25
|
|
26
26
|
## Documentation
|
27
27
|
|
28
|
-
* The library is 100% RDoc-documented [here](http://www.rubydoc.info/gems/minigl
|
28
|
+
* The library is 100% RDoc-documented [here](http://www.rubydoc.info/gems/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.0.
|
32
|
+
## Version 2.0.9
|
33
33
|
|
34
|
-
* Added the `
|
34
|
+
* Added the `round` option to `Sprite#draw` and `GameObject#draw`.
|
35
|
+
* Fixed `GameObject#draw` when drawing rotated with non-null `img_gap`.
|
data/lib/minigl/game_object.rb
CHANGED
@@ -137,9 +137,12 @@ module MiniGL
|
|
137
137
|
# to draw it vertically flipped.
|
138
138
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
139
139
|
# will be drawn on top of the ones with smaller z-orders.
|
140
|
+
# [round] Specify whether the drawing coordinates should be rounded to an
|
141
|
+
# integer before drawing, to avoid little distortions of the image.
|
142
|
+
# Only applies when the image is not rotated.
|
140
143
|
#
|
141
144
|
# *Obs.:* This method accepts named parameters.
|
142
|
-
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)
|
145
|
+
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0, round = false)
|
143
146
|
if map.is_a? Hash
|
144
147
|
scale_x = map.fetch(:scale_x, 1)
|
145
148
|
scale_y = map.fetch(:scale_y, 1)
|
@@ -148,6 +151,7 @@ module MiniGL
|
|
148
151
|
angle = map.fetch(:angle, nil)
|
149
152
|
flip = map.fetch(:flip, nil)
|
150
153
|
z_index = map.fetch(:z_index, 0)
|
154
|
+
round = map.fetch(:round, false)
|
151
155
|
map = map.fetch(:map, nil)
|
152
156
|
end
|
153
157
|
|
@@ -158,8 +162,9 @@ module MiniGL
|
|
158
162
|
z_index, angle, 0.5, 0.5, (flip == :horiz ? -scale_x : scale_x),
|
159
163
|
(flip == :vert ? -scale_y : scale_y), color
|
160
164
|
else
|
161
|
-
|
162
|
-
|
165
|
+
x = @x - (map ? map.cam.x : 0) + (flip == :horiz ? scale_x * @img[0].width : 0)
|
166
|
+
y = @y - (map ? map.cam.y : 0) + (flip == :vert ? scale_y * @img[0].height : 0)
|
167
|
+
@img[@img_index].draw (round ? x.round : x), (round ? y.round : y),
|
163
168
|
z_index, (flip == :horiz ? -scale_x : scale_x),
|
164
169
|
(flip == :vert ? -scale_y : scale_y), color
|
165
170
|
end
|
@@ -238,9 +243,12 @@ module MiniGL
|
|
238
243
|
# to draw it vertically flipped.
|
239
244
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
240
245
|
# will be drawn on top of the ones with smaller z-orders.
|
246
|
+
# [round] Specify whether the drawing coordinates should be rounded to an
|
247
|
+
# integer before drawing, to avoid little distortions of the image.
|
248
|
+
# Only applies when the image is not rotated.
|
241
249
|
#
|
242
250
|
# *Obs.:* This method accepts named parameters.
|
243
|
-
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)
|
251
|
+
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0, round = false)
|
244
252
|
if map.is_a? Hash
|
245
253
|
scale_x = map.fetch(:scale_x, 1)
|
246
254
|
scale_y = map.fetch(:scale_y, 1)
|
@@ -249,18 +257,24 @@ module MiniGL
|
|
249
257
|
angle = map.fetch(:angle, nil)
|
250
258
|
flip = map.fetch(:flip, nil)
|
251
259
|
z_index = map.fetch(:z_index, 0)
|
260
|
+
round = map.fetch(:round, false)
|
252
261
|
map = map.fetch(:map, nil)
|
253
262
|
end
|
254
263
|
|
255
264
|
color = (alpha << 24) | color
|
256
265
|
if angle
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
266
|
+
center_x = @x + @w * 0.5
|
267
|
+
center_y = @y + @h * 0.5
|
268
|
+
o_x = center_x - @x - @img_gap.x
|
269
|
+
o_y = center_y - @y - @img_gap.y
|
270
|
+
@img[@img_index].draw_rot @x + (flip == :horiz ? -1 : 1) * (@img_gap.x + o_x) - (map ? map.cam.x : 0),
|
271
|
+
@y + (flip == :vert ? -1 : 1) * (@img_gap.y + o_y) - (map ? map.cam.y : 0),
|
272
|
+
z_index, angle, o_x.to_f / @img[0].width, o_y.to_f / @img[0].height,
|
273
|
+
(flip == :horiz ? -scale_x : scale_x), (flip == :vert ? -scale_y : scale_y), color
|
261
274
|
else
|
262
|
-
|
263
|
-
|
275
|
+
x = @x + (flip == :horiz ? -1 : 1) * @img_gap.x - (map ? map.cam.x : 0) + (flip == :horiz ? @w : 0)
|
276
|
+
y = @y + (flip == :vert ? -1 : 1) * @img_gap.y - (map ? map.cam.y : 0) + (flip == :vert ? @h : 0)
|
277
|
+
@img[@img_index].draw (round ? x.round : x), (round ? y.round : y),
|
264
278
|
z_index, (flip == :horiz ? -scale_x : scale_x),
|
265
279
|
(flip == :vert ? -scale_y : scale_y), color
|
266
280
|
end
|
Binary file
|
@@ -0,0 +1,76 @@
|
|
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="100"
|
13
|
+
height="100"
|
14
|
+
viewBox="0 0 100 100"
|
15
|
+
id="svg2"
|
16
|
+
version="1.1"
|
17
|
+
inkscape:version="0.91 r13725"
|
18
|
+
sodipodi:docname="square3.svg"
|
19
|
+
inkscape:export-filename="/home/victor/aleva/minigl/test/data/img/square3.png"
|
20
|
+
inkscape:export-xdpi="90"
|
21
|
+
inkscape:export-ydpi="90">
|
22
|
+
<defs
|
23
|
+
id="defs4" />
|
24
|
+
<sodipodi:namedview
|
25
|
+
id="base"
|
26
|
+
pagecolor="#ffffff"
|
27
|
+
bordercolor="#666666"
|
28
|
+
borderopacity="1.0"
|
29
|
+
inkscape:pageopacity="0.0"
|
30
|
+
inkscape:pageshadow="2"
|
31
|
+
inkscape:zoom="8.62"
|
32
|
+
inkscape:cx="50"
|
33
|
+
inkscape:cy="50"
|
34
|
+
inkscape:document-units="px"
|
35
|
+
inkscape:current-layer="layer1"
|
36
|
+
showgrid="false"
|
37
|
+
inkscape:snap-global="false"
|
38
|
+
units="px"
|
39
|
+
inkscape:window-width="1920"
|
40
|
+
inkscape:window-height="1025"
|
41
|
+
inkscape:window-x="0"
|
42
|
+
inkscape:window-y="0"
|
43
|
+
inkscape:window-maximized="1" />
|
44
|
+
<metadata
|
45
|
+
id="metadata7">
|
46
|
+
<rdf:RDF>
|
47
|
+
<cc:Work
|
48
|
+
rdf:about="">
|
49
|
+
<dc:format>image/svg+xml</dc:format>
|
50
|
+
<dc:type
|
51
|
+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
52
|
+
<dc:title></dc:title>
|
53
|
+
</cc:Work>
|
54
|
+
</rdf:RDF>
|
55
|
+
</metadata>
|
56
|
+
<g
|
57
|
+
inkscape:label="Layer 1"
|
58
|
+
inkscape:groupmode="layer"
|
59
|
+
id="layer1"
|
60
|
+
transform="translate(0,-952.36216)">
|
61
|
+
<rect
|
62
|
+
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.2"
|
63
|
+
id="rect4133"
|
64
|
+
width="100"
|
65
|
+
height="100"
|
66
|
+
x="0"
|
67
|
+
y="952.36218" />
|
68
|
+
<rect
|
69
|
+
y="1002.3622"
|
70
|
+
x="50"
|
71
|
+
height="40"
|
72
|
+
width="40"
|
73
|
+
id="rect4135"
|
74
|
+
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.2" />
|
75
|
+
</g>
|
76
|
+
</svg>
|
data/test/game.rb
CHANGED
@@ -6,10 +6,11 @@ class MyGame < GameWindow
|
|
6
6
|
super 800, 600, false
|
7
7
|
|
8
8
|
# @img = Res.img :img1
|
9
|
-
@obj1 = GameObject.new
|
9
|
+
@obj1 = GameObject.new 50, 50, 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
|
13
|
+
@obj4 = Sprite.new 500, 0, :img1
|
13
14
|
@objs = []
|
14
15
|
8.times { @objs << GameObject.new(384, 284, 32, 32, :check, Vector.new(0, 0), 2, 4) }
|
15
16
|
@flip = nil
|
@@ -43,10 +44,10 @@ class MyGame < GameWindow
|
|
43
44
|
|
44
45
|
def update
|
45
46
|
KB.update
|
46
|
-
@obj1.y -=
|
47
|
-
@obj1.x +=
|
48
|
-
@obj1.y +=
|
49
|
-
@obj1.x -=
|
47
|
+
begin @obj1.y -= 0.714; @obj4.y -= 0.714 end if KB.key_held? Gosu::KbUp
|
48
|
+
begin @obj1.x += 0.714; @obj4.x += 0.714 end if KB.key_down? Gosu::KbRight
|
49
|
+
begin @obj1.y += 0.714; @obj4.y += 0.714 end if KB.key_held? Gosu::KbDown
|
50
|
+
begin @obj1.x -= 0.714; @obj4.x -= 0.714 end if KB.key_down? Gosu::KbLeft
|
50
51
|
@btn.set_position rand(700), rand(550) if KB.key_pressed? Gosu::KbSpace
|
51
52
|
@btn.enabled = !@btn.enabled if KB.key_pressed? Gosu::KbLeftControl
|
52
53
|
@chk.checked = false if KB.key_pressed? Gosu::KbEscape
|
@@ -70,8 +71,8 @@ class MyGame < GameWindow
|
|
70
71
|
|
71
72
|
Mouse.update
|
72
73
|
if Mouse.double_click? :left
|
73
|
-
@obj1.x = Mouse.x
|
74
|
-
@obj1.y = Mouse.y
|
74
|
+
@obj1.x = Mouse.x
|
75
|
+
@obj1.y = Mouse.y
|
75
76
|
end
|
76
77
|
if Mouse.button_released? :right
|
77
78
|
if @flip.nil?; @flip = :horiz
|
@@ -100,6 +101,7 @@ class MyGame < GameWindow
|
|
100
101
|
@obj1.draw color: 0x33ff33, angle: (@angle == 0 ? nil : @angle)
|
101
102
|
@obj2.draw angle: (@angle == 0 ? nil : @angle), scale_x: 0.5, scale_y: 1.4
|
102
103
|
@obj3.draw flip: @flip
|
104
|
+
@obj4.draw round: true
|
103
105
|
@objs.each { |o| o.draw }
|
104
106
|
@writer1.write_line text: 'Testing effect 1', x: 400, y: 260, color: 0xffffff, effect: :border
|
105
107
|
@writer2.write_line 'Second effect test', 400, 280, :center, 0xffffff, 255, :border, 0xff0000, 2
|
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.0.
|
4
|
+
version: 2.0.9
|
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: 2018-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- test/data/img/square.svg
|
54
54
|
- test/data/img/square2.png
|
55
55
|
- test/data/img/square2.svg
|
56
|
+
- test/data/img/square3.png
|
57
|
+
- test/data/img/square3.svg
|
56
58
|
- test/data/img/sub/image.png
|
57
59
|
- test/data/img/text.png
|
58
60
|
- test/data/img/tile1.png
|
@@ -111,8 +113,10 @@ test_files:
|
|
111
113
|
- test/data/tileset/tileset1.png
|
112
114
|
- test/data/img/check.png
|
113
115
|
- test/data/img/image.png
|
116
|
+
- test/data/img/square3.png
|
114
117
|
- test/data/img/square.svg
|
115
118
|
- test/data/img/tile2b.png
|
119
|
+
- test/data/img/square3.svg
|
116
120
|
- test/data/img/text.png
|
117
121
|
- test/data/img/img1.png
|
118
122
|
- test/data/img/barfg.svg
|