gosu_extensions 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -7,10 +7,18 @@ module InitializerHooks
7
7
  mattr_accessor :hooks # { class => [blocks] }
8
8
  self.hooks = {}
9
9
 
10
- # Calls the hooks in order of registration.
10
+ # Runs the hooks for this instance for
11
+ # each class and superclass up to Sprite.
11
12
  #
12
13
  def after_initialize
13
- hooks = InitializerHooks.hooks[self.class]
14
+ self.class.ancestors.each do |klass|
15
+ run_hooks_for klass
16
+ break if klass == Sprite
17
+ end
18
+ end
19
+
20
+ def run_hooks_for klass
21
+ hooks = InitializerHooks.hooks[klass]
14
22
  hooks && hooks.each do |hook|
15
23
  self.instance_eval &hook
16
24
  end
@@ -46,18 +46,16 @@ module Damaging extend Trait
46
46
  klass.extend ClassMethods
47
47
  end
48
48
 
49
- def initialize window
49
+ def initialize *args
50
50
  raise DamageMissingError.new unless respond_to?(:damage)
51
- super window
51
+ super *args
52
52
  end
53
53
 
54
54
  module ClassMethods
55
-
56
55
  def damage damage = nil, &block
57
- block = lambda { damage } unless block_given?
56
+ block ||= lambda { damage }
58
57
  define_method :damage, &block
59
58
  end
60
-
61
59
  end
62
60
 
63
61
  end
@@ -6,14 +6,16 @@ module Hitpoints extend Trait
6
6
  #
7
7
  manual <<-MANUAL
8
8
  Defines:
9
- hitpoints <some trait>
10
-
9
+ hitpoints <some number>
10
+ hitpoints { <some dynamically generated number> }
11
+
11
12
  Example:
12
13
  hitpoints 10_000
14
+ hitpoints { rand(100) + 50 }
13
15
 
14
16
  Call hit!(damage = 1) to remove hitpoints. This will call
15
17
  * callback hit if hitpoints are still higher than 0.
16
- * kill!, and if not available, destroy! if hitpoints are lower than 0.
18
+ * kill!, and if not available, destroy! if hitpoints are equal or lower than 0.
17
19
  MANUAL
18
20
 
19
21
  def self.included target_class
@@ -24,13 +26,15 @@ module Hitpoints extend Trait
24
26
 
25
27
  # Define the amount of hitpoints of the thing.
26
28
  #
27
- def hitpoints amount
29
+ def hitpoints amount = nil, &block
28
30
  include InstanceMethods
29
31
  class_inheritable_accessor :prototype_hitpoints
30
32
  self.prototype_hitpoints = amount
31
33
 
32
- hook = lambda { self.hitpoints = self.class.prototype_hitpoints }
33
- InitializerHooks.register self, &hook
34
+ InitializerHooks.register self do
35
+ self.hitpoints = amount || block.call
36
+ end
37
+
34
38
  end
35
39
 
36
40
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 5
9
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-21 00:00:00 +02:00
18
+ date: 2010-05-11 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency