gosu_extensions 0.3.6 → 0.3.7

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
@@ -8,15 +8,27 @@ module InitializerHooks
8
8
  self.hooks = {}
9
9
 
10
10
  # Runs the hooks for this instance for
11
- # each class and superclass up to Sprite.
11
+ # each class and superclass from Sprite on down.
12
12
  #
13
13
  def after_initialize
14
- self.class.ancestors.each do |klass|
15
- run_hooks_for klass
16
- break if klass == Sprite
17
- end
14
+ relevant_ancestors.each { |klass| run_hooks_for klass }
15
+ end
16
+
17
+ # Relevant ancestors for self.
18
+ #
19
+ def relevant_ancestors
20
+ ancestors = self.class.ancestors
21
+ sprite? ? ancestors[0..ancestors.index(Sprite)] : ancestors[0..0]
18
22
  end
19
23
 
24
+ # Is this class a sprite?
25
+ #
26
+ def sprite?
27
+ is_a? Sprite
28
+ end
29
+
30
+ # Get and run the hooks for the class.
31
+ #
20
32
  def run_hooks_for klass
21
33
  hooks = InitializerHooks.hooks[klass]
22
34
  hooks && hooks.each do |hook|
data/lib/units/sprite.rb CHANGED
@@ -42,7 +42,12 @@ class Sprite
42
42
  # Default rotation is upwards.
43
43
  #
44
44
  def rotation
45
- @rotation || -Rotation::Half
45
+ @rotation || -Rotation::Quarter
46
+ end
47
+ #
48
+ #
49
+ def rotation= rotation
50
+ @rotation = rotation % (2*Math::PI)
46
51
  end
47
52
 
48
53
  class << self
@@ -60,7 +65,7 @@ class Sprite
60
65
  def rotation amount = nil, &block
61
66
  block ||= lambda { amount }
62
67
  InitializerHooks.append self do
63
- self.rotation = block[]
68
+ self.rotation = block.call
64
69
  end
65
70
  end
66
71
  def random_rotation
@@ -154,12 +159,6 @@ class Sprite
154
159
  #
155
160
  def moved; end
156
161
 
157
- #
158
- #
159
- def rotation= rotation
160
- @rotation = rotation % (2*Math::PI)
161
- end
162
-
163
162
  # Movement rules
164
163
  #
165
164
  # Note: Use these in method move.
data/lib/units/thing.rb CHANGED
@@ -20,6 +20,7 @@ class Thing < Sprite
20
20
  end
21
21
 
22
22
  class << self
23
+
23
24
  @@form_shape_class_mapping = {
24
25
  :circle => CP::Shape::Circle, # :circle, radius
25
26
  :poly => CP::Shape::Poly, # :poly, CP::Vec2.new(-22, -18), CP::Vec2.new(-22, -10), etc.
@@ -38,6 +39,8 @@ class Thing < Sprite
38
39
  params << CP::Vec2.new(0.0, 0.0) unless CP::Vec2 === args.first
39
40
 
40
41
  @shape = shape_class.new *params
42
+ @shape.body.a = -Rotation::Quarter # default rotation
43
+ @shape
41
44
  end
42
45
  end
43
46
  def mass amount
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 6
9
- version: 0.3.6
8
+ - 7
9
+ version: 0.3.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke