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
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Using chipmunks collision handling", acceptance: true do
|
4
|
+
|
5
|
+
define_actor :rock do
|
6
|
+
has_behavior :physical => {shape: :circle,
|
7
|
+
mass: 10,
|
8
|
+
friction: 1.7,
|
9
|
+
elasticity: 0.4,
|
10
|
+
radius: 10,
|
11
|
+
moment: 150
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
define_actor :hard_place do
|
16
|
+
has_behavior :physical => {shape: :circle,
|
17
|
+
mass: 10,
|
18
|
+
friction: 1.7,
|
19
|
+
elasticity: 0.4,
|
20
|
+
radius: 10,
|
21
|
+
moment: 150,
|
22
|
+
fixed: true
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'shows that two overlapping objects collide' do
|
27
|
+
#scope cheatzys
|
28
|
+
rock = nil
|
29
|
+
hard_place = nil
|
30
|
+
game.stage do |stage| # instance of TestingStage
|
31
|
+
# TODO order issue here
|
32
|
+
require 'chipmunk'
|
33
|
+
load "#{GAMEBOX_PATH}core/physics.rb"
|
34
|
+
|
35
|
+
@physics_manager = this_object_context[:physics_manager]
|
36
|
+
@physics_manager.configure
|
37
|
+
# TODO move these optionally to configure?
|
38
|
+
@physics_manager.elastic_iterations = 4
|
39
|
+
@physics_manager.damping = 0.4
|
40
|
+
|
41
|
+
rock = create_actor :rock, x: 0, y: 0
|
42
|
+
hard_place = create_actor :hard_place, x: 0, y: 0
|
43
|
+
@physics_manager.add_collision_func :rock, :hard_place do |collision_rock, collision_hard_place|
|
44
|
+
@collision_rock = collision_rock
|
45
|
+
@collision_hard_place = collision_hard_place
|
46
|
+
end
|
47
|
+
end
|
48
|
+
see_stage_ivars collision_rock: nil, collision_hard_place: nil
|
49
|
+
update 1
|
50
|
+
# TODO not sure about this one..
|
51
|
+
update 1
|
52
|
+
see_stage_ivars collision_rock: rock, collision_hard_place: hard_place
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'shows that an object in motion can collide and that gravity is moving things' do
|
56
|
+
rock = nil
|
57
|
+
hard_place = nil
|
58
|
+
game.stage do |stage| # instance of TestingStage
|
59
|
+
# TODO order issue here
|
60
|
+
require 'chipmunk'
|
61
|
+
load "#{GAMEBOX_PATH}core/physics.rb"
|
62
|
+
|
63
|
+
@physics_manager = this_object_context[:physics_manager]
|
64
|
+
@physics_manager.configure
|
65
|
+
# TODO move these optionally to configure?
|
66
|
+
@physics_manager.elastic_iterations = 4
|
67
|
+
@physics_manager.damping = 0.4
|
68
|
+
@physics_manager.gravity = vec2(0,500)
|
69
|
+
|
70
|
+
rock = create_actor :rock, x: 0, y: -20
|
71
|
+
|
72
|
+
hard_place = create_actor :hard_place, x: 0, y: 0
|
73
|
+
@physics_manager.add_collision_func :rock, :hard_place do |collision_rock, collision_hard_place|
|
74
|
+
@collision_rock = collision_rock
|
75
|
+
@collision_hard_place = collision_hard_place
|
76
|
+
end
|
77
|
+
end
|
78
|
+
see_stage_ivars collision_rock: nil, collision_hard_place: nil
|
79
|
+
update 500
|
80
|
+
see_stage_ivars collision_rock: rock, collision_hard_place: hard_place
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Using fps actor", acceptance: true do
|
4
|
+
it 'draws and updates the fps label' do
|
5
|
+
game.stage do |stage| # instance of TestingStage
|
6
|
+
@fps = create_actor :fps, font_name: 'arial', font_size: 20
|
7
|
+
end
|
8
|
+
|
9
|
+
game.should have_actor(:fps)
|
10
|
+
game.should have_actor(:label)
|
11
|
+
draw
|
12
|
+
see_text_drawn "", in: arial_20
|
13
|
+
|
14
|
+
Gosu.stubs(:fps).returns(99)
|
15
|
+
draw
|
16
|
+
see_text_drawn "", in: arial_20
|
17
|
+
|
18
|
+
update 100
|
19
|
+
draw
|
20
|
+
see_text_drawn "99", in: arial_20
|
21
|
+
|
22
|
+
remove_fps
|
23
|
+
|
24
|
+
game.should_not have_actor(:fps)
|
25
|
+
game.should_not have_actor(:label)
|
26
|
+
|
27
|
+
pending "check color of drawn fonts"
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
let!(:arial_20) { mock_font('arial', 20) }
|
32
|
+
|
33
|
+
def remove_fps
|
34
|
+
game.current_stage.instance_variable_get("@fps").remove
|
35
|
+
# TODO is this needed?
|
36
|
+
update 1
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "pausing in gamebox", acceptance: true do
|
4
|
+
|
5
|
+
define_behavior :shoot_rock do |beh|
|
6
|
+
beh.requires :timer_manager
|
7
|
+
beh.setup do
|
8
|
+
actor.has_attributes rocks_shot: 0
|
9
|
+
timer_manager.add_timer 'shoot_rock', 1_000 do
|
10
|
+
actor.react_to :shoot_rock
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
react_to do |msg, *args|
|
15
|
+
actor.rocks_shot += 1 if msg == :shoot_rock
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
define_actor :volcano do
|
20
|
+
has_behavior :shoot_rock
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it 'allows timers and all updates from the director to be paused / unpaused' do
|
25
|
+
game.stage do |stage| # instance of TestingStage
|
26
|
+
@counter = 0
|
27
|
+
timer_manager.add_timer 'stage_timer', 2000 do
|
28
|
+
@counter += 1
|
29
|
+
end
|
30
|
+
create_actor :volcano
|
31
|
+
end
|
32
|
+
see_actor_attrs :volcano, rocks_shot: 0
|
33
|
+
see_stage_ivars counter: 0
|
34
|
+
|
35
|
+
update 100
|
36
|
+
see_actor_attrs :volcano, rocks_shot: 0
|
37
|
+
see_stage_ivars counter: 0
|
38
|
+
|
39
|
+
update 901
|
40
|
+
see_actor_attrs :volcano, rocks_shot: 1
|
41
|
+
see_stage_ivars counter: 0
|
42
|
+
|
43
|
+
pause
|
44
|
+
update 2001
|
45
|
+
see_actor_attrs :volcano, rocks_shot: 1
|
46
|
+
see_stage_ivars counter: 0
|
47
|
+
|
48
|
+
update 2001
|
49
|
+
see_actor_attrs :volcano, rocks_shot: 1
|
50
|
+
see_stage_ivars counter: 0
|
51
|
+
|
52
|
+
unpause
|
53
|
+
update 2001
|
54
|
+
see_actor_attrs :volcano, rocks_shot: 2
|
55
|
+
see_stage_ivars counter: 1
|
56
|
+
|
57
|
+
pending "add more actors _during_ the pause"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Using timers", acceptance: true do
|
4
|
+
|
5
|
+
define_behavior :shoot_rock do |beh|
|
6
|
+
beh.requires :timer_manager
|
7
|
+
beh.setup do
|
8
|
+
actor.has_attributes rocks_shot: 0
|
9
|
+
timer_manager.add_timer 'shoot_rock', 1_000 do
|
10
|
+
actor.react_to :shoot_rock
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
react_to do |msg, *args|
|
15
|
+
actor.rocks_shot += 1 if msg == :shoot_rock
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
define_actor :volcano do
|
20
|
+
has_behavior :shoot_rock
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it 'allows behaviors to get fired from timers' do
|
25
|
+
game.stage do |stage| # instance of TestingStage
|
26
|
+
@counter = 0
|
27
|
+
timer_manager.add_timer 'stage_timer', 2000 do
|
28
|
+
@counter += 1
|
29
|
+
end
|
30
|
+
create_actor :volcano
|
31
|
+
end
|
32
|
+
see_actor_attrs :volcano, rocks_shot: 0
|
33
|
+
see_stage_ivars counter: 0
|
34
|
+
|
35
|
+
update 100
|
36
|
+
see_actor_attrs :volcano, rocks_shot: 0
|
37
|
+
see_stage_ivars counter: 0
|
38
|
+
|
39
|
+
update 901
|
40
|
+
see_actor_attrs :volcano, rocks_shot: 1
|
41
|
+
see_stage_ivars counter: 0
|
42
|
+
|
43
|
+
update 2001
|
44
|
+
see_actor_attrs :volcano, rocks_shot: 2
|
45
|
+
see_stage_ivars counter: 1
|
46
|
+
|
47
|
+
update 1
|
48
|
+
see_actor_attrs :volcano, rocks_shot: 3
|
49
|
+
see_stage_ivars counter: 1
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe :animated do
|
4
|
+
it 'needs updated tests'
|
5
|
+
|
6
|
+
let(:opts) { {} }
|
7
|
+
subject { subcontext[:behavior_factory].add_behavior actor, :animated, opts }
|
8
|
+
let(:director) { evented_stub(stub_everything('director')) }
|
9
|
+
let(:subcontext) do
|
10
|
+
it = nil
|
11
|
+
Conject.default_object_context.in_subcontext{|ctx|it = ctx};
|
12
|
+
_mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
|
13
|
+
_mocks.each do |k,v|
|
14
|
+
it[k] = v
|
15
|
+
it[:director] = director
|
16
|
+
end
|
17
|
+
it
|
18
|
+
end
|
19
|
+
let!(:actor) { subcontext[:actor] }
|
20
|
+
|
21
|
+
let(:image0) { stub('image 1', width: 5, height: 6) }
|
22
|
+
let(:image1) { stub('image 2', width: 7, height: 8) }
|
23
|
+
let(:images) { [image0, image1] }
|
24
|
+
|
25
|
+
before do
|
26
|
+
@resource_manager.stubs(:load_animation_set).returns(images)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should define attributes on @actor' do
|
30
|
+
subject
|
31
|
+
actor.should respond_to(:image)
|
32
|
+
actor.should respond_to(:action)
|
33
|
+
actor.should respond_to(:width)
|
34
|
+
actor.should respond_to(:height)
|
35
|
+
actor.should respond_to(:image=)
|
36
|
+
actor.should respond_to(:action=)
|
37
|
+
actor.should respond_to(:width=)
|
38
|
+
actor.should respond_to(:height=)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'shouldnt update frame for non-animating' do
|
42
|
+
subject
|
43
|
+
actor.animating = false
|
44
|
+
actor.image.should == image0
|
45
|
+
director.fire :update, 61
|
46
|
+
|
47
|
+
actor.image.should == image0
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should update frame for animating' do
|
51
|
+
subject
|
52
|
+
actor.image.should == image0
|
53
|
+
|
54
|
+
director.fire :update, 61
|
55
|
+
actor.image.should == image1
|
56
|
+
|
57
|
+
director.fire :update, 60
|
58
|
+
actor.image.should == image0
|
59
|
+
|
60
|
+
director.fire :update, 30
|
61
|
+
actor.image.should == image0
|
62
|
+
director.fire :update, 30
|
63
|
+
actor.image.should == image1
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should set the action and animate accordingly for single frame' do
|
68
|
+
subject
|
69
|
+
actor.animating = true
|
70
|
+
@resource_manager.expects(:load_animation_set).with(actor, :foo).returns([image1])
|
71
|
+
actor.action = :foo
|
72
|
+
|
73
|
+
actor.animating.should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set the action and animate accordingly for many frames' do
|
77
|
+
subject
|
78
|
+
actor.animating = false
|
79
|
+
@resource_manager.expects(:load_animation_set).with(actor, :foo).returns(images)
|
80
|
+
actor.action = :foo
|
81
|
+
|
82
|
+
actor.animating.should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe :collidable do
|
4
|
+
let(:opts) { {} }
|
5
|
+
subject { subcontext[:behavior_factory].add_behavior actor, :collidable, opts }
|
6
|
+
|
7
|
+
let(:director) { evented_stub(stub_everything('director')) }
|
8
|
+
let!(:subcontext) do
|
9
|
+
it = nil
|
10
|
+
Conject.default_object_context.in_subcontext{|ctx|it = ctx};
|
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
|
+
it[:director] = director
|
15
|
+
end
|
16
|
+
it
|
17
|
+
end
|
18
|
+
let!(:actor) { subcontext[:actor] }
|
19
|
+
|
20
|
+
before do
|
21
|
+
@stage.stubs(:register_collidable)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "aabb shape" do
|
25
|
+
let(:opts) do
|
26
|
+
{:shape => :aabb,
|
27
|
+
:cw_world_points => [
|
28
|
+
[-15,10],[15,10],
|
29
|
+
[15,-10], [-15,10]
|
30
|
+
]}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "constructs based on points" do
|
34
|
+
subject
|
35
|
+
actor.shape_type.should == :aabb
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "circle shape" do
|
40
|
+
let(:opts) do
|
41
|
+
{shape: :circle, radius: 20}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should recalculate_collidable_cache on position_changed' do
|
45
|
+
subject
|
46
|
+
actor.shape.expects(:recalculate_collidable_cache)
|
47
|
+
actor.react_to :position_changed
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should calculate center point for circle' do
|
51
|
+
actor.has_attributes x: 3, y: 6
|
52
|
+
subject
|
53
|
+
|
54
|
+
actor.center_x.should be_within(0.001).of(3)
|
55
|
+
actor.center_y.should be_within(0.001).of(6)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "polygon shape" do
|
60
|
+
let(:opts) do
|
61
|
+
{shape: :polygon, points: [[0,0],[10,7],[20,10]]}
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should calculate center point for polygon' do
|
65
|
+
subject
|
66
|
+
actor.center_x.should be_within(0.001).of(10)
|
67
|
+
actor.center_y.should be_within(0.001).of(5)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should translate points to world coords for poly' do
|
71
|
+
actor.has_attributes x: 10, y: 5
|
72
|
+
subject
|
73
|
+
actor.cw_world_points.should == [[10,5],[20,12],[30,15]]
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should translate lines to world coords lines' do
|
77
|
+
subject
|
78
|
+
actor.cw_world_lines.should == [
|
79
|
+
[[0,0],[10,7]],
|
80
|
+
[[10,7],[20,10]],
|
81
|
+
[[20,10],[0,0]]
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should translate world lines to edge normals' do
|
86
|
+
subject
|
87
|
+
|
88
|
+
actor.cw_world_edge_normals.should == [
|
89
|
+
[-7,10], [-3,10], [10,-20]
|
90
|
+
]
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should cache calcs until reset' do
|
94
|
+
subject
|
95
|
+
# prime the cache
|
96
|
+
actor.cw_world_points.should == [[0,0],[10,7],[20,10]]
|
97
|
+
actor.cw_world_lines.should == [
|
98
|
+
[[0,0],[10,7]],
|
99
|
+
[[10,7],[20,10]],
|
100
|
+
[[20,10],[0,0]]
|
101
|
+
]
|
102
|
+
actor.cw_world_edge_normals.should == [
|
103
|
+
[-7,10], [-3,10], [10,-20]
|
104
|
+
]
|
105
|
+
|
106
|
+
actor.x = 10
|
107
|
+
actor.y = 5
|
108
|
+
actor.cw_world_points.should == [[0,0],[10,7],[20,10]]
|
109
|
+
actor.cw_world_lines.should == [
|
110
|
+
[[0,0],[10,7]],
|
111
|
+
[[10,7],[20,10]],
|
112
|
+
[[20,10],[0,0]]
|
113
|
+
]
|
114
|
+
actor.cw_world_edge_normals.should == [
|
115
|
+
[-7,10], [-3,10], [10,-20]
|
116
|
+
]
|
117
|
+
|
118
|
+
# triggers the recalc cache
|
119
|
+
director.fire :update, 4
|
120
|
+
|
121
|
+
actor.cw_world_points.should == [[10,5],[20,12],[30,15]]
|
122
|
+
actor.cw_world_lines.should == [
|
123
|
+
[[10,5],[20,12]],
|
124
|
+
[[20,12],[30,15]],
|
125
|
+
[[30,15],[10,5]]
|
126
|
+
]
|
127
|
+
actor.cw_world_edge_normals.should == [
|
128
|
+
[-7,10], [-3,10], [10,-20]
|
129
|
+
]
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|