gosu_extensions 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.23
1
+ 0.1.24
@@ -28,7 +28,8 @@ class GameWindow < Gosu::Window
28
28
  :gravity_vector
29
29
  attr_reader :environment,
30
30
  :moveables,
31
- :font
31
+ :font,
32
+ :scheduling
32
33
  attr_accessor :background_path,
33
34
  :background_hard_borders
34
35
 
@@ -46,15 +47,17 @@ class GameWindow < Gosu::Window
46
47
  setup_background
47
48
 
48
49
  setup_steps
49
- setup_waves
50
50
  setup_scheduling
51
51
  setup_font
52
52
 
53
53
  setup_containers
54
54
 
55
55
  setup_environment
56
+
56
57
  setup_enemies
57
58
  setup_players
59
+ setup_waves
60
+
58
61
  setup_collisions
59
62
 
60
63
  install_main_loop
@@ -158,6 +161,9 @@ class GameWindow < Gosu::Window
158
161
  end
159
162
  end
160
163
 
164
+ # Setup methods
165
+ #
166
+
161
167
  def setup_window
162
168
  self.caption = self.class.caption || ""
163
169
  end
@@ -180,14 +186,12 @@ class GameWindow < Gosu::Window
180
186
  end
181
187
  def setup_containers
182
188
  @players = []
189
+ @waves = Waves.new self, @scheduling
183
190
  end
184
191
  def setup_steps
185
192
  @step = 0
186
193
  @dt = 1.0 / 60.0
187
194
  end
188
- def setup_waves
189
- @waves = Waves.new self
190
- end
191
195
  def setup_scheduling
192
196
  @scheduling = Scheduling.new
193
197
  end
@@ -202,12 +206,11 @@ class GameWindow < Gosu::Window
202
206
  @environment.window = self
203
207
  @environment.damping = -self.damping + 1 # recalculate the damping such that 0.0 has no damping.
204
208
  end
205
-
206
209
  # Override.
207
210
  #
208
211
  def setup_players; end
209
212
  def setup_enemies; end
210
-
213
+ def setup_waves; end
211
214
  #
212
215
  #
213
216
  # Example:
@@ -231,23 +234,20 @@ class GameWindow < Gosu::Window
231
234
  @controls << Control.new(self, object)
232
235
  end
233
236
 
234
- def next_step
235
- @step += 1
236
- @waves.check @step # TODO maybe the waves should move into the scheduling
237
- @scheduling.step
238
- end
239
-
240
-
241
- # Core methods used by the extensions "framework"
237
+ # Main loop methods.
242
238
  #
243
239
 
244
- # The main loop.
245
- #
246
240
  # TODO implement hooks.
247
241
  #
248
242
  def update
249
243
  @current_loop.call
250
244
  end
245
+ # Advances to the next step in the game.
246
+ #
247
+ def next_step
248
+ @step += 1
249
+ @scheduling.step
250
+ end
251
251
  # Each step, this is called to handle any input.
252
252
  #
253
253
  def handle_input
@@ -258,7 +258,31 @@ class GameWindow < Gosu::Window
258
258
  def step_physics
259
259
  @environment.step @dt
260
260
  end
261
+ # Moves each moveable.
262
+ #
263
+ def move
264
+ @moveables.move
265
+ end
266
+ # Handles the targeting process.
267
+ #
268
+ def targeting
269
+ @moveables.targeting
270
+ end
271
+ # Remove the shapes that are marked for removal.
272
+ #
273
+ def remove_shapes
274
+ @remove_shapes.remove_from @environment, @moveables
275
+ end
276
+
277
+ # Adding things.
278
+ #
261
279
 
280
+ # Moveables register themselves here.
281
+ #
282
+ def register moveable
283
+ @moveables.register moveable
284
+ moveable.add_to @environment
285
+ end
262
286
  # Things unregister themselves here.
263
287
  #
264
288
  # Note: Use as follows in a Thing.
@@ -273,7 +297,6 @@ class GameWindow < Gosu::Window
273
297
  def unregister thing
274
298
  remove thing.shape
275
299
  end
276
-
277
300
  # Remove this shape the next turn.
278
301
  #
279
302
  # Note: Internal use. Use unregister to properly remove a moveable.
@@ -281,6 +304,14 @@ class GameWindow < Gosu::Window
281
304
  def remove shape
282
305
  @remove_shapes.add shape
283
306
  end
307
+ # Is the thing registered?
308
+ #
309
+ def registered? thing
310
+ @moveables.registered? thing
311
+ end
312
+
313
+ # Scheduling
314
+ #
284
315
 
285
316
  # Run some code at relative time <time>.
286
317
  #
@@ -296,40 +327,16 @@ class GameWindow < Gosu::Window
296
327
  @scheduling.add time, &code
297
328
  end
298
329
 
299
- # Moves each moveable.
300
- #
301
- def move
302
- @moveables.move
303
- end
304
- # Handles the targeting process.
305
- #
306
- def targeting
307
- @moveables.targeting
308
- end
309
330
 
310
331
  # Utility Methods
311
332
  #
312
333
 
313
- #
314
- #
315
334
  # Example:
316
335
  # * x, y = uniform_random_position
317
336
  #
318
337
  def uniform_random_position
319
338
  [rand(self.width), rand(self.height)]
320
339
  end
321
-
322
- #
323
- #
324
- # Example:
325
- # imprint do
326
- # circle x, y, radius, :fill => true, :color => :black
327
- # end
328
- #
329
- def imprint &block
330
- @background_image.paint &block
331
- end
332
-
333
340
  # Randomly adds a Thing to a uniform random position.
334
341
  #
335
342
  def randomly_add type
@@ -337,32 +344,12 @@ class GameWindow < Gosu::Window
337
344
  thing.warp_to *uniform_random_position
338
345
  register thing
339
346
  end
340
-
341
- # Moveables register themselves here.
342
- #
343
- def register moveable
344
- @moveables.register moveable
345
- moveable.add_to @environment
346
- end
347
-
348
- # Remove the shapes that are marked for removal.
349
- #
350
- def remove_shapes
351
- @remove_shapes.remove_from @environment, @moveables
352
- end
353
-
354
347
  # Revives the player if not already in.
355
348
  #
356
349
  def revive player
357
350
  register player unless registered?(player) # player.registered?
358
351
  end
359
352
 
360
- # Is the thing registered?
361
- #
362
- def registered? thing
363
- @moveables.registered? thing
364
- end
365
-
366
353
  # Drawing methods
367
354
  #
368
355
 
@@ -395,6 +382,19 @@ class GameWindow < Gosu::Window
395
382
  def draw_ui
396
383
 
397
384
  end
385
+ #
386
+ #
387
+ # Example:
388
+ # imprint do
389
+ # circle x, y, radius, :fill => true, :color => :black
390
+ # end
391
+ #
392
+ def imprint &block
393
+ @background_image.paint &block
394
+ end
395
+
396
+ # Input handling.
397
+ #
398
398
 
399
399
  #
400
400
  #
@@ -16,8 +16,8 @@ class Scheduling
16
16
 
17
17
  # Adds a code block at time time.
18
18
  #
19
- def add time = 1, &code
20
- @threads << [time, code]
19
+ def add time = 1, proc = nil, &code
20
+ @threads << [time, code || proc]
21
21
  end
22
22
 
23
23
  # Does two things:
@@ -0,0 +1,35 @@
1
+ #
2
+ #
3
+ class Wave
4
+
5
+ attr_reader :generated_type, :execution_amount, :positioning_function
6
+
7
+ UniformRandom = lambda { |window, instance| instance.warp_to *window.uniform_random_position }
8
+ TopBorder = lambda { |window, instance| instance.warp_to rand(window.width), 0 }
9
+ RightBorder = lambda { |window, instance| instance.warp_to window.width, rand(window.height) }
10
+ BottomBorder = lambda { |window, instance| instance.warp_to rand(window.width), window.height }
11
+ LeftBorder = lambda { |window, instance| instance.warp_to 0, rand(window.height) }
12
+
13
+ #
14
+ #
15
+ # Note: The function needs a param generated_type.
16
+ #
17
+ def initialize generated_type, execution_amount = 1, &positioning_function
18
+ @generated_type = generated_type
19
+ @execution_amount = execution_amount
20
+ @positioning_function = positioning_function || UniformRandom
21
+ end
22
+
23
+ #
24
+ #
25
+ def for_scheduling window
26
+ lambda do
27
+ self.execution_amount.times do
28
+ instance = self.generated_type.new window
29
+ window.register instance
30
+ self.positioning_function.call(window, instance)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -2,33 +2,25 @@
2
2
  #
3
3
  class Waves
4
4
 
5
- #
6
- #
7
- def initialize window
8
- @window = window
9
- @waves = {}
10
- end
5
+ attr_reader :window, :scheduling
11
6
 
12
7
  #
13
8
  #
14
- def add amount, type, time
15
- @waves[time] ||= []
16
- @waves[time] << [amount, type]
9
+ def initialize window, scheduling
10
+ @window = window
11
+ @scheduling = scheduling
17
12
  end
18
13
 
19
14
  #
20
15
  #
21
- def check time
22
- if wave? time
23
- types = @waves[time]
24
- types.each { |amount, type| amount.times { @window.randomly_add type } }
25
- end
16
+ def add time, generated_type, times, &generation
17
+ add_wave time, Wave.new(generated_type, times, &generation)
26
18
  end
27
19
 
28
20
  #
29
21
  #
30
- def wave? time
31
- !@waves[time].nil?
22
+ def add_wave time, wave
23
+ scheduling.add time, wave.for_scheduling(window)
32
24
  end
33
25
 
34
26
  end
@@ -30,11 +30,12 @@ require 'it_is_a'
30
30
 
31
31
  require 'moveables'
32
32
  require 'remove_shapes'
33
+ require 'wave'
34
+ require 'waves'
33
35
  require 'scheduling'
34
36
  require 'game_window'
35
37
  require 'control'
36
38
  require 'controls'
37
- require 'waves'
38
39
  require 'layer'
39
40
 
40
41
  $:.unshift File.join(File.dirname(__FILE__), '/traits')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 23
9
- version: 0.1.23
8
+ - 24
9
+ version: 0.1.24
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-07 00:00:00 +02:00
17
+ date: 2010-04-08 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - lib/core/trait.rb
67
67
  - lib/core/traits.rb
68
68
  - lib/core/vector_utilities.rb
69
+ - lib/core/wave.rb
69
70
  - lib/core/waves.rb
70
71
  - lib/extensions/module.rb
71
72
  - lib/extensions/numeric.rb