minigl 2.2.4 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5575ec51f8c440578ef76b9056ca136c4005996f7805c92786e28d40ea7c9e4b
4
- data.tar.gz: 5c162f0097923b8cfac025a2a933f6f6432e7c6cd4a8e7b3a5cefd8f5b55c992
3
+ metadata.gz: 79bd9440a172b26f147083ef8bd486af9adcaded814bf84473535c24704f2ded
4
+ data.tar.gz: 667b535e408b7d3302e45c4b3d02fe5fa20d85c4e31b8af68eaa4f1023851a68
5
5
  SHA512:
6
- metadata.gz: 41075c7445649d528d30fd6cf9801be78f8831bec10f2cf2515c9786a681959125f751e2d7d8d6550700ab86f3074a1df27a5ed7e47271dc5972304ea8e6800d
7
- data.tar.gz: 2c4557739d0910a795bb41229c3d58e76116b8e46d5b8ba9a34d73d556eea51faef61931a10fe23e4f9ba0b72da79ccd938df4046ad5d66c6ae071530212c42f
6
+ metadata.gz: 6a26a33090716a53212cf084158ed623cb9d54e28407a990e8238f2784ca679a08d42908a03c23266836e830943afde4f5176f4d8946ba7302530f895d5b347a
7
+ data.tar.gz: e60f740c8eec1033d01adb79af11d2960e709bd5a0df1165949622a6ba43ce49e9dc8fcb8d7f6c0ba93bd550fad1382dbf2ed73187038162561489b01f206399
data/README.md CHANGED
@@ -5,9 +5,9 @@ top of the [Gosu](http://www.libgosu.org/) gem.
5
5
 
6
6
  It provides the following features:
7
7
 
8
- * Resource management (images, sounds, ...)
9
- * Input manipulation (keyboard, mouse, ...)
10
- * UI (text, buttons, text fields, ...)
8
+ * Resource management (images, sound effects, songs, tilesets, fonts)
9
+ * Input manipulation (keyboard, mouse, joystick)
10
+ * UI (text, buttons, text fields, drop-down lists, progress bars)
11
11
  * Basic physics and collision checking
12
12
  * Animated objects
13
13
 
@@ -29,7 +29,11 @@ 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.2.4
32
+ ## Version 2.2.8
33
33
 
34
- * Fixed components being updated in invisible `Panel`s.
35
- * Clarified the documentation of the `Map` class.
34
+ * Add `stop_time` parameter to the `cycle` method of `Movement` (included in `GameObject`).
35
+
36
+ ## Contributing
37
+
38
+ Contributions are very welcome. Feel free to fork and send pull requests.
39
+ Also, you can support my work by donating bitcoins to this wallet: bc1qsp7mypdqvkt88xtnarmaytt0etxfccxr5pt5tk
@@ -37,6 +37,9 @@ module MiniGL
37
37
  # The height of the component
38
38
  attr_reader :h
39
39
 
40
+ # The text of the component
41
+ attr_reader :text
42
+
40
43
  attr_reader :anchor, :anchor_offset_x, :anchor_offset_y # :nodoc:
41
44
 
42
45
  # Determines whether the control is enabled, i.e., will process user input.
@@ -52,6 +55,8 @@ module MiniGL
52
55
  # for each specific component class.
53
56
  attr_accessor :params
54
57
 
58
+ attr_accessor :panel # :nodoc:
59
+
55
60
  def initialize(x, y, font, text, text_color, disabled_text_color) # :nodoc:
56
61
  @x = x
57
62
  @y = y
@@ -127,6 +132,7 @@ module MiniGL
127
132
  controls.each do |c|
128
133
  _, x, y = FormUtils.check_anchor(c.anchor, c.anchor_offset_x, c.anchor_offset_y, c.w, c.h, @w, @h)
129
134
  c.set_position(@x + x, @y + y)
135
+ c.panel = self
130
136
  end
131
137
 
132
138
  if img
@@ -537,9 +543,6 @@ module MiniGL
537
543
 
538
544
  # This class represents a text field (input).
539
545
  class TextField < Component
540
- # The current text inside the text field.
541
- attr_reader :text
542
-
543
546
  # The current 'locale' used for detecting the keys. THIS FEATURE IS
544
547
  # INCOMPLETE!
545
548
  attr_reader :locale
@@ -1460,6 +1463,22 @@ module MiniGL
1460
1463
  super(x, y, font, text, text_color, disabled_text_color)
1461
1464
  end
1462
1465
 
1466
+ # Changes the label's text.
1467
+ #
1468
+ # Parameters:
1469
+ # [new_text] The new text to show in the label.
1470
+ def text=(new_text)
1471
+ @text = new_text
1472
+ @w = @font.text_width(@text) * @scale_x
1473
+ x = @anchor_offset_x; y = @anchor_offset_y
1474
+ _, x, y = FormUtils.check_anchor(@anchor, x, y, @w, @h, panel ? panel.w : G.window.width, panel ? panel.h : G.window.height)
1475
+ if panel
1476
+ set_position(panel.x + x, panel.y + y)
1477
+ else
1478
+ set_position(x, y)
1479
+ end
1480
+ end
1481
+
1463
1482
  # Draws the label.
1464
1483
  #
1465
1484
  # Parameters:
@@ -100,10 +100,14 @@ module MiniGL
100
100
  @anim_counter += 1
101
101
  return unless @anim_counter >= interval
102
102
 
103
- @index_index += 1
104
- @img_index = indices[@index_index]
105
- @anim_counter = 0
106
- @animate_once_control = 2 if @index_index == indices.length - 1
103
+ if @index_index == indices.length - 1
104
+ @animate_once_control = 2
105
+ yield if block_given?
106
+ else
107
+ @index_index += 1
108
+ @img_index = indices[@index_index]
109
+ @anim_counter = 0
110
+ end
107
111
  end
108
112
 
109
113
  # Resets the animation timer and immediately changes the image index to
@@ -247,9 +247,7 @@ module MiniGL
247
247
  end
248
248
  end
249
249
 
250
- #class JSHelper
251
-
252
- # Exposes methods for controlling keyboard events.
250
+ # Exposes methods for controlling keyboard and gamepad events.
253
251
  module KB
254
252
  class << self
255
253
  # This is called by <code>GameWindow.initialize</code>. Don't call it
@@ -278,7 +276,27 @@ module MiniGL
278
276
  Gosu::KB_PAGE_UP, Gosu::KB_PERIOD, Gosu::KB_RETURN, Gosu::KB_RIGHT,
279
277
  Gosu::KB_RIGHT_ALT, Gosu::KB_RIGHT_BRACKET, Gosu::KB_RIGHT_CONTROL,
280
278
  Gosu::KB_RIGHT_META, Gosu::KB_RIGHT_SHIFT, Gosu::KB_SEMICOLON,
281
- Gosu::KB_SLASH, Gosu::KB_SPACE, Gosu::KB_TAB, Gosu::KB_UP
279
+ Gosu::KB_SLASH, Gosu::KB_SPACE, Gosu::KB_TAB, Gosu::KB_UP,
280
+ Gosu::GP_0_BUTTON_0, Gosu::GP_0_BUTTON_1, Gosu::GP_0_BUTTON_2, Gosu::GP_0_BUTTON_3,
281
+ Gosu::GP_0_BUTTON_4, Gosu::GP_0_BUTTON_5, Gosu::GP_0_BUTTON_6, Gosu::GP_0_BUTTON_7,
282
+ Gosu::GP_0_BUTTON_8, Gosu::GP_0_BUTTON_9, Gosu::GP_0_BUTTON_10, Gosu::GP_0_BUTTON_11,
283
+ Gosu::GP_0_BUTTON_12, Gosu::GP_0_BUTTON_13, Gosu::GP_0_BUTTON_14, Gosu::GP_0_BUTTON_15,
284
+ Gosu::GP_0_DOWN, Gosu::GP_0_LEFT, Gosu::GP_0_RIGHT, Gosu::GP_0_UP,
285
+ Gosu::GP_1_BUTTON_0, Gosu::GP_1_BUTTON_1, Gosu::GP_1_BUTTON_2, Gosu::GP_1_BUTTON_3,
286
+ Gosu::GP_1_BUTTON_4, Gosu::GP_1_BUTTON_5, Gosu::GP_1_BUTTON_6, Gosu::GP_1_BUTTON_7,
287
+ Gosu::GP_1_BUTTON_8, Gosu::GP_1_BUTTON_9, Gosu::GP_1_BUTTON_10, Gosu::GP_1_BUTTON_11,
288
+ Gosu::GP_1_BUTTON_12, Gosu::GP_1_BUTTON_13, Gosu::GP_1_BUTTON_14, Gosu::GP_1_BUTTON_15,
289
+ Gosu::GP_1_DOWN, Gosu::GP_1_LEFT, Gosu::GP_1_RIGHT, Gosu::GP_1_UP,
290
+ Gosu::GP_2_BUTTON_0, Gosu::GP_2_BUTTON_1, Gosu::GP_2_BUTTON_2, Gosu::GP_2_BUTTON_3,
291
+ Gosu::GP_2_BUTTON_4, Gosu::GP_2_BUTTON_5, Gosu::GP_2_BUTTON_6, Gosu::GP_2_BUTTON_7,
292
+ Gosu::GP_2_BUTTON_8, Gosu::GP_2_BUTTON_9, Gosu::GP_2_BUTTON_10, Gosu::GP_2_BUTTON_11,
293
+ Gosu::GP_2_BUTTON_12, Gosu::GP_2_BUTTON_13, Gosu::GP_2_BUTTON_14, Gosu::GP_2_BUTTON_15,
294
+ Gosu::GP_2_DOWN, Gosu::GP_2_LEFT, Gosu::GP_2_RIGHT, Gosu::GP_2_UP,
295
+ Gosu::GP_3_BUTTON_0, Gosu::GP_3_BUTTON_1, Gosu::GP_3_BUTTON_2, Gosu::GP_3_BUTTON_3,
296
+ Gosu::GP_3_BUTTON_4, Gosu::GP_3_BUTTON_5, Gosu::GP_3_BUTTON_6, Gosu::GP_3_BUTTON_7,
297
+ Gosu::GP_3_BUTTON_8, Gosu::GP_3_BUTTON_9, Gosu::GP_3_BUTTON_10, Gosu::GP_3_BUTTON_11,
298
+ Gosu::GP_3_BUTTON_12, Gosu::GP_3_BUTTON_13, Gosu::GP_3_BUTTON_14, Gosu::GP_3_BUTTON_15,
299
+ Gosu::GP_3_DOWN, Gosu::GP_3_LEFT, Gosu::GP_3_RIGHT, Gosu::GP_3_UP,
282
300
  ]
283
301
  @down = []
284
302
  @prev_down = []
@@ -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
@@ -504,16 +501,32 @@ module MiniGL
504
501
  # of the objects being carried.
505
502
  # [obst_ramps] Ramps to consider when moving objects from the +obstacles+
506
503
  # array, as described for +obst_obstacles+.
507
- def cycle(points, speed, obstacles = nil, obst_obstacles = nil, obst_ramps = nil)
508
- @cur_point = 0 if @cur_point.nil?
509
- if obstacles
510
- move_carrying points[@cur_point], speed, obstacles, obst_obstacles, obst_ramps
511
- else
512
- move_free points[@cur_point], speed
504
+ # [stop_time] Optional stop time (in frames) when the object reaches each of
505
+ # the points.
506
+ def cycle(points, speed, obstacles = nil, obst_obstacles = nil, obst_ramps = nil, stop_time = 0)
507
+ unless @cycle_setup
508
+ @cur_point = 0 if @cur_point.nil?
509
+ if obstacles
510
+ move_carrying points[@cur_point], speed, obstacles, obst_obstacles, obst_ramps
511
+ else
512
+ move_free points[@cur_point], speed
513
+ end
513
514
  end
514
515
  if @speed.x == 0 and @speed.y == 0
515
- if @cur_point == points.length - 1; @cur_point = 0
516
- else; @cur_point += 1; end
516
+ unless @cycle_setup
517
+ @cycle_timer = 0
518
+ @cycle_setup = true
519
+ end
520
+ if @cycle_timer >= stop_time
521
+ if @cur_point == points.length - 1
522
+ @cur_point = 0
523
+ else
524
+ @cur_point += 1
525
+ end
526
+ @cycle_setup = false
527
+ else
528
+ @cycle_timer += 1
529
+ end
517
530
  end
518
531
  end
519
532
 
@@ -35,7 +35,7 @@ class MyGame < GameWindow
35
35
 
36
36
  @panel = Panel.new(10, 10, 720, 520, [
37
37
  Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn),
38
- Label.new(0, 70, @font1, 'Teste de label', 0xcccccc, 0x666666, 1, 1, :north),
38
+ @lbl = Label.new(0, 70, @font1, 'Teste de label', 0, 0x666666, 1, 1, :north),
39
39
  TextField.new(x: 5, y: 40, font: @font1, text: 'Opa', img: :text, margin_x: 5, margin_y: 5, anchor: :top_left),
40
40
  Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :top),
41
41
  DropDownList.new(x: 0, y: 40, width: 150, height: 25, font: @font1, options: ['olá amigos', 'opção 2', 'terceira'], anchor: :north),
@@ -49,6 +49,8 @@ class MyGame < GameWindow
49
49
  ProgressBar.new(0, 40, 200, 20, :barbg, :barfg, 3456, 70, 2, 2, @font1, 0xff000080, nil, nil, 1, 1, :bottom)
50
50
  ], :text, :tiled, true, 2, 2, :bottom_right)
51
51
 
52
+ @lbl2 = Label.new(x: 5, y: 5, font: @font1, text: 'top-right corner label test', anchor: :top_right)
53
+
52
54
  @eff = Effect.new(100, 100, :check, 2, 4, 10, nil, nil, '1')
53
55
 
54
56
  @angle = 0
@@ -79,6 +81,8 @@ class MyGame < GameWindow
79
81
  @panel.visible = !@panel.visible if KB.key_pressed? Gosu::KbM
80
82
 
81
83
  @panel.add_component(Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southeast)) if KB.key_pressed?(Gosu::KbB)
84
+ @lbl.text = 'Test of changed text' if KB.key_pressed?(Gosu::KB_C)
85
+ @lbl2.text = 'Shorter text' if KB.key_pressed?(Gosu::KB_X)
82
86
 
83
87
  @pb.increase 1 if KB.key_down? Gosu::KbD
84
88
  @pb.decrease 1 if KB.key_down? Gosu::KbA
@@ -116,6 +120,11 @@ class MyGame < GameWindow
116
120
  @objs.each_with_index do |o, i|
117
121
  o.move_free(i * 45, 3)
118
122
  end
123
+
124
+ @obj3.animate_once([1, 2, 3, 4], 15) do
125
+ puts 'acabou'
126
+ end
127
+ @obj3.set_animation 0 if KB.key_pressed? Gosu::KB_0
119
128
  end
120
129
 
121
130
  def draw
@@ -140,6 +149,7 @@ class MyGame < GameWindow
140
149
  @chk.draw
141
150
  @txt.draw
142
151
  @pb.draw 0x66
152
+ @lbl2.draw
143
153
 
144
154
  @panel.draw(204, 10)
145
155
 
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.4
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: 2019-02-22 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
@@ -93,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.6
96
+ rubygems_version: 3.1.2
98
97
  signing_key:
99
98
  specification_version: 4
100
99
  summary: MiniGL