minigl 2.0.7 → 2.0.8

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
  SHA1:
3
- metadata.gz: 6a008a59987965b59eb3079c99aa5a2b60f82fbd
4
- data.tar.gz: 4e3e3eca4a1f661d932a3cabc06c1af59d91bf05
3
+ metadata.gz: f2d491becfcc152fa203005e847196c2e8478b16
4
+ data.tar.gz: a24b621bb5ba72fcfed720ef25b80bdce7df9e24
5
5
  SHA512:
6
- metadata.gz: 300cfcd662ddaa79cfcd52adb847412acdfd4adcca706d1803dd566b7ce73f9ce2b05fe11eeb73a3d7ba04ea23fddfac41bf71e811424e1d23746ae297b32d4d
7
- data.tar.gz: 97f6e31b2896c911599f676c16700ad8300e9aacef9602dcbfc2617c03537dd2895316a4e0e813aa70acd2d7599783fc02088b3c3b8c4fc38da95c8c7e92f850
6
+ metadata.gz: 7d176e2cdc27315f39b357ba35eaaaaef109891d8187b961b30b73f13dc8b5c14e40619b3f5af470ae07ff49e4eb3f59df9ab16b396f7804611fe9141e2cc273
7
+ data.tar.gz: c9e3862fd8dc80b0541f2cddf9db7d83c10d9e17bbd329dd3c56cb14c0dd9d7c80fad90a30fb73f2505709276db950f4cd4429664bf3aa737e241cde35cc7173
data/README.md CHANGED
@@ -29,7 +29,6 @@ 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.0.7
32
+ ## Version 2.0.8
33
33
 
34
- * Fixed the camera position for maps smaller than the screen.
35
- * Added `animate_once` method to `Sprite`.
34
+ * Added the `set_speed` option to `Movement#move`.
@@ -225,28 +225,37 @@ module MiniGL
225
225
  # objects that <code>include Movement</code>.
226
226
  # [ramps] An array of ramps to be considered in the collision checking.
227
227
  # Ramps must be instances of Ramp (or derived classes).
228
- def move(forces, obst, ramps)
229
- forces.x += G.gravity.x; forces.y += G.gravity.y
230
- forces.x += @stored_forces.x; forces.y += @stored_forces.y
231
- @stored_forces.x = @stored_forces.y = 0
232
-
233
- forces.x = 0 if (forces.x < 0 and @left) or (forces.x > 0 and @right)
234
- forces.y = 0 if (forces.y < 0 and @top) or (forces.y > 0 and @bottom)
235
-
236
- if @bottom.is_a? Ramp
237
- if @bottom.ratio > G.ramp_slip_threshold
238
- forces.x += (@bottom.left ? -1 : 1) * (@bottom.ratio - G.ramp_slip_threshold) * G.ramp_slip_force / G.ramp_slip_threshold
239
- elsif forces.x > 0 && @bottom.left || forces.x < 0 && !@bottom.left
240
- forces.x *= @bottom.factor
228
+ # [set_speed] Set this flag to +true+ to cause the +forces+ vector to be
229
+ # treated as a speed vector, i.e., the object's speed will be
230
+ # directly set to the given values. The force of gravity will
231
+ # also be ignored in this case.
232
+ def move(forces, obst, ramps, set_speed = false)
233
+ if set_speed
234
+ @speed.x = forces.x
235
+ @speed.y = forces.y
236
+ else
237
+ forces.x += G.gravity.x; forces.y += G.gravity.y
238
+ forces.x += @stored_forces.x; forces.y += @stored_forces.y
239
+ @stored_forces.x = @stored_forces.y = 0
240
+
241
+ forces.x = 0 if (forces.x < 0 and @left) or (forces.x > 0 and @right)
242
+ forces.y = 0 if (forces.y < 0 and @top) or (forces.y > 0 and @bottom)
243
+
244
+ if @bottom.is_a? Ramp
245
+ if @bottom.ratio > G.ramp_slip_threshold
246
+ forces.x += (@bottom.left ? -1 : 1) * (@bottom.ratio - G.ramp_slip_threshold) * G.ramp_slip_force / G.ramp_slip_threshold
247
+ elsif forces.x > 0 && @bottom.left || forces.x < 0 && !@bottom.left
248
+ forces.x *= @bottom.factor
249
+ end
241
250
  end
251
+
252
+ @speed.x += forces.x / @mass; @speed.y += forces.y / @mass
242
253
  end
243
254
 
244
- @speed.x += forces.x / @mass; @speed.y += forces.y / @mass
245
255
  @speed.x = 0 if @speed.x.abs < G.min_speed.x
246
256
  @speed.y = 0 if @speed.y.abs < G.min_speed.y
247
257
  @speed.x = (@speed.x <=> 0) * @max_speed.x if @speed.x.abs > @max_speed.x
248
258
  @speed.y = (@speed.y <=> 0) * @max_speed.y if @speed.y.abs > @max_speed.y
249
-
250
259
  @prev_speed = @speed.clone
251
260
 
252
261
  x = @speed.x < 0 ? @x + @speed.x : @x
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.91 r13725"
17
+ sodipodi:docname="square2.svg"
18
+ inkscape:export-filename="/home/victor/aleva/minigl/test/data/img/square2.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="11.429795"
32
+ inkscape:cy="25"
33
+ inkscape:document-units="px"
34
+ inkscape:current-layer="layer1"
35
+ showgrid="false"
36
+ inkscape:window-width="1920"
37
+ inkscape:window-height="1026"
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:#99ffff;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>
data/test/mov_game.rb CHANGED
@@ -7,7 +7,8 @@ class MyGame < GameWindow
7
7
  super 800, 600, false
8
8
 
9
9
  @obj = GameObject.new(0, 0, 50, 50, :square)
10
- # @obj.max_speed.x = 3
10
+ @obj2 = GameObject.new(100, 0, 50, 50, :square2)
11
+
11
12
  @obsts = [
12
13
  Block.new(0, 600, 800, 1, false),
13
14
  Block.new(-1, 0, 1, 600, false),
@@ -39,26 +40,26 @@ class MyGame < GameWindow
39
40
  forces = Vector.new(0, 0)
40
41
  if @obj.bottom
41
42
  forces.y -= 15 if KB.key_pressed?(Gosu::KbSpace)
42
- if KB.key_down?(Gosu::KbLeft)
43
- forces.x -= 0.5
44
- end
45
- if KB.key_down?(Gosu::KbRight)
46
- forces.x += 0.5
47
- end
43
+ forces.x -= 0.5 if KB.key_down?(Gosu::KbLeft)
44
+ forces.x += 0.5 if KB.key_down?(Gosu::KbRight)
48
45
  forces.x -= @obj.speed.x * 0.1
49
46
  else
50
47
  forces.x -= 0.2 if KB.key_down?(Gosu::KbLeft)
51
48
  forces.x += 0.2 if KB.key_down?(Gosu::KbRight)
52
49
  end
53
50
  @obj.move(forces, @obsts, @ramps)
54
- # puts @obj.x
55
- # @cyc_obj.cycle(@cycle, 5, [@obj], @obsts, @ramps)
56
- # puts @obj.bottom
51
+
52
+ speed = Vector.new(0, 0)
53
+ speed.y -= 3 if KB.key_down? Gosu::KbW
54
+ speed.y += 3 if KB.key_down? Gosu::KbS
55
+ speed.x -= 3 if KB.key_down? Gosu::KbA
56
+ speed.x += 3 if KB.key_down? Gosu::KbD
57
+ @obj2.move(speed, @obsts, @ramps, true)
57
58
  end
58
59
 
59
60
  def draw
60
61
  @obj.draw
61
- # @cyc_obj.draw
62
+ @obj2.draw
62
63
  @obsts.each do |o|
63
64
  draw_quad o.x, o.y, 0xffffffff,
64
65
  o.x + o.w, o.y, 0xffffffff,
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.7
4
+ version: 2.0.8
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: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -51,6 +51,8 @@ files:
51
51
  - test/data/img/img1.png
52
52
  - test/data/img/square.png
53
53
  - test/data/img/square.svg
54
+ - test/data/img/square2.png
55
+ - test/data/img/square2.svg
54
56
  - test/data/img/sub/image.png
55
57
  - test/data/img/text.png
56
58
  - test/data/img/tile1.png
@@ -116,6 +118,8 @@ test_files:
116
118
  - test/data/img/barfg.svg
117
119
  - test/data/img/barbg.svg
118
120
  - test/data/img/tile2.png
121
+ - test/data/img/square2.svg
122
+ - test/data/img/square2.png
119
123
  - test/data/img/tile2.svg
120
124
  - test/data/img/square.png
121
125
  - test/data/img/barbg.png