gosu_extensions 0.1.28 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.28
1
+ 0.2.0
@@ -0,0 +1,10 @@
1
+ class Environment < CP::Space
2
+
3
+ # Remove body and shape from self.
4
+ #
5
+ def remove shape
6
+ self.remove_body shape.body
7
+ self.remove_shape shape
8
+ end
9
+
10
+ end
@@ -199,7 +199,7 @@ class GameWindow < Gosu::Window
199
199
  @font = Gosu::Font.new self, self.font_name, self.font_size
200
200
  end
201
201
  def setup_environment
202
- @environment = CP::Space.new
202
+ @environment = Environment.new
203
203
  class << @environment
204
204
  attr_accessor :window
205
205
  end
@@ -2,6 +2,9 @@
2
2
  #
3
3
  class RemoveShapes
4
4
 
5
+ attr_reader :shapes
6
+ delegate :clear, :empty?, :to => :@shapes
7
+
5
8
  def initialize
6
9
  @shapes = []
7
10
  end
@@ -9,7 +12,7 @@ class RemoveShapes
9
12
  #
10
13
  #
11
14
  def add shape
12
- @shapes << shape
15
+ shapes << shape
13
16
  end
14
17
 
15
18
  #
@@ -23,13 +26,12 @@ class RemoveShapes
23
26
  # We would probably solve this by creating a separate @remove_bodies array to remove the Bodies
24
27
  # of the Stars that were gathered by the Player
25
28
  #
26
- return if @shapes.empty?
27
- @shapes.each do |shape|
28
- environment.remove_body shape.body
29
- environment.remove_shape shape
30
- moveables.remove shape
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.
31
33
  end
32
- @shapes.clear
34
+ clear
33
35
  end
34
36
 
35
37
  end
@@ -33,6 +33,7 @@ require 'remove_shapes'
33
33
  require 'wave'
34
34
  require 'waves'
35
35
  require 'scheduling'
36
+ require 'environment'
36
37
  require 'game_window'
37
38
  require 'control'
38
39
  require 'controls'
data/lib/units/thing.rb CHANGED
@@ -31,29 +31,45 @@ class Thing
31
31
  @layer || Layer::Players
32
32
  end
33
33
 
34
+ def mass
35
+ 0.1
36
+ end
37
+ def moment
38
+ 0.1
39
+ end
40
+
34
41
  class << self
35
- @@form_shape_class_mapping = { :circle => CP::Shape::Circle }
36
- def shape form
42
+ @@form_shape_class_mapping = {
43
+ :circle => CP::Shape::Circle, # :circle, radius
44
+ :poly => CP::Shape::Poly, # :poly, CP::Vec2.new(-22, -18), CP::Vec2.new(-22, -10), etc.
45
+ :segment => CP::Shape::Segment # :segment, ...
46
+ # TODO :image => # Special, just traces the extent of the image.
47
+ }
48
+ def shape form, *args
37
49
  form_shape_class_mapping = @@form_shape_class_mapping
50
+ define_method :radius do
51
+ args.first # TODO fix!
52
+ end
38
53
  InitializerHooks.append self do
39
54
  shape_class = form_shape_class_mapping[form]
40
55
  raise "Shape #{form} does not exist." unless shape_class
41
- @shape = shape_class.new(CP::Body.new(self.mass, self.moment), self.radius, CP::Vec2.new(0.0, 0.0))
56
+
57
+ params = []
58
+ params << CP::Body.new(self.mass, self.moment)
59
+ params += args
60
+ params << CP::Vec2.new(0.0, 0.0)
61
+
62
+ @shape = shape_class.new *params
42
63
  end
43
64
  end
44
65
  def mass amount
45
66
  define_method :mass do
46
- amount || 1.0
67
+ amount
47
68
  end
48
69
  end
49
70
  def moment amount
50
71
  define_method :moment do
51
- amount || 1.0
52
- end
53
- end
54
- def radius amount
55
- define_method :radius do
56
- amount || 10.0
72
+ amount
57
73
  end
58
74
  end
59
75
 
@@ -0,0 +1,53 @@
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
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 28
9
- version: 0.1.28
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-09 00:00:00 +02:00
17
+ date: 2010-04-11 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - generator/gogogosu.rb
56
56
  - lib/core/control.rb
57
57
  - lib/core/controls.rb
58
+ - lib/core/environment.rb
58
59
  - lib/core/game_window.rb
59
60
  - lib/core/initializer_hooks.rb
60
61
  - lib/core/it_is_a.rb
@@ -126,6 +127,7 @@ test_files:
126
127
  - spec/lib/core/it_is_a_spec.rb
127
128
  - spec/lib/core/layer_spec.rb
128
129
  - spec/lib/core/moveables_spec.rb
130
+ - spec/lib/core/remove_shapes_spec.rb
129
131
  - spec/lib/core/trait_spec.rb
130
132
  - spec/lib/core/traits_spec.rb
131
133
  - spec/lib/extensions/module_spec.rb