gosu_extensions 0.1.15 → 0.1.16

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.15
1
+ 0.1.16
data/lib/units/thing.rb CHANGED
@@ -22,6 +22,11 @@ class Thing
22
22
 
23
23
  # Default layer is Layer::Players.
24
24
  #
25
+ def self.layer layer
26
+ InitializerHooks.register self do
27
+ self.layer = layer
28
+ end
29
+ end
25
30
  def layer
26
31
  @layer || Layer::Players
27
32
  end
@@ -64,12 +69,6 @@ class Thing
64
69
  end
65
70
  end
66
71
 
67
- def layer layer
68
- InitializerHooks.register self do
69
- self.layer = layer
70
- end
71
- end
72
-
73
72
  # Plays a random sound of the given sounds.
74
73
  #
75
74
  def plays paths, options = {}
@@ -122,20 +121,22 @@ class Thing
122
121
  result
123
122
  end
124
123
 
125
- # Add this thing to a space.
124
+ # Add this thing to an environment.
126
125
  #
127
126
  # Note: Adds the body and the shape.
128
127
  #
129
- def add_to space
130
- space.add_body @shape.body
131
- space.add_shape @shape
128
+ def add_to environment
129
+ environment.add_body self.shape.body # could develop into adding multiple bodies
130
+ environment.add_shape self.shape
132
131
  end
133
132
 
134
- # TODO include size
133
+ # Draws its image.
135
134
  #
136
135
  def draw
137
- # size = self.momentary_size TODO
138
- self.image.draw_rot self.position.x, self.position.y, self.layer, self.drawing_rotation, 0.5, 0.5, 1.0, 1.0
136
+ self.image.draw_rot self.position.x, self.position.y, self.layer, self.drawing_rotation, 0.5, 0.5, *self.current_size
137
+ end
138
+ def current_size
139
+ [1.0, 1.0] # default implementation - change this to [1.0, 2.0] if you want a "light" version ;)
139
140
  end
140
141
 
141
142
  end
@@ -7,12 +7,107 @@ describe Thing do
7
7
  @thing = Thing.new @window
8
8
  end
9
9
 
10
+ describe "current_size" do
11
+ it "should return [1.0, 1.0] by default" do
12
+ @thing.current_size.should == [1.0, 1.0]
13
+ end
14
+ end
15
+
16
+ describe "draw" do
17
+ before(:each) do
18
+ @image = stub :image
19
+ @thing.stub! :image => @image,
20
+ :position => Struct.new(:x, :y).new(:some_x, :some_y),
21
+ :layer => :some_layer,
22
+ :drawing_rotation => :some_drawing_rotation,
23
+ :current_size => [:size_x, :size_y]
24
+ end
25
+ it "should delegate to the image" do
26
+ @image.should_receive(:draw_rot).once.with :some_x, :some_y, :some_layer, :some_drawing_rotation, 0.5, 0.5, :size_x, :size_y
27
+
28
+ @thing.draw
29
+ end
30
+ end
31
+
32
+ describe "add_to" do
33
+ before(:each) do
34
+ @environment = stub :environment, :null_object => true
35
+ @body = stub :body
36
+ @shape = stub :shape, :body => @body
37
+ @thing.stub! :shape => @shape
38
+ end
39
+ it "should add its body to the given environment" do
40
+ @environment.should_receive(:add_body).once.with @body
41
+
42
+ @thing.add_to @environment
43
+ end
44
+ it "should add its shape to the given environment" do
45
+ @environment.should_receive(:add_shape).once.with @shape
46
+
47
+ @thing.add_to @environment
48
+ end
49
+ end
50
+
51
+ describe "threaded" do
52
+ it "should delegate to the window" do
53
+ some_block = Proc.new {}
54
+
55
+ @window.should_receive(:threaded).once.with :some_time, &some_block
56
+
57
+ @thing.threaded :some_time, &some_block
58
+ end
59
+ end
60
+
10
61
  describe "window" do
11
62
  it "should return the window" do
12
63
  @thing.window.should == @window
13
64
  end
14
65
  end
15
66
 
67
+ describe "destroy!" do
68
+ context 'already destroyed' do
69
+ before(:each) do
70
+ @thing.destroyed = true
71
+ end
72
+ it "should not unregister" do
73
+ @window.should_receive(:unregister).never
74
+
75
+ @thing.destroy!
76
+ end
77
+ it "should not set destroyed" do
78
+ @thing.should_receive(:destroyed=).never
79
+
80
+ @thing.destroy!
81
+ end
82
+ end
83
+ context 'not yet destroyed' do
84
+ before(:each) do
85
+ @window.stub! :unregister => nil
86
+ end
87
+ it "should unregister" do
88
+ @window.should_receive(:unregister).once.with @thing
89
+
90
+ @thing.destroy!
91
+ end
92
+ it "should set destroyed" do
93
+ @thing.should_receive(:destroyed=).once.with true
94
+
95
+ @thing.destroy!
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "destroyed?" do
101
+ it "should be false after creating the object" do
102
+ @thing.destroyed?.should == false
103
+ end
104
+ end
105
+ describe "destroyed=" do
106
+ it "should exist" do
107
+ lambda { @thing.destroyed = true }.should_not raise_error
108
+ end
109
+ end
110
+
16
111
  describe "layer" do
17
112
  context 'default' do
18
113
  it "should be on the player layer" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 15
9
- version: 0.1.15
8
+ - 16
9
+ version: 0.1.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke