minigl 2.2.8 → 2.2.9

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/minigl/movement.rb +30 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b4770937913304de29f2696a7d7a0e75fc468185579efa3b421a4abe46253e8
4
- data.tar.gz: 84c72db0c03039a09767d39138b681201a2d5028e3ef278b1096b1c89b9e472d
3
+ metadata.gz: 79bd9440a172b26f147083ef8bd486af9adcaded814bf84473535c24704f2ded
4
+ data.tar.gz: 667b535e408b7d3302e45c4b3d02fe5fa20d85c4e31b8af68eaa4f1023851a68
5
5
  SHA512:
6
- metadata.gz: 36242a7d0fd3c52df939408e744bc01139b2b34b7f9b3f86e6e64989778a0eb51b48fa7eb56ebf74c8a0e59a6781cadf186e4cd0719002afa6abf4c2f14998c3
7
- data.tar.gz: b0706f37c19fd9e48bf43fc0921b9c9991e355044c5e99374df4821a5be18b5abda87c73375d1cdc84a3bd964a28fbc7e0c176c2e78167b50ebcd5ae015a2137
6
+ metadata.gz: 6a26a33090716a53212cf084158ed623cb9d54e28407a990e8238f2784ca679a08d42908a03c23266836e830943afde4f5176f4d8946ba7302530f895d5b347a
7
+ data.tar.gz: e60f740c8eec1033d01adb79af11d2960e709bd5a0df1165949622a6ba43ce49e9dc8fcb8d7f6c0ba93bd550fad1382dbf2ed73187038162561489b01f206399
@@ -360,17 +360,16 @@ module MiniGL
360
360
  # [speed] If the first argument is a forces vector, then this should be
361
361
  # +nil+. If it is a point, then this is the constant speed at which
362
362
  # the object will move (provided as a scalar, not a vector).
363
- # [obstacles] An array of obstacles to be considered in the collision
364
- # checking, and carried along when colliding from above.
365
- # Obstacles must be instances of Block (or derived classes),
366
- # or objects that <code>include Movement</code>.
367
- # [obst_obstacles] Obstacles that should be considered when moving objects
368
- # from the +obstacles+ array, i.e., these obstacles won't
369
- # interfere in the elevator's movement, but in the movement
370
- # of the objects being carried.
371
- # [obst_ramps] Ramps to consider when moving objects from the +obstacles+
372
- # array, as described for +obst_obstacles+.
373
- def move_carrying(arg, speed, obstacles, obst_obstacles, obst_ramps)
363
+ # [carried_objs] An array of objects that can potentially be carried by
364
+ # this object while it moves. The objects must respond to
365
+ # +x+, +y+, +w+ and +h+.
366
+ # [obstacles] Obstacles that should be considered for collision checking
367
+ # with the carried objects, if they include the +Movement+
368
+ # module, and with this object too, if moving with forces.
369
+ # [ramps] Ramps that should be considered for the carried objects, if they
370
+ # include the +Movement+ module, and for this object too, if moving
371
+ # with forces.
372
+ def move_carrying(arg, speed, carried_objs, obstacles, ramps)
374
373
  if speed
375
374
  x_d = arg.x - @x; y_d = arg.y - @y
376
375
  distance = Math.sqrt(x_d**2 + y_d**2)
@@ -382,18 +381,11 @@ module MiniGL
382
381
 
383
382
  @speed.x = 1.0 * x_d * speed / distance
384
383
  @speed.y = 1.0 * y_d * speed / distance
385
- else
386
- arg += G.gravity
387
- @speed.x += arg.x / @mass; @speed.y += arg.y / @mass
388
- @speed.x = 0 if @speed.x.abs < G.min_speed.x
389
- @speed.y = 0 if @speed.y.abs < G.min_speed.y
390
- @speed.x = (@speed.x <=> 0) * @max_speed.x if @speed.x.abs > @max_speed.x
391
- @speed.y = (@speed.y <=> 0) * @max_speed.y if @speed.y.abs > @max_speed.y
384
+ x_aim = @x + @speed.x; y_aim = @y + @speed.y
392
385
  end
393
386
 
394
- x_aim = @x + @speed.x; y_aim = @y + @speed.y
395
387
  passengers = []
396
- obstacles.each do |o|
388
+ carried_objs.each do |o|
397
389
  if @x + @w > o.x && o.x + o.w > @x
398
390
  foot = o.y + o.h
399
391
  if foot.round(6) == @y.round(6) || @speed.y < 0 && foot < @y && foot > y_aim
@@ -415,25 +407,30 @@ module MiniGL
415
407
  @y = y_aim
416
408
  end
417
409
  else
418
- @x = x_aim; @y = y_aim
410
+ move(arg, obstacles, ramps)
419
411
  end
420
412
 
421
413
  forces = Vector.new @x - prev_x, @y - prev_y
422
414
  prev_g = G.gravity.clone
423
415
  G.gravity.x = G.gravity.y = 0
424
416
  passengers.each do |p|
425
- prev_speed = p.speed.clone
426
- prev_forces = p.stored_forces.clone
427
- prev_bottom = p.bottom
428
- p.speed.x = p.speed.y = 0
429
- p.stored_forces.x = p.stored_forces.y = 0
430
- p.instance_exec { @bottom = nil }
431
- p.move forces * p.mass, obst_obstacles, obst_ramps
432
- p.speed.x = prev_speed.x
433
- p.speed.y = prev_speed.y
434
- p.stored_forces.x = prev_forces.x
435
- p.stored_forces.y = prev_forces.y
436
- p.instance_exec(prev_bottom) { |b| @bottom = b }
417
+ if p.class.included_modules.include?(Movement)
418
+ prev_speed = p.speed.clone
419
+ prev_forces = p.stored_forces.clone
420
+ prev_bottom = p.bottom
421
+ p.speed.x = p.speed.y = 0
422
+ p.stored_forces.x = p.stored_forces.y = 0
423
+ p.instance_exec { @bottom = nil }
424
+ p.move(forces * p.mass, obstacles, ramps)
425
+ p.speed.x = prev_speed.x
426
+ p.speed.y = prev_speed.y
427
+ p.stored_forces.x = prev_forces.x
428
+ p.stored_forces.y = prev_forces.y
429
+ p.instance_exec(prev_bottom) { |b| @bottom = b }
430
+ else
431
+ p.x += forces.x
432
+ p.y += forces.y
433
+ end
437
434
  end
438
435
  G.gravity = prev_g
439
436
  end
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.2.8
4
+ version: 2.2.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: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2020-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu