gamebox 0.0.6 → 0.0.7

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 (81) hide show
  1. data/History.txt +14 -0
  2. data/Manifest.txt +40 -37
  3. data/README.txt +2 -2
  4. data/Rakefile +27 -20
  5. data/TODO.txt +8 -8
  6. data/bin/gamebox +7 -1
  7. data/docs/getting_started.rdoc +2 -5
  8. data/docs/logo.png +0 -0
  9. data/lib/gamebox.rb +12 -1
  10. data/lib/gamebox/actor.rb +34 -9
  11. data/lib/gamebox/actor_factory.rb +25 -14
  12. data/lib/gamebox/actor_view.rb +6 -6
  13. data/lib/gamebox/{logo.rb → actors/logo.rb} +0 -0
  14. data/lib/gamebox/{score.rb → actors/score.rb} +2 -1
  15. data/lib/gamebox/{svg_actor.rb → actors/svg_actor.rb} +3 -4
  16. data/lib/gamebox/ai/polaris.rb +2 -0
  17. data/lib/gamebox/behavior.rb +3 -0
  18. data/lib/gamebox/{animated.rb → behaviors/animated.rb} +13 -5
  19. data/lib/gamebox/{graphical.rb → behaviors/graphical.rb} +11 -1
  20. data/lib/gamebox/{layered.rb → behaviors/layered.rb} +14 -0
  21. data/lib/gamebox/{physical.rb → behaviors/physical.rb} +41 -14
  22. data/lib/gamebox/{updatable.rb → behaviors/updatable.rb} +1 -1
  23. data/lib/gamebox/{templates/template_app → data}/config/objects.yml +4 -2
  24. data/lib/gamebox/data/graphics/logo.png +0 -0
  25. data/lib/gamebox/event_compat.rb +285 -0
  26. data/lib/gamebox/ftor.rb +2 -0
  27. data/lib/gamebox/gamebox_application.rb +12 -1
  28. data/lib/gamebox/generators/actor_generator.rb +2 -2
  29. data/lib/gamebox/generators/view_generator.rb +42 -0
  30. data/lib/gamebox/input_manager.rb +88 -21
  31. data/lib/gamebox/{aliasing.rb → lib/aliasing.rb} +0 -0
  32. data/lib/gamebox/{templates/template_app/lib → lib}/diy.rb +0 -0
  33. data/lib/gamebox/{inflections.rb → lib/inflections.rb} +0 -0
  34. data/lib/gamebox/{inflector.rb → lib/inflector.rb} +2 -2
  35. data/lib/gamebox/{linked_list.rb → lib/linked_list.rb} +0 -0
  36. data/lib/gamebox/{metaclass.rb → lib/metaclass.rb} +0 -0
  37. data/lib/gamebox/lib/numbers_ext.rb +3 -0
  38. data/lib/gamebox/{platform.rb → lib/platform.rb} +0 -0
  39. data/lib/gamebox/{publisher_ext.rb → lib/publisher_ext.rb} +0 -0
  40. data/lib/gamebox/{sorted_list.rb → lib/sorted_list.rb} +0 -0
  41. data/lib/gamebox/lib/surface_ext.rb +76 -0
  42. data/lib/gamebox/physical_director.rb +1 -1
  43. data/lib/gamebox/{physical_level.rb → physical_stage.rb} +28 -18
  44. data/lib/gamebox/physics.rb +2 -2
  45. data/lib/gamebox/resource_manager.rb +77 -8
  46. data/lib/gamebox/sound_manager.rb +15 -17
  47. data/lib/gamebox/stage.rb +143 -0
  48. data/lib/gamebox/stage_manager.rb +110 -0
  49. data/lib/gamebox/svg_document.rb +1 -1
  50. data/lib/gamebox/tasks/gamebox_tasks.rb +1 -1
  51. data/lib/gamebox/templates/{test_actor.erb → actor_spec.erb} +2 -2
  52. data/lib/gamebox/templates/actor_view.erb +8 -0
  53. data/lib/gamebox/templates/actor_view_spec.erb +10 -0
  54. data/lib/gamebox/templates/template_app/Rakefile +4 -4
  55. data/lib/gamebox/templates/template_app/config/game.yml +1 -0
  56. data/lib/gamebox/templates/template_app/config/stage_config.yml +2 -0
  57. data/lib/gamebox/templates/template_app/script/generate +2 -1
  58. data/lib/gamebox/templates/template_app/{test → spec}/helper.rb +0 -0
  59. data/lib/gamebox/templates/template_app/src/{demo_level.rb → demo_stage.rb} +5 -3
  60. data/lib/gamebox/templates/template_app/src/game.rb +4 -6
  61. data/lib/gamebox/version.rb +3 -2
  62. data/lib/gamebox/viewport.rb +18 -9
  63. data/lib/gamebox/{graphical_actor_view.rb → views/graphical_actor_view.rb} +13 -1
  64. data/lib/gamebox/wrapped_screen.rb +2 -1
  65. data/spec/actor_spec.rb +57 -0
  66. data/{test/test_animated.rb → spec/animated_spec.rb} +5 -6
  67. data/spec/helper.rb +24 -0
  68. data/{test/test_line_of_site.rb → spec/line_of_site_spec.rb} +1 -1
  69. data/{test/test_physical.rb → spec/physical_spec.rb} +3 -4
  70. data/{test/test_polaris.rb → spec/polaris_spec.rb} +1 -1
  71. data/{test/test_viewport.rb → spec/viewport_spec.rb} +11 -8
  72. metadata +53 -50
  73. data/docs/gamebox04_big.png +0 -0
  74. data/lib/gamebox/level.rb +0 -65
  75. data/lib/gamebox/mode.rb +0 -123
  76. data/lib/gamebox/mode_manager.rb +0 -80
  77. data/lib/gamebox/numbers_ext.rb +0 -3
  78. data/lib/gamebox/surface_ext.rb +0 -37
  79. data/lib/gamebox/templates/template_app/config/mode_level_config.yml +0 -3
  80. data/test/helper.rb +0 -26
  81. data/test/test_actor.rb +0 -36
@@ -42,7 +42,7 @@ class SvgDocument
42
42
  if transform and transform =~ /translate\(\s*(.+?)\s*,\s*(.+?\)\s*)/
43
43
  vec2($1.to_f, ty = $2.to_f)
44
44
  else
45
- ZeroVec2
45
+ ZERO_VEC_2
46
46
  end
47
47
  end
48
48
  end
@@ -1,4 +1,4 @@
1
- require 'gamebox/platform'
1
+ require 'gamebox/lib/platform'
2
2
 
3
3
  task :default => :run
4
4
  desc "Run the game"
@@ -3,8 +3,8 @@ require '<%= Inflector.underscore @actor_name %>'
3
3
 
4
4
  describe 'a new <%= @actor_name %>' do
5
5
  before do
6
- opts = {:level=>"level", :input=>"input", :resources=>"resource"}
7
- @test_me = <%= @actor_name %>.new opts
6
+ # opts = {:stage=>"stage", :input=>"input", :resources=>"resource"}
7
+ # @test_me = <%= @actor_name %>.new opts
8
8
  end
9
9
 
10
10
  it 'should do something'
@@ -0,0 +1,8 @@
1
+ require 'actor_view'
2
+
3
+ class <%= @actor_view_name %> < ActorView
4
+
5
+ def draw(target,x_off,y_off)
6
+ # put in custom draw code here using @actor as the model
7
+ end
8
+ end
@@ -0,0 +1,10 @@
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
@@ -21,8 +21,8 @@ end
21
21
 
22
22
  require 'spec/rake/spectask'
23
23
  desc "Run all specs"
24
- Spec::Rake::SpecTask.new('specs') do |t|
25
- t.spec_opts = ["-r", "./test/helper"]
26
- t.spec_files = FileList['test//test_*.rb']
24
+ Spec::Rake::SpecTask.new('rspec') do |t|
25
+ t.spec_opts = ["-r", "./spec/helper"]
26
+ t.spec_files = FileList['spec//*_spec.rb']
27
27
  end
28
- task :test => :specs
28
+ task :test => :rspec
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  :sound: true
3
+ :auto_quit: :escape
3
4
  :fullscreen: false
4
5
  :screen_resolution:
5
6
  - 1024
@@ -0,0 +1,2 @@
1
+ :stages:
2
+ - :demo:
@@ -4,5 +4,6 @@ require 'rubygems'
4
4
 
5
5
  app_root = File.join(File.dirname(__FILE__),'..')
6
6
  $: << app_root
7
- require 'config/environment'
7
+ $: << File.join(app_root,'config')
8
+ require 'environment'
8
9
  require 'gamebox_generator'
@@ -1,7 +1,8 @@
1
- require 'level'
1
+ require 'stage'
2
2
  require 'ftor'
3
- class DemoLevel < Level
3
+ class DemoStage < Stage
4
4
  def setup
5
+ super
5
6
  @my_actor = create_actor :my_actor
6
7
  @my_actor.x = 10
7
8
  @my_actor.y = 10
@@ -10,11 +11,12 @@ class DemoLevel < Level
10
11
  20.times { @stars << Ftor.new(rand(viewport.width),rand(viewport.height)) }
11
12
  end
12
13
 
13
- def draw(target, x_off, y_off)
14
+ def draw(target)
14
15
  target.fill [25,25,25,255]
15
16
  for star in @stars
16
17
  target.draw_circle_s([star.x,star.y],1,[255,255,255,255])
17
18
  end
19
+ super
18
20
  end
19
21
  end
20
22
 
@@ -1,21 +1,19 @@
1
1
  class Game
2
2
 
3
3
  constructor :wrapped_screen, :input_manager, :sound_manager,
4
- :mode_manager
4
+ :stage_manager
5
5
 
6
6
  def setup
7
- # @sound_manager.play :current_rider
8
-
9
- @mode_manager.change_mode_to :default
7
+ @stage_manager.change_stage_to :demo
10
8
  end
11
9
 
12
10
  def update(time)
13
- @mode_manager.update time
11
+ @stage_manager.update time
14
12
  draw
15
13
  end
16
14
 
17
15
  def draw
18
- @mode_manager.draw @wrapped_screen
16
+ @stage_manager.draw @wrapped_screen
19
17
  @wrapped_screen.flip
20
18
  end
21
19
 
@@ -2,9 +2,10 @@ module Gamebox
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
7
+ ARRAY = [MAJOR, MINOR, TINY]
8
+ STRING = ARRAY.join('.')
8
9
  end
9
10
  end
10
11
 
@@ -8,7 +8,7 @@ class Viewport
8
8
  can_fire :scrolled
9
9
 
10
10
  attr_accessor :x_offset, :y_offset, :follow_target, :width,
11
- :height
11
+ :height, :x_offset_range, :y_offset_range
12
12
 
13
13
  def debug
14
14
  "xoff:#{@x_offset} yoff:#{@y_offset}"
@@ -23,13 +23,13 @@ class Viewport
23
23
  end
24
24
 
25
25
  def x_offset(layer=1)
26
- return 0 if layer == Float::Infinity
26
+ return 0 if layer == Float::INFINITY
27
27
  return @x_offset if layer == 1
28
28
  @x_offset / layer
29
29
  end
30
30
 
31
31
  def y_offset(layer=1)
32
- return 0 if layer == Float::Infinity
32
+ return 0 if layer == Float::INFINITY
33
33
  return @y_offset if layer == 1
34
34
  @y_offset / layer
35
35
  end
@@ -37,28 +37,37 @@ class Viewport
37
37
  def update(time)
38
38
  scrolled = false
39
39
  if @follow_target
40
- x_diff = @width/2 + @follow_offset_x - @follow_target.x - @x_offset
40
+ x = @follow_target.x
41
+ y = @follow_target.y
42
+ if @x_offset_range
43
+ x = @x_offset_range.min if @x_offset_range.min > x
44
+ x = @x_offset_range.max if @x_offset_range.max < x
45
+ end
46
+ if @y_offset_range
47
+ y = @y_offset_range.min if @y_offset_range.min > y
48
+ y = @y_offset_range.max if @y_offset_range.max < y
49
+ end
50
+ x_diff = @width/2 + @follow_offset_x - x - @x_offset
41
51
  if x_diff.abs > @buffer_x
42
52
  # move screen
43
53
  if x_diff > 0
44
54
  @x_offset += x_diff - @buffer_x
45
- scrolled = true
46
55
  else
47
56
  @x_offset += x_diff + @buffer_x
48
- scrolled = true
49
57
  end
58
+ scrolled = true
50
59
  end
51
60
 
52
- y_diff = @height/2 + @follow_offset_y - @follow_target.y - @y_offset
61
+
62
+ y_diff = @height/2 + @follow_offset_y - y - @y_offset
53
63
  if y_diff.abs > @buffer_y
54
64
  # move screen
55
65
  if y_diff > 0
56
66
  @y_offset += y_diff - @buffer_y
57
- scrolled = true
58
67
  else
59
68
  @y_offset += y_diff + @buffer_y
60
- scrolled = true
61
69
  end
70
+ scrolled = true
62
71
  end
63
72
 
64
73
  fire :scrolled if scrolled
@@ -27,7 +27,19 @@ class GraphicalActorView < ActorView
27
27
  end
28
28
 
29
29
  else
30
- img.blit target.screen, [x+x_off,y+y_off]
30
+ if @actor.is?(:graphical) && @actor.graphical.tiled?
31
+ x_tiles = @actor.graphical.num_x_tiles
32
+ y_tiles = @actor.graphical.num_y_tiles
33
+ img_w, img_h = *img.size
34
+ x_tiles.times do |col|
35
+ y_tiles.times do |row|
36
+ img.blit target.screen, [x+x_off+col*img_w,y+y_off+row*img_h]
37
+ end
38
+ end
39
+ else
40
+ img.blit target.screen, [x+x_off,y+y_off]
41
+ end
42
+
31
43
  end
32
44
  end
33
45
  end
@@ -7,7 +7,8 @@ class WrappedScreen
7
7
  flags << HWSURFACE
8
8
  flags << DOUBLEBUF
9
9
  flags << FULLSCREEN if @config_manager[:fullscreen]
10
- @screen = Screen.set_mode [w,h], 0, flags
10
+ flags << OPENGL if @config_manager[:opengl]
11
+ @screen = Screen.open [w,h], 0, flags
11
12
  end
12
13
  def method_missing(name,*args)
13
14
  @screen.send name, *args
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__),'helper')
2
+ require 'actor'
3
+ require 'behavior'
4
+
5
+ describe 'A new actor' do
6
+ before do
7
+ opts = {:stage=>"stage", :input=>"input", :resources=>"resource"}
8
+ @actor = Actor.new opts
9
+ end
10
+
11
+ it 'should be alive' do
12
+ @actor.alive?.should be_true
13
+ end
14
+
15
+ it 'should be at (0,0)' do
16
+ @actor.x.should equal(0)
17
+ @actor.y.should equal(0)
18
+ end
19
+
20
+ it 'should have atts set' do
21
+ @actor.stage.should == "stage"
22
+ @actor.input_manager.should == "input"
23
+ @actor.resource_manager.should == "resource"
24
+ @actor.behaviors.size.should equal(0)
25
+ end
26
+
27
+ it 'should fire anything' do
28
+ Proc.new {
29
+ @actor.when :foofoo_bar do
30
+ "blah"
31
+ end
32
+ }.should_not raise_error
33
+ end
34
+
35
+ it 'should inherit parents behaviors' do
36
+ @shawn = Shawn.new {}
37
+ @shawn.is?(:smart).should be_true
38
+ end
39
+
40
+ it 'should be able to override parents behaviors' do
41
+ @james = JamesKilton.new {}
42
+ @james.is?(:smart).should be_true
43
+ @james.instance_variable_get('@behaviors')[:smart].instance_variable_get('@opts').should == {:really=>true}
44
+ end
45
+
46
+ it 'should maintain order of behaviors'
47
+
48
+ end
49
+ class Cool < Behavior; end
50
+ class Smart < Behavior; end
51
+ class Coder < Actor
52
+ has_behavior :smart, :cool
53
+ end
54
+ class Shawn < Coder; end
55
+ class JamesKilton < Coder
56
+ has_behavior :smart => {:really => true}
57
+ end
@@ -1,12 +1,11 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__),'helper')
2
2
  require 'animated'
3
- require 'mocha'
4
3
 
5
4
  describe 'A new animated behavior' do
6
5
  before do
7
6
  @rm = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'])
8
7
 
9
- opts = {:level=>"level", :input=>"input", :resources=>@rm}
8
+ opts = {:stage=>"stage", :input=>"input", :resources=>@rm}
10
9
  @actor = Actor.new opts
11
10
  @animated = Animated.new @actor
12
11
  end
@@ -22,14 +21,14 @@ describe 'A new animated behavior' do
22
21
  it 'shouldn\'t update frame for non-animating' do
23
22
  @animated.stop_animating
24
23
 
25
- @animated.update Animated::FRAME_UPDATE_TIME+1
24
+ @animated.update @animated.frame_update_time+1
26
25
 
27
26
  @animated.frame_time.should equal(0)
28
27
  @animated.frame_num.should equal(0)
29
28
  end
30
29
 
31
30
  it 'should update frame for animating' do
32
- time_passed = Animated::FRAME_UPDATE_TIME-1
31
+ time_passed = @animated.frame_update_time-1
33
32
  @animated.update time_passed
34
33
  @animated.frame_time.should equal(time_passed)
35
34
  @animated.frame_num.should equal(0)
@@ -40,7 +39,7 @@ describe 'A new animated behavior' do
40
39
  @animated.frame_time.should equal(1)
41
40
  @animated.frame_num.should equal(1)
42
41
 
43
- time_passed_again = Animated::FRAME_UPDATE_TIME
42
+ time_passed_again = @animated.frame_update_time
44
43
  @animated.update time_passed_again
45
44
  # we rolled over the time
46
45
  @animated.frame_time.should equal(1)
data/spec/helper.rb ADDED
@@ -0,0 +1,24 @@
1
+ here = File.dirname(__FILE__)
2
+ gamebox_root = File.expand_path(File.join(here, '..', 'lib'))
3
+
4
+ #$LOAD_PATH.unshift File.expand_path(gamebox_root, 'gamebox')
5
+ require 'rubygems'
6
+ require 'spec'
7
+
8
+ # TODO this lives in both gamebox.rb and here... seems strange
9
+ [
10
+ "gamebox",
11
+ "gamebox/actors",
12
+ "gamebox/ai",
13
+ "gamebox/behaviors",
14
+ "gamebox/generators",
15
+ "gamebox/lib",
16
+ "gamebox/tasks",
17
+ "gamebox/views"
18
+ ].each do |path|
19
+ $LOAD_PATH.unshift File.join(gamebox_root,path)
20
+ end
21
+
22
+ require 'metaclass'
23
+ require 'actor'
24
+
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__),'helper')
2
2
  require 'ai/line_of_site'
3
3
  require 'ai/two_d_grid_map'
4
4
 
@@ -1,7 +1,6 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__),'helper')
2
2
  require 'physical'
3
3
  require 'actor'
4
- require 'mocha'
5
4
 
6
5
  class CircleActor < Actor
7
6
  has_behaviors :physical => {:shape => :circle,
@@ -11,9 +10,9 @@ end
11
10
 
12
11
  describe 'A new physical behavior' do
13
12
  before do
14
- @level = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'],:register_physical_object => true)
13
+ @stage = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'],:register_physical_object => true)
15
14
 
16
- opts = {:level=>@level, :input=>"input", :resources=>"rm"}
15
+ opts = {:stage=>@stage, :input=>"input", :resources=>"rm"}
17
16
  @actor = CircleActor.new opts
18
17
  @physical = @actor.physical
19
18
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__),'helper')
2
2
  require 'ai/polaris'
3
3
  require 'ai/two_d_grid_map'
4
4
 
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require File.join(File.dirname(__FILE__),'helper')
2
2
  require 'viewport'
3
3
 
4
4
  class Vec
@@ -47,12 +47,12 @@ describe 'A new viewport' do
47
47
  @viewport.y_offset(2).should equal(-150)
48
48
  end
49
49
 
50
- it 'should return a zero offset on Infinity' do
50
+ it 'should return a zero offset on INFINITY' do
51
51
  @viewport.x_offset = -200
52
52
  @viewport.y_offset = -300
53
53
 
54
- @viewport.x_offset(Float::Infinity).should equal(0)
55
- @viewport.y_offset(Float::Infinity).should equal(0)
54
+ @viewport.x_offset(Float::INFINITY).should equal(0)
55
+ @viewport.y_offset(Float::INFINITY).should equal(0)
56
56
  end
57
57
 
58
58
  it 'shouldn\'t update anything unless following a target' do
@@ -87,12 +87,13 @@ describe 'A new viewport' do
87
87
 
88
88
  it 'should follow a target if target has gone left;up of its buffer' do
89
89
  actor = Vec.new 900, 200
90
+ @viewport.should_receive(:fire).with(:scrolled).twice
90
91
  @viewport.follow actor, [0,0], [100,200]
91
92
 
92
93
  @viewport.update 100
93
94
  actor.x = 810
94
95
  actor.y = 10
95
-
96
+
96
97
  @viewport.update 100
97
98
  @viewport.x_offset.should equal(-500)
98
99
  @viewport.y_offset.should equal(100)
@@ -105,8 +106,10 @@ describe 'A new viewport' do
105
106
  @viewport.y_offset.should equal(101)
106
107
  end
107
108
 
108
- it 'should fire :scrolled event when targeting an actor'
109
+ it 'should fire :scrolled event when targeting an actor' do
110
+ actor = Vec.new 900, 200
111
+ @viewport.should_receive(:fire).with(:scrolled)
112
+ @viewport.follow actor, [0,0], [100,200]
113
+ end
109
114
 
110
- it 'should fire :scrolled event from update when the actor moves'
111
-
112
115
  end