gamebox 0.3.4 → 0.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +38 -0
- data/Rakefile +1 -10
- data/TODO.txt +6 -6
- data/app_generators/gamebox_generator.rb +95 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/.gitignore +0 -0
- data/app_generators/templates/Gemfile +7 -0
- data/app_generators/templates/NEXT_STEPS.txt +1 -0
- data/{lib/gamebox/templates/template_app/README → app_generators/templates/README.rdoc} +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/Rakefile +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/config/boot.rb +0 -0
- data/app_generators/templates/config/environment.rb +30 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/config/game.yml +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/fonts/FONTS_GO_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/graphics/GRAPHICS_GO_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/music/MUSIC_GOES_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/sounds/SOUND_FX_GO_HERE +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_spec.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_view.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_view_spec.erb +0 -0
- data/app_generators/templates/script/generate +12 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/spec/helper.rb +0 -0
- data/app_generators/templates/src/actors/player.rb +8 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/src/app.rb +0 -0
- data/app_generators/templates/src/demo_stage.rb +7 -0
- data/bin/gamebox +8 -70
- data/component_generators/actor_generator.rb +17 -0
- data/docs/CODE_REVIEW +1 -1
- data/docs/REFACTOR_NOTES.txt +25 -0
- data/docs/getting_started.rdoc +1 -1
- data/gamebox.gemspec +7 -4
- data/lib/gamebox.rb +6 -3
- data/lib/gamebox/actors/collidable_debugger.rb +13 -15
- data/lib/gamebox/actors/curtain.rb +44 -43
- data/lib/gamebox/actors/emitter.rb +3 -42
- data/lib/gamebox/actors/fps.rb +13 -6
- data/lib/gamebox/actors/label.rb +42 -34
- data/lib/gamebox/actors/logo.rb +2 -4
- data/lib/gamebox/actors/score.rb +37 -27
- data/lib/gamebox/actors/svg_actor.rb +45 -32
- data/lib/gamebox/behaviors/animated.rb +39 -59
- data/lib/gamebox/behaviors/audible.rb +14 -14
- data/lib/gamebox/behaviors/collidable.rb +65 -36
- data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +2 -3
- data/lib/gamebox/behaviors/collidable/collidable_shape.rb +6 -4
- data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
- data/lib/gamebox/behaviors/emitting.rb +48 -0
- data/lib/gamebox/behaviors/graphical.rb +22 -56
- data/lib/gamebox/behaviors/layered.rb +8 -21
- data/lib/gamebox/behaviors/physical.rb +202 -213
- data/lib/gamebox/behaviors/positioned.rb +16 -0
- data/lib/gamebox/behaviors/projectile.rb +15 -0
- data/lib/gamebox/behaviors/visible.rb +16 -0
- data/lib/gamebox/core/aabb_helpers.rb +61 -0
- data/lib/gamebox/core/aabb_node.rb +118 -0
- data/lib/gamebox/core/aabb_tree.rb +137 -0
- data/lib/gamebox/core/actor.rb +102 -0
- data/lib/gamebox/core/actor_factory.rb +56 -0
- data/lib/gamebox/core/actor_view.rb +63 -0
- data/lib/gamebox/core/actor_view_factory.rb +40 -0
- data/lib/gamebox/{arbiter.rb → core/arbiter.rb} +31 -34
- data/lib/gamebox/{backstage.rb → core/backstage.rb} +0 -0
- data/lib/gamebox/core/behavior.rb +64 -0
- data/lib/gamebox/core/behavior_factory.rb +56 -0
- data/lib/gamebox/{class_finder.rb → core/class_finder.rb} +0 -0
- data/lib/gamebox/{config_manager.rb → core/config_manager.rb} +1 -1
- data/lib/gamebox/core/configuration.rb +39 -0
- data/lib/gamebox/core/core.rb +30 -0
- data/lib/gamebox/core/deprecated.rb +15 -0
- data/lib/gamebox/{director.rb → core/director.rb} +6 -11
- data/lib/gamebox/core/font_style.rb +26 -0
- data/lib/gamebox/core/font_style_factory.rb +11 -0
- data/lib/gamebox/core/game.rb +19 -0
- data/lib/gamebox/{hooked_gosu_window.rb → core/hooked_gosu_window.rb} +12 -6
- data/lib/gamebox/{input_manager.rb → core/input_manager.rb} +106 -99
- data/lib/gamebox/core/physics.rb +22 -0
- data/lib/gamebox/{physical_stage.rb → core/physics_manager.rb} +36 -30
- data/lib/gamebox/{resource_manager.rb → core/resource_manager.rb} +19 -18
- data/lib/gamebox/{sound_manager.rb → core/sound_manager.rb} +9 -7
- data/lib/gamebox/{stage.rb → core/stage.rb} +42 -80
- data/lib/gamebox/{stage_manager.rb → core/stage_manager.rb} +46 -53
- data/lib/gamebox/{stagehand.rb → core/stagehand.rb} +0 -0
- data/lib/gamebox/{svg_document.rb → core/svg_document.rb} +0 -0
- data/lib/gamebox/core/timer_manager.rb +50 -0
- data/lib/gamebox/{viewport.rb → core/viewport.rb} +2 -3
- data/lib/gamebox/{wrapped_screen.rb → core/wrapped_screen.rb} +12 -19
- data/lib/gamebox/gamebox_application.rb +7 -15
- data/lib/gamebox/lib/evented_attributes.rb +51 -0
- data/lib/gamebox/{ftor.rb → lib/ftor.rb} +0 -0
- data/lib/gamebox/lib/min_max_helpers.rb +10 -0
- data/lib/gamebox/lib/rect.rb +112 -54
- data/lib/gamebox/lib/yoda.rb +46 -0
- data/lib/gamebox/spec/helper.rb +317 -12
- data/lib/gamebox/stagehands/spatial_tree_stagehand.rb +61 -0
- data/lib/gamebox/version.rb +8 -3
- data/lib/gamebox/views/graphical_actor_view.rb +22 -29
- data/script/perf_aabb.rb +56 -0
- data/script/perf_array_access.rb +16 -0
- data/script/perf_collisions.rb +37 -18
- data/script/perf_struct_vs_array.rb +7 -7
- data/spec/acceptance/animation_spec.rb +65 -0
- data/spec/acceptance/basic_actor_lifecycle_spec.rb +92 -0
- data/spec/acceptance/built_in_collision_handling_spec.rb +55 -0
- data/spec/acceptance/chipmunk_collision_handling_spec.rb +83 -0
- data/spec/acceptance/fps_actor_spec.rb +40 -0
- data/spec/acceptance/pausing_spec.rb +61 -0
- data/spec/acceptance/timer_usage_spec.rb +53 -0
- data/spec/actors/emitter_spec.rb +5 -0
- data/spec/{label_spec.rb → actors/label_spec.rb} +1 -1
- data/spec/behaviors/animated_spec.rb +85 -0
- data/spec/behaviors/collidable_spec.rb +134 -0
- data/spec/{physical_spec.rb → behaviors/physical_spec.rb} +2 -1
- data/spec/behaviors/positioned_spec.rb +6 -0
- data/spec/behaviors/projectile_spec.rb +6 -0
- data/spec/core/aabb_tree_spec.rb +109 -0
- data/spec/core/actor_factory_spec.rb +44 -0
- data/spec/core/actor_spec.rb +78 -0
- data/spec/core/actor_view_spec.rb +53 -0
- data/spec/{arbiter_spec.rb → core/arbiter_spec.rb} +29 -30
- data/spec/core/backstage_spec.rb +37 -0
- data/spec/core/behavior_factory_spec.rb +50 -0
- data/spec/core/behavior_spec.rb +8 -0
- data/spec/core/configuration_spec.rb +8 -0
- data/spec/core/core_spec.rb +13 -0
- data/spec/core/font_style_factory_spec.rb +17 -0
- data/spec/core/font_style_spec.rb +41 -0
- data/spec/core/hooked_gosu_window_spec.rb +75 -0
- data/spec/core/input_manager_spec.rb +285 -0
- data/spec/core/physics_manager_spec.rb +11 -0
- data/spec/core/resource_manager_spec.rb +12 -0
- data/spec/core/stage_manager_spec.rb +140 -0
- data/spec/core/stage_spec.rb +73 -0
- data/spec/core/timer_manager_spec.rb +89 -0
- data/spec/{viewport_spec.rb → core/viewport_spec.rb} +6 -3
- data/spec/core/wrapped_screen_spec.rb +26 -0
- data/spec/fixtures/game.yml +7 -0
- data/spec/fixtures/snelpling/idle/1.png +0 -0
- data/spec/fixtures/snelpling/jump/1.png +0 -0
- data/spec/fixtures/snelpling/jump/2.png +0 -0
- data/spec/fixtures/snelpling/jump/3.png +0 -0
- data/spec/helper.rb +8 -0
- data/spec/{class_finder_spec.rb → lib/class_finder_spec.rb} +2 -1
- data/spec/stagehands/spatial_tree_stagehand_spec.rb +19 -0
- data/spec/views/graphical_actor_view_spec.rb +116 -0
- metadata +343 -144
- data/README.txt +0 -34
- data/lib/gamebox/actor.rb +0 -179
- data/lib/gamebox/actor_factory.rb +0 -57
- data/lib/gamebox/actor_view.rb +0 -44
- data/lib/gamebox/actors/spatial_debugger.rb +0 -62
- data/lib/gamebox/behavior.rb +0 -70
- data/lib/gamebox/behaviors/timed.rb +0 -33
- data/lib/gamebox/behaviors/updatable.rb +0 -12
- data/lib/gamebox/console_app.rb +0 -41
- data/lib/gamebox/gamebox_generator.rb +0 -32
- data/lib/gamebox/generators/actor_generator.rb +0 -43
- data/lib/gamebox/generators/view_generator.rb +0 -42
- data/lib/gamebox/physical_director.rb +0 -17
- data/lib/gamebox/physics.rb +0 -32
- data/lib/gamebox/spatial_bucket.rb +0 -9
- data/lib/gamebox/spatial_hash.rb +0 -194
- data/lib/gamebox/spatial_stagehand.rb +0 -80
- data/lib/gamebox/templates/template_app/Gemfile +0 -6
- data/lib/gamebox/templates/template_app/config/environment.rb +0 -23
- data/lib/gamebox/templates/template_app/config/stage_config.yml +0 -2
- data/lib/gamebox/templates/template_app/script/generate +0 -7
- data/lib/gamebox/templates/template_app/src/demo_stage.rb +0 -11
- data/lib/gamebox/templates/template_app/src/game.rb +0 -19
- data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -14
- data/script/perf_spatial_hash.rb +0 -64
- data/spec/actor_factory_spec.rb +0 -61
- data/spec/actor_spec.rb +0 -71
- data/spec/actor_view_spec.rb +0 -61
- data/spec/animated_spec.rb +0 -83
- data/spec/backstage_spec.rb +0 -45
- data/spec/behavior_spec.rb +0 -28
- data/spec/collidable_spec.rb +0 -135
- data/spec/emitter_spec.rb +0 -20
- data/spec/input_manager_spec.rb +0 -134
- data/spec/resource_manager_spec.rb +0 -13
- data/spec/spatial_hash_spec.rb +0 -119
- data/spec/spatial_stagehand_spec.rb +0 -93
- data/spec/stage_manager_spec.rb +0 -25
- data/spec/stage_spec.rb +0 -65
data/spec/backstage_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe 'A new backstage' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
@backstage = Backstage.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should construct' do
|
11
|
-
@backstage.should_not be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should return nil if not found' do
|
15
|
-
@backstage.get(:foo).should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should return the value if found' do
|
19
|
-
@backstage.set(:foo,:foo_val).should == :foo_val
|
20
|
-
@backstage.get(:foo).should == :foo_val
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should replace with new values' do
|
24
|
-
@backstage.set(:foo,:foo_val).should == :foo_val
|
25
|
-
@backstage.get(:foo).should == :foo_val
|
26
|
-
|
27
|
-
@backstage.set(:foo,:other_val).should == :other_val
|
28
|
-
@backstage.get(:foo).should == :other_val
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should properly offer bracket notation' do
|
32
|
-
@backstage[:foo] = :val
|
33
|
-
@backstage[:foo].should == :val
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should raise if an Actor strolls off backstage' do
|
37
|
-
class Foo < Actor
|
38
|
-
def initialize;end
|
39
|
-
end
|
40
|
-
foo = Foo.new
|
41
|
-
|
42
|
-
lambda{ @backstage[:foo] = foo }.should raise_error
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/spec/behavior_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe 'A new behavior' do
|
5
|
-
before do
|
6
|
-
@actor = stub
|
7
|
-
@target = Behavior.new @actor
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should auto-require behaviors that it depends on'
|
11
|
-
it 'should relegate properly' do
|
12
|
-
@target.expects(:foo).returns(:bar)
|
13
|
-
@target.relegates :foo
|
14
|
-
|
15
|
-
@actor.foo.should == :bar
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should un-relegate properly' do
|
19
|
-
@target.expects(:foo).returns(:bar)
|
20
|
-
@target.relegates :foo
|
21
|
-
@actor.foo.should == :bar
|
22
|
-
|
23
|
-
@target.removed
|
24
|
-
|
25
|
-
@actor.respond_to?(:foo).should be_false
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
data/spec/collidable_spec.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
class SizedActor < Actor
|
4
|
-
def width;12;end
|
5
|
-
def height;10;end
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'A new collidable behavior' do
|
9
|
-
before do
|
10
|
-
@stage = stub(:register_collidable => nil)
|
11
|
-
@actor_opts = {:actor_type => :actor, :stage=>@stage, :input=>"input", :resources=> :rm}
|
12
|
-
@actor = Actor.new @actor_opts
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
describe "aabb shape" do
|
17
|
-
before do
|
18
|
-
@behavior_opts = {:shape => :aabb,
|
19
|
-
:cw_world_points => [
|
20
|
-
[-15,10],[15,10],
|
21
|
-
[15,-10], [-15,10]
|
22
|
-
]}
|
23
|
-
@actor = SizedActor.new @actor_opts
|
24
|
-
@collidable = Collidable.new @actor, @behavior_opts
|
25
|
-
end
|
26
|
-
|
27
|
-
it "constructs based on points" do
|
28
|
-
@collidable.collidable_shape.should == :aabb
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "circle shape" do
|
33
|
-
before do
|
34
|
-
@behavior_opts = {:shape => :circle}
|
35
|
-
@collidable = Collidable.new @actor, @behavior_opts
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should recalculate_collidable_cache on update' do
|
39
|
-
@collidable.shape.expects(:recalculate_collidable_cache)
|
40
|
-
@collidable.update 4
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should relegate methods on actor' do
|
44
|
-
@collidable.expects(:width).returns(44)
|
45
|
-
@actor.width.should == 44
|
46
|
-
@collidable.expects(:height).returns(45)
|
47
|
-
@actor.height.should == 45
|
48
|
-
|
49
|
-
@collidable.expects(:collidable_shape).returns(:circlez)
|
50
|
-
@actor.collidable_shape.should == :circlez
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should calculate center point for circle' do
|
54
|
-
@actor.x = 3
|
55
|
-
@actor.y = 6
|
56
|
-
@collidable = Collidable.new @actor, :shape => :circle, :radius => 20
|
57
|
-
@collidable.center_x.should be_within(0.001).of(3)
|
58
|
-
@collidable.center_y.should be_within(0.001).of(6)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "polygon shape" do
|
63
|
-
it 'should calculate center point for polygon' do
|
64
|
-
@collidable = Collidable.new @actor, :shape => :polygon, :points => [[0,0],[10,7],[20,10]]
|
65
|
-
@collidable.center_x.should be_within(0.001).of(10)
|
66
|
-
@collidable.center_y.should be_within(0.001).of(5)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should translate points to world coords for poly' do
|
70
|
-
@actor.x = 10
|
71
|
-
@actor.y = 5
|
72
|
-
@collidable = Collidable.new @actor, :shape => :polygon, :points => [[0,0],[10,7],[20,10]]
|
73
|
-
@collidable.cw_world_points.should == [[10,5],[20,12],[30,15]]
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should translate lines to world coords lines' do
|
77
|
-
@collidable = Collidable.new @actor, :shape => :polygon, :points => [[0,0],[10,7],[20,10]]
|
78
|
-
|
79
|
-
@collidable.cw_world_lines.should == [
|
80
|
-
[[0,0],[10,7]],
|
81
|
-
[[10,7],[20,10]],
|
82
|
-
[[20,10],[0,0]]
|
83
|
-
]
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should translate world lines to edge normals' do
|
87
|
-
@collidable = Collidable.new @actor, :shape => :polygon,
|
88
|
-
:points => [[0,0],[10,7],[20,10]]
|
89
|
-
|
90
|
-
@collidable.cw_world_edge_normals.should == [
|
91
|
-
[-7,10], [-3,10], [10,-20]
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should cache calcs until reset' do
|
96
|
-
@collidable = Collidable.new @actor, :shape => :polygon,
|
97
|
-
:points => [[0,0],[10,7],[20,10]]
|
98
|
-
# prime the cache
|
99
|
-
@collidable.cw_world_points.should == [[0,0],[10,7],[20,10]]
|
100
|
-
@collidable.cw_world_lines.should == [
|
101
|
-
[[0,0],[10,7]],
|
102
|
-
[[10,7],[20,10]],
|
103
|
-
[[20,10],[0,0]]
|
104
|
-
]
|
105
|
-
@collidable.cw_world_edge_normals.should == [
|
106
|
-
[-7,10], [-3,10], [10,-20]
|
107
|
-
]
|
108
|
-
|
109
|
-
@actor.x = 10
|
110
|
-
@actor.y = 5
|
111
|
-
@collidable.cw_world_points.should == [[0,0],[10,7],[20,10]]
|
112
|
-
@collidable.cw_world_lines.should == [
|
113
|
-
[[0,0],[10,7]],
|
114
|
-
[[10,7],[20,10]],
|
115
|
-
[[20,10],[0,0]]
|
116
|
-
]
|
117
|
-
@collidable.cw_world_edge_normals.should == [
|
118
|
-
[-7,10], [-3,10], [10,-20]
|
119
|
-
]
|
120
|
-
|
121
|
-
@collidable.clear_collidable_cache
|
122
|
-
@collidable.cw_world_points.should == [[10,5],[20,12],[30,15]]
|
123
|
-
@collidable.cw_world_lines.should == [
|
124
|
-
[[10,5],[20,12]],
|
125
|
-
[[20,12],[30,15]],
|
126
|
-
[[30,15],[10,5]]
|
127
|
-
]
|
128
|
-
@collidable.cw_world_edge_normals.should == [
|
129
|
-
[-7,10], [-3,10], [10,-20]
|
130
|
-
]
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
data/spec/emitter_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Emitter do
|
4
|
-
before do
|
5
|
-
@stage = stub_everything
|
6
|
-
# @stage.expects(:sound_manager)
|
7
|
-
# @stage.expects(:respond_to?).with(:register_physical_object).returns(true)
|
8
|
-
# @stage.expects(:register_physical_object).with(any_args)
|
9
|
-
|
10
|
-
@emitter = create_actor :emitter, {:stage => @stage}
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should be' do
|
14
|
-
@emitter.should be
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should add a timer for spawning particle actors' do
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/input_manager_spec.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
describe InputManager do
|
4
|
-
before do
|
5
|
-
@config = stub(:[] => nil)
|
6
|
-
@window = mock
|
7
|
-
@wrapped_screen = stub(:screen => @window)
|
8
|
-
end
|
9
|
-
let(:subject) { InputManager.new :config_manager => @config, :wrapped_screen => @wrapped_screen }
|
10
|
-
|
11
|
-
describe "mouse drag event" do
|
12
|
-
it "should fire after a mouse down, mouse motion, mouse up" do
|
13
|
-
from_x = 40
|
14
|
-
from_y = 20
|
15
|
-
to_x = 140
|
16
|
-
to_y = 120
|
17
|
-
@window.stubs(:mouse_x).returns(from_x)
|
18
|
-
@window.stubs(:mouse_y).returns(from_y)
|
19
|
-
|
20
|
-
event_data = {:from => [from_x, from_y],:to => [to_x, to_y]}
|
21
|
-
exp_event = {
|
22
|
-
:type => :mouse,
|
23
|
-
:id => MsLeft,
|
24
|
-
:action => :up,
|
25
|
-
:callback_key => :mouse_drag,
|
26
|
-
:data => event_data
|
27
|
-
}
|
28
|
-
|
29
|
-
subject.stubs(:fire).with(:event_received, any_parameters)
|
30
|
-
|
31
|
-
subject.expects(:fire).with(:event_received, exp_event)
|
32
|
-
|
33
|
-
subject._handle_event(MsLeft, :down)
|
34
|
-
subject._handle_event(nil, :motion)
|
35
|
-
@window.stubs(:mouse_x).returns(to_x)
|
36
|
-
@window.stubs(:mouse_y).returns(to_y)
|
37
|
-
subject._handle_event(MsLeft, :up)
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "standard keyboard events" do
|
43
|
-
it 'calls the callbacks for the correct events' do
|
44
|
-
r_pressed = 0
|
45
|
-
y_pressed = 0
|
46
|
-
subject.reg :keyboard_down, KbR do
|
47
|
-
r_pressed += 1
|
48
|
-
end
|
49
|
-
subject.reg :keyboard_down, KbY do
|
50
|
-
y_pressed += 1
|
51
|
-
end
|
52
|
-
|
53
|
-
subject._handle_event(KbT, :down)
|
54
|
-
r_pressed.should == 0
|
55
|
-
y_pressed.should == 0
|
56
|
-
|
57
|
-
subject._handle_event(KbR, :up)
|
58
|
-
r_pressed.should == 0
|
59
|
-
y_pressed.should == 0
|
60
|
-
|
61
|
-
subject._handle_event(KbR, :down)
|
62
|
-
r_pressed.should == 1
|
63
|
-
y_pressed.should == 0
|
64
|
-
|
65
|
-
subject._handle_event(KbY, :down)
|
66
|
-
r_pressed.should == 1
|
67
|
-
y_pressed.should == 1
|
68
|
-
|
69
|
-
subject.clear_hooks self
|
70
|
-
|
71
|
-
# has now been unregistered
|
72
|
-
subject._handle_event(KbR, :down)
|
73
|
-
r_pressed.should == 1
|
74
|
-
|
75
|
-
subject._handle_event(KbY, :down)
|
76
|
-
y_pressed.should == 1
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'passes along args'
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "mapping an event id to a boolean" do
|
83
|
-
it "should set an ivar to true as long as the event id is down" do
|
84
|
-
listener = Struct.new(:left).new
|
85
|
-
subject.while_pressed KbLeft, listener, :left
|
86
|
-
|
87
|
-
listener.left.should be_false
|
88
|
-
|
89
|
-
subject._handle_event(KbLeft, :down)
|
90
|
-
listener.left.should be_true
|
91
|
-
|
92
|
-
subject._handle_event(GpLeft, :down)
|
93
|
-
listener.left.should be_true
|
94
|
-
|
95
|
-
subject._handle_event(GpLeft, :up)
|
96
|
-
listener.left.should be_true
|
97
|
-
|
98
|
-
subject._handle_event(KbT, :up)
|
99
|
-
listener.left.should be_true
|
100
|
-
|
101
|
-
subject._handle_event(KbLeft, :up)
|
102
|
-
listener.left.should be_false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "mapping multiple keys to a boolean" do
|
107
|
-
it "should set an ivar to true as long as ANY of the keys are down" do
|
108
|
-
pending
|
109
|
-
listener = Struct.new(:left).new
|
110
|
-
subject.while_pressed [KbLeft, GpLeft], listener, :left
|
111
|
-
|
112
|
-
listener.left.should be_false
|
113
|
-
|
114
|
-
subject._handle_event(KbLeft, :down)
|
115
|
-
listener.left.should be_true
|
116
|
-
|
117
|
-
subject._handle_event(GpLeft, :down)
|
118
|
-
listener.left.should be_true
|
119
|
-
|
120
|
-
subject._handle_event(KbT, :up)
|
121
|
-
listener.left.should be_true
|
122
|
-
|
123
|
-
subject._handle_event(KbP, :down)
|
124
|
-
listener.left.should be_true
|
125
|
-
|
126
|
-
subject._handle_event(GpLeft, :up)
|
127
|
-
listener.left.should be_true
|
128
|
-
|
129
|
-
subject._handle_event(KbLeft, :up)
|
130
|
-
listener.left.should be_false
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
describe 'A new resource manager' do
|
4
|
-
before do
|
5
|
-
@res_man = ResourceManager.new :wrapped_screen => stub(:screen => :fake_gosu)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should load an actor image' do
|
9
|
-
@res_man.expects(:load_image).with("string.png").returns(:surf)
|
10
|
-
@res_man.load_actor_image("FoopyPants").should == :surf
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/spec/spatial_hash_spec.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe 'a new SpacialHash' do
|
5
|
-
before do
|
6
|
-
@hash = SpatialHash.new 10
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should be constructable' do
|
10
|
-
@hash.cell_size.should == 10
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'can add a point' do
|
14
|
-
pt = Point.new 2, 3
|
15
|
-
@hash.add pt
|
16
|
-
@hash.buckets[0][0].first.should == pt
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'can add a neg point' do
|
20
|
-
pt = Point.new -2, 3
|
21
|
-
@hash.add pt
|
22
|
-
@hash.buckets[-1][0].first.should == pt
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'can add a square' do
|
26
|
-
box = Item.new 2, 3, 12, 13
|
27
|
-
@hash.add box
|
28
|
-
|
29
|
-
buckets = @hash.buckets
|
30
|
-
|
31
|
-
buckets[0][0].first.should == box
|
32
|
-
buckets[0][1].first.should == box
|
33
|
-
buckets[1][0].first.should == box
|
34
|
-
buckets[1][1].first.should == box
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'can add a box' do
|
38
|
-
box = Item.new 3, 3, 12, 2
|
39
|
-
@hash.add box
|
40
|
-
|
41
|
-
buckets = @hash.buckets
|
42
|
-
buckets[0][0].first.should == box
|
43
|
-
buckets[1][0].first.should == box
|
44
|
-
|
45
|
-
buckets[0][1].should be_nil
|
46
|
-
buckets[1][1].should be_nil
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'can remove points' do
|
51
|
-
pt = Point.new -2, 3
|
52
|
-
@hash.add pt
|
53
|
-
@hash.buckets[-1][0].should_not be_empty
|
54
|
-
@hash.remove pt
|
55
|
-
|
56
|
-
@hash.buckets[-1][0].should be_empty
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'can remove boxes' do
|
60
|
-
box = Item.new 2, 3, 12, 13
|
61
|
-
@hash.add box
|
62
|
-
@hash.buckets[0][0].should_not be_empty
|
63
|
-
@hash.buckets[0][1].should_not be_empty
|
64
|
-
@hash.buckets[1][0].should_not be_empty
|
65
|
-
@hash.buckets[1][1].should_not be_empty
|
66
|
-
|
67
|
-
@hash.remove box
|
68
|
-
|
69
|
-
@hash.buckets[0][0].should be_empty
|
70
|
-
@hash.buckets[0][1].should be_empty
|
71
|
-
@hash.buckets[1][0].should be_empty
|
72
|
-
@hash.buckets[1][1].should be_empty
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can lookup objects for an x,y location' do
|
76
|
-
box = Item.new 2, 3, 12, 13
|
77
|
-
@hash.add box
|
78
|
-
|
79
|
-
@hash.items_at(5, 7).include?(box).should be_true
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'can rehash all the items' do
|
83
|
-
box = Item.new 2, 3, 12, 13
|
84
|
-
@hash.add box
|
85
|
-
@hash.rehash
|
86
|
-
|
87
|
-
buckets = @hash.buckets
|
88
|
-
buckets[0][0].first.should == box
|
89
|
-
buckets[0][1].first.should == box
|
90
|
-
buckets[1][0].first.should == box
|
91
|
-
buckets[1][1].first.should == box
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'can find items in a box'
|
95
|
-
end
|
96
|
-
|
97
|
-
class Point
|
98
|
-
extend Publisher
|
99
|
-
can_fire :remove_me
|
100
|
-
include Kvo
|
101
|
-
kvo_attr_accessor :x, :y
|
102
|
-
def initialize(x,y)
|
103
|
-
self.x = x
|
104
|
-
self.y = y
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class Item
|
109
|
-
extend Publisher
|
110
|
-
can_fire :remove_me
|
111
|
-
include Kvo
|
112
|
-
kvo_attr_accessor :x, :y, :width, :height
|
113
|
-
def initialize(x,y,w=1,h=1)
|
114
|
-
self.x = x
|
115
|
-
self.y = y
|
116
|
-
self.width = w
|
117
|
-
self.height = h
|
118
|
-
end
|
119
|
-
end
|