gamebox 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ pkg
4
4
  doc
5
5
  coverage
6
6
  .DS_Store
7
+ .yardoc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.1.0
data/docs/gamebox.bat ADDED
@@ -0,0 +1,3 @@
1
+ set RUBYOPT=
2
+ bin\rubyw.exe src\src\app.rb
3
+
data/docs/logo.ico ADDED
Binary file
data/gamebox.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gamebox}
8
- s.version = "0.0.9"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shawn Anderson", "Jason Roelofs", "Karlin Fox"]
12
- s.date = %q{2010-04-10}
12
+ s.date = %q{2010-04-24}
13
13
  s.default_executable = %q{gamebox}
14
14
  s.description = %q{Framework for building and distributing games using Rubygame}
15
15
  s.email = %q{shawn42@gmail.com}
@@ -26,7 +26,9 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "bin/gamebox",
28
28
  "docs/CODE_REVIEW",
29
+ "docs/gamebox.bat",
29
30
  "docs/getting_started.rdoc",
31
+ "docs/logo.ico",
30
32
  "docs/logo.png",
31
33
  "gamebox.gemspec",
32
34
  "lib/gamebox.rb",
@@ -34,6 +36,7 @@ Gem::Specification.new do |s|
34
36
  "lib/gamebox/actor_factory.rb",
35
37
  "lib/gamebox/actor_view.rb",
36
38
  "lib/gamebox/actors/curtain.rb",
39
+ "lib/gamebox/actors/fps.rb",
37
40
  "lib/gamebox/actors/label.rb",
38
41
  "lib/gamebox/actors/logo.rb",
39
42
  "lib/gamebox/actors/score.rb",
@@ -83,6 +86,7 @@ Gem::Specification.new do |s|
83
86
  "lib/gamebox/resource_manager.rb",
84
87
  "lib/gamebox/sound_manager.rb",
85
88
  "lib/gamebox/spatial_hash.rb",
89
+ "lib/gamebox/spatial_stagehand.rb",
86
90
  "lib/gamebox/spec/helper.rb",
87
91
  "lib/gamebox/stage.rb",
88
92
  "lib/gamebox/stage_manager.rb",
@@ -94,6 +98,7 @@ Gem::Specification.new do |s|
94
98
  "lib/gamebox/templates/actor_view.erb",
95
99
  "lib/gamebox/templates/actor_view_spec.erb",
96
100
  "lib/gamebox/templates/template_app/.gitignore",
101
+ "lib/gamebox/templates/template_app/Gemfile",
97
102
  "lib/gamebox/templates/template_app/README",
98
103
  "lib/gamebox/templates/template_app/Rakefile",
99
104
  "lib/gamebox/templates/template_app/config/boot.rb",
@@ -126,6 +131,7 @@ Gem::Specification.new do |s|
126
131
  "spec/physical_spec.rb",
127
132
  "spec/resource_manager_spec.rb",
128
133
  "spec/spatial_hash_spec.rb",
134
+ "spec/stage_manager_spec.rb",
129
135
  "spec/stage_spec.rb",
130
136
  "spec/viewport_spec.rb"
131
137
  ]
@@ -147,6 +153,7 @@ Gem::Specification.new do |s|
147
153
  "spec/physical_spec.rb",
148
154
  "spec/resource_manager_spec.rb",
149
155
  "spec/spatial_hash_spec.rb",
156
+ "spec/stage_manager_spec.rb",
150
157
  "spec/stage_spec.rb",
151
158
  "spec/viewport_spec.rb"
152
159
  ]
@@ -0,0 +1,23 @@
1
+ class FpsView < ActorView
2
+ def draw(target,x_off,y_off)
3
+ text = @actor.fps.to_s
4
+ text = '0'*(6-text.size)+text if text.size < 6
5
+
6
+ font = @stage.resource_manager.load_font 'Asimov.ttf', 30
7
+ text_image = font.render text, true, [250,250,250,255]
8
+
9
+ x = @actor.x
10
+ y = @actor.y
11
+
12
+ text_image.blit target.screen, [x,y]
13
+ end
14
+ end
15
+ class Fps < Actor
16
+
17
+ has_behavior :layered => {:layer => 999}
18
+
19
+ def fps
20
+ input_manager.current_framerate.round
21
+ end
22
+
23
+ end
@@ -2,18 +2,21 @@
2
2
  module Arbiter
3
3
 
4
4
  def register_collidable(actor)
5
+ @spatial_hash = stagehand(:spatial)
5
6
  @collidable_actors ||= []
6
7
  unless @collidable_actors.include? actor
7
8
  actor.when :remove_me do
8
9
  unregister_collidable actor
9
10
  end
10
11
  @collidable_actors << actor
12
+ @spatial_hash.add(actor)
11
13
  end
12
14
  end
13
15
 
14
16
  def unregister_collidable(actor)
15
17
  @collidable_actors ||= []
16
18
  @collidable_actors.delete actor
19
+ @spatial_hash.remove(actor)
17
20
  end
18
21
 
19
22
  def on_collision_of(first_objs, second_objs, &block)
@@ -33,31 +36,46 @@ module Arbiter
33
36
  end
34
37
  end
35
38
 
39
+ def run_callbacks(collisions)
40
+ collisions.each do |collision|
41
+ first = collision.first
42
+ second = collision.last
43
+
44
+ colliders = @collision_handlers[first.actor_type]
45
+ callback = colliders[second.actor_type] unless colliders.nil?
46
+ callback.call first, second unless callback.nil?
47
+ end
48
+ end
49
+
36
50
  def find_collisions
37
51
  @collidable_actors ||= []
38
- collisions = []
39
52
  tmp_collidable_actors = @collidable_actors.dup
53
+ collisions = {}
40
54
 
41
55
  @collidable_actors.each do |first|
42
-
43
- tmp_collidable_actors.delete first
56
+ x = first.x - @spatial_hash.cell_size
57
+ y = first.y - @spatial_hash.cell_size
58
+ w = @spatial_hash.cell_size * 3
59
+ h = w
60
+ tmp_collidable_actors = @spatial_hash.items_in(x,y,w,h)
44
61
 
45
62
  tmp_collidable_actors.each do |second|
46
- if collide?(first, second)
47
- collisions << [first,second]
63
+ if first != second && collide?(first, second)
64
+ collisions[second] ||= []
65
+ if !collisions[second].include?(first)
66
+ collisions[first] ||= []
67
+ collisions[first] << second
68
+ end
48
69
  end
49
70
  end
50
-
51
71
  end
52
-
53
- collisions.each do |collision|
54
- first = collision.first
55
- second = collision.last
56
-
57
- colliders = @collision_handlers[first.actor_type]
58
- callback = colliders[second.actor_type] unless colliders.nil?
59
- callback.call first, second unless callback.nil?
72
+ unique_collisions = []
73
+ collisions.each do |first,seconds|
74
+ seconds.each do |second|
75
+ unique_collisions << [first,second]
76
+ end
60
77
  end
78
+ run_callbacks unique_collisions
61
79
  end
62
80
 
63
81
  def collide?(object, other)
Binary file
@@ -74,6 +74,11 @@ class InputManager
74
74
  @clock.target_framerate
75
75
  end
76
76
 
77
+ # Returns the current framerate.
78
+ def current_framerate
79
+ @clock.framerate
80
+ end
81
+
77
82
  # This is where the queue gets pumped. This gets called from your game application.
78
83
  def main_loop(game)
79
84
  catch(:rubygame_quit) do
@@ -1,5 +1,12 @@
1
1
  module Publisher
2
2
  module InstanceMethods
3
+ def can_fire?(event)
4
+ events = self.class.class_eval { @published_events }
5
+ events = self.class.published_events
6
+ return true if events == :any_event_is_ok
7
+ return false unless events and events.include?(event)
8
+ return true
9
+ end
3
10
  def unsubscribe_all(listener)
4
11
  if @subscriptions
5
12
  for event in @subscriptions.keys
@@ -53,7 +53,7 @@ class SoundManager
53
53
  volume = opts.delete :volume
54
54
  @sound_thread = Thread.new do
55
55
  @sounds[what].volume = volume if volume
56
- @sounds[what].dup.play opts
56
+ @sounds[what].play opts
57
57
  end
58
58
  end
59
59
  end
@@ -1,6 +1,6 @@
1
1
  class SpatialHash
2
2
 
3
- attr_accessor :cell_size
3
+ attr_reader :cell_size
4
4
 
5
5
  def initialize(cell_size)
6
6
  @cell_size = cell_size.to_f
@@ -8,6 +8,11 @@ class SpatialHash
8
8
  @items = []
9
9
  end
10
10
 
11
+ def cell_size=(new_size)
12
+ @cell_size = new_size
13
+ rehash
14
+ end
15
+
11
16
  def rehash
12
17
  items = @items
13
18
  @items = []
@@ -32,10 +37,12 @@ class SpatialHash
32
37
  end
33
38
 
34
39
  def lookup(item)
35
- w = 1
36
- h = 1
37
40
  w = item.width if item.respond_to? :width
38
41
  h = item.height if item.respond_to? :height
42
+
43
+ w ||= 1
44
+ h ||= 1
45
+
39
46
  x = item.x
40
47
  y = item.y
41
48
  min_x, min_y = bucket_for x, y
@@ -82,5 +89,29 @@ class SpatialHash
82
89
  end
83
90
  end
84
91
 
92
+ def items_in(x,y,w,h)
93
+ return items_at x, y if ((w.nil? || w == 1) && (h.nil? || w == 1))
94
+
95
+ min_x, min_y = bucket_for x, y
96
+ if w == 1 && h == 1
97
+ max_x = min_x
98
+ max_y = min_y
99
+ else
100
+ max_x, max_y = bucket_for x+w-1, y+h-1
101
+ end
102
+
103
+ items = []
104
+ (max_x-min_x+1).times do |i|
105
+ (max_y-min_y+1).times do |j|
106
+ bucket_x = min_x + i
107
+ bucket_y = min_y + j
108
+ unless @buckets[bucket_x].nil? || @buckets[bucket_x][bucket_y].nil?
109
+ items << @buckets[bucket_x][bucket_y]
110
+ end
111
+ end
112
+ end
113
+ items.flatten.uniq
114
+ end
115
+
85
116
  end
86
117
 
@@ -0,0 +1,37 @@
1
+ require 'spatial_hash'
2
+
3
+ class SpatialStagehand < Stagehand
4
+
5
+ DEFAULT_PARAMS = {
6
+ :cell_size = 50
7
+ }
8
+ def setup
9
+ merged_opts = DEFAULT_PARAMS.merge opts
10
+ @spatial_actors = SpatialHash.new merged_opts[:cell_size]
11
+ end
12
+
13
+ def cell_size
14
+ @spatial_actors.cell_size
15
+ end
16
+
17
+ def add(actor)
18
+ @spatial_actors.add actor
19
+ end
20
+
21
+ def remove(actor)
22
+ @spatial_actors.remove actor
23
+ end
24
+
25
+ def update(time)
26
+ @spatial_actors.rehash
27
+ end
28
+
29
+ def items_at(x,y)
30
+ @spatial_actors.items_at x, y
31
+ end
32
+
33
+ def items_in(x,y,w,h)
34
+ @spatial_actors.items_in x, y, w, h
35
+ end
36
+
37
+ end
@@ -63,7 +63,9 @@ class StageManager
63
63
  puts "last stage, exiting"
64
64
  exit
65
65
  end
66
- @stages.delete @stage_names[index+1]
66
+ stage = @stages.delete @stage_names[index+1]
67
+ @input_manager.clear_hooks stage
68
+
67
69
  change_stage_to @stage_names[index+1], *args
68
70
  end
69
71
 
@@ -73,14 +75,18 @@ class StageManager
73
75
  puts "first stage, exiting"
74
76
  exit
75
77
  end
76
- @stages.delete @stage_names[index-1]
78
+ stage = @stages.delete @stage_names[index-1]
79
+ @input_manager.clear_hooks stage
77
80
  change_stage_to @stage_names[index-1], *args
78
81
  end
79
82
 
80
83
  def restart_stage(*args)
81
84
  current_stage.curtain_dropping *args
82
85
  index = @stage_names.index @stage
83
- @stages.delete @stage_names[index]
86
+
87
+ stage = @stages.delete @stage_names[index]
88
+ @input_manager.clear_hooks stage
89
+
84
90
  change_stage_to @stage, *args
85
91
  end
86
92
 
@@ -26,6 +26,12 @@ task :debug do |t|
26
26
  end
27
27
  end
28
28
 
29
+ desc "Bundle in all required gems"
30
+ task :bundle do |t|
31
+ sh "bundle package"
32
+ sh "bundle install vendor/bundle --disable-shared-gems"
33
+ end
34
+
29
35
  begin
30
36
  require 'spec/rake/spectask'
31
37
  desc "Run all specs"
@@ -39,3 +45,5 @@ rescue LoadError
39
45
  puts "warning: rspec not installed"
40
46
  puts "install with gem install rspec"
41
47
  end
48
+
49
+
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+ gem "gamebox"
3
+ gem "publisher"
4
+ gem "diy"
5
+ gem "rubygame"
@@ -14,3 +14,23 @@ STATS_DIRECTORIES = [
14
14
  %w(Libraries lib/),
15
15
  ].collect { |name, dir| [ name, "#{APP_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
16
16
 
17
+ namespace :dist do
18
+ task :vendor do
19
+ sh 'wget http://github.com/downloads/shawn42/gamebox/vendor.zip; unzip vendor.zip; rm vendor.zip'
20
+ end
21
+ task :win do
22
+ # create dist dir
23
+ FileUtils.mkdir "dist" unless File.exist? "dist"
24
+ # pull down windows app shell
25
+ # expand into place
26
+ sh 'cd dist; wget http://github.com/downloads/shawn42/gamebox/gamebox_app.zip; unzip gamebox_app.zip; mv gamebox_app/* .; rm gamebox_app.zip; rm -rf gamebox_app'
27
+
28
+ # copy config/src/lib/data into dist/src
29
+ %w{vendor config data }.each do |dir|
30
+ FileUtils.cp_r dir, File.join('dist','src', dir) if File.exist? dir
31
+ end
32
+ FileUtils.cp_r 'src', File.join('dist', 'src')
33
+
34
+ # create zip of dist?
35
+ end
36
+ end
@@ -1,29 +1,41 @@
1
- require 'rubygems'
2
- ADDITIONAL_LOAD_PATHS = []
3
- ADDITIONAL_LOAD_PATHS.concat %w(
4
- src
5
- lib
6
- config
7
- ../../lib
8
- ).map { |dir| File.dirname(__FILE__) + "/../" + dir }.select { |dir| File.directory?(dir) }
9
-
10
- ADDITIONAL_LOAD_PATHS.each do |path|
11
- $:.push path
12
- end
13
-
14
- APP_ROOT = File.dirname(__FILE__) + "/../"
15
- CONFIG_PATH = APP_ROOT + "config/"
16
- DATA_PATH = APP_ROOT + "data/"
17
- SOUND_PATH = APP_ROOT + "data/sounds/"
18
- MUSIC_PATH = APP_ROOT + "data/music/"
19
- GFX_PATH = APP_ROOT + "data/graphics/"
20
- FONTS_PATH = APP_ROOT + "data/fonts/"
21
-
22
- require 'gamebox'
23
-
24
- GAMEBOX_DATA_PATH = GAMEBOX_PATH + "data/"
25
- GAMEBOX_SOUND_PATH = GAMEBOX_PATH + "data/sounds/"
26
- GAMEBOX_MUSIC_PATH = GAMEBOX_PATH + "data/music/"
27
- GAMEBOX_GFX_PATH = GAMEBOX_PATH + "data/graphics/"
28
- GAMEBOX_FONTS_PATH = GAMEBOX_PATH + "data/fonts/"
29
-
1
+
2
+ unless ENV['OCRA_EXECUTABLE'].nil?
3
+ APP_ROOT = "#{File.join(File.dirname($0),"..")}/"
4
+ Dir.chdir(File.join(File.dirname($0),"..",'src'))
5
+ else
6
+ APP_ROOT = "#{File.join(File.dirname($0),"..")}/"
7
+ end
8
+
9
+ gems = Dir[APP_ROOT+"vendor/gems/*"]
10
+ gems.each do |bundled_gem|
11
+ $:.unshift bundled_gem+"/lib"
12
+ end
13
+
14
+ ADDITIONAL_LOAD_PATHS = []
15
+ ADDITIONAL_LOAD_PATHS.concat %w(
16
+ src
17
+ lib
18
+ config
19
+ ../../lib
20
+ ).map { |dir| File.join(APP_ROOT,dir) }
21
+
22
+ ADDITIONAL_LOAD_PATHS.each do |path|
23
+ $:.unshift path
24
+ end
25
+
26
+
27
+
28
+ CONFIG_PATH = APP_ROOT + "config/"
29
+ DATA_PATH = APP_ROOT + "data/"
30
+ SOUND_PATH = APP_ROOT + "data/sounds/"
31
+ MUSIC_PATH = APP_ROOT + "data/music/"
32
+ GFX_PATH = APP_ROOT + "data/graphics/"
33
+ FONTS_PATH = APP_ROOT + "data/fonts/"
34
+
35
+ require 'gamebox'
36
+
37
+ GAMEBOX_DATA_PATH = GAMEBOX_PATH + "data/"
38
+ GAMEBOX_SOUND_PATH = GAMEBOX_PATH + "data/sounds/"
39
+ GAMEBOX_MUSIC_PATH = GAMEBOX_PATH + "data/music/"
40
+ GAMEBOX_GFX_PATH = GAMEBOX_PATH + "data/graphics/"
41
+ GAMEBOX_FONTS_PATH = GAMEBOX_PATH + "data/fonts/"
@@ -1,8 +1,6 @@
1
- #!/usr/bin/env ruby
2
- $: << "#{File.dirname(__FILE__)}/../config"
3
-
4
- require 'environment'
5
-
6
- if $0 == __FILE__
7
- GameboxApp.run ARGV, ENV
8
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.join(File.dirname($0),"..","config")
4
+ require 'environment'
5
+
6
+ GameboxApp.run ARGV, ENV
@@ -1,8 +1,8 @@
1
1
  module Gamebox
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 9
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  ARRAY = [MAJOR, MINOR, TINY]
8
8
  STRING = ARRAY.join('.')
@@ -22,6 +22,13 @@ class Viewport
22
22
  @height = height
23
23
  end
24
24
 
25
+ def scroll(x_delta,y_delta)
26
+ @x_offset += x_delta
27
+ @y_offset += y_delta
28
+
29
+ fire :scrolled
30
+ end
31
+
25
32
  def x_offset(layer=1)
26
33
  return 0 if layer == Float::INFINITY
27
34
  return @x_offset if layer == 1
@@ -11,5 +11,5 @@ describe 'A new collidable behavior' do
11
11
 
12
12
  it 'should define methods on actor' do
13
13
  @actor.respond_to?(:shape).should be_true
14
- end
14
+ end
15
15
  end
data/spec/helper.rb CHANGED
@@ -20,5 +20,6 @@ require 'spec'
20
20
  end
21
21
 
22
22
  require 'metaclass'
23
+ require 'constructor'
23
24
  require 'actor'
24
25
 
@@ -82,6 +82,8 @@ describe 'a new SpacialHash' do
82
82
  buckets[1][0].first.should == box
83
83
  buckets[1][1].first.should == box
84
84
  end
85
+
86
+ it 'can find items in a box'
85
87
  end
86
88
 
87
89
  class Point
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__),'helper')
2
+ require 'stage_manager'
3
+
4
+ describe 'A new stage manager' do
5
+ before do
6
+ # opts = {:resource_manager => stub, :actor_factory => stub, :input_manager => stub,
7
+ # :sound_manager => stub, :config_manager => stub}
8
+ # @stage_manager = StageManager.new opts
9
+ end
10
+
11
+ it 'should construct' #do
12
+ # @stage_manager.should_not be_nil
13
+ # end
14
+
15
+ describe '#prev_stage' do
16
+ it 'should exit on prev_stage of first stage'
17
+ it 'should go to prev stage'
18
+ end
19
+ describe '#next_stage' do
20
+ it 'should exit on next_stage of last stage'
21
+ it 'should go to next stage'
22
+ end
23
+ describe '#restart_stage' do
24
+ it 'should restart the current stage'
25
+ end
26
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 9
9
- version: 0.0.9
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shawn Anderson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-04-10 00:00:00 -04:00
19
+ date: 2010-04-24 00:00:00 -04:00
20
20
  default_executable: gamebox
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -96,7 +96,9 @@ files:
96
96
  - VERSION
97
97
  - bin/gamebox
98
98
  - docs/CODE_REVIEW
99
+ - docs/gamebox.bat
99
100
  - docs/getting_started.rdoc
101
+ - docs/logo.ico
100
102
  - docs/logo.png
101
103
  - gamebox.gemspec
102
104
  - lib/gamebox.rb
@@ -104,6 +106,7 @@ files:
104
106
  - lib/gamebox/actor_factory.rb
105
107
  - lib/gamebox/actor_view.rb
106
108
  - lib/gamebox/actors/curtain.rb
109
+ - lib/gamebox/actors/fps.rb
107
110
  - lib/gamebox/actors/label.rb
108
111
  - lib/gamebox/actors/logo.rb
109
112
  - lib/gamebox/actors/score.rb
@@ -153,6 +156,7 @@ files:
153
156
  - lib/gamebox/resource_manager.rb
154
157
  - lib/gamebox/sound_manager.rb
155
158
  - lib/gamebox/spatial_hash.rb
159
+ - lib/gamebox/spatial_stagehand.rb
156
160
  - lib/gamebox/spec/helper.rb
157
161
  - lib/gamebox/stage.rb
158
162
  - lib/gamebox/stage_manager.rb
@@ -164,6 +168,7 @@ files:
164
168
  - lib/gamebox/templates/actor_view.erb
165
169
  - lib/gamebox/templates/actor_view_spec.erb
166
170
  - lib/gamebox/templates/template_app/.gitignore
171
+ - lib/gamebox/templates/template_app/Gemfile
167
172
  - lib/gamebox/templates/template_app/README
168
173
  - lib/gamebox/templates/template_app/Rakefile
169
174
  - lib/gamebox/templates/template_app/config/boot.rb
@@ -196,6 +201,7 @@ files:
196
201
  - spec/physical_spec.rb
197
202
  - spec/resource_manager_spec.rb
198
203
  - spec/spatial_hash_spec.rb
204
+ - spec/stage_manager_spec.rb
199
205
  - spec/stage_spec.rb
200
206
  - spec/viewport_spec.rb
201
207
  has_rdoc: true
@@ -240,5 +246,6 @@ test_files:
240
246
  - spec/physical_spec.rb
241
247
  - spec/resource_manager_spec.rb
242
248
  - spec/spatial_hash_spec.rb
249
+ - spec/stage_manager_spec.rb
243
250
  - spec/stage_spec.rb
244
251
  - spec/viewport_spec.rb