gamebox 0.4.0.rc4 → 0.4.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/TODO.txt +0 -2
  2. data/bin/gamebox +28 -5
  3. data/gamebox.gemspec +1 -2
  4. data/lib/gamebox.rb +4 -0
  5. data/lib/gamebox/behaviors/{input_stater.rb → input_mapper.rb} +1 -1
  6. data/lib/gamebox/behaviors/physical.rb +11 -0
  7. data/lib/gamebox/core/actor.rb +2 -0
  8. data/lib/gamebox/core/behavior_factory.rb +3 -4
  9. data/lib/gamebox/core/configuration.rb +0 -1
  10. data/lib/gamebox/core/hooked_gosu_window.rb +9 -1
  11. data/lib/gamebox/core/physics_manager.rb +39 -19
  12. data/lib/gamebox/core/stage.rb +8 -13
  13. data/lib/gamebox/spec/helper.rb +6 -0
  14. data/lib/gamebox/version.rb +1 -1
  15. data/spec/acceptance/basic_actor_lifecycle_spec.rb +11 -1
  16. data/spec/acceptance/built_in_collision_handling_spec.rb +3 -3
  17. data/spec/acceptance/chipmunk_collision_handling_spec.rb +0 -2
  18. data/spec/acceptance/{input_stater_spec.rb → input_mapper_spec.rb} +1 -1
  19. data/spec/acceptance/pausing_spec.rb +29 -8
  20. data/spec/acceptance/timer_usage_spec.rb +5 -5
  21. data/spec/behaviors/animated_spec.rb +0 -2
  22. data/spec/behaviors/positioned_spec.rb +41 -2
  23. data/spec/core/arbiter_spec.rb +19 -1
  24. data/spec/core/hooked_gosu_window_spec.rb +10 -0
  25. data/spec/core/stage_spec.rb +74 -46
  26. data/{app_generators/templates → templates/app}/.gitignore +0 -0
  27. data/{app_generators/templates/Gemfile → templates/app/Gemfile.tt} +1 -1
  28. data/{app_generators/templates → templates/app}/NEXT_STEPS.txt +0 -0
  29. data/{app_generators/templates → templates/app}/README.rdoc +0 -0
  30. data/{app_generators/templates → templates/app}/Rakefile +0 -0
  31. data/{app_generators/templates → templates/app}/config/boot.rb +0 -0
  32. data/{app_generators/templates → templates/app}/config/environment.rb +2 -2
  33. data/{app_generators/templates → templates/app}/config/game.yml +0 -0
  34. data/{app_generators/templates → templates/app}/data/fonts/FONTS_GO_HERE +0 -0
  35. data/{app_generators/templates → templates/app}/data/graphics/GRAPHICS_GO_HERE +0 -0
  36. data/{app_generators/templates → templates/app}/data/music/MUSIC_GOES_HERE +0 -0
  37. data/{app_generators/templates → templates/app}/data/sounds/SOUND_FX_GO_HERE +0 -0
  38. data/{app_generators/templates → templates/app}/spec/helper.rb +0 -0
  39. data/{app_generators/templates → templates/app}/src/actors/player.rb +0 -0
  40. data/{app_generators/templates → templates/app}/src/app.rb +0 -0
  41. data/{app_generators/templates → templates/app}/src/demo_stage.rb +0 -0
  42. metadata +24 -46
  43. data/app_generators/gamebox_generator.rb +0 -95
  44. data/app_generators/templates/script/actor.erb +0 -10
  45. data/app_generators/templates/script/actor_spec.erb +0 -11
  46. data/app_generators/templates/script/actor_view.erb +0 -6
  47. data/app_generators/templates/script/actor_view_spec.erb +0 -10
  48. data/app_generators/templates/script/generate +0 -12
data/TODO.txt CHANGED
@@ -1,5 +1,4 @@
1
1
  TAKE YOUR PICK:
2
- - convert generators to thor
3
2
  - update README.rdoc in template app
4
3
  - generate sample Gemfile with current gamebox version
5
4
 
@@ -7,7 +6,6 @@ TAKE YOUR PICK:
7
6
  - game.yml settings .. ^^^
8
7
 
9
8
  - nice helpers for testing behaviors
10
-
11
9
  - add define_style that defines a bucket of behaviors
12
10
  - add helper for has_required_attributes on an actor from a behavior (checking that opts for the behavior has said key)
13
11
 
data/bin/gamebox CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'active_support'
4
- require 'rubigen'
3
+ require 'thor'
5
4
  require 'gamebox'
6
5
 
7
6
  def print_version
@@ -13,6 +12,30 @@ if ARGV.include?('-v') || ARGV.include?('--version')
13
12
  exit 0
14
13
  end
15
14
 
16
- require 'rubigen/scripts/generate'
17
- RubiGen::Base.use_application_sources!
18
- RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'gamebox')
15
+ class GameboxThorCommand < Thor
16
+ include Thor::Actions
17
+
18
+ def self.source_root
19
+ File.join(File.dirname(__FILE__), "../templates/")
20
+ end
21
+
22
+ desc "new PATH", "Generates a new gamebox game at PATH."
23
+ def new(*args)
24
+ game_name = args[0]
25
+ self.destination_root = game_name
26
+
27
+ if Gamebox::VERSION::RC > 0
28
+ @gamebox_version = Gamebox::VERSION::STRING
29
+ else
30
+ @gamebox_version = "~> "+[Gamebox::VERSION::MAJOR, Gamebox::VERSION::MINOR, '0'].join('.')
31
+ end
32
+
33
+ directory "app", "."
34
+
35
+ end
36
+
37
+
38
+
39
+ end
40
+
41
+ GameboxThorCommand.start
data/gamebox.gemspec CHANGED
@@ -22,9 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "publisher"
23
23
  s.add_dependency "conject", ">= 0.0.5"
24
24
  s.add_dependency "tween"
25
- s.add_dependency "activesupport", '3.0.0'
26
25
  s.add_dependency "i18n"
27
- s.add_dependency "rubigen"
26
+ s.add_dependency "thor", ">= 0.15.2"
28
27
  s.add_dependency "require_all"
29
28
  s.add_dependency "kvo", ">= 0.0.2"
30
29
 
data/lib/gamebox.rb CHANGED
@@ -16,6 +16,10 @@ end
16
16
  begin
17
17
  require 'pry'
18
18
  require 'pry-remote'
19
+ rescue LoadError
20
+ end
21
+
22
+ begin
19
23
  require 'chipmunk'
20
24
  rescue LoadError
21
25
  end
@@ -1,4 +1,4 @@
1
- define_behavior :input_stater do
1
+ define_behavior :input_mapper do
2
2
  requires :input_manager
3
3
 
4
4
  setup do
@@ -105,6 +105,13 @@ Behavior.define :physical do
105
105
  verts = @opts[:verts].dup
106
106
  verts << @opts[:verts][0]
107
107
  actor.segment_groups << verts
108
+
109
+ when :segment
110
+ @radius = @opts[:radius] || 0
111
+ @endpoints = @opts[:endpoints].collect{ |pt| vec2(*pt.to_a) }
112
+ @moment_of_inertia ||= @opts[:fixed] ? Float::INFINITY : CP::moment_for_segment(@mass, @endpoints[0], @endpoints[1])
113
+ actor.body = CP::Body.new(@mass, @moment_of_inertia)
114
+ actor.shape = CP::Shape::Segment.new(actor.body, @endpoints[0], @endpoints[1], @radius)
108
115
  end
109
116
 
110
117
  actor.shape.actor = actor
@@ -133,6 +140,10 @@ Behavior.define :physical do
133
140
  actor.segment_groups << verts
134
141
  when :circle
135
142
  part_shape = CP::Shape::Circle.new(actor.body, part_def[:radius], part_def[:offset])
143
+ when :segment
144
+ radius = part_def[:radius] || 0
145
+ endpoints = part_def[:endpoints].collect{ |pt| vec2(*pt.to_a) }
146
+ part_shape = CP::Shape::Segment.new(endpoints[0], endpoints[1], radius)
136
147
  else
137
148
  raise "unsupported sub shape type"
138
149
  end
@@ -19,6 +19,8 @@ class Actor
19
19
  self.actor_type = opts[:actor_type]
20
20
  end
21
21
 
22
+ # Used by BehaviorFactory#add_behavior.
23
+ # That's probably what you want to use from within another behavior
22
24
  def add_behavior(name, behavior)
23
25
  @behaviors[name] = behavior
24
26
  end
@@ -5,10 +5,9 @@
5
5
  # or by dynamically creating one at runtime via another behavior.
6
6
  class BehaviorFactory
7
7
 
8
- # Build a behavior. Takes a symbol or a Hash.
9
- # add_behavior(:shootable) or add_behavior(:shootable => {:range=>3})
10
- # this will create a new instance of Shootable and pass
11
- # :range=>3 to it
8
+ # Build a behavior.
9
+ # add_behavior(actor, :shootable) or add_behavior(actor, :shootable, :range=>3)
10
+ # this will create a new instance of Shootable and pass :range=>3 to it
12
11
  def add_behavior(actor, behavior_name, opts = {})
13
12
  raise "nil actor" if actor.nil?
14
13
  raise "nil behavior definition" if behavior_name.nil?
@@ -13,7 +13,6 @@ module Gamebox
13
13
  end
14
14
  end
15
15
 
16
- # add_setting :output, :alias => :output_stream
17
16
  add_setting :config_path
18
17
  add_setting :data_path
19
18
  add_setting :music_path
@@ -1,4 +1,5 @@
1
1
  module GosuWindowAPI
2
+ MAX_UPDATE_SIZE_IN_MILLIS = 500
2
3
  def initialize(width, height, fullscreen)
3
4
  super(width, height, fullscreen)
4
5
  end
@@ -7,7 +8,14 @@ module GosuWindowAPI
7
8
  millis = Gosu::milliseconds
8
9
 
9
10
  # ignore the first update
10
- fire :update, (millis - @last_millis) if @last_millis
11
+ if @last_millis
12
+ delta = millis
13
+ delta -= @last_millis if millis > @last_millis
14
+ delta = MAX_UPDATE_SIZE_IN_MILLIS if delta > MAX_UPDATE_SIZE_IN_MILLIS
15
+
16
+ fire :update, delta
17
+ end
18
+
11
19
  @last_millis = millis
12
20
  end
13
21
 
@@ -1,27 +1,56 @@
1
1
  # PhysicsManager creates and manages chipmunks space.
2
2
  class PhysicsManager
3
3
  extend Forwardable
4
- def_delegators :@space, :elastic_iterations=, :damping=, :gravity=
4
+ def_delegators( :@space,
5
+ :damping, :damping=,
6
+ :gravity, :gravity=,
7
+ :iterations, :iterations= )
5
8
 
6
9
  attr_accessor :space
10
+
11
+ # Time per physics step, in milliseconds (default 15). Small steps
12
+ # make the simulation more stable than large steps, but if the step
13
+ # is too small, it may negatively affect performance, i.e. cause
14
+ # very high CPU use and/or low framerate.
15
+ attr_reader :step_size
16
+ def step_size=(new_step_size)
17
+ @step_size = new_step_size.to_f
18
+ @step_size_seconds = @step_size / 1000
19
+ end
20
+
21
+
7
22
  def configure
8
23
  @space = CP::Space.new
9
- @space.iterations = 20
10
- @space.elastic_iterations = 5
24
+ @space.iterations = 10
25
+ self.step_size = 15
26
+ @leftover_step_time = 0
27
+ end
28
+
29
+
30
+ def update(time)
31
+ update_physics time
11
32
  end
12
33
 
13
- PHYSICS_STEP = 25.0
14
34
  def update_physics(time)
15
35
  unless @physics_paused
16
- steps = (time/PHYSICS_STEP).ceil
17
- # from chipmunk demo
18
- dt = 1.0/60/steps
36
+ @leftover_step_time += time
37
+ steps = (@leftover_step_time / @step_size).ceil
19
38
  steps.times do
20
- @space.step dt
39
+ @space.step @step_size_seconds
21
40
  end
41
+ @leftover_step_time -= (steps * @step_size).round
22
42
  end
23
43
  end
24
44
 
45
+
46
+ def pause
47
+ pause_physics
48
+ end
49
+
50
+ def unpause
51
+ restart_physics
52
+ end
53
+
25
54
  def pause_physics
26
55
  @physics_paused = true
27
56
  end
@@ -30,9 +59,6 @@ class PhysicsManager
30
59
  @physics_paused = false
31
60
  end
32
61
 
33
- def update(time)
34
- update_physics time
35
- end
36
62
 
37
63
  # allows for passing arrays of collision types not just single ones
38
64
  # add_collision_func([:foo,:bar], [:baz,:yar]) becomes:
@@ -71,6 +97,7 @@ class PhysicsManager
71
97
  end
72
98
  end
73
99
 
100
+
74
101
  def register_physical_constraint(constraint)
75
102
  @space.add_constraint constraint
76
103
  end
@@ -93,6 +120,7 @@ class PhysicsManager
93
120
  end
94
121
  end
95
122
 
123
+
96
124
  # Find any / all objects who's bounding box currently contains
97
125
  # the passed in screen position. Requires a block as this sets
98
126
  # a callback all the way down in Chipmunk and could be called
@@ -105,12 +133,4 @@ class PhysicsManager
105
133
  # block.call(actor)
106
134
  # end
107
135
  # end
108
-
109
- def pause
110
- pause_physics
111
- end
112
-
113
- def unpause
114
- restart_physics
115
- end
116
136
  end
@@ -13,7 +13,7 @@ class Stage
13
13
  kid.construct_with *self.object_definition.component_names
14
14
  end
15
15
 
16
- attr_accessor :drawables, :opts, :viewport, :backstage
16
+ attr_accessor :opts, :viewport, :backstage
17
17
 
18
18
  def configure(backstage, opts)
19
19
  res = config_manager[:screen_resolution]
@@ -133,19 +133,14 @@ class Stage
133
133
  # move all actors from one layer to another
134
134
  # note, this will remove all actors in that layer!
135
135
  def move_layer(from_parallax, from_layer, to_parallax, to_layer)
136
- drawable_list = @drawables[from_parallax].delete from_layer
136
+ drawable_list = @drawables[from_parallax][from_layer].dup
137
137
 
138
-
139
- if drawable_list
140
- prev_drawable_list = @drawables[to_parallax].delete to_layer
141
- @drawables[to_parallax][to_layer] = drawable_list
142
- drawable_list.each do |drawable|
143
- drawable.parallax = to_parallax
144
- drawable.layer = to_layer
145
- end
138
+ drawable_list.each do |drawable|
139
+ unregister_drawable drawable
140
+ drawable.parallax = to_parallax
141
+ drawable.layer = to_layer
142
+ register_drawable drawable
146
143
  end
147
- prev_drawable_list
148
-
149
144
  end
150
145
 
151
146
  def on_pause(&block)
@@ -194,7 +189,7 @@ class Stage
194
189
  # modal_actor :dialog, x: 40, y: 50, message: "WOW"
195
190
  def modal_actor(*args)
196
191
  on_pause do
197
- pause_actor = spawn *args
192
+ pause_actor = create_actor *args
198
193
  pause_actor.when :remove_me do
199
194
  @pause_listeners = nil
200
195
  unpause
@@ -272,6 +272,12 @@ module GameboxAcceptanceSpecHelpers
272
272
  game.current_stage.unpause
273
273
  end
274
274
 
275
+ def remove_actor(actor_type)
276
+ act = game.actor(actor_type)
277
+ act.should be
278
+ act.remove
279
+ end
280
+
275
281
  def see_actor_attrs(actor_type, attrs)
276
282
  act = game.actor(actor_type)
277
283
  act.should be
@@ -3,7 +3,7 @@ module Gamebox
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
5
  TINY = 0
6
- RC = 4
6
+ RC = 5
7
7
 
8
8
  if RC > 0
9
9
  ARRAY = [MAJOR, MINOR, TINY, "rc#{RC}"]
@@ -65,6 +65,10 @@ describe "The basic life cycle of an actor", acceptance: true do
65
65
  end
66
66
  end
67
67
 
68
+ define_actor :monkey do
69
+ has_attributes bananas: 3
70
+ end
71
+
68
72
 
69
73
  it 'creates an actor from within stage with the correct behaviors and updates' do
70
74
  game.stage do |stage|
@@ -98,6 +102,12 @@ describe "The basic life cycle of an actor", acceptance: true do
98
102
  see_actor_attrs :mc_bane, x: 500, y: 30
99
103
  end
100
104
 
101
- it 'uses default values from actor definition'
105
+ it 'uses default values from actor definition' do
106
+ game.stage do |stage|
107
+ create_actor :monkey
108
+ end
109
+ see_actor_attrs :monkey, bananas: 3
110
+ end
111
+
102
112
  end
103
113
 
@@ -16,7 +16,7 @@ describe "Using gamebox's built in collision handling", acceptance: true do
16
16
  laser = nil
17
17
  alien = nil
18
18
  game.stage do |stage| # instance of TestingStage
19
- laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 5, vel_y: 1
19
+ laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 50, vel_y: 1
20
20
  alien = create_actor :alien, x: 0, y: 0
21
21
  on_collision_of :frickin_laser, :alien do |collision_laser, collision_alien|
22
22
  @collision_laser = collision_laser
@@ -34,7 +34,7 @@ describe "Using gamebox's built in collision handling", acceptance: true do
34
34
  laser = nil
35
35
  alien = nil
36
36
  game.stage do |stage| # instance of TestingStage
37
- laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 5, vel_y: 0
37
+ laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 50, vel_y: 0
38
38
  alien = create_actor :alien, x: 31, y: 0
39
39
  on_collision_of :frickin_laser, :alien do |collision_laser, collision_alien|
40
40
  @collision_laser = collision_laser
@@ -45,7 +45,7 @@ describe "Using gamebox's built in collision handling", acceptance: true do
45
45
  # now the laser moved and will be checked for collisions _next_ update
46
46
  update 1
47
47
  # trigger the next round of collision detection
48
- update 2000
48
+ update 200
49
49
  # TODO not sure about this one..
50
50
  update 1
51
51
  see_stage_ivars collision_laser: laser, collision_alien: alien
@@ -35,7 +35,6 @@ describe "Using chipmunks collision handling", acceptance: true do
35
35
  @physics_manager = this_object_context[:physics_manager]
36
36
  @physics_manager.configure
37
37
  # TODO move these optionally to configure?
38
- @physics_manager.elastic_iterations = 4
39
38
  @physics_manager.damping = 0.4
40
39
 
41
40
  rock = create_actor :rock, x: 0, y: 0
@@ -63,7 +62,6 @@ describe "Using chipmunks collision handling", acceptance: true do
63
62
  @physics_manager = this_object_context[:physics_manager]
64
63
  @physics_manager.configure
65
64
  # TODO move these optionally to configure?
66
- @physics_manager.elastic_iterations = 4
67
65
  @physics_manager.damping = 0.4
68
66
  @physics_manager.gravity = vec2(0,500)
69
67
 
@@ -4,7 +4,7 @@ describe "Using input stater", acceptance: true do
4
4
 
5
5
 
6
6
  define_actor :foxy do
7
- has_behavior input_stater: {
7
+ has_behavior input_mapper: {
8
8
  [KbLeft] => :move_left,
9
9
  [KbRight, KbD] => :move_right
10
10
  }
@@ -6,7 +6,7 @@ describe "pausing in gamebox", acceptance: true do
6
6
  beh.requires :timer_manager
7
7
  beh.setup do
8
8
  actor.has_attributes rocks_shot: 0
9
- timer_manager.add_timer 'shoot_rock', 1_000 do
9
+ timer_manager.add_timer 'shoot_rock', 100 do
10
10
  actor.react_to :shoot_rock
11
11
  end
12
12
  end
@@ -22,9 +22,9 @@ describe "pausing in gamebox", acceptance: true do
22
22
 
23
23
 
24
24
  it 'allows timers and all updates from the director to be paused / unpaused' do
25
- game.stage do |stage| # instance of TestingStage
25
+ game.stage do |stage|
26
26
  @counter = 0
27
- timer_manager.add_timer 'stage_timer', 2000 do
27
+ timer_manager.add_timer 'stage_timer', 200 do
28
28
  @counter += 1
29
29
  end
30
30
  create_actor :mountain
@@ -48,30 +48,51 @@ describe "pausing in gamebox", acceptance: true do
48
48
  see_actor_attrs :mountain, rocks_shot: 0
49
49
  see_stage_ivars counter: 0
50
50
 
51
- update 100
51
+ update 10
52
52
  see_actor_attrs :mountain, rocks_shot: 0
53
53
  see_stage_ivars counter: 0
54
54
 
55
- update 901
55
+ update 91
56
56
  see_actor_attrs :mountain, rocks_shot: 1
57
57
  see_stage_ivars counter: 0
58
58
 
59
59
  press_key KbP
60
60
  game.should have_actor(:label)
61
- update 2001
61
+ update 201
62
62
  see_actor_attrs :mountain, rocks_shot: 1
63
63
  see_stage_ivars counter: 0
64
64
 
65
- update 2001
65
+ update 201
66
66
  see_actor_attrs :mountain, rocks_shot: 1
67
67
  see_stage_ivars counter: 0
68
68
 
69
69
  press_key KbP
70
70
  game.should_not have_actor(:label)
71
- update 2001
71
+ update 201
72
72
  see_actor_attrs :mountain, rocks_shot: 2
73
73
  see_stage_ivars counter: 1
74
74
  end
75
75
 
76
+ it 'modal actor pauses, shows actor, unpauses when that actor dies' do
77
+ game.stage do |stage|
78
+ modal_actor :label, text: "pause" do
79
+ @some_unpause_indicator = true
80
+ end
81
+ end
82
+
83
+ see_stage_ivars some_unpause_indicator: nil
84
+ game.should have_actor(:label)
85
+ see_actor_attrs :label, text: "pause"
86
+
87
+ remove_actor :label
88
+
89
+ game.should_not have_actor(:label)
90
+ see_stage_ivars some_unpause_indicator: true
91
+ end
92
+
76
93
  end
77
94
 
95
+
96
+
97
+
98
+
@@ -6,7 +6,7 @@ describe "Using timers", acceptance: true do
6
6
  beh.requires :timer_manager
7
7
  beh.setup do
8
8
  actor.has_attributes rocks_shot: 0
9
- timer_manager.add_timer 'shoot_rock', 1_000 do
9
+ timer_manager.add_timer 'shoot_rock', 100 do
10
10
  actor.react_to :shoot_rock
11
11
  end
12
12
  end
@@ -24,7 +24,7 @@ describe "Using timers", acceptance: true do
24
24
  it 'allows behaviors to get fired from timers' do
25
25
  game.stage do |stage| # instance of TestingStage
26
26
  @counter = 0
27
- timer_manager.add_timer 'stage_timer', 2000 do
27
+ timer_manager.add_timer 'stage_timer', 200 do
28
28
  @counter += 1
29
29
  end
30
30
  create_actor :volcano
@@ -32,15 +32,15 @@ describe "Using timers", acceptance: true do
32
32
  see_actor_attrs :volcano, rocks_shot: 0
33
33
  see_stage_ivars counter: 0
34
34
 
35
- update 100
35
+ update 10
36
36
  see_actor_attrs :volcano, rocks_shot: 0
37
37
  see_stage_ivars counter: 0
38
38
 
39
- update 901
39
+ update 91
40
40
  see_actor_attrs :volcano, rocks_shot: 1
41
41
  see_stage_ivars counter: 0
42
42
 
43
- update 2001
43
+ update 201
44
44
  see_actor_attrs :volcano, rocks_shot: 2
45
45
  see_stage_ivars counter: 1
46
46
 
@@ -1,8 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  describe :animated do
4
- it 'needs updated tests'
5
-
6
4
  let(:opts) { {} }
7
5
  subject { subcontext[:behavior_factory].add_behavior actor, :animated, opts }
8
6
  let(:director) { evented_stub(stub_everything('director')) }
@@ -1,6 +1,45 @@
1
1
  require 'helper'
2
2
 
3
3
  describe :positioned do
4
- it 'defines x,y on actor'
5
- it 'rolls up x and y changes to position_changed on update'
4
+
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
+ _mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
11
+ _mocks.each do |k,v|
12
+ it[k] = v
13
+ it[:director] = director
14
+ end
15
+ it
16
+ end
17
+ let!(:actor) { subcontext[:actor] }
18
+ let(:opts) { {} }
19
+
20
+ context "empty options" do
21
+ it 'defines x,y on actor' do
22
+ subject
23
+ actor.x.should == 0
24
+ actor.y.should == 0
25
+ end
26
+ end
27
+
28
+ it 'rolls up x and y changes to position_changed on update' do
29
+ subject
30
+ actor.x = 99
31
+
32
+ expects_event(actor, :position_changed) do
33
+ director.fire :update, 50
34
+ end
35
+ end
36
+
37
+ context "options passed in" do
38
+ let(:opts) { { x: 5, y: 8} }
39
+ it 'defines x,y on actor' do
40
+ subject
41
+ actor.x.should == 5
42
+ actor.y.should == 8
43
+ end
44
+ end
6
45
  end
@@ -241,7 +241,25 @@ describe 'Arbiter' do
241
241
  end
242
242
 
243
243
  describe '#collide_aabb_circle' do
244
- it 'should collide overlapping box and circle'
244
+ it 'should collide overlapping box and circle' do
245
+ a = stub(:center_x => 0, :center_y => 0, :width => 30, :height => 20,
246
+ :shape_type => :aabb, :radius => 10,
247
+ :cw_world_points => [
248
+ [-15,10],[15,10],
249
+ [15,-10], [-15,10]
250
+ ],
251
+ :cw_world_lines => [
252
+ [[-15,10],[15,10]],
253
+ [[15,10],[15,-10]],
254
+ [[15,-10],[-15,10]],
255
+ [[-15,10],[-15,10]]
256
+ ],
257
+ :cw_world_edge_normals => [[1,0],[0,1]])
258
+ b = stub(:center_x => 5, :center_y => 5, :width => 10, :height => 2,
259
+ :shape_type => :circle, :radius => 10)
260
+
261
+ @arbiter.collide_aabb_circle?(a,b).should be_true
262
+ end
245
263
  end
246
264
 
247
265
  describe "#find_collisions" do
@@ -28,6 +28,16 @@ describe HookedGosuWindow do
28
28
  end
29
29
  end
30
30
 
31
+ it 'truncates an update to 500 millis in case of computer sleep' do
32
+ subject.instance_variable_set('@last_millis', 0)
33
+ Gosu.stubs(:milliseconds).returns 501
34
+
35
+ expects_event subject, :update, [[500]] do
36
+ subject.update
37
+ end
38
+
39
+ end
40
+
31
41
  it 'fires initial update with deltas' do
32
42
  subject.instance_variable_set('@last_millis', 30)
33
43
  Gosu.stubs(:milliseconds).returns 58
@@ -4,15 +4,35 @@ describe Stage do
4
4
  inject_mocks :input_manager, :actor_factory, :resource_manager,
5
5
  :sound_manager, :config_manager, :director, :this_object_context,
6
6
  :timer_manager
7
- FakeDrawable = Struct.new :layer, :parallax
7
+
8
+ let(:a) { stub('a', layer: 0, parallax: 0) }
9
+ let(:b) { stub('b', layer: 0, parallax: 0) }
10
+
11
+ let(:c) { stub('c', layer: 1, parallax: 0) }
12
+ let(:d) { stub('d', layer: 2, parallax: 0) }
13
+ let(:e) { stub('e', layer: 3, parallax: 0) }
14
+ let(:f) { stub('f', layer: 4, parallax: 0) }
15
+
16
+ let(:x) { stub('x', layer: 0, parallax: 1) }
17
+ let(:y) { stub('y', layer: 2, parallax: 1) }
18
+
19
+ let(:z) { stub('z', layer: 0, parallax: 3) }
20
+ let(:target) { stub }
21
+ let(:viewport) { stub }
8
22
 
9
23
  before do
10
24
  @config_manager.stubs(:[]).with(:screen_resolution).returns([800,600])
11
25
  @actor_factory.stubs(:director=)
12
- @viewport = stub
13
- Viewport.stubs(:new).with(800, 600).returns(@viewport)
14
- @this_object_context.expects(:[]=).with(:viewport, @viewport)
26
+ Viewport.stubs(:new).with(800, 600).returns(viewport)
27
+ @this_object_context.expects(:[]=).with(:viewport, viewport)
15
28
  subject.configure(:backstage, {})
29
+
30
+ viewport.stubs(:x_offset).with(0).returns(:trans_x_zero)
31
+ viewport.stubs(:y_offset).with(0).returns(:trans_y_zero)
32
+ viewport.stubs(:x_offset).with(1).returns(:trans_x_one)
33
+ viewport.stubs(:y_offset).with(1).returns(:trans_y_one)
34
+ viewport.stubs(:x_offset).with(3).returns(:trans_x_three)
35
+ viewport.stubs(:y_offset).with(3).returns(:trans_y_three)
16
36
  end
17
37
 
18
38
  it 'should construct' do
@@ -23,51 +43,59 @@ describe Stage do
23
43
  subject.backstage.should == :backstage
24
44
  end
25
45
 
26
- it 'should register drawables by parallax and layer'
27
- it 'should unregister drawables by parallax and layer'
28
- it 'should draw drawables by parallax and layers' do
29
- a = FakeDrawable.new
30
- b = FakeDrawable.new
31
- c = FakeDrawable.new
32
- d = FakeDrawable.new
33
- e = FakeDrawable.new
34
- f = FakeDrawable.new
35
- x = FakeDrawable.new
36
- y = FakeDrawable.new
37
- z = FakeDrawable.new
38
- subject.drawables = {
39
- 2 => {3=> [a,b,c]},
40
- 6 => {7=> [d,e,f]},
41
- 9 => {13=> [x,y,z]},
42
- }
43
- subject.move_layer(2, 3, 6, 7).should == [d,e,f]
44
- subject.drawables[6][7].should_not be_nil
45
- subject.drawables[6][7].should == [a,b,c]
46
- subject.drawables[2][3].should be_nil
46
+ it 'registers and draws drawables by parallax and layers' do
47
+ subject.register_drawable a
48
+ subject.register_drawable b
49
+ subject.register_drawable c
50
+ subject.register_drawable d
51
+ subject.register_drawable e
52
+ subject.register_drawable f
53
+ subject.register_drawable x
54
+ subject.register_drawable y
55
+ subject.register_drawable z
56
+
57
+ a.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 4)
58
+ b.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 4)
59
+ c.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 5)
60
+ d.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 6)
61
+ e.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 7)
62
+ f.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 8)
63
+ x.expects(:draw).with(target, :trans_x_one, :trans_y_one, 2)
64
+ y.expects(:draw).with(target, :trans_x_one, :trans_y_one, 3)
65
+ z.expects(:draw).with(target, :trans_x_three, :trans_y_three, 1)
66
+
67
+ subject.draw(target)
47
68
  end
48
- it 'should move drawables layers' do
49
69
 
50
- a = FakeDrawable.new
51
- b = FakeDrawable.new
52
- c = FakeDrawable.new
53
- d = FakeDrawable.new
54
- e = FakeDrawable.new
55
- f = FakeDrawable.new
56
- x = FakeDrawable.new
57
- y = FakeDrawable.new
58
- z = FakeDrawable.new
59
- subject.drawables = {
60
- 2 => {3=> [a,b,c]},
61
- 6 => {7=> [d,e,f]},
62
- 9 => {13=> [x,y,z]},
63
- }
64
- subject.move_layer(2, 3, 6, 7).should == [d,e,f]
65
- subject.drawables[6][7].should_not be_nil
66
- subject.drawables[6][7].should == [a,b,c]
67
- subject.drawables[2][3].should be_nil
70
+ it 'should unregister drawables by parallax and layer' do
71
+ subject.register_drawable a
72
+ subject.register_drawable b
73
+
74
+ subject.unregister_drawable a
75
+ b.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 1)
76
+
77
+ subject.draw(target)
68
78
  end
69
79
 
70
- describe "#modal_actor" do
71
- it 'pauses, shows actor, unpauses when that actor dies; ug, how to test this?'
80
+ it 'should move drawables layers' do
81
+ subject.register_drawable a
82
+ subject.register_drawable b
83
+ subject.register_drawable x
84
+ subject.register_drawable y
85
+
86
+ a.expects(:parallax=).with(1)
87
+ b.expects(:parallax=).with(1)
88
+ a.expects(:layer=).with(4)
89
+ b.expects(:layer=).with(4)
90
+
91
+ subject.move_layer 0, 0, 1, 4
92
+
93
+ a.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 3)
94
+ b.expects(:draw).with(target, :trans_x_zero, :trans_y_zero, 3)
95
+ x.expects(:draw).with(target, :trans_x_one, :trans_y_one, 1)
96
+ y.expects(:draw).with(target, :trans_x_one, :trans_y_one, 2)
97
+
98
+ subject.draw(target)
72
99
  end
100
+
73
101
  end
@@ -2,6 +2,6 @@ source "http://rubygems.org"
2
2
  # uncomment for chipmunk
3
3
  # gem 'chipmunk'
4
4
  gem 'require_all'
5
- gem "gamebox", '>= 0.4.0'
5
+ gem "gamebox", '<%= @gamebox_version %>'
6
6
  gem "conject"
7
7
  gem "rspec"
@@ -8,14 +8,14 @@ Gamebox.configure do |config|
8
8
  config.music_path = APP_ROOT + "data/music/"
9
9
  config.sound_path = APP_ROOT + "data/sounds/"
10
10
  config.gfx_path = APP_ROOT + "data/graphics/"
11
- config.fonts_path = APP_ROOT + "data/fonts"
11
+ config.fonts_path = APP_ROOT + "data/fonts/"
12
12
 
13
13
  config.gb_config_path = GAMEBOX_PATH + "config/"
14
14
  config.gb_data_path = GAMEBOX_PATH + "data/"
15
15
  config.gb_music_path = GAMEBOX_PATH + "data/music/"
16
16
  config.gb_sound_path = GAMEBOX_PATH + "data/sounds/"
17
17
  config.gb_gfx_path = GAMEBOX_PATH + "data/graphics/"
18
- config.gb_fonts_path = GAMEBOX_PATH + "data/fonts"
18
+ config.gb_fonts_path = GAMEBOX_PATH + "data/fonts/"
19
19
 
20
20
  # config.stages = [:demo]
21
21
  # config.game_name = "Untitled Game"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc4
4
+ version: 0.4.0.rc5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-05-28 00:00:00.000000000 Z
14
+ date: 2012-06-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gosu
@@ -77,22 +77,6 @@ dependencies:
77
77
  - - ! '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
- - !ruby/object:Gem::Dependency
81
- name: activesupport
82
- requirement: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - '='
86
- - !ruby/object:Gem::Version
87
- version: 3.0.0
88
- type: :runtime
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - '='
94
- - !ruby/object:Gem::Version
95
- version: 3.0.0
96
80
  - !ruby/object:Gem::Dependency
97
81
  name: i18n
98
82
  requirement: !ruby/object:Gem::Requirement
@@ -110,13 +94,13 @@ dependencies:
110
94
  - !ruby/object:Gem::Version
111
95
  version: '0'
112
96
  - !ruby/object:Gem::Dependency
113
- name: rubigen
97
+ name: thor
114
98
  requirement: !ruby/object:Gem::Requirement
115
99
  none: false
116
100
  requirements:
117
101
  - - ! '>='
118
102
  - !ruby/object:Gem::Version
119
- version: '0'
103
+ version: 0.15.2
120
104
  type: :runtime
121
105
  prerelease: false
122
106
  version_requirements: !ruby/object:Gem::Requirement
@@ -124,7 +108,7 @@ dependencies:
124
108
  requirements:
125
109
  - - ! '>='
126
110
  - !ruby/object:Gem::Version
127
- version: '0'
111
+ version: 0.15.2
128
112
  - !ruby/object:Gem::Dependency
129
113
  name: require_all
130
114
  requirement: !ruby/object:Gem::Requirement
@@ -344,28 +328,6 @@ files:
344
328
  - README.md
345
329
  - Rakefile
346
330
  - TODO.txt
347
- - app_generators/gamebox_generator.rb
348
- - app_generators/templates/.gitignore
349
- - app_generators/templates/Gemfile
350
- - app_generators/templates/NEXT_STEPS.txt
351
- - app_generators/templates/README.rdoc
352
- - app_generators/templates/Rakefile
353
- - app_generators/templates/config/boot.rb
354
- - app_generators/templates/config/environment.rb
355
- - app_generators/templates/config/game.yml
356
- - app_generators/templates/data/fonts/FONTS_GO_HERE
357
- - app_generators/templates/data/graphics/GRAPHICS_GO_HERE
358
- - app_generators/templates/data/music/MUSIC_GOES_HERE
359
- - app_generators/templates/data/sounds/SOUND_FX_GO_HERE
360
- - app_generators/templates/script/actor.erb
361
- - app_generators/templates/script/actor_spec.erb
362
- - app_generators/templates/script/actor_view.erb
363
- - app_generators/templates/script/actor_view_spec.erb
364
- - app_generators/templates/script/generate
365
- - app_generators/templates/spec/helper.rb
366
- - app_generators/templates/src/actors/player.rb
367
- - app_generators/templates/src/app.rb
368
- - app_generators/templates/src/demo_stage.rb
369
331
  - bin/gamebox
370
332
  - component_generators/actor_generator.rb
371
333
  - docs/CODE_REVIEW
@@ -392,7 +354,7 @@ files:
392
354
  - lib/gamebox/behaviors/collidable/polygon_collidable.rb
393
355
  - lib/gamebox/behaviors/emitting.rb
394
356
  - lib/gamebox/behaviors/graphical.rb
395
- - lib/gamebox/behaviors/input_stater.rb
357
+ - lib/gamebox/behaviors/input_mapper.rb
396
358
  - lib/gamebox/behaviors/layered.rb
397
359
  - lib/gamebox/behaviors/physical.rb
398
360
  - lib/gamebox/behaviors/positioned.rb
@@ -473,7 +435,7 @@ files:
473
435
  - spec/acceptance/built_in_collision_handling_spec.rb
474
436
  - spec/acceptance/chipmunk_collision_handling_spec.rb
475
437
  - spec/acceptance/fps_actor_spec.rb
476
- - spec/acceptance/input_stater_spec.rb
438
+ - spec/acceptance/input_mapper_spec.rb
477
439
  - spec/acceptance/pausing_spec.rb
478
440
  - spec/acceptance/timer_usage_spec.rb
479
441
  - spec/actors/emitter_spec.rb
@@ -513,6 +475,22 @@ files:
513
475
  - spec/lib/class_finder_spec.rb
514
476
  - spec/stagehands/spatial_tree_stagehand_spec.rb
515
477
  - spec/views/graphical_actor_view_spec.rb
478
+ - templates/app/.gitignore
479
+ - templates/app/Gemfile.tt
480
+ - templates/app/NEXT_STEPS.txt
481
+ - templates/app/README.rdoc
482
+ - templates/app/Rakefile
483
+ - templates/app/config/boot.rb
484
+ - templates/app/config/environment.rb
485
+ - templates/app/config/game.yml
486
+ - templates/app/data/fonts/FONTS_GO_HERE
487
+ - templates/app/data/graphics/GRAPHICS_GO_HERE
488
+ - templates/app/data/music/MUSIC_GOES_HERE
489
+ - templates/app/data/sounds/SOUND_FX_GO_HERE
490
+ - templates/app/spec/helper.rb
491
+ - templates/app/src/actors/player.rb
492
+ - templates/app/src/app.rb
493
+ - templates/app/src/demo_stage.rb
516
494
  homepage: http://shawn42.github.com/gamebox
517
495
  licenses: []
518
496
  post_install_message:
@@ -543,7 +521,7 @@ test_files:
543
521
  - spec/acceptance/built_in_collision_handling_spec.rb
544
522
  - spec/acceptance/chipmunk_collision_handling_spec.rb
545
523
  - spec/acceptance/fps_actor_spec.rb
546
- - spec/acceptance/input_stater_spec.rb
524
+ - spec/acceptance/input_mapper_spec.rb
547
525
  - spec/acceptance/pausing_spec.rb
548
526
  - spec/acceptance/timer_usage_spec.rb
549
527
  - spec/actors/emitter_spec.rb
@@ -1,95 +0,0 @@
1
- require 'rbconfig'
2
-
3
- class GameboxGenerator < RubiGen::Base
4
- DEFAULT_SHEBANG = File.join(RbConfig::CONFIG['bindir'],
5
- RbConfig::CONFIG['ruby_install_name'])
6
-
7
- default_options :shebang => DEFAULT_SHEBANG
8
-
9
- attr_reader :app_name, :module_name
10
-
11
- def initialize(runtime_args, runtime_options = {})
12
- super
13
- usage if args.empty?
14
- @destination_root = args.shift
15
- @app_name = File.basename(File.expand_path(@destination_root))
16
- @module_name = app_name.camelize
17
- extract_options
18
- end
19
-
20
- def manifest
21
- # Use /usr/bin/env if no special shebang was specified
22
- script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
23
- windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
24
-
25
- record do |m|
26
- # Root directory and all subdirectories.
27
- m.directory ''
28
- BASEDIRS.each { |path| m.directory path }
29
-
30
- # Root
31
- m.template_copy_each %w( Rakefile
32
- README.rdoc
33
- config/environment.rb
34
- )
35
-
36
- m.file_copy_each %w(
37
- Gemfile
38
- config/boot.rb
39
- config/game.yml
40
-
41
- data/fonts/FONTS_GO_HERE
42
- data/graphics/GRAPHICS_GO_HERE
43
- data/music/MUSIC_GOES_HERE
44
- data/sounds/SOUND_FX_GO_HERE
45
-
46
- spec/helper.rb
47
-
48
- src/app.rb
49
- src/demo_stage.rb
50
- src/actors/player.rb
51
- )
52
-
53
- m.readme 'NEXT_STEPS.txt'
54
-
55
- # Scripts
56
- # %w( generate ).each do |file|
57
- # m.template "script/#{file}", "script/#{file}", script_options
58
- # # m.template "script/win_script.cmd", "script/#{file}.cmd",
59
- # # :assigns => { :filename => file } if windows
60
- # end
61
-
62
- end
63
- end
64
-
65
- protected
66
- def banner
67
- <<-EOS
68
- Create a stub for a gamebox game.
69
-
70
- Usage: gamebox /path/to/your/app [options]"
71
- EOS
72
- end
73
-
74
- def add_options!(opts)
75
- opts.separator ''
76
- opts.separator "Gamebox options:"
77
- opts.on("-v", "--version", "Show the #{File.basename($0)} version number.")
78
- end
79
-
80
- def extract_options
81
- end
82
-
83
- # Installation skeleton. Intermediate directories are automatically
84
- # created so don't sweat their absence here.
85
- BASEDIRS = %w(
86
- src/actors
87
- spec
88
- data/fonts
89
- data/graphics
90
- data/music
91
- data/sounds
92
- config
93
- )
94
- end
95
-
@@ -1,10 +0,0 @@
1
- class <%= @actor_name %> < Actor
2
- <% if @behaviors %>
3
- has_baviors <%= @behaviors.join "," %>
4
- <% end %>
5
-
6
- def setup
7
- # register for events here
8
- # or pull stuff out of @opts
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- require 'helper'
2
- require '<%= Inflector.underscore @actor_name %>'
3
-
4
- describe 'a new <%= @actor_name %>' do
5
- before do
6
- # opts = {:stage=>"stage", :input=>"input", :resources=>"resource"}
7
- # @test_me = <%= @actor_name %>.new opts
8
- end
9
-
10
- it 'should do something'
11
- end
@@ -1,6 +0,0 @@
1
- class <%= @actor_view_name %> < ActorView
2
-
3
- def draw(target,x_off,y_off,z)
4
- # put in custom draw code here using @actor as the model
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- require 'helper'
2
- require '<%= Inflector.underscore @actor_view_name %>'
3
-
4
- describe 'a new <%= @actor_view_name %>' do
5
- before do
6
- #@test_me = <%= @actor_view_name %>.new "stage", "actor"
7
- end
8
-
9
- it 'should do something'
10
- end
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- require 'active_support'
5
- require 'rubigen'
6
- require APP_ROOT + '/config/environment'
7
-
8
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
9
-
10
- require 'rubigen/scripts/generate'
11
- RubiGen::Base.use_component_sources!
12
- RubiGen::Scripts::Generate.new.run(ARGV, source: GAMEBOX_PATH + '/component_generators/templates' )