gosu_extensions 0.2.9 → 0.3.0

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/lib/units/thing.rb CHANGED
@@ -14,6 +14,10 @@ class Thing < Sprite
14
14
  100.0
15
15
  end
16
16
 
17
+ def layer
18
+ Layer::Players
19
+ end
20
+
17
21
  class << self
18
22
  @@form_shape_class_mapping = {
19
23
  :circle => CP::Shape::Circle, # :circle, radius
@@ -76,12 +80,6 @@ class Thing < Sprite
76
80
 
77
81
  end
78
82
 
79
- # Unregister with the environment if destroyed.
80
- #
81
- def destroy!
82
- self.window.unregister self if super
83
- end
84
-
85
83
  # Add this thing to an environment.
86
84
  #
87
85
  # Note: Adds the body and the shape.
@@ -93,6 +91,7 @@ class Thing < Sprite
93
91
 
94
92
  # Movement and Position
95
93
  #
94
+ def move;end
96
95
 
97
96
  #
98
97
  #
@@ -3,24 +3,25 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Attachable do
4
4
 
5
5
  before(:each) do
6
- @attachable = test_class_with(Attachable).new stub(:window)
6
+ @window = stub :window, :things => []
7
+ @pod = stub :pod, :relative_position => :relative_position, :rotation => :some_rotation
8
+ @attachable = test_class_with(Attachable).new @window
9
+ @attachable.pod = @pod
7
10
  end
8
11
 
9
12
  describe "move_relative" do
10
13
  before(:each) do
11
14
  @attachable.stub! :position= => nil, :rotation= => nil
12
-
13
- @pod = stub :pod, :relative_position => :relative_position, :rotation => :some_rotation
14
15
  end
15
16
  it "should set the position to the pod's position plus the relative position" do
16
17
  @attachable.should_receive(:position=).once.with :relative_position
17
18
 
18
- @attachable.move_relative @pod
19
+ @attachable.move_relative
19
20
  end
20
21
  it "should set the rotation to the pod's rotation" do
21
22
  @attachable.should_receive(:rotation=).once.with :some_rotation
22
23
 
23
- @attachable.move_relative @pod
24
+ @attachable.move_relative
24
25
  end
25
26
  end
26
27
 
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Controllable do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @window = stub :window, :things => []
7
7
  end
8
8
 
9
9
  describe "controls" do
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Damaging do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @window = stub :window, :things => []
7
7
  end
8
8
 
9
9
  context 'damage given as block' do
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Imageable do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @window = stub :window, :things => []
7
7
  Resources.stub! :root => 'some/root'
8
8
  end
9
9
 
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Shooter do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @window = stub :window, :things => []
7
7
 
8
8
  @shooter = test_class_with(Shooter).new @window
9
9
  end
@@ -98,7 +98,7 @@ describe Shooter do
98
98
  end
99
99
  end
100
100
  it 'should set the shooting_range' do
101
- @shooter_class.new(:some_window).muzzle_rotation.should == :some_rotation_calculation_result
101
+ @shooter_class.new(@window).muzzle_rotation.should == :some_rotation_calculation_result
102
102
  end
103
103
  end
104
104
  end
@@ -118,7 +118,7 @@ describe Shooter do
118
118
  end
119
119
  end
120
120
  it 'should set the shooting_range' do
121
- @shooter_class.new(:some_window).muzzle_velocity.should == :some_velocity_calculation_result
121
+ @shooter_class.new(@window).muzzle_velocity.should == :some_velocity_calculation_result
122
122
  end
123
123
  end
124
124
  end
@@ -138,7 +138,7 @@ describe Shooter do
138
138
  end
139
139
  end
140
140
  it 'should set the shooting_range' do
141
- @shooter_class.new(:some_window).muzzle_position.should == :some_position_calculation_result
141
+ @shooter_class.new(@window).muzzle_position.should == :some_position_calculation_result
142
142
  end
143
143
  end
144
144
  end
@@ -150,7 +150,7 @@ describe Shooter do
150
150
  end
151
151
  end
152
152
  it 'should set the shooting_range' do
153
- @shooter_class.new(:some_window).shot_type.should == :some_type
153
+ @shooter_class.new(@window).shot_type.should == :some_type
154
154
  end
155
155
  end
156
156
 
@@ -161,7 +161,7 @@ describe Shooter do
161
161
  end
162
162
  end
163
163
  it 'should set the shooting_rate' do
164
- @shooter_class.new(:some_window).shooting_rate.should be_close(16, 0.1)
164
+ @shooter_class.new(@window).shooting_rate.should be_close(16, 0.1)
165
165
  end
166
166
  end
167
167
 
@@ -172,7 +172,7 @@ describe Shooter do
172
172
  end
173
173
  end
174
174
  it 'should set the shooting_range' do
175
- @shooter_class.new(:some_window).shooting_range.should == :some_range
175
+ @shooter_class.new(@window).shooting_range.should == :some_range
176
176
  end
177
177
  end
178
178
 
@@ -22,9 +22,8 @@ describe Shot do
22
22
 
23
23
  describe "shoot_from" do
24
24
  before(:each) do
25
- @window = stub :window, :null_object => true
26
- @shot.stub :position= => nil
27
- @shot.stub :window => @window
25
+ @shot.stub :position= => nil, :show => nil
26
+ @shot.stub :window => stub(:window)
28
27
  @shooter = stub :shooter, :muzzle_position => :some_muzzle_position
29
28
  end
30
29
  it "should return itself" do
@@ -40,9 +39,8 @@ describe Shot do
40
39
 
41
40
  @shot.shoot_from @shooter
42
41
  end
43
- it "should register itself with the window" do
44
- # TODO Or should it?
45
- @window.should_receive(:register).once.with @shot
42
+ it "should show itself" do
43
+ @shot.should_receive(:show).once
46
44
 
47
45
  @shot.shoot_from @shooter
48
46
  end
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe UserInterface do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @window = stub :window, :things => []
7
7
  @user_interface = test_class_with(UserInterface).new @window
8
8
  end
9
9
 
@@ -3,7 +3,8 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
3
3
  describe Thing do
4
4
 
5
5
  before(:each) do
6
- @window = stub :window
6
+ @things = stub :things
7
+ @window = stub :window, :things => @things
7
8
  @thing = Thing.new @window
8
9
  end
9
10
 
@@ -82,10 +83,10 @@ describe Thing do
82
83
  end
83
84
  context 'not yet destroyed' do
84
85
  before(:each) do
85
- @window.stub! :unregister => nil
86
+ @things.stub! :remove => nil
86
87
  end
87
- it "should unregister" do
88
- @window.should_receive(:unregister).once.with @thing
88
+ it "should remove" do
89
+ @things.should_receive(:remove).once.with @thing
89
90
 
90
91
  @thing.destroy!
91
92
  end
@@ -98,8 +99,8 @@ describe Thing do
98
99
  end
99
100
 
100
101
  describe "destroyed?" do
101
- it "should be false after creating the object" do
102
- @thing.destroyed?.should == false
102
+ it "should be nil after creating the object" do
103
+ @thing.destroyed?.should == nil
103
104
  end
104
105
  end
105
106
  describe "destroyed=" do
@@ -121,7 +122,7 @@ describe Thing do
121
122
  end
122
123
  end
123
124
  it "should be on the non default layer" do
124
- Thong.new(:some_window).layer.should == :non_default_layer
125
+ Thong.new(@window).layer.should == :non_default_layer
125
126
  end
126
127
  end
127
128
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 9
9
- version: 0.2.9
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
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-13 00:00:00 +02:00
18
+ date: 2010-04-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,11 +63,12 @@ files:
63
63
  - lib/core/initializer_hooks.rb
64
64
  - lib/core/it_is_a.rb
65
65
  - lib/core/layer.rb
66
- - lib/core/moveables.rb
67
- - lib/core/remove_shapes.rb
66
+ - lib/core/objects.rb
68
67
  - lib/core/resources.rb
69
68
  - lib/core/rotation.rb
70
69
  - lib/core/scheduling.rb
70
+ - lib/core/sprites.rb
71
+ - lib/core/things.rb
71
72
  - lib/core/trait.rb
72
73
  - lib/core/traits.rb
73
74
  - lib/core/vector_utilities.rb
@@ -135,8 +136,6 @@ test_files:
135
136
  - spec/lib/core/initializer_hooks_spec.rb
136
137
  - spec/lib/core/it_is_a_spec.rb
137
138
  - spec/lib/core/layer_spec.rb
138
- - spec/lib/core/moveables_spec.rb
139
- - spec/lib/core/remove_shapes_spec.rb
140
139
  - spec/lib/core/trait_spec.rb
141
140
  - spec/lib/core/traits_spec.rb
142
141
  - spec/lib/extensions/module_spec.rb
@@ -1,33 +0,0 @@
1
- # Holds the moveables that are moved and drawn.
2
- #
3
- class Moveables
4
-
5
- delegate :each, :to => :@elements
6
-
7
- def initialize elements = []
8
- @elements = elements
9
- end
10
-
11
- def register moveable
12
- @elements << moveable
13
- end
14
- def registered? moveable
15
- @elements.include? moveable
16
- end
17
- def remove shape
18
- @elements.delete_if { |element| element.shape == shape }
19
- end
20
-
21
- def draw
22
- @elements.each &:draw
23
- end
24
- def move
25
- @elements.each &:move
26
- end
27
- def targeting
28
- @elements.select { |m| m.respond_to? :target }.each do |gun|
29
- gun.target *@elements.select { |m| m.kind_of? Enemy }
30
- end
31
- end
32
-
33
- end
@@ -1,37 +0,0 @@
1
- #
2
- #
3
- class RemoveShapes
4
-
5
- attr_reader :shapes
6
- delegate :clear, :empty?, :to => :@shapes
7
-
8
- def initialize
9
- @shapes = []
10
- end
11
-
12
- #
13
- #
14
- def add shape
15
- shapes << shape
16
- end
17
-
18
- #
19
- #
20
- def remove_from environment, moveables
21
- # This iterator makes an assumption of one Shape per Star making it safe to remove
22
- # each Shape's Body as it comes up
23
- # If our Stars had multiple Shapes, as would be required if we were to meticulously
24
- # define their true boundaries, we couldn't do this as we would remove the Body
25
- # multiple times
26
- # We would probably solve this by creating a separate @remove_bodies array to remove the Bodies
27
- # of the Stars that were gathered by the Player
28
- #
29
- return if empty?
30
- shapes.each do |shape|
31
- environment.remove shape
32
- moveables.remove shape # TODO Should the environment be the owner of the moveables? Probably, yes.
33
- end
34
- clear
35
- end
36
-
37
- end
@@ -1,91 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
-
3
- describe Moveables do
4
-
5
- # TODO targeting
6
-
7
- describe "move" do
8
- before(:each) do
9
- @element1 = stub :element1
10
- @element2 = stub :element2
11
- @elements = [@element1, @element2]
12
- @moveables = Moveables.new @elements
13
- end
14
- it "should delegate to each" do
15
- @element1.should_receive(:move).once.with
16
- @element2.should_receive(:move).once.with
17
-
18
- @moveables.move
19
- end
20
- end
21
-
22
- describe "draw" do
23
- before(:each) do
24
- @element1 = stub :element1
25
- @element2 = stub :element2
26
- @elements = [@element1, @element2]
27
- @moveables = Moveables.new @elements
28
- end
29
- it "should delegate to each" do
30
- @element1.should_receive(:draw).once.with
31
- @element2.should_receive(:draw).once.with
32
-
33
- @moveables.draw
34
- end
35
- end
36
-
37
- describe "remove" do
38
- before(:each) do
39
- @ok = stub :ok, :shape => :the_shape_to_be_removed
40
- @wrong = stub :wrong, :shape => :not_the_right_shape
41
- @elements = [@wrong, @wrong, @ok, @wrong]
42
- @moveables = Moveables.new @elements
43
- end
44
- it "should remove the ok element" do
45
- @moveables.remove(:the_shape_to_be_removed).should == [@wrong, @wrong, @wrong]
46
- end
47
- end
48
-
49
- context 'default' do
50
- before(:each) do
51
- @elements = stub :elements
52
- @moveables = Moveables.new @elements
53
- end
54
-
55
- describe "registered?" do
56
- context 'not yet registered' do
57
- before(:each) do
58
- @elements.should_receive(:include?).once.with(:some_moveable).and_return false
59
- end
60
- it "should return false" do
61
- @moveables.registered?(:some_moveable).should == false
62
- end
63
- end
64
- context 'already registered' do
65
- before(:each) do
66
- @elements.should_receive(:include?).once.with(:some_moveable).and_return true
67
- end
68
- it "should return true" do
69
- @moveables.registered?(:some_moveable).should == true
70
- end
71
- end
72
- end
73
-
74
- describe "register" do
75
- it "should register a moveable" do
76
- @elements.should_receive(:<<).once.with :some_moveable
77
-
78
- @moveables.register :some_moveable
79
- end
80
- end
81
-
82
- describe "each" do
83
- it "should delegate each to its elements" do
84
- @elements.should_receive(:each).once
85
-
86
- @moveables.each
87
- end
88
- end
89
- end
90
-
91
- end
@@ -1,53 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '/../../spec_helper')
2
-
3
- describe RemoveShapes do
4
-
5
- before(:each) do
6
- @remove_shapes = RemoveShapes.new
7
- end
8
-
9
- it "should have no shapes, unprimed" do
10
- @remove_shapes.empty?.should == true
11
- end
12
-
13
- describe "add" do
14
- before(:each) do
15
- @shapes = stub :shapes
16
- @remove_shapes.stub! :shapes => @shapes
17
- end
18
- it "should << the shape to the shapes" do
19
- @shapes.should_receive(:<<).once.with :some_shape
20
-
21
- @remove_shapes.add :some_shape
22
- end
23
- end
24
-
25
- describe "remove_from" do
26
- context 'without shapes' do
27
- before(:each) do
28
- @remove_shapes.stub! :empty? => true
29
- end
30
- it "should just return" do
31
- @remove_shapes.should_receive(:shapes).never
32
-
33
- @remove_shapes.remove_from stub, stub
34
- end
35
- end
36
- context 'with shapes' do
37
- before(:each) do
38
- @shape = stub :shape
39
- @remove_shapes.stub! :empty? => false, :shapes => [@shape]
40
- end
41
- it "should remove the shapes from the environment and the moveables" do
42
- environment = stub :environment
43
- moveables = stub :moveables
44
-
45
- environment.should_receive(:remove).once.with @shape
46
- moveables.should_receive(:remove).once.with @shape
47
-
48
- @remove_shapes.remove_from environment, moveables
49
- end
50
- end
51
- end
52
-
53
- end