gamebox 0.4.0.rc5 → 0.4.0.rc11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/README.md +205 -127
  2. data/bin/gamebox +49 -3
  3. data/bin/gb +87 -0
  4. data/gamebox.gemspec +4 -3
  5. data/lib/gamebox.rb +1 -1
  6. data/lib/gamebox/actors/collidable_debugger.rb +4 -4
  7. data/lib/gamebox/actors/icon.rb +7 -0
  8. data/lib/gamebox/actors/label.rb +41 -42
  9. data/lib/gamebox/behaviors/animated.rb +6 -0
  10. data/lib/gamebox/behaviors/audible.rb +1 -2
  11. data/lib/gamebox/behaviors/collidable.rb +1 -1
  12. data/lib/gamebox/behaviors/graphical.rb +8 -4
  13. data/lib/gamebox/behaviors/physical.rb +6 -1
  14. data/lib/gamebox/behaviors/positioned.rb +4 -11
  15. data/lib/gamebox/behaviors/projectile.rb +8 -0
  16. data/lib/gamebox/behaviors/visible.rb +3 -3
  17. data/lib/gamebox/core/aabb_tree.rb +1 -1
  18. data/lib/gamebox/core/actor.rb +37 -50
  19. data/lib/gamebox/core/actor_definition.rb +41 -0
  20. data/lib/gamebox/core/actor_view.rb +6 -21
  21. data/lib/gamebox/core/actor_view_definition.rb +19 -0
  22. data/lib/gamebox/core/actor_view_factory.rb +9 -3
  23. data/lib/gamebox/core/behavior.rb +8 -27
  24. data/lib/gamebox/core/behavior_definition.rb +24 -0
  25. data/lib/gamebox/core/config_manager.rb +45 -30
  26. data/lib/gamebox/core/configuration.rb +5 -0
  27. data/lib/gamebox/core/core.rb +4 -0
  28. data/lib/gamebox/core/debug_helpers.rb +46 -0
  29. data/lib/gamebox/core/director.rb +32 -5
  30. data/lib/gamebox/core/event_symbols.rb +214 -0
  31. data/lib/gamebox/core/game.rb +1 -1
  32. data/lib/gamebox/core/input_manager.rb +1 -4
  33. data/lib/gamebox/core/input_mapper.rb +85 -0
  34. data/lib/gamebox/core/physics.rb +7 -3
  35. data/lib/gamebox/core/physics_manager.rb +5 -1
  36. data/lib/gamebox/core/renderer.rb +72 -0
  37. data/lib/gamebox/core/stage.rb +25 -81
  38. data/lib/gamebox/core/stage_definition.rb +60 -0
  39. data/lib/gamebox/core/stage_factory.rb +56 -0
  40. data/lib/gamebox/core/stage_manager.rb +5 -11
  41. data/lib/gamebox/core/timer_manager.rb +6 -2
  42. data/lib/gamebox/core/viewport.rb +12 -5
  43. data/lib/gamebox/core/wrapped_screen.rb +8 -5
  44. data/lib/gamebox/gamebox_application.rb +21 -19
  45. data/lib/gamebox/lib/array_ext.rb +9 -0
  46. data/lib/gamebox/lib/observable_attributes.rb +24 -0
  47. data/lib/gamebox/lib/vector2.rb +432 -0
  48. data/lib/gamebox/post_setup_handlers/file_watcher.rb +37 -0
  49. data/lib/gamebox/post_setup_handlers/gamebox_debug_helpers.rb +13 -0
  50. data/lib/gamebox/post_setup_handlers/pry_remote_server.rb +29 -0
  51. data/lib/gamebox/spec/helper.rb +165 -17
  52. data/lib/gamebox/tasks/gamebox_tasks.rake +27 -12
  53. data/lib/gamebox/version.rb +1 -1
  54. data/lib/gamebox/views/graphical_actor_view.rb +4 -5
  55. data/script/perf_aabb.rb +13 -8
  56. data/spec/acceptance/animation_spec.rb +1 -3
  57. data/spec/acceptance/basic_actor_lifecycle_spec.rb +1 -1
  58. data/spec/acceptance/fps_actor_spec.rb +8 -12
  59. data/spec/acceptance/input_mapper_spec.rb +17 -24
  60. data/spec/acceptance/update_ordering_spec.rb +64 -0
  61. data/spec/actors/label_spec.rb +90 -5
  62. data/spec/behaviors/animated_spec.rb +1 -1
  63. data/spec/behaviors/collidable_spec.rb +7 -15
  64. data/spec/behaviors/positioned_spec.rb +12 -5
  65. data/spec/core/actor_spec.rb +31 -3
  66. data/spec/core/actor_view_spec.rb +1 -1
  67. data/spec/core/behavior_spec.rb +3 -0
  68. data/spec/core/configuration_spec.rb +49 -2
  69. data/spec/core/input_mapper_spec.rb +7 -0
  70. data/spec/core/renderer_spec.rb +89 -0
  71. data/spec/core/stage_definition_spec.rb +41 -0
  72. data/spec/core/stage_manager_spec.rb +11 -11
  73. data/spec/core/stage_spec.rb +38 -78
  74. data/spec/core/viewport_spec.rb +5 -2
  75. data/spec/core/wrapped_screen_spec.rb +18 -12
  76. data/spec/views/graphical_actor_view_spec.rb +33 -62
  77. data/templates/actor_template.erb +11 -0
  78. data/templates/app/README.md +1 -0
  79. data/templates/app/src/actors/{player.rb → player_actor.rb} +3 -1
  80. data/templates/app/src/behaviors/.gitkeep +0 -0
  81. data/templates/app/src/stages/demo_stage.rb +14 -0
  82. data/templates/behavior_template.erb +13 -0
  83. data/templates/stage_template.erb +13 -0
  84. metadata +60 -21
  85. data/component_generators/actor_generator.rb +0 -17
  86. data/lib/gamebox/actors/emitter.rb +0 -12
  87. data/lib/gamebox/behaviors/emitting.rb +0 -48
  88. data/lib/gamebox/behaviors/input_mapper.rb +0 -11
  89. data/lib/gamebox/lib/ftor.rb +0 -372
  90. data/spec/actors/emitter_spec.rb +0 -5
  91. data/templates/app/NEXT_STEPS.txt +0 -1
  92. data/templates/app/README.rdoc +0 -24
  93. data/templates/app/src/demo_stage.rb +0 -7
@@ -3,7 +3,7 @@ module Gamebox
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
5
  TINY = 0
6
- RC = 5
6
+ RC = 11
7
7
 
8
8
  if RC > 0
9
9
  ARRAY = [MAJOR, MINOR, TINY, "rc#{RC}"]
@@ -1,5 +1,5 @@
1
1
 
2
- ActorView.define :graphical_actor_view do
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.draw_rot offset_x+col*img_w, offset_y+row*img_h, z, actor.rotation, x_scale, y_scale
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
- if actor.respond_to? :rotation
34
- rot = actor.rotation || 0.0
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
@@ -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
- # Benchmark.bm(60) do |b|
25
- # b.report("full") do
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.neighbors_of thing do
50
+ tree.query thing.bb do
47
51
  end
52
+
48
53
  tree.remove it
49
54
  end
50
- # end
51
- # end
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| # instance of TestingStage
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
@@ -45,7 +45,7 @@ describe "The basic life cycle of an actor", acceptance: true do
45
45
 
46
46
  define_actor_view :mc_bane_view do
47
47
  requires :resource_manager # needs these injected
48
- configure do
48
+ setup do
49
49
  @image = resource_manager.load_actor_image(actor)
50
50
  end
51
51
 
@@ -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| # instance of TestingStage
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 stater", acceptance: true do
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
- see_actor_attrs :foxy,
19
- move_left: false
20
- see_actor_attrs :foxy,
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
- see_actor_attrs :foxy,
27
- move_left: true
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
- see_actor_attrs :foxy,
34
- move_right: false
27
+ input.move_left?.should be_true
28
+ input.move_right?.should be_false
35
29
 
36
- press_key KbRight
37
30
 
38
- see_actor_attrs :foxy,
39
- move_right: true
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
- see_actor_attrs :foxy,
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
@@ -1,10 +1,95 @@
1
1
  require 'helper'
2
2
 
3
- describe 'a new Label' do
4
- before do
5
- # opts = {:stage=>"stage", :input=>"input", :resources=>"resource"}
6
- # @test_me = Label.new opts
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
- it 'should do something'
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 *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
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.react_to :position_changed
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 == [