minigl 1.2.0 → 1.2.1

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/lib/minigl/global.rb +41 -33
  4. data/test/game.rb +9 -5
  5. metadata +16 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 820be7bb9e24c286a9ca663fbf70cc370a0d11a2
4
- data.tar.gz: f372d5c224eff4a4626ab37927046e95a1856b25
3
+ metadata.gz: ee71302e4c1c310af7e3c6357b99d7678c26c7a2
4
+ data.tar.gz: 828af95552ce471ca273253326553c483421ea23
5
5
  SHA512:
6
- metadata.gz: f74e6b225327cd6698ad5fefb440f6d7fdac65f03cc5ef5a316fd8cff853739c5a116d6c613c31a343142246efa1fd2a4bfdbe1ae6d7b12ef899d85f3d39ec89
7
- data.tar.gz: bd8055ded3952b4029e44ec6710a52146fb54a04b2a6e89e3edcf1228b3fdda045270f62b82b1881b3cd6afb50b184fec644d73ac182dc504e63476a6d15ec90
6
+ metadata.gz: 679b54d84b1c9df920e8fa425532554c1ee4d9abc651c38bf222e74dcb9469548aad710656be78e5d7807bfad6d576cb60fba73c03887f426ffaf6ba6d8c310b
7
+ data.tar.gz: d36f9fee78e3fcd54a47d422f5bfa82fee2479e6ec47f7d2ffe560703ba09e063645017f0c490a2f4363472d70f59f3029dc5a6e79f935e3957c8e50c1095702
data/README.md CHANGED
@@ -10,7 +10,8 @@ It provides the following features:
10
10
  * Basic physics and collision checking
11
11
  * Animated objects
12
12
 
13
- More functionalities are coming. Feel free to contribute!
13
+ More functionalities are coming. Feel free to contribute! You can send feedback
14
+ to victordavidsantos@gmail.com.
14
15
 
15
16
  Please note:
16
17
 
data/lib/minigl/global.rb CHANGED
@@ -2,23 +2,28 @@ require 'gosu'
2
2
 
3
3
  module AGL
4
4
  Vector = Struct.new :x, :y
5
-
5
+
6
6
  class Rectangle
7
7
  attr_accessor :x, :y, :w, :h
8
-
8
+
9
9
  def initialize x, y, w, h
10
10
  @x = x; @y = y; @w = w; @h = h
11
11
  end
12
-
12
+
13
13
  def intersects r
14
14
  @x < r.x + r.w && @x + @w > r.x && @y < r.y + r.h && @y + @h > r.y
15
15
  end
16
16
  end
17
17
 
18
18
  class Game
19
- def self.initialize window, gravity = Vector.new(0, 1)
19
+ def self.initialize window, gravity = Vector.new(0, 1),
20
+ kb_held_delay = 40, kb_held_interval = 5,
21
+ double_click_delay = 8
20
22
  @@window = window
21
23
  @@gravity = gravity
24
+ @@kb_held_delay = kb_held_delay
25
+ @@kb_held_interval = kb_held_interval
26
+ @@double_click_delay = double_click_delay
22
27
 
23
28
  KB.initialize
24
29
  Mouse.initialize
@@ -27,10 +32,13 @@ module AGL
27
32
 
28
33
  def self.window; @@window; end
29
34
  def self.gravity; @@gravity; end
35
+ def self.kb_held_delay; @@kb_held_delay; end
36
+ def self.kb_held_interval; @@kb_held_interval; end
37
+ def self.double_click_delay; @@double_click_delay; end
30
38
  end
31
39
 
32
40
  #class JSHelper
33
-
41
+
34
42
  class KB
35
43
  def self.initialize
36
44
  @@keys = [
@@ -57,18 +65,18 @@ module AGL
57
65
  @@held_timer = {}
58
66
  @@held_interval = {}
59
67
  end
60
-
68
+
61
69
  def self.update
62
70
  @@held_timer.each do |k, v|
63
- if v < 40; @@held_timer[k] += 1
71
+ if v < Game.kb_held_delay; @@held_timer[k] += 1
64
72
  else
65
73
  @@held_interval[k] = 0
66
74
  @@held_timer.delete k
67
75
  end
68
76
  end
69
-
77
+
70
78
  @@held_interval.each do |k, v|
71
- if v < 5; @@held_interval[k] += 1
79
+ if v < Game.kb_held_interval; @@held_interval[k] += 1
72
80
  else; @@held_interval[k] = 0; end
73
81
  end
74
82
 
@@ -84,24 +92,24 @@ module AGL
84
92
  end
85
93
  end
86
94
  end
87
-
95
+
88
96
  def self.key_pressed? key
89
97
  @@prev_down.index(key).nil? and @@down.index(key)
90
98
  end
91
-
99
+
92
100
  def self.key_down? key
93
101
  @@down.index(key)
94
102
  end
95
-
103
+
96
104
  def self.key_released? key
97
105
  @@prev_down.index(key) and @@down.index(key).nil?
98
106
  end
99
-
107
+
100
108
  def self.key_held? key
101
- @@held_interval[key] == 5
109
+ @@held_interval[key] == Game.kb_held_interval
102
110
  end
103
111
  end
104
-
112
+
105
113
  class Mouse
106
114
  def self.initialize
107
115
  @@down = {}
@@ -109,17 +117,17 @@ module AGL
109
117
  @@dbl_click = {}
110
118
  @@dbl_click_timer = {}
111
119
  end
112
-
120
+
113
121
  def self.update
114
122
  @@prev_down = @@down.clone
115
123
  @@down.clear
116
124
  @@dbl_click.clear
117
-
125
+
118
126
  @@dbl_click_timer.each do |k, v|
119
- if v < 8; @@dbl_click_timer[k] += 1
127
+ if v < Game.double_click_delay; @@dbl_click_timer[k] += 1
120
128
  else; @@dbl_click_timer.delete k; end
121
129
  end
122
-
130
+
123
131
  k1 = [Gosu::MsLeft, Gosu::MsMiddle, Gosu::MsRight]
124
132
  k2 = [:left, :middle, :right]
125
133
  for i in 0..2
@@ -131,30 +139,30 @@ module AGL
131
139
  @@dbl_click_timer[k2[i]] = 0
132
140
  end
133
141
  end
134
-
142
+
135
143
  @@x = Game.window.mouse_x.round
136
144
  @@y = Game.window.mouse_y.round
137
145
  end
138
-
146
+
139
147
  def self.x; @@x; end
140
148
  def self.y; @@y; end
141
-
149
+
142
150
  def self.button_pressed? btn
143
151
  @@down[btn] and not @@prev_down[btn]
144
152
  end
145
-
153
+
146
154
  def self.button_down? btn
147
155
  @@down[btn]
148
156
  end
149
-
157
+
150
158
  def self.button_released? btn
151
159
  @@prev_down[btn] and not @@down[btn]
152
160
  end
153
-
161
+
154
162
  def self.double_click? btn
155
163
  @@dbl_click[btn]
156
164
  end
157
-
165
+
158
166
  def self.over? x, y, w, h
159
167
  @@x >= x and @@x < x + w and @@y >= y and @@y < y + h
160
168
  end
@@ -171,7 +179,7 @@ module AGL
171
179
  @@fonts = Hash.new
172
180
  @@global_fonts = Hash.new
173
181
  end
174
-
182
+
175
183
  def self.img id, global = false, tileable = false, ext = ".png"
176
184
  if global; a = @@global_imgs; else; a = @@imgs; end
177
185
  return a[id] if a[id]
@@ -179,7 +187,7 @@ module AGL
179
187
  img = Gosu::Image.new Game.window, s, tileable
180
188
  a[id] = img
181
189
  end
182
-
190
+
183
191
  def self.imgs id, sprite_cols, sprite_rows, global = false, ext = ".png"
184
192
  if global; a = @@global_imgs; else; a = @@imgs; end
185
193
  return a[id] if a[id]
@@ -187,7 +195,7 @@ module AGL
187
195
  imgs = Gosu::Image.load_tiles Game.window, s, -sprite_cols, -sprite_rows, false
188
196
  a[id] = imgs
189
197
  end
190
-
198
+
191
199
  def self.tileset id, tile_width = 32, tile_height = 32, global = false, ext = ".png"
192
200
  if global; a = @@global_tilesets; else; a = @@tilesets; end
193
201
  return a[id] if a[id]
@@ -195,7 +203,7 @@ module AGL
195
203
  tileset = Gosu::Image.load_tiles Game.window, s, tile_width, tile_height, true
196
204
  a[id] = tileset
197
205
  end
198
-
206
+
199
207
  def self.sound id, global = false, ext = ".wav"
200
208
  if global; a = @@global_sounds; else; a = @@sounds; end
201
209
  return a[id] if a[id]
@@ -203,7 +211,7 @@ module AGL
203
211
  sound = Gosu::Sample.new Game.window, s
204
212
  a[id] = sound
205
213
  end
206
-
214
+
207
215
  def self.song id, global = false, ext = ".ogg"
208
216
  if global; a = @@global_sounds; else; a = @@sounds; end
209
217
  return a[id] if a[id]
@@ -219,11 +227,11 @@ module AGL
219
227
  font = Gosu::Font.new Game.window, s, size
220
228
  a[id] = font
221
229
  end
222
-
230
+
223
231
  # def self.text id
224
232
  # G.texts[G.lang][id.to_sym]
225
233
  # end
226
-
234
+
227
235
  def self.clear
228
236
  @@imgs.clear
229
237
  @@tilesets.clear
data/test/game.rb CHANGED
@@ -4,10 +4,11 @@ include AGL
4
4
  class MyGame < Gosu::Window
5
5
  def initialize
6
6
  super 800, 600, false # creating a 800 x 600 window, not full screen
7
- Game.initialize self # initializing MiniGL for this window
7
+ Game.initialize self, Vector.new(0, 1), 10, 2, 20
8
8
 
9
9
  @img = Res.img :img1
10
10
  @font = Res.font :font1, 20
11
+ @writer = TextHelper.new @font, 5
11
12
  @x = 0
12
13
  @y = 0
13
14
  end
@@ -18,13 +19,13 @@ class MyGame < Gosu::Window
18
19
 
19
20
  def update
20
21
  KB.update
21
- @y -= 1 if KB.key_down? Gosu::KbUp
22
+ @y -= 1 if KB.key_held? Gosu::KbUp
22
23
  @x += 1 if KB.key_down? Gosu::KbRight
23
- @y += 1 if KB.key_down? Gosu::KbDown
24
+ @y += 1 if KB.key_held? Gosu::KbDown
24
25
  @x -= 1 if KB.key_down? Gosu::KbLeft
25
26
 
26
27
  Mouse.update
27
- if Mouse.button_pressed? :left
28
+ if Mouse.double_click? :left
28
29
  @x = Mouse.x - @img.width / 2
29
30
  @y = Mouse.y - @img.height / 2
30
31
  end
@@ -32,7 +33,10 @@ class MyGame < Gosu::Window
32
33
 
33
34
  def draw
34
35
  @img.draw @x, @y, 0
35
- @font.draw "Testing fonts", 20, 560, 0
36
+ @writer.write_breaking "Testing multiple line text.\nThis should draw text "\
37
+ "across multiple lines, respecting a limit width. "\
38
+ "Furthermore, the text must be right-aligned.",
39
+ 780, 300, 300, :right
36
40
  end
37
41
  end
38
42
 
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: 1.2.0
4
+ version: 1.2.1
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: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -36,25 +36,25 @@ executables: []
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - data/font/font1.ttf
43
+ - data/img/image.png
44
+ - data/img/img1.png
45
+ - data/tileset/tileset1.png
39
46
  - lib/minigl.rb
40
47
  - lib/minigl/forms.rb
48
+ - lib/minigl/game_object.rb
41
49
  - lib/minigl/global.rb
42
- - lib/minigl/text.rb
43
50
  - lib/minigl/map.rb
44
51
  - lib/minigl/movement.rb
45
- - lib/minigl/game_object.rb
46
- - data/tileset/tileset1.png
47
- - data/img/image.png
48
- - data/img/img1.png
49
- - data/font/font1.ttf
50
- - Rakefile
51
- - LICENSE
52
- - README.md
52
+ - lib/minigl/text.rb
53
53
  - test/game.rb
54
54
  - test/game_object_tests.rb
55
- - test/res_tests.rb
56
55
  - test/map_tests.rb
57
56
  - test/movement_tests.rb
57
+ - test/res_tests.rb
58
58
  homepage: https://github.com/victords/minigl
59
59
  licenses:
60
60
  - GPL-2
@@ -75,13 +75,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.0.14
78
+ rubygems_version: 2.2.2
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: MiniGL
82
82
  test_files:
83
+ - test/movement_tests.rb
84
+ - test/map_tests.rb
83
85
  - test/game.rb
84
- - test/game_object_tests.rb
85
86
  - test/res_tests.rb
86
- - test/map_tests.rb
87
- - test/movement_tests.rb
87
+ - test/game_object_tests.rb