gamebox 0.4.0.rc5 → 0.4.0.rc11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +205 -127
- data/bin/gamebox +49 -3
- data/bin/gb +87 -0
- data/gamebox.gemspec +4 -3
- data/lib/gamebox.rb +1 -1
- data/lib/gamebox/actors/collidable_debugger.rb +4 -4
- data/lib/gamebox/actors/icon.rb +7 -0
- data/lib/gamebox/actors/label.rb +41 -42
- data/lib/gamebox/behaviors/animated.rb +6 -0
- data/lib/gamebox/behaviors/audible.rb +1 -2
- data/lib/gamebox/behaviors/collidable.rb +1 -1
- data/lib/gamebox/behaviors/graphical.rb +8 -4
- data/lib/gamebox/behaviors/physical.rb +6 -1
- data/lib/gamebox/behaviors/positioned.rb +4 -11
- data/lib/gamebox/behaviors/projectile.rb +8 -0
- data/lib/gamebox/behaviors/visible.rb +3 -3
- data/lib/gamebox/core/aabb_tree.rb +1 -1
- data/lib/gamebox/core/actor.rb +37 -50
- data/lib/gamebox/core/actor_definition.rb +41 -0
- data/lib/gamebox/core/actor_view.rb +6 -21
- data/lib/gamebox/core/actor_view_definition.rb +19 -0
- data/lib/gamebox/core/actor_view_factory.rb +9 -3
- data/lib/gamebox/core/behavior.rb +8 -27
- data/lib/gamebox/core/behavior_definition.rb +24 -0
- data/lib/gamebox/core/config_manager.rb +45 -30
- data/lib/gamebox/core/configuration.rb +5 -0
- data/lib/gamebox/core/core.rb +4 -0
- data/lib/gamebox/core/debug_helpers.rb +46 -0
- data/lib/gamebox/core/director.rb +32 -5
- data/lib/gamebox/core/event_symbols.rb +214 -0
- data/lib/gamebox/core/game.rb +1 -1
- data/lib/gamebox/core/input_manager.rb +1 -4
- data/lib/gamebox/core/input_mapper.rb +85 -0
- data/lib/gamebox/core/physics.rb +7 -3
- data/lib/gamebox/core/physics_manager.rb +5 -1
- data/lib/gamebox/core/renderer.rb +72 -0
- data/lib/gamebox/core/stage.rb +25 -81
- data/lib/gamebox/core/stage_definition.rb +60 -0
- data/lib/gamebox/core/stage_factory.rb +56 -0
- data/lib/gamebox/core/stage_manager.rb +5 -11
- data/lib/gamebox/core/timer_manager.rb +6 -2
- data/lib/gamebox/core/viewport.rb +12 -5
- data/lib/gamebox/core/wrapped_screen.rb +8 -5
- data/lib/gamebox/gamebox_application.rb +21 -19
- data/lib/gamebox/lib/array_ext.rb +9 -0
- data/lib/gamebox/lib/observable_attributes.rb +24 -0
- data/lib/gamebox/lib/vector2.rb +432 -0
- data/lib/gamebox/post_setup_handlers/file_watcher.rb +37 -0
- data/lib/gamebox/post_setup_handlers/gamebox_debug_helpers.rb +13 -0
- data/lib/gamebox/post_setup_handlers/pry_remote_server.rb +29 -0
- data/lib/gamebox/spec/helper.rb +165 -17
- data/lib/gamebox/tasks/gamebox_tasks.rake +27 -12
- data/lib/gamebox/version.rb +1 -1
- data/lib/gamebox/views/graphical_actor_view.rb +4 -5
- data/script/perf_aabb.rb +13 -8
- data/spec/acceptance/animation_spec.rb +1 -3
- data/spec/acceptance/basic_actor_lifecycle_spec.rb +1 -1
- data/spec/acceptance/fps_actor_spec.rb +8 -12
- data/spec/acceptance/input_mapper_spec.rb +17 -24
- data/spec/acceptance/update_ordering_spec.rb +64 -0
- data/spec/actors/label_spec.rb +90 -5
- data/spec/behaviors/animated_spec.rb +1 -1
- data/spec/behaviors/collidable_spec.rb +7 -15
- data/spec/behaviors/positioned_spec.rb +12 -5
- data/spec/core/actor_spec.rb +31 -3
- data/spec/core/actor_view_spec.rb +1 -1
- data/spec/core/behavior_spec.rb +3 -0
- data/spec/core/configuration_spec.rb +49 -2
- data/spec/core/input_mapper_spec.rb +7 -0
- data/spec/core/renderer_spec.rb +89 -0
- data/spec/core/stage_definition_spec.rb +41 -0
- data/spec/core/stage_manager_spec.rb +11 -11
- data/spec/core/stage_spec.rb +38 -78
- data/spec/core/viewport_spec.rb +5 -2
- data/spec/core/wrapped_screen_spec.rb +18 -12
- data/spec/views/graphical_actor_view_spec.rb +33 -62
- data/templates/actor_template.erb +11 -0
- data/templates/app/README.md +1 -0
- data/templates/app/src/actors/{player.rb → player_actor.rb} +3 -1
- data/templates/app/src/behaviors/.gitkeep +0 -0
- data/templates/app/src/stages/demo_stage.rb +14 -0
- data/templates/behavior_template.erb +13 -0
- data/templates/stage_template.erb +13 -0
- metadata +60 -21
- data/component_generators/actor_generator.rb +0 -17
- data/lib/gamebox/actors/emitter.rb +0 -12
- data/lib/gamebox/behaviors/emitting.rb +0 -48
- data/lib/gamebox/behaviors/input_mapper.rb +0 -11
- data/lib/gamebox/lib/ftor.rb +0 -372
- data/spec/actors/emitter_spec.rb +0 -5
- data/templates/app/NEXT_STEPS.txt +0 -1
- data/templates/app/README.rdoc +0 -24
- data/templates/app/src/demo_stage.rb +0 -7
data/lib/gamebox/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
define_actor_view :graphical_actor_view do
|
3
3
|
|
4
4
|
draw do |target, x_off, y_off, z|
|
5
5
|
img = actor.do_or_do_not(:image)
|
@@ -17,7 +17,6 @@ ActorView.define :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
|
-
# TODO add ? ableness to actor attributes
|
21
20
|
if actor.do_or_do_not(:tiled)
|
22
21
|
x_tiles = actor.num_x_tiles
|
23
22
|
y_tiles = actor.num_y_tiles
|
@@ -26,12 +25,12 @@ ActorView.define :graphical_actor_view do
|
|
26
25
|
x_tiles.times do |col|
|
27
26
|
y_tiles.times do |row|
|
28
27
|
# TODO why is there a nasty black line between these that jitters?
|
29
|
-
img.
|
28
|
+
img.draw offset_x+col*img_w, offset_y+row*img_h, z, x_scale, y_scale
|
30
29
|
end
|
31
30
|
end
|
32
31
|
else
|
33
|
-
|
34
|
-
|
32
|
+
rot = actor.do_or_do_not :rotation
|
33
|
+
if rot
|
35
34
|
img.draw_rot offset_x, offset_y, z, rot, 0.5, 0.5, x_scale, y_scale, color
|
36
35
|
else
|
37
36
|
img.draw offset_x, offset_y, z, x_scale, y_scale, color
|
data/script/perf_aabb.rb
CHANGED
@@ -15,14 +15,18 @@ class BoxedActor
|
|
15
15
|
@h = h
|
16
16
|
end
|
17
17
|
|
18
|
+
def bb
|
19
|
+
@bb ||= Rect.new(x,y,w,h)
|
20
|
+
end
|
21
|
+
|
18
22
|
end
|
19
|
-
require 'perftools'
|
20
|
-
PerfTools::CpuProfiler.start("/tmp/perf.txt")
|
23
|
+
# require 'perftools'
|
24
|
+
# PerfTools::CpuProfiler.start("/tmp/perf.txt")
|
21
25
|
|
22
26
|
|
23
27
|
NUM = 1_000
|
24
|
-
|
25
|
-
|
28
|
+
Benchmark.bm(60) do |b|
|
29
|
+
b.report("full") do
|
26
30
|
tree = SpatialTreeStagehand.new :thing, :thing
|
27
31
|
|
28
32
|
thing = BoxedActor.new 1, 2, 3, 4
|
@@ -43,14 +47,15 @@ NUM = 1_000
|
|
43
47
|
t.x += rand(40)-20
|
44
48
|
end
|
45
49
|
|
46
|
-
tree.
|
50
|
+
tree.query thing.bb do
|
47
51
|
end
|
52
|
+
|
48
53
|
tree.remove it
|
49
54
|
end
|
50
|
-
|
51
|
-
|
55
|
+
end
|
56
|
+
end
|
52
57
|
|
53
|
-
PerfTools::CpuProfiler.stop
|
58
|
+
# PerfTools::CpuProfiler.stop
|
54
59
|
# be pprof.rb --text /tmp/perf.txt
|
55
60
|
|
56
61
|
|
@@ -26,7 +26,7 @@ describe "Using animation", acceptance: true do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'animates correctly' do
|
29
|
-
game.stage do |stage|
|
29
|
+
game.stage do |stage|
|
30
30
|
create_actor :snelpling
|
31
31
|
end
|
32
32
|
|
@@ -57,8 +57,6 @@ describe "Using animation", acceptance: true do
|
|
57
57
|
draw
|
58
58
|
|
59
59
|
see_image_drawn snelpling_jump_1_png
|
60
|
-
|
61
|
-
pending "add callback checks?"
|
62
60
|
end
|
63
61
|
|
64
62
|
end
|
@@ -1,39 +1,35 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe "Using fps actor", acceptance: true do
|
4
|
+
|
5
|
+
let!(:arial_20) { mock_font('arial', 20) }
|
6
|
+
|
4
7
|
it 'draws and updates the fps label' do
|
5
|
-
game.stage do |stage|
|
6
|
-
@fps = create_actor :fps, font_name: 'arial', font_size: 20
|
8
|
+
game.stage do |stage|
|
9
|
+
@fps = create_actor :fps, font_name: 'arial', font_size: 20, color: Color::RED
|
7
10
|
end
|
8
11
|
|
9
12
|
game.should have_actor(:fps)
|
10
13
|
game.should have_actor(:label)
|
11
14
|
draw
|
12
|
-
see_text_drawn "", in: arial_20
|
15
|
+
see_text_drawn "", in: arial_20, color: Color::RED
|
13
16
|
|
14
17
|
Gosu.stubs(:fps).returns(99)
|
15
18
|
draw
|
16
|
-
see_text_drawn "", in: arial_20
|
19
|
+
see_text_drawn "", in: arial_20, color: Color::RED
|
17
20
|
|
18
21
|
update 100
|
19
22
|
draw
|
20
|
-
see_text_drawn "99", in: arial_20
|
23
|
+
see_text_drawn "99", in: arial_20, color: Color::RED
|
21
24
|
|
22
25
|
remove_fps
|
23
26
|
|
24
27
|
game.should_not have_actor(:fps)
|
25
28
|
game.should_not have_actor(:label)
|
26
|
-
|
27
|
-
pending "check color of drawn fonts"
|
28
|
-
|
29
29
|
end
|
30
30
|
|
31
|
-
let!(:arial_20) { mock_font('arial', 20) }
|
32
|
-
|
33
31
|
def remove_fps
|
34
32
|
game.current_stage.instance_variable_get("@fps").remove
|
35
|
-
# TODO is this needed?
|
36
|
-
update 1
|
37
33
|
end
|
38
34
|
|
39
35
|
end
|
@@ -1,47 +1,40 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe "Using input
|
4
|
-
|
3
|
+
describe "Using input mapper", acceptance: true do
|
5
4
|
|
6
5
|
define_actor :foxy do
|
7
|
-
has_behavior input_mapper: {
|
8
|
-
[KbLeft] => :move_left,
|
9
|
-
[KbRight, KbD] => :move_right
|
10
|
-
}
|
11
6
|
end
|
12
7
|
|
13
8
|
it 'sets actor state based on input' do
|
14
9
|
game.stage do |stage| # instance of TestingStage
|
15
|
-
create_actor :foxy
|
10
|
+
foxy = create_actor :foxy
|
11
|
+
foxy.input.map_input 'left' => :move_left,
|
12
|
+
'right' => :move_right,
|
13
|
+
'd' => :move_right
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
move_right: false
|
16
|
+
input = game.actor(:foxy).input
|
17
|
+
input.move_left?.should be_false
|
18
|
+
input.move_right?.should be_false
|
22
19
|
|
23
20
|
press_key KbLeft
|
24
21
|
press_key KbD
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
see_actor_attrs :foxy,
|
30
|
-
move_right: true
|
23
|
+
input.move_left?.should be_true
|
24
|
+
input.move_right?.should be_true
|
31
25
|
|
32
26
|
release_key KbD
|
33
|
-
|
34
|
-
|
27
|
+
input.move_left?.should be_true
|
28
|
+
input.move_right?.should be_false
|
35
29
|
|
36
|
-
press_key KbRight
|
37
30
|
|
38
|
-
|
39
|
-
|
31
|
+
press_key KbRight
|
32
|
+
input.move_left?.should be_true
|
33
|
+
input.move_right?.should be_true
|
40
34
|
|
41
35
|
release_key KbRight
|
42
|
-
|
43
|
-
|
44
|
-
move_right: false
|
36
|
+
input.move_left?.should be_true
|
37
|
+
input.move_right?.should be_false
|
45
38
|
end
|
46
39
|
|
47
40
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Updates and their order", acceptance: true do
|
4
|
+
|
5
|
+
define_behavior :double_value do |beh|
|
6
|
+
beh.requires :director
|
7
|
+
beh.setup do
|
8
|
+
actor.has_attributes value: 1
|
9
|
+
director.when :pre_update do |time|
|
10
|
+
actor.value *= 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
define_behavior :plus_one do |beh|
|
16
|
+
beh.requires :director
|
17
|
+
beh.setup do
|
18
|
+
actor.has_attributes value: 1
|
19
|
+
director.when :update do |time|
|
20
|
+
actor.value += 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
define_behavior :triple_value do |beh|
|
26
|
+
beh.requires :director
|
27
|
+
beh.setup do
|
28
|
+
actor.has_attributes value: 1
|
29
|
+
director.when :post_update do |time|
|
30
|
+
actor.value *= 3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
define_actor :math_man do
|
36
|
+
has_behaviors :triple_value, :double_value, :plus_one
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it 'updates get fired in the correct order' do
|
41
|
+
game.stage do |stage| # instance of TestingStage
|
42
|
+
create_actor :math_man
|
43
|
+
end
|
44
|
+
|
45
|
+
see_actor_attrs :math_man, value: 1
|
46
|
+
update 10
|
47
|
+
|
48
|
+
see_actor_attrs :math_man, value: 9
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'modifies update order from the stage' do
|
53
|
+
game.stage do |stage| # instance of TestingStage
|
54
|
+
director.update_slots = [:update, :post_update, :pre_update ]
|
55
|
+
create_actor :math_man
|
56
|
+
end
|
57
|
+
|
58
|
+
see_actor_attrs :math_man, value: 1
|
59
|
+
update 10
|
60
|
+
|
61
|
+
see_actor_attrs :math_man, value: 12
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
data/spec/actors/label_spec.rb
CHANGED
@@ -1,10 +1,95 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe :label do
|
4
|
+
|
5
|
+
subjectify_actor(:label)
|
6
|
+
|
7
|
+
it 'has the label behavior' do
|
8
|
+
behaviors = subject.instance_variable_get('@behaviors')
|
9
|
+
behaviors.should include(:label)
|
7
10
|
end
|
8
11
|
|
9
|
-
|
12
|
+
describe "#behavior" do
|
13
|
+
subjectify_behavior(:label)
|
14
|
+
|
15
|
+
before do
|
16
|
+
@actor.stubs(has_attributes: nil, font_name: "fonty.ttf",
|
17
|
+
font_size: 22, color: :red)
|
18
|
+
@font_style_factory.stubs(:build)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets up attributes on actor' do
|
22
|
+
@actor.expects(:has_attributes).with(
|
23
|
+
text: "",
|
24
|
+
font_size: 30,
|
25
|
+
font_name: "Asimov.ttf",
|
26
|
+
color: [250,250,250,255],
|
27
|
+
width: 0,
|
28
|
+
height: 0,
|
29
|
+
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)
|
32
|
+
|
33
|
+
subject.setup
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'listens for text changes' do
|
37
|
+
subject.setup
|
38
|
+
@actor.stubs(text: "foo")
|
39
|
+
|
40
|
+
font_style = stub(height: 13)
|
41
|
+
font_style.stubs(:calc_width).with("foo").returns(73)
|
42
|
+
@actor.stubs(font_style: font_style)
|
43
|
+
|
44
|
+
@actor.expects(:width=).with(73)
|
45
|
+
@actor.expects(:height=).with(13)
|
46
|
+
|
47
|
+
@actor.fire :text_changed
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'listens for font color changes' do
|
51
|
+
subject.setup
|
52
|
+
font_style = stub
|
53
|
+
font_style.expects(:color=).with(:red)
|
54
|
+
@actor.stubs(font_style: font_style, color: :red)
|
55
|
+
|
56
|
+
@actor.fire :color_changed
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'listens for font name changes' do
|
60
|
+
subject.setup
|
61
|
+
@actor.stubs(text: "foo", font_name: "asimov.ttf")
|
62
|
+
|
63
|
+
font_style = stub(height: 13)
|
64
|
+
font_style.stubs(:calc_width).with("foo").returns(73)
|
65
|
+
|
66
|
+
font_style.expects(:name=).with("asimov.ttf")
|
67
|
+
font_style.expects(:reload)
|
68
|
+
@actor.expects(:width=).with(73)
|
69
|
+
@actor.expects(:height=).with(13)
|
70
|
+
|
71
|
+
@actor.stubs(font_style: font_style)
|
72
|
+
|
73
|
+
@actor.fire :font_name_changed
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'listens for font size changes' do
|
77
|
+
subject.setup
|
78
|
+
@actor.stubs(text: "foo", font_size: 14)
|
79
|
+
|
80
|
+
font_style = stub(height: 13)
|
81
|
+
font_style.stubs(:calc_width).with("foo").returns(73)
|
82
|
+
|
83
|
+
font_style.expects(:size=).with(14)
|
84
|
+
font_style.expects(:reload)
|
85
|
+
@actor.expects(:width=).with(73)
|
86
|
+
@actor.expects(:height=).with(13)
|
87
|
+
|
88
|
+
@actor.stubs(font_style: font_style)
|
89
|
+
|
90
|
+
@actor.fire :font_size_changed
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
10
94
|
end
|
95
|
+
|
@@ -7,10 +7,10 @@ describe :animated do
|
|
7
7
|
let(:subcontext) do
|
8
8
|
it = nil
|
9
9
|
Conject.default_object_context.in_subcontext{|ctx|it = ctx};
|
10
|
+
it[:director] = director
|
10
11
|
_mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
|
11
12
|
_mocks.each do |k,v|
|
12
13
|
it[k] = v
|
13
|
-
it[:director] = director
|
14
14
|
end
|
15
15
|
it
|
16
16
|
end
|
@@ -8,11 +8,15 @@ describe :collidable do
|
|
8
8
|
let!(:subcontext) do
|
9
9
|
it = nil
|
10
10
|
Conject.default_object_context.in_subcontext{|ctx|it = ctx};
|
11
|
-
_mocks = create_mocks *(
|
11
|
+
_mocks = create_mocks *(
|
12
|
+
[:stage] +
|
13
|
+
Actor.object_definition.component_names +
|
14
|
+
ActorView.object_definition.component_names -
|
15
|
+
[:actor, :behavior, :this_object_context])
|
12
16
|
_mocks.each do |k,v|
|
13
17
|
it[k] = v
|
14
|
-
it[:director] = director
|
15
18
|
end
|
19
|
+
it[:director] = director
|
16
20
|
it
|
17
21
|
end
|
18
22
|
let!(:actor) { subcontext[:actor] }
|
@@ -44,7 +48,7 @@ describe :collidable do
|
|
44
48
|
it 'should recalculate_collidable_cache on position_changed' do
|
45
49
|
subject
|
46
50
|
actor.shape.expects(:recalculate_collidable_cache)
|
47
|
-
actor.
|
51
|
+
actor.send :emit, :position_changed
|
48
52
|
end
|
49
53
|
|
50
54
|
it 'should calculate center point for circle' do
|
@@ -105,18 +109,6 @@ describe :collidable do
|
|
105
109
|
|
106
110
|
actor.x = 10
|
107
111
|
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
112
|
|
121
113
|
actor.cw_world_points.should == [[10,5],[20,12],[30,15]]
|
122
114
|
actor.cw_world_lines.should == [
|