gosu_extensions 0.3.3 → 0.3.4

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.3
1
+ 0.3.4
@@ -4,7 +4,7 @@ module Attachable extend Trait
4
4
 
5
5
  Detach = :detach
6
6
 
7
- attr_accessor :relative_position, :pod
7
+ attr_accessor :relative_position, :relative_rotation, :pod
8
8
 
9
9
  def detach
10
10
  pod.detach self
@@ -13,12 +13,18 @@ module Attachable extend Trait
13
13
  # Callback after detachment.
14
14
  #
15
15
  def detached; end
16
+ #
17
+ # after attachment
18
+ #
19
+ def attached
20
+ self.relative_rotation = pod.rotation + self.rotation
21
+ end
16
22
 
17
23
  # Move relative to the pod.
18
24
  #
19
25
  def move_relative
20
26
  self.position = pod.relative_position self
21
- self.rotation = pod.rotation unless self.kind_of? Turnable
27
+ self.rotation = pod.relative_rotation self unless self.kind_of? Turnable
22
28
  end
23
29
 
24
30
  end
data/lib/traits/pod.rb CHANGED
@@ -75,6 +75,7 @@ module Pod extend Trait
75
75
  attachment.extend Attachable # This is where Ruby shines.
76
76
  attachment.pod = self
77
77
  attachment.show
78
+ attachment.attached
78
79
  end
79
80
 
80
81
  #
@@ -96,6 +97,11 @@ module Pod extend Trait
96
97
  def relative_position attachment
97
98
  self.position + attachment.relative_position.rotate(self.rotation_vector)
98
99
  end
100
+ #
101
+ #
102
+ def relative_rotation attachment
103
+ self.rotation + attachment.relative_rotation
104
+ end
99
105
 
100
106
  #
101
107
  #
@@ -14,8 +14,12 @@ module Shooter extend Trait
14
14
  end
15
15
  end
16
16
  module Velocity
17
- def self.front initial_speed
18
- lambda { |_| self.rotation_vector*initial_speed }
17
+ def self.front initial_speed, random = nil
18
+ if random
19
+ lambda { |_| (self.rotation_vector + CP::Vec2.new(rand*random, rand*random))*initial_speed }
20
+ else
21
+ lambda { |_| self.rotation_vector*initial_speed }
22
+ end
19
23
  end
20
24
  end
21
25
  module Rotation
@@ -129,7 +133,7 @@ module Shooter extend Trait
129
133
  sometimes :loading, self.shooting_rate do
130
134
  projectile = self.shot.shoot_from self
131
135
  projectile.rotation = self.muzzle_rotation
132
- # projectile.velocity = self.muzzle_rotation.normalize
136
+ # projectile.velocity = self.muzzle_rotation.radians_to_vec2.normalize
133
137
  projectile.speed = self.muzzle_velocity * projectile.velocity + self.speed
134
138
  end
135
139
  end
@@ -4,7 +4,7 @@ describe Attachable do
4
4
 
5
5
  before(:each) do
6
6
  @window = stub :window, :things => []
7
- @pod = stub :pod, :relative_position => :relative_position, :rotation => :some_rotation
7
+ @pod = stub :pod, :relative_position => :relative_position, :relative_rotation => :relative_rotation, :rotation => :some_rotation
8
8
  @attachable = test_class_with(Attachable).new @window
9
9
  @attachable.pod = @pod
10
10
  end
@@ -19,7 +19,7 @@ describe Attachable do
19
19
  @attachable.move_relative
20
20
  end
21
21
  it "should set the rotation to the pod's rotation" do
22
- @attachable.should_receive(:rotation=).once.with :some_rotation
22
+ @attachable.should_receive(:rotation=).once.with :relative_rotation
23
23
 
24
24
  @attachable.move_relative
25
25
  end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
+
3
+ describe Pod do
4
+
5
+ # describe "instance" do
6
+ # before(:each) do
7
+ # @things = stub :things, :null_object => true
8
+ # @window = stub :window, :things => @things
9
+ # @pod = test_class_with(Pod).new @window
10
+ # end
11
+ # describe "attach" do
12
+ # before(:each) do
13
+ # @attachable = Class.new(Thing) do
14
+ # shape :circle, 8
15
+ # end.new @window
16
+ # end
17
+ # it "should not fail" do
18
+ # lambda { @pod.attach(@attachable, 10, 20) }.should_not raise_error
19
+ # end
20
+ # end
21
+ # end
22
+
23
+ # describe "class traits" do
24
+ # before(:each) do
25
+ # @window = stub :window, :things => []
26
+ # end
27
+ # describe "attach" do
28
+ # before(:each) do
29
+ # klass = Class.new(Thing) do
30
+ # shape :circle, 10
31
+ # end
32
+ # @pod = test_class_with(Pod) do
33
+ # attach klass, 10, 10
34
+ # end.new @window
35
+ # end
36
+ # it "should have one attachment" do
37
+ # @pod.attachments.should == []
38
+ # end
39
+ # end
40
+ # end
41
+
42
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 3
9
- version: 0.3.3
8
+ - 4
9
+ version: 0.3.4
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-16 00:00:00 +02:00
18
+ date: 2010-04-19 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -148,6 +148,7 @@ test_files:
148
148
  - spec/lib/traits/controllable_spec.rb
149
149
  - spec/lib/traits/damaging_spec.rb
150
150
  - spec/lib/traits/imageable_spec.rb
151
+ - spec/lib/traits/pod_spec.rb
151
152
  - spec/lib/traits/shooter_spec.rb
152
153
  - spec/lib/traits/short_lived_spec.rb
153
154
  - spec/lib/traits/shot_spec.rb