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 +1 -1
- data/lib/core/initializer_hooks.rb +17 -5
- data/lib/units/sprite.rb +7 -8
- data/lib/units/thing.rb +3 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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
|
11
|
+
# each class and superclass from Sprite on down.
|
12
12
|
#
|
13
13
|
def after_initialize
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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::
|
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
|