gamebox 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -2
  3. data/gamebox.gemspec +1 -1
  4. data/lib/gamebox/actors/collidable_debugger.rb +3 -4
  5. data/lib/gamebox/actors/label.rb +2 -0
  6. data/lib/gamebox/actors/score.rb +4 -25
  7. data/lib/gamebox/behaviors/animated_with_spritemap.rb +97 -0
  8. data/lib/gamebox/behaviors/collidable.rb +6 -14
  9. data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +2 -3
  10. data/lib/gamebox/behaviors/graphical.rb +2 -1
  11. data/lib/gamebox/behaviors/physical.rb +1 -1
  12. data/lib/gamebox/behaviors/positioned.rb +10 -4
  13. data/lib/gamebox/core/actor.rb +1 -1
  14. data/lib/gamebox/core/actor_factory.rb +2 -0
  15. data/lib/gamebox/core/arbiter.rb +2 -0
  16. data/lib/gamebox/core/font_style.rb +2 -2
  17. data/lib/gamebox/core/input_mapper.rb +4 -4
  18. data/lib/gamebox/core/resource_manager.rb +2 -2
  19. data/lib/gamebox/core/viewport.rb +78 -54
  20. data/lib/gamebox/spec/helper.rb +2 -3
  21. data/lib/gamebox/tasks/gamebox_tasks.rake +1 -90
  22. data/lib/gamebox/version.rb +2 -2
  23. data/lib/gamebox/views/graphical_actor_view.rb +11 -6
  24. data/spec/acceptance/input_mapper_spec.rb +14 -14
  25. data/spec/actors/label_spec.rb +13 -4
  26. data/spec/behaviors/collidable_spec.rb +2 -2
  27. data/spec/behaviors/positioned_spec.rb +27 -30
  28. data/spec/core/actor_spec.rb +2 -2
  29. data/spec/core/input_mapper_spec.rb +1 -1
  30. data/spec/core/resource_manager_spec.rb +20 -4
  31. data/spec/core/viewport_spec.rb +202 -108
  32. data/spec/views/graphical_actor_view_spec.rb +4 -1
  33. data/templates/app/Gemfile.tt +3 -1
  34. data/templates/app/Rakefile +51 -0
  35. data/templates/app/config/environment.rb +2 -1
  36. data/templates/app/config/game.yml +0 -1
  37. data/templates/app/spec/helper.rb +1 -1
  38. data/templates/app/src/views/.gitkeep +0 -0
  39. metadata +51 -97
@@ -23,6 +23,7 @@ module GameboxSpecHelpers
23
23
  before {
24
24
  @_beh_mock_names = Behavior.object_definition.component_names
25
25
  @actor = evented_stub(mock("actor_for_#{behavior_name}"))
26
+ @actor.stubs(has_attribute: nil, do_or_do_not: nil)
26
27
  @_mocks_created = create_mocks *(@_beh_mock_names - [:actor])
27
28
  @_mocks_created[:actor] = @actor
28
29
 
@@ -206,9 +207,7 @@ class EventedStub
206
207
  def method_missing(name, *args)
207
208
  @inner_stub.send name, *args
208
209
  end
209
- def fire(*args)
210
- super
211
- end
210
+ public :fire
212
211
  end
213
212
 
214
213
  module GameboxAcceptanceSpecHelpers
@@ -49,7 +49,7 @@ namespace :generate do
49
49
  File.open(File.join(File.dirname(__FILE__), "../../..", "/templates/#{generator_name}_template.erb")) do |io|
50
50
  template = ERB.new io.read
51
51
  instance_variable_set("@#{generator_name}_name", args["#{generator_name}_name"])
52
- File.open "#{APP_ROOT}src/#{ generator_name}s/#{args["#{generator_name}_name"]}_#{generator_name}.rb", "w" do |out|
52
+ File.open "#{APP_ROOT}src/#{ generator_name}s/#{args["#{generator_name}_name"]}.rb", "w" do |out|
53
53
  out.puts template.result binding
54
54
  end
55
55
  end
@@ -57,92 +57,3 @@ namespace :generate do
57
57
  end
58
58
  end
59
59
 
60
- namespace :dist do
61
- desc "Build a .app for your gamebox game"
62
- task :mac do
63
- GAME_NAME = "UntitledGame" unless defined?(GAME_NAME)
64
- # DL template os x app
65
- remote_file = "gosu-mac-wrapper-#{Gosu::VERSION}.tar.gz"
66
- mac_build = "#{APP_ROOT}build/mac"
67
- local_file = "#{mac_build}/#{remote_file}"
68
-
69
- require 'net/http'
70
- mkdir_p mac_build
71
- # if false
72
- Net::HTTP.start("www.libgosu.org") do |http|
73
- resp = http.get("/downloads/#{remote_file}")
74
- open(local_file, "wb") { |file| file.write(resp.body) }
75
- end
76
- # end
77
-
78
- # Expand it
79
- cd mac_build
80
- `tar xzf #{remote_file}`
81
- app_name = "#{GAME_NAME}.app"
82
- contents = "#{app_name}/Contents"
83
- resources = "#{contents}/Resources"
84
- dot_app_lib = "#{resources}/lib"
85
- gem_vendored = "#{mac_build}/#{resources}/gems"
86
-
87
- mv 'RubyGosu App.app', app_name
88
- %w(config data src).each do |src|
89
- cp_r "../../#{src}", resources
90
- end
91
-
92
- # TODO remove chingu / chipmunk / etc
93
- clean_em_out = %w(chingu chingu.rb).map{|it| "#{dot_app_lib}/#{it}"}
94
- rm_rf clean_em_out#, :verbose => true, :noop => true
95
-
96
- cd APP_ROOT
97
- p `bundle --system package`
98
- p `bundle package`
99
- p `bundle --deployment`
100
- mkdir_p gem_vendored
101
- rejects = %w(chipmunk gosu)
102
- Dir["vendor/bundle/ruby/**/gems/**/lib"].each do |gemmy|
103
- cp_r gemmy, gem_vendored unless rejects.any?{|exclude| gemmy.match exclude}
104
- end
105
-
106
- cd mac_build
107
- File.open "#{resources}/Main.rb", "w+" do |main|
108
- main.puts <<-EOS
109
- $: << "\#{File.dirname(__FILE__)}/config"
110
-
111
- $: << "\#{File.dirname(__FILE__)}/gems/lib"
112
-
113
- rejects = %w(spec src/app.rb vendor Main.rb)
114
- ok_dirs = %w(config gems src)
115
- REQUIRE_ALLS = ok_dirs.map{|dir| Dir.glob("\#{dir}/*.rb").reject{ |f| rejects.any?{|exclude| f.match exclude}}}.flatten
116
-
117
- require 'environment'
118
-
119
- GameboxApp.run ARGV, ENV
120
- EOS
121
- end
122
-
123
- # modify plist file
124
- # UntitledGame
125
- cd "#{GAME_NAME}.app/Contents"
126
- plist = File.open("Info.plist").read
127
- File.open("Info.plist", 'w+') do |f|
128
- f.puts plist.gsub "UntitledGame", GAME_NAME
129
- end
130
- end
131
-
132
- task :win do
133
- # create dist dir
134
- FileUtils.mkdir "#{APP_ROOT}dist" unless File.exist? "dist"
135
- # pull down windows app shell
136
- # expand into place
137
- sh 'cd #{APP_ROOT}dist; wget http://github.com/downloads/shawn42/gamebox/gamebox_app.zip; unzip gamebox_app.zip; mv gamebox_app/* .; rm gamebox_app.zip; rm -rf gamebox_app'
138
-
139
- # copy config/src/lib/data into dist/src
140
- %w{vendor config data }.each do |dir|
141
- FileUtils.cp_r dir, File.join('dist','src', dir) if File.exist? dir
142
- end
143
- FileUtils.cp_r 'src', File.join('dist', 'src')
144
-
145
- # create zip of dist?
146
- end
147
- end
148
-
@@ -1,8 +1,8 @@
1
1
  module Gamebox
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 4
5
- TINY = 1
4
+ MINOR = 5
5
+ TINY = 0
6
6
  RC = 0
7
7
 
8
8
  if RC > 0
@@ -17,6 +17,14 @@ define_actor_view :graphical_actor_view do
17
17
  x_scale = actor.do_or_do_not(:x_scale) || 1
18
18
  y_scale = actor.do_or_do_not(:y_scale) || 1
19
19
 
20
+ anchor_x = 0.5
21
+ anchor_y = 0.5
22
+ anchor_point = actor.do_or_do_not(:anchor) || :center
23
+ if anchor_point == :top_left
24
+ anchor_x = 0
25
+ anchor_y = 0
26
+ end
27
+
20
28
  if actor.do_or_do_not(:tiled)
21
29
  x_tiles = actor.num_x_tiles
22
30
  y_tiles = actor.num_y_tiles
@@ -25,16 +33,13 @@ define_actor_view :graphical_actor_view do
25
33
  x_tiles.times do |col|
26
34
  y_tiles.times do |row|
27
35
  # TODO why is there a nasty black line between these that jitters?
36
+ # is it float precision vs integers for location?
28
37
  img.draw offset_x+col*img_w, offset_y+row*img_h, z, x_scale, y_scale
29
38
  end
30
39
  end
31
40
  else
32
- rot = actor.do_or_do_not :rotation
33
- if rot
34
- img.draw_rot offset_x, offset_y, z, rot, 0.5, 0.5, x_scale, y_scale, color
35
- else
36
- img.draw offset_x, offset_y, z, x_scale, y_scale, color
37
- end
41
+ rot = actor.do_or_do_not(:rotation) || 0
42
+ img.draw_rot offset_x, offset_y, z, rot, anchor_x, anchor_y, x_scale, y_scale, color
38
43
  end
39
44
  end
40
45
 
@@ -8,33 +8,33 @@ describe "Using input mapper", acceptance: true do
8
8
  it 'sets actor state based on input' do
9
9
  game.stage do |stage| # instance of TestingStage
10
10
  foxy = create_actor :foxy
11
- foxy.input.map_input 'left' => :move_left,
12
- 'right' => :move_right,
13
- 'd' => :move_right
11
+ foxy.controller.map_controls 'left' => :move_left,
12
+ 'right' => :move_right,
13
+ 'd' => :move_right
14
14
  end
15
15
 
16
- input = game.actor(:foxy).input
17
- input.move_left?.should be_false
18
- input.move_right?.should be_false
16
+ controller = game.actor(:foxy).controller
17
+ controller.move_left?.should be_false
18
+ controller.move_right?.should be_false
19
19
 
20
20
  press_key KbLeft
21
21
  press_key KbD
22
22
 
23
- input.move_left?.should be_true
24
- input.move_right?.should be_true
23
+ controller.move_left?.should be_true
24
+ controller.move_right?.should be_true
25
25
 
26
26
  release_key KbD
27
- input.move_left?.should be_true
28
- input.move_right?.should be_false
27
+ controller.move_left?.should be_true
28
+ controller.move_right?.should be_false
29
29
 
30
30
 
31
31
  press_key KbRight
32
- input.move_left?.should be_true
33
- input.move_right?.should be_true
32
+ controller.move_left?.should be_true
33
+ controller.move_right?.should be_true
34
34
 
35
35
  release_key KbRight
36
- input.move_left?.should be_true
37
- input.move_right?.should be_false
36
+ controller.move_left?.should be_true
37
+ controller.move_right?.should be_false
38
38
  end
39
39
 
40
40
  end
@@ -12,10 +12,13 @@ describe :label do
12
12
  describe "#behavior" do
13
13
  subjectify_behavior(:label)
14
14
 
15
+ let(:stylish_font) { stub(calc_width: 22, height: 30) }
16
+
15
17
  before do
16
- @actor.stubs(has_attributes: nil, font_name: "fonty.ttf",
17
- font_size: 22, color: :red)
18
+ @actor.stubs(has_attributes: nil, font_name: "fonty.ttf", text: "some text",
19
+ font_size: 22, color: :red, :width= => nil, :height= => nil)
18
20
  @font_style_factory.stubs(:build)
21
+ @actor.stubs(:font_style).returns(stylish_font)
19
22
  end
20
23
 
21
24
  it 'sets up attributes on actor' do
@@ -27,8 +30,14 @@ describe :label do
27
30
  width: 0,
28
31
  height: 0,
29
32
  layer: 1)
30
- @font_style_factory.stubs(:build).with('fonty.ttf', 22, :red).returns(:stylish_font)
31
- @actor.expects(:has_attributes).with(font_style: :stylish_font)
33
+ @font_style_factory.stubs(:build).with('fonty.ttf', 22, :red).returns(stylish_font)
34
+ @actor.expects(:has_attributes).with(font_style: stylish_font)
35
+
36
+ stylish_font.stubs(:calc_width).with("some text").returns(:some_stylish_width)
37
+ stylish_font.stubs(:height).returns(:some_stylish_height)
38
+
39
+ @actor.expects(:width=).with(:some_stylish_width)
40
+ @actor.expects(:height=).with(:some_stylish_height)
32
41
 
33
42
  subject
34
43
  end
@@ -22,12 +22,12 @@ describe :collidable do
22
22
  let!(:actor) { subcontext[:actor] }
23
23
 
24
24
  before do
25
- @stage.stubs(:register_collidable)
25
+ @stage.stubs :register_collidable
26
26
  end
27
27
 
28
28
  describe "aabb shape" do
29
29
  let(:opts) do
30
- {:shape => :aabb,
30
+ {shape: :aabb,
31
31
  :cw_world_points => [
32
32
  [-15,10],[15,10],
33
33
  [15,-10], [-15,10]
@@ -1,52 +1,49 @@
1
1
  require 'helper'
2
2
 
3
3
  describe :positioned do
4
+ subjectify_behavior :positioned
4
5
 
5
- subject { subcontext[:behavior_factory].add_behavior actor, :positioned, opts }
6
- let(:director) { evented_stub(stub_everything('director')) }
7
- let(:subcontext) do
8
- it = nil
9
- Conject.default_object_context.in_subcontext{|ctx|it = ctx};
10
- it[:director] = director
11
- _mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
12
- _mocks.each do |k,v|
13
- it[k] = v
14
- end
15
- it
16
- end
17
- let!(:actor) { subcontext[:actor] }
18
6
  let(:opts) { {} }
7
+ before do
8
+ actor.stubs(:has_attributes)
9
+ end
19
10
 
20
11
  context "empty options" do
21
- it 'defines x,y on actor' do
12
+ it 'defines x,y,position on actor' do
13
+ actor.expects(:has_attributes).with(x: 0, y: 0, position: vec2(0,0))
22
14
  subject
23
- actor.x.should == 0
24
- actor.y.should == 0
25
15
  end
26
16
  end
27
17
 
28
- it 'keeps position up to date w/ x and y' do
18
+ it 'updates position on x change' do
29
19
  subject
30
- called = 0
31
- actor.when(:position_changed) do
32
- called += 1
33
- end
34
- actor.x = 99
35
- called.should == 1
36
20
 
37
- actor.y = 8
21
+ actor.expects(:position=).with(vec2(1,2))
22
+ actor.stubs(x: 1, y: 2)
23
+ actor.fire(:x_changed)
24
+ end
38
25
 
39
- called.should == 2
40
- actor.position.x.should == 99
41
- actor.position.y.should == 8
26
+ it 'updates position on y change' do
27
+ subject
28
+
29
+ actor.expects(:position=).with(vec2(1,2))
30
+ actor.stubs(x: 1, y: 2)
31
+ actor.fire(:y_changed)
42
32
  end
43
33
 
44
34
  context "options passed in" do
45
35
  let(:opts) { { x: 5, y: 8} }
46
- it 'defines x,y on actor' do
36
+ it 'defines x,y,position on actor' do
37
+ actor.expects(:has_attributes).with(x: 5, y: 8, position: vec2(5,8))
47
38
  subject
48
- actor.x.should == 5
49
- actor.y.should == 8
50
39
  end
51
40
  end
41
+
42
+ it "keeps x and y up to date if position changes" do
43
+ subject
44
+
45
+ actor.expects(:update_attributes).with(x: 2, y: 3)
46
+ actor.stubs(position: vec2(2,3))
47
+ actor.fire(:position_changed)
48
+ end
52
49
  end
@@ -48,10 +48,10 @@ describe Actor do
48
48
  end
49
49
  end
50
50
 
51
- describe "#input" do
51
+ describe "#controller" do
52
52
  it 'pulls an input mapper from the context' do
53
53
  @this_object_context.stubs(:[]).with(:input_mapper).returns(:mapz)
54
- subject.input.should == :mapz
54
+ subject.controller.should == :mapz
55
55
  end
56
56
  end
57
57
 
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
  describe InputMapper do
3
- describe '#map_input' do
3
+ describe '#map_controls' do
4
4
  it 'registers single up / down keys'
5
5
  it 'registers the same key to many actions'
6
6
  end
@@ -1,12 +1,28 @@
1
1
  require 'helper'
2
2
 
3
3
  describe 'A new resource manager' do
4
- let(:actor) { stub 'actor', actor_type: 'string' }
5
4
  subject { ResourceManager.new :wrapped_screen => stub(:screen => :fake_gosu) }
6
5
 
7
- it 'should load an actor image' do
8
- subject.expects(:load_image).with("string.png").returns(:surf)
9
- subject.load_actor_image(actor).should == :surf
6
+ context 'no image_name' do
7
+ let(:actor) { stub 'actor', actor_type: 'string', do_or_do_not: nil }
8
+
9
+ it 'should load an actor image' do
10
+ subject.expects(:load_image).with("string.png").returns(:surf)
11
+ subject.load_actor_image(actor).should == :surf
12
+ end
13
+ end
14
+
15
+ context 'with image_name' do
16
+ let(:actor) {
17
+ a = stub('actor')
18
+ a.stubs(:do_or_do_not).with(:image_name).returns('string')
19
+ a
20
+ }
21
+
22
+ it 'should load an actor image' do
23
+ subject.expects(:load_image).with("string.png").returns(:surf)
24
+ subject.load_actor_image(actor).should == :surf
25
+ end
10
26
  end
11
27
 
12
28
  end
@@ -20,29 +20,205 @@ describe Viewport do
20
20
  subject.x_offset.should == 0
21
21
  subject.y_offset.should == 0
22
22
  end
23
-
24
- it 'should center the viewport on an actor when follow' do
25
- actor = Vec.new 900, 200
26
- subject.follow actor
27
-
28
- subject.x_offset.should == -500
29
- subject.y_offset.should == 100
30
- subject.follow_target.should equal(actor)
23
+
24
+ describe "#stay_centered_on" do
25
+
26
+ it 'should center the viewport on an actor when stay_centered_on' do
27
+ actor = Vec.new 900, 200
28
+ subject.stay_centered_on actor
29
+
30
+ subject.x_offset.should == -500
31
+ subject.y_offset.should == 100
32
+ subject.follow_target.should equal(actor)
33
+ end
34
+
35
+ it 'should center the viewport on an actor (plus offset) when stay_centered_on' do
36
+ actor = Vec.new 900, 200
37
+ subject.stay_centered_on actor, x_offset: -40, y_offset: 20
38
+
39
+ subject.x_offset.should == -460
40
+ subject.y_offset.should == 80
41
+ subject.follow_target.should equal(actor)
42
+ end
43
+
44
+ it 'should stay_centered_on a target if target has gone right;down of its buffer' do
45
+ actor = Vec.new 900, 200
46
+ subject.stay_centered_on actor, x_chain_length: 100, y_chain_length: 200
47
+
48
+ subject.update 100
49
+ actor.x = 990
50
+ actor.y = 390
51
+
52
+ subject.update 100
53
+ subject.x_offset.should == -500
54
+ subject.y_offset.should == 100
55
+
56
+ actor.x = 1001
57
+ actor.y = 401
58
+ subject.update 100
59
+
60
+ subject.x_offset.should == -501
61
+ subject.y_offset.should == 99
62
+ end
63
+
64
+ it 'should stay_centered_on a target if target has gone left;up of its buffer' do
65
+ actor = Vec.new 900, 200
66
+ subject.expects(:fire).with(:scrolled).twice
67
+ subject.stay_centered_on actor, x_chain_length: 100, y_chain_length: 200
68
+
69
+ subject.update 100
70
+ actor.x = 810
71
+ actor.y = 10
72
+
73
+ subject.update 100
74
+ subject.x_offset.should == -500
75
+ subject.y_offset.should == 100
76
+
77
+ actor.x = 799
78
+ actor.y = -1
79
+ subject.update 100
80
+
81
+ subject.x_offset.should == -499
82
+ subject.y_offset.should == 101
83
+ end
84
+
85
+ it 'should respect the speed setting' do
86
+ actor = Vec.new 900, 200
87
+ subject.speed = 0.5
88
+ subject.stay_centered_on actor, x_chain_length: 100, y_chain_length: 200
89
+
90
+ subject.update 100
91
+ actor.x = 990
92
+ actor.y = 390
93
+
94
+ subject.update 100
95
+ subject.x_offset.should == -500
96
+ subject.y_offset.should == 100
97
+
98
+ actor.x = 1002
99
+ actor.y = 402
100
+ subject.update 100
101
+
102
+ subject.x_offset.should == -501
103
+ subject.y_offset.should == 99
104
+
105
+ end
106
+
107
+ it 'should fire :scrolled event when targeting an actor' do
108
+ actor = Vec.new 900, 200
109
+ subject.expects(:fire).with(:scrolled)
110
+ subject.stay_centered_on actor, x_chain_length: 100, y_chain_length: 200
111
+ end
112
+ end
113
+
114
+ describe "#follow" do
115
+
116
+ it 'should center the viewport on an actor when follow' do
117
+ actor = Vec.new 900, 200
118
+ subject.follow actor
119
+
120
+ subject.x_offset.should == -500
121
+ subject.y_offset.should == 100
122
+ subject.follow_target.should equal(actor)
123
+ end
124
+
125
+ it 'should center the viewport on an actor (plus offset) when follow' do
126
+ actor = Vec.new 900, 200
127
+ subject.follow actor, [40,-20]
128
+
129
+ subject.x_offset.should == -460
130
+ subject.y_offset.should == 80
131
+ subject.follow_target.should equal(actor)
132
+ end
133
+
134
+ it 'should follow a target if target has gone right;down of its buffer' do
135
+ actor = Vec.new 900, 200
136
+ subject.follow actor, [0,0], [100,200]
137
+
138
+ subject.update 100
139
+ actor.x = 990
140
+ actor.y = 390
141
+
142
+ subject.update 100
143
+ subject.x_offset.should == -500
144
+ subject.y_offset.should == 100
145
+
146
+ actor.x = 1001
147
+ actor.y = 401
148
+ subject.update 100
149
+
150
+ subject.x_offset.should == -501
151
+ subject.y_offset.should == 99
152
+ end
153
+
154
+ it 'should follow a target if target has gone left;up of its buffer' do
155
+ actor = Vec.new 900, 200
156
+ subject.expects(:fire).with(:scrolled).twice
157
+ subject.follow actor, [0,0], [100,200]
158
+
159
+ subject.update 100
160
+ actor.x = 810
161
+ actor.y = 10
162
+
163
+ subject.update 100
164
+ subject.x_offset.should == -500
165
+ subject.y_offset.should == 100
166
+
167
+ actor.x = 799
168
+ actor.y = -1
169
+ subject.update 100
170
+
171
+ subject.x_offset.should == -499
172
+ subject.y_offset.should == 101
173
+ end
174
+
175
+ it 'should respect the speed setting' do
176
+ actor = Vec.new 900, 200
177
+ subject.speed = 0.5
178
+ subject.follow actor, [0,0], [100,200]
179
+
180
+ subject.update 100
181
+ actor.x = 990
182
+ actor.y = 390
183
+
184
+ subject.update 100
185
+ subject.x_offset.should == -500
186
+ subject.y_offset.should == 100
187
+
188
+ actor.x = 1002
189
+ actor.y = 402
190
+ subject.update 100
191
+
192
+ subject.x_offset.should == -501
193
+ subject.y_offset.should == 99
194
+
195
+ end
196
+
197
+ it 'should fire :scrolled event when targeting an actor' do
198
+ actor = Vec.new 900, 200
199
+ subject.expects(:fire).with(:scrolled)
200
+ subject.follow actor, [0,0], [100,200]
201
+ end
202
+
31
203
  end
32
-
33
- it 'should center the viewport on an actor (plus offset) when follow' do
34
- actor = Vec.new 900, 200
35
- subject.follow actor, [40,-20]
36
-
37
- subject.x_offset.should == -460
38
- subject.y_offset.should == 80
39
- subject.follow_target.should equal(actor)
204
+
205
+ it 'enforces speed is >= 0 and <= 1' do
206
+ subject.speed.should == 1
207
+
208
+ subject.speed = 0
209
+ subject.speed.should == 0
210
+
211
+ subject.speed = 2
212
+ subject.speed.should == 1
213
+
214
+ subject.speed = 0.1
215
+ subject.speed.should be_within(0.001).of(0.1)
40
216
  end
41
-
217
+
42
218
  it 'should respect parallax scrolling layers for offsets' do
43
219
  subject.x_offset = -200
44
220
  subject.y_offset = -300
45
-
221
+
46
222
  subject.x_offset(2).should == -100
47
223
  subject.y_offset(2).should == -150
48
224
  end
@@ -50,102 +226,20 @@ describe Viewport do
50
226
  it 'should return a zero offset on INFINITY' do
51
227
  subject.x_offset = -200
52
228
  subject.y_offset = -300
53
-
229
+
54
230
  subject.x_offset(Float::INFINITY).should == 0
55
231
  subject.y_offset(Float::INFINITY).should == 0
56
232
  end
57
-
58
- it 'shouldn\'t update anything unless following a target' do
233
+
234
+ it "shouldn't update anything unless following a target" do
59
235
  subject.x_offset = -200
60
236
  subject.y_offset = -300
61
-
237
+
62
238
  subject.update 3000
63
-
239
+
64
240
  subject.x_offset.should == -200
65
241
  subject.y_offset.should == -300
66
242
  end
67
-
68
- it 'should follow a target if target has gone right;down of its buffer' do
69
- actor = Vec.new 900, 200
70
- subject.follow actor, [0,0], [100,200]
71
-
72
- subject.update 100
73
- actor.x = 990
74
- actor.y = 390
75
-
76
- subject.update 100
77
- subject.x_offset.should == -500
78
- subject.y_offset.should == 100
79
-
80
- actor.x = 1001
81
- actor.y = 401
82
- subject.update 100
83
-
84
- subject.x_offset.should == -501
85
- subject.y_offset.should == 99
86
- end
87
-
88
- it 'should follow a target if target has gone left;up of its buffer' do
89
- actor = Vec.new 900, 200
90
- subject.expects(:fire).with(:scrolled).twice
91
- subject.follow actor, [0,0], [100,200]
92
-
93
- subject.update 100
94
- actor.x = 810
95
- actor.y = 10
96
-
97
- subject.update 100
98
- subject.x_offset.should == -500
99
- subject.y_offset.should == 100
100
-
101
- actor.x = 799
102
- actor.y = -1
103
- subject.update 100
104
-
105
- subject.x_offset.should == -499
106
- subject.y_offset.should == 101
107
- end
108
-
109
- it 'should respect the speed setting' do
110
- actor = Vec.new 900, 200
111
- subject.speed = 0.5
112
- subject.follow actor, [0,0], [100,200]
113
-
114
- subject.update 100
115
- actor.x = 990
116
- actor.y = 390
117
-
118
- subject.update 100
119
- subject.x_offset.should == -500
120
- subject.y_offset.should == 100
121
-
122
- actor.x = 1002
123
- actor.y = 402
124
- subject.update 100
125
-
126
- subject.x_offset.should == -501
127
- subject.y_offset.should == 99
128
-
129
- end
130
-
131
- it 'enforces speed is >= 0 and <= 1' do
132
- subject.speed.should == 1
133
-
134
- subject.speed = 0
135
- subject.speed.should == 0
136
-
137
- subject.speed = 2
138
- subject.speed.should == 1
139
-
140
- subject.speed = 0.1
141
- subject.speed.should be_within(0.001).of(0.1)
142
- end
143
-
144
- it 'should fire :scrolled event when targeting an actor' do
145
- actor = Vec.new 900, 200
146
- subject.expects(:fire).with(:scrolled)
147
- subject.follow actor, [0,0], [100,200]
148
- end
149
243
 
150
244
  describe "#bounds" do
151
245
  it 'returns the bounds as [x1,y1,x2,y2]' do
@@ -157,9 +251,9 @@ describe Viewport do
157
251
  bounds = subject.bounds
158
252
  bounds.left.should == 10
159
253
  bounds.top.should == 100
160
- bounds.width.should == 810
161
- bounds.height.should == 700
254
+ bounds.width.should == 800
255
+ bounds.height.should == 600
162
256
  end
163
257
  end
164
-
258
+
165
259
  end