gosu_extensions 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/gogogosu +33 -0
- data/lib/traits/shooter.rb +1 -2
- data/spec/lib/traits/shooter_spec.rb +215 -2
- data/spec/lib/traits/turnable_spec.rb +10 -10
- metadata +6 -6
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.19
|
data/bin/gogogosu
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# TODO remove
|
3
|
+
|
4
|
+
Signal.trap("INT") { puts; exit } # CTRL-C
|
5
|
+
|
6
|
+
File.open(File.join(File.dirname(__FILE__), '../VERSION')) do |f|
|
7
|
+
puts "Gosu Extensions #{f.read}"
|
8
|
+
end
|
9
|
+
|
10
|
+
application = ARGV.first
|
11
|
+
|
12
|
+
puts "Usage: gogogosu <application_name>" and exit(1) unless application
|
13
|
+
|
14
|
+
require File.dirname(__FILE__) + '/../generator/gogogosu'
|
15
|
+
|
16
|
+
generator = Generator::Gogogosu.new
|
17
|
+
|
18
|
+
generator.dir application do
|
19
|
+
generator.dir 'lib' do
|
20
|
+
|
21
|
+
end
|
22
|
+
generator.dir 'media' do
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
puts <<-START
|
28
|
+
Great!
|
29
|
+
|
30
|
+
Now proceed as follows:
|
31
|
+
1. cd #{application}
|
32
|
+
2.
|
33
|
+
START
|
data/lib/traits/shooter.rb
CHANGED
@@ -29,7 +29,6 @@ module Shooter extend Trait
|
|
29
29
|
def shooting_range
|
30
30
|
@shooting_range || @shooting_range = 300
|
31
31
|
end
|
32
|
-
|
33
32
|
def shooting_rate
|
34
33
|
@shooting_rate || @shooting_rate = (SUBSTEPS**2).to_f/2
|
35
34
|
end
|
@@ -90,7 +89,7 @@ module Shooter extend Trait
|
|
90
89
|
@muzzle_rotation = rotation
|
91
90
|
end
|
92
91
|
def shoot? target = nil
|
93
|
-
target.nil? ? true : target.distance_from(self)
|
92
|
+
target.nil? ? true : target.distance_from(self) <= self.shooting_range
|
94
93
|
end
|
95
94
|
def shoot target = nil
|
96
95
|
return unless shoot? target
|
@@ -3,12 +3,225 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
|
3
3
|
describe Shooter do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@
|
7
|
-
|
6
|
+
@window = stub :window
|
7
|
+
|
8
|
+
@shooter = test_class_with(Shooter).new @window
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'shoot' do
|
12
|
+
context 'shoot? false' do
|
13
|
+
before(:each) do
|
14
|
+
@shooter.stub! :shoot? => false
|
15
|
+
end
|
16
|
+
it 'should return without doing anything' do
|
17
|
+
@shooter.should_receive(:sometimes).never
|
18
|
+
|
19
|
+
@shooter.shoot
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'shoot?' do
|
25
|
+
context 'nil target given' do
|
26
|
+
it 'should return true' do
|
27
|
+
@shooter.shoot?(nil).should == true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context 'no target given' do
|
31
|
+
it 'should return true' do
|
32
|
+
@shooter.shoot?.should == true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'target given' do
|
36
|
+
before(:each) do
|
37
|
+
@shooter = test_class_with(Shooter) do
|
38
|
+
range 300
|
39
|
+
end.new @window
|
40
|
+
end
|
41
|
+
context 'distance equal the range' do
|
42
|
+
before(:each) do
|
43
|
+
@target = stub :target, :distance_from => 300
|
44
|
+
end
|
45
|
+
it 'should return true' do
|
46
|
+
@shooter.shoot?(@target).should == true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context 'distance smaller than range' do
|
50
|
+
before(:each) do
|
51
|
+
@target = stub :target, :distance_from => 200
|
52
|
+
end
|
53
|
+
it 'should return true' do
|
54
|
+
@shooter.shoot?(@target).should == true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context 'distance larger than range' do
|
58
|
+
before(:each) do
|
59
|
+
@target = stub :target, :distance_from => 600
|
60
|
+
end
|
61
|
+
it 'should return false' do
|
62
|
+
@shooter.shoot?(@target).should == false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'shot' do
|
69
|
+
it 'should return a new shot instance of type shot_type' do
|
70
|
+
shot_type = stub :shot_type, :new => :some_shot_instance
|
71
|
+
|
72
|
+
@shooter.stub! :shot_type => shot_type
|
73
|
+
|
74
|
+
@shooter.shot.should == :some_shot_instance
|
75
|
+
end
|
76
|
+
it 'should initialize the shot with its window' do
|
77
|
+
shot_type = stub :shot_type
|
78
|
+
@shooter.stub! :shot_type => shot_type
|
79
|
+
|
80
|
+
shot_type.should_receive(:new).once.with @window
|
81
|
+
|
82
|
+
@shooter.shot
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'muzzle_rotation' do
|
87
|
+
context 'default' do
|
88
|
+
it 'should use the default calculation' do
|
89
|
+
@shooter.stub! :rotation => :some_rotation
|
90
|
+
|
91
|
+
@shooter.muzzle_rotation.should == :some_rotation
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context 'non-default' do
|
95
|
+
before(:each) do
|
96
|
+
@shooter_class = test_class_with(Shooter) do
|
97
|
+
muzzle_rotation { :some_rotation_calculation_result }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
it 'should set the shooting_range' do
|
101
|
+
@shooter_class.new(:some_window).muzzle_rotation.should == :some_rotation_calculation_result
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'muzzle_velocity' do
|
107
|
+
context 'default' do
|
108
|
+
it 'should use the default calculation' do
|
109
|
+
@shooter.stub! :rotation_vector => :some_velocity
|
110
|
+
|
111
|
+
@shooter.muzzle_velocity.should == :some_velocity
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context 'non-default' do
|
115
|
+
before(:each) do
|
116
|
+
@shooter_class = test_class_with(Shooter) do
|
117
|
+
muzzle_velocity { :some_velocity_calculation_result }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
it 'should set the shooting_range' do
|
121
|
+
@shooter_class.new(:some_window).muzzle_velocity.should == :some_velocity_calculation_result
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'muzzle_position' do
|
127
|
+
context 'default' do
|
128
|
+
it 'should use the default calculation' do
|
129
|
+
@shooter.stub! :position => "position + ", :rotation_vector => "rotation", :radius => 3
|
130
|
+
|
131
|
+
@shooter.muzzle_position.should == "position + rotationrotationrotation"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
context 'non-default' do
|
135
|
+
before(:each) do
|
136
|
+
@shooter_class = test_class_with(Shooter) do
|
137
|
+
muzzle_position { :some_position_calculation_result }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
it 'should set the shooting_range' do
|
141
|
+
@shooter_class.new(:some_window).muzzle_position.should == :some_position_calculation_result
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'shoots' do
|
147
|
+
before(:each) do
|
148
|
+
@shooter_class = test_class_with(Shooter) do
|
149
|
+
shoots :some_type
|
150
|
+
end
|
151
|
+
end
|
152
|
+
it 'should set the shooting_range' do
|
153
|
+
@shooter_class.new(:some_window).shot_type.should == :some_type
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'frequency' do
|
158
|
+
before(:each) do
|
159
|
+
@shooter_class = test_class_with(Shooter) do
|
160
|
+
frequency 3.14
|
161
|
+
end
|
162
|
+
end
|
163
|
+
it 'should set the shooting_rate' do
|
164
|
+
@shooter_class.new(:some_window).shooting_rate.should be_close(16, 0.1)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'range' do
|
169
|
+
before(:each) do
|
170
|
+
@shooter_class = test_class_with(Shooter) do
|
171
|
+
range :some_range
|
172
|
+
end
|
173
|
+
end
|
174
|
+
it 'should set the shooting_range' do
|
175
|
+
@shooter_class.new(:some_window).shooting_range.should == :some_range
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe 'shooting_rate' do
|
180
|
+
context 'default' do
|
181
|
+
it 'should return the default' do
|
182
|
+
@shooter.shooting_rate.should == 50.0
|
183
|
+
end
|
184
|
+
end
|
185
|
+
context 'non-default' do
|
186
|
+
before(:each) do
|
187
|
+
@shooter.shooting_rate = :some_rate
|
188
|
+
end
|
189
|
+
it 'should return the set range' do
|
190
|
+
@shooter.shooting_rate.should == :some_rate
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'shooting_range' do
|
196
|
+
context 'default' do
|
197
|
+
it 'should return the default' do
|
198
|
+
@shooter.shooting_range.should == 300
|
199
|
+
end
|
200
|
+
end
|
201
|
+
context 'non-default' do
|
202
|
+
before(:each) do
|
203
|
+
@shooter.shooting_range = :some_range
|
204
|
+
end
|
205
|
+
it 'should return the set range' do
|
206
|
+
@shooter.shooting_range.should == :some_range
|
207
|
+
end
|
8
208
|
end
|
9
209
|
end
|
210
|
+
|
10
211
|
it "should define a constant Shoot" do
|
11
212
|
Shooter::Shoot.should == :shoot
|
12
213
|
end
|
214
|
+
it 'should have a reader shot_type' do
|
215
|
+
lambda { @shooter.shot_type }.should_not raise_error
|
216
|
+
end
|
217
|
+
it 'should have a writer shot_type' do
|
218
|
+
lambda { @shooter.shot_type = :some_shot_type }.should_not raise_error
|
219
|
+
end
|
220
|
+
it 'should have a writer shooting_range' do
|
221
|
+
lambda { @shooter.shooting_range = :some_range }.should_not raise_error
|
222
|
+
end
|
223
|
+
it 'should have a writer shooting_rate' do
|
224
|
+
lambda { @shooter.shooting_rate = :some_rate }.should_not raise_error
|
225
|
+
end
|
13
226
|
|
14
227
|
end
|
@@ -2,6 +2,15 @@ require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Turnable do
|
4
4
|
|
5
|
+
describe "Constants" do
|
6
|
+
it "should have turn left" do
|
7
|
+
Turnable::Left.should == :turn_left
|
8
|
+
end
|
9
|
+
it "should have turn right" do
|
10
|
+
Turnable::Right.should == :turn_right
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
5
14
|
context 'default' do
|
6
15
|
before(:each) do
|
7
16
|
@turnable = Class.new do
|
@@ -27,16 +36,7 @@ describe Turnable do
|
|
27
36
|
end.new
|
28
37
|
@turnable.stub! :rotation => 1.0
|
29
38
|
end
|
30
|
-
|
31
|
-
describe "Constants" do
|
32
|
-
it "should have turn left" do
|
33
|
-
Turnable::Left.should == :turn_left
|
34
|
-
end
|
35
|
-
it "should have turn right" do
|
36
|
-
Turnable::Right.should == :turn_right
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
39
|
+
|
40
40
|
describe "turn_speed" do
|
41
41
|
it "should have a defined turn_speed method" do
|
42
42
|
lambda { @turnable.turn_speed }.should_not raise_error
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 19
|
9
|
+
version: 0.1.19
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -14,8 +14,8 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
18
|
-
default_executable:
|
17
|
+
date: 2010-04-06 00:00:00 +02:00
|
18
|
+
default_executable: gogogosu
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: gosu
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
version_requirements: *id002
|
44
44
|
description: ""
|
45
45
|
email: florian.hanke@gmail.com
|
46
|
-
executables:
|
47
|
-
|
46
|
+
executables:
|
47
|
+
- gogogosu
|
48
48
|
extensions: []
|
49
49
|
|
50
50
|
extra_rdoc_files: []
|