gosu_extensions 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  gemspec.email = "florian.hanke@gmail.com"
7
7
  gemspec.homepage = "http://www.github.com/floere/gosu_extensions"
8
8
  gemspec.description = ""
9
- gemspec.authors = ["Florian Hanke"]
9
+ gemspec.authors = ["Florian Hanke", "Severin Schoepke (various improvements)"]
10
10
  gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
11
11
  gemspec.files = FileList["[A-Z]*", "{generator,lib}/**/*"]
12
12
  gemspec.test_files = FileList["spec/**/*_spec.rb"]
@@ -26,4 +26,6 @@ require 'spec/rake/spectask'
26
26
  desc "Run all specs in spec directory"
27
27
  Spec::Rake::SpecTask.new(:spec) do |t|
28
28
  t.spec_files = FileList['spec/**/*_spec.rb']
29
- end
29
+ end
30
+
31
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -35,11 +35,10 @@ class Collision
35
35
  #
36
36
  def simple_package definition
37
37
  lambda do |this_shape, _|
38
- # TODO break if found.
39
- #
40
- window.moveables.each do |movable|
41
- if movable.shape == this_shape
42
- movable.instance_eval &definition
38
+ window.moveables.each do |moveable|
39
+ if moveable.shape == this_shape
40
+ moveable.instance_eval &definition
41
+ break
43
42
  end
44
43
  end
45
44
  end
@@ -50,15 +49,14 @@ class Collision
50
49
  def complex_package definition
51
50
  lambda do |this_shape, that_shape|
52
51
  this_that = Array.new(2)
53
- # TODO break if found
54
- #
55
- window.moveables.each do |movable|
56
- if movable.shape == this_shape
57
- this_that[0] = movable
52
+ window.moveables.each do |moveable|
53
+ if moveable.shape == this_shape
54
+ this_that[0] = moveable
58
55
  end
59
- if movable.shape == that_shape
60
- this_that[1] = movable
56
+ if moveable.shape == that_shape
57
+ this_that[1] = moveable
61
58
  end
59
+ break if this_that.all?
62
60
  end
63
61
  definition.call *this_that
64
62
  end
data/lib/core/control.rb CHANGED
@@ -13,7 +13,7 @@ class Control
13
13
  #
14
14
  #
15
15
  def mapping?
16
- @mapping && !@mapping.empty?
16
+ @mapping.present?
17
17
  end
18
18
 
19
19
  #
@@ -247,7 +247,7 @@ class GameWindow < Gosu::Window
247
247
  @environment.window = self
248
248
  @environment.damping = -self.damping + 1 # recalculate the damping such that 0.0 has no damping.
249
249
  end
250
- # Callbacks:
250
+ # Callbacks.
251
251
  #
252
252
  def setup_players; end
253
253
  def setup_enemies; end
@@ -24,8 +24,6 @@ class Scheduling
24
24
  # 1. Move one step in time.
25
25
  # 2. Execute all blocks with time 0.
26
26
  #
27
- # TODO Rewrite to be faster.
28
- #
29
27
  # FIXME - threads added while threads are handled!
30
28
  #
31
29
  def step
@@ -39,14 +39,20 @@ end
39
39
 
40
40
  module InstanceMethods
41
41
 
42
+ #
43
+ #
42
44
  def destroyed!
43
45
  stop_generating!
44
46
  end
45
47
 
48
+ #
49
+ #
46
50
  def stop_generating!
47
51
  @stop_generating = true
48
52
  end
49
53
 
54
+ #
55
+ #
50
56
  def generation klass, every_rate, til
51
57
  return lambda {} if @stop_generating
52
58
  lambda do
@@ -56,12 +62,17 @@ end
56
62
  end
57
63
  end
58
64
 
59
- def generate klass
60
- generated = klass.new self.window
61
- generated.warp self.position
62
- self.window.register generated
63
- end
64
-
65
+ end
66
+
67
+ # Returns the generated thing.
68
+ #
69
+ # TODO generate klass, times = 1, &after_generation ?
70
+ #
71
+ def generate klass
72
+ generated = klass.new self.window
73
+ generated.warp self.position
74
+ self.window.register generated
75
+ generated
65
76
  end
66
77
 
67
78
  end
@@ -47,6 +47,7 @@ module Hitpoints extend Trait
47
47
  def hit!
48
48
 
49
49
  end
50
+
50
51
  # Hit the thing with that much damage.
51
52
  #
52
53
  # hit!-s if hitpoints higher than 0
@@ -55,15 +56,8 @@ module Hitpoints extend Trait
55
56
  #
56
57
  def hit damage = 1
57
58
  self.hitpoints -= damage
58
- if self.hitpoints > 0
59
- hit!
60
- else
61
- if respond_to?(:kill!)
62
- kill!
63
- else
64
- destroy!
65
- end
66
- end
59
+ hit! if hitpoints > 0
60
+ respond_to?(:kill!) ? kill! : destroy! if hitpoints == 0
67
61
  end
68
62
 
69
63
  end
data/lib/traits/lives.rb CHANGED
@@ -43,14 +43,17 @@ module Lives extend Trait
43
43
  3
44
44
  end
45
45
 
46
+ # Override to handle killed!
47
+ #
48
+ def killed!
49
+
50
+ end
51
+
46
52
  # Does three things:
47
53
  # * Deduct 1 live.
48
54
  # * Check to see if the amount is 0.
49
55
  # * Calls #destroy! if yes.
50
56
  #
51
- def killed!
52
-
53
- end
54
57
  def kill!
55
58
  self.lives -= 1
56
59
  killed! if self.lives > 0
@@ -9,17 +9,7 @@ module Targeting
9
9
  # TODO fire arc
10
10
  #
11
11
  def acquire *targets
12
- closest = nil
13
- lowest_distance = nil
14
-
15
- targets.each do |target|
16
- distance = (target.position - self.position).length
17
- next if lowest_distance && distance > lowest_distance
18
- lowest_distance = distance
19
- closest = target
20
- end
21
-
22
- closest
12
+ targets.sort_by {|target| distance = (target.position - self.position).length }.first
23
13
  end
24
14
  end
25
15
 
data/lib/units/sprite.rb CHANGED
@@ -46,7 +46,7 @@ class Sprite
46
46
  def rotation amount = nil, &block
47
47
  # Override default.
48
48
  #
49
- to_execute = block_given? ? block : lambda { amount }
49
+ to_execute = block || lambda { amount }
50
50
  InitializerHooks.append self do
51
51
  self.rotation = to_execute[]
52
52
  end
metadata CHANGED
@@ -5,11 +5,12 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
13
+ - Severin Schoepke (various improvements)
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []