gamebox 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/Manifest.txt +40 -37
- data/README.txt +2 -2
- data/Rakefile +27 -20
- data/TODO.txt +8 -8
- data/bin/gamebox +7 -1
- data/docs/getting_started.rdoc +2 -5
- data/docs/logo.png +0 -0
- data/lib/gamebox.rb +12 -1
- data/lib/gamebox/actor.rb +34 -9
- data/lib/gamebox/actor_factory.rb +25 -14
- data/lib/gamebox/actor_view.rb +6 -6
- data/lib/gamebox/{logo.rb → actors/logo.rb} +0 -0
- data/lib/gamebox/{score.rb → actors/score.rb} +2 -1
- data/lib/gamebox/{svg_actor.rb → actors/svg_actor.rb} +3 -4
- data/lib/gamebox/ai/polaris.rb +2 -0
- data/lib/gamebox/behavior.rb +3 -0
- data/lib/gamebox/{animated.rb → behaviors/animated.rb} +13 -5
- data/lib/gamebox/{graphical.rb → behaviors/graphical.rb} +11 -1
- data/lib/gamebox/{layered.rb → behaviors/layered.rb} +14 -0
- data/lib/gamebox/{physical.rb → behaviors/physical.rb} +41 -14
- data/lib/gamebox/{updatable.rb → behaviors/updatable.rb} +1 -1
- data/lib/gamebox/{templates/template_app → data}/config/objects.yml +4 -2
- data/lib/gamebox/data/graphics/logo.png +0 -0
- data/lib/gamebox/event_compat.rb +285 -0
- data/lib/gamebox/ftor.rb +2 -0
- data/lib/gamebox/gamebox_application.rb +12 -1
- data/lib/gamebox/generators/actor_generator.rb +2 -2
- data/lib/gamebox/generators/view_generator.rb +42 -0
- data/lib/gamebox/input_manager.rb +88 -21
- data/lib/gamebox/{aliasing.rb → lib/aliasing.rb} +0 -0
- data/lib/gamebox/{templates/template_app/lib → lib}/diy.rb +0 -0
- data/lib/gamebox/{inflections.rb → lib/inflections.rb} +0 -0
- data/lib/gamebox/{inflector.rb → lib/inflector.rb} +2 -2
- data/lib/gamebox/{linked_list.rb → lib/linked_list.rb} +0 -0
- data/lib/gamebox/{metaclass.rb → lib/metaclass.rb} +0 -0
- data/lib/gamebox/lib/numbers_ext.rb +3 -0
- data/lib/gamebox/{platform.rb → lib/platform.rb} +0 -0
- data/lib/gamebox/{publisher_ext.rb → lib/publisher_ext.rb} +0 -0
- data/lib/gamebox/{sorted_list.rb → lib/sorted_list.rb} +0 -0
- data/lib/gamebox/lib/surface_ext.rb +76 -0
- data/lib/gamebox/physical_director.rb +1 -1
- data/lib/gamebox/{physical_level.rb → physical_stage.rb} +28 -18
- data/lib/gamebox/physics.rb +2 -2
- data/lib/gamebox/resource_manager.rb +77 -8
- data/lib/gamebox/sound_manager.rb +15 -17
- data/lib/gamebox/stage.rb +143 -0
- data/lib/gamebox/stage_manager.rb +110 -0
- data/lib/gamebox/svg_document.rb +1 -1
- data/lib/gamebox/tasks/gamebox_tasks.rb +1 -1
- data/lib/gamebox/templates/{test_actor.erb → actor_spec.erb} +2 -2
- data/lib/gamebox/templates/actor_view.erb +8 -0
- data/lib/gamebox/templates/actor_view_spec.erb +10 -0
- data/lib/gamebox/templates/template_app/Rakefile +4 -4
- data/lib/gamebox/templates/template_app/config/game.yml +1 -0
- data/lib/gamebox/templates/template_app/config/stage_config.yml +2 -0
- data/lib/gamebox/templates/template_app/script/generate +2 -1
- data/lib/gamebox/templates/template_app/{test → spec}/helper.rb +0 -0
- data/lib/gamebox/templates/template_app/src/{demo_level.rb → demo_stage.rb} +5 -3
- data/lib/gamebox/templates/template_app/src/game.rb +4 -6
- data/lib/gamebox/version.rb +3 -2
- data/lib/gamebox/viewport.rb +18 -9
- data/lib/gamebox/{graphical_actor_view.rb → views/graphical_actor_view.rb} +13 -1
- data/lib/gamebox/wrapped_screen.rb +2 -1
- data/spec/actor_spec.rb +57 -0
- data/{test/test_animated.rb → spec/animated_spec.rb} +5 -6
- data/spec/helper.rb +24 -0
- data/{test/test_line_of_site.rb → spec/line_of_site_spec.rb} +1 -1
- data/{test/test_physical.rb → spec/physical_spec.rb} +3 -4
- data/{test/test_polaris.rb → spec/polaris_spec.rb} +1 -1
- data/{test/test_viewport.rb → spec/viewport_spec.rb} +11 -8
- metadata +53 -50
- data/docs/gamebox04_big.png +0 -0
- data/lib/gamebox/level.rb +0 -65
- data/lib/gamebox/mode.rb +0 -123
- data/lib/gamebox/mode_manager.rb +0 -80
- data/lib/gamebox/numbers_ext.rb +0 -3
- data/lib/gamebox/surface_ext.rb +0 -37
- data/lib/gamebox/templates/template_app/config/mode_level_config.yml +0 -3
- data/test/helper.rb +0 -26
- data/test/test_actor.rb +0 -36
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Anderson
|
8
|
+
- Jason Roelofs
|
9
|
+
- Karlin Fox
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
13
|
|
12
|
-
date: 2009-
|
14
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
15
|
default_executable:
|
14
16
|
dependencies:
|
15
17
|
- !ruby/object:Gem::Dependency
|
@@ -52,8 +54,11 @@ dependencies:
|
|
52
54
|
- !ruby/object:Gem::Version
|
53
55
|
version: 2.3.1
|
54
56
|
version:
|
55
|
-
description:
|
56
|
-
email:
|
57
|
+
description: A game template for building and distributing Rubygame games. See docs/getting_started.rdoc for help getting started.
|
58
|
+
email:
|
59
|
+
- shawn42@gmail.com
|
60
|
+
- jameskilton@gmail.com
|
61
|
+
- karlin.fox@gmail.com
|
57
62
|
executables:
|
58
63
|
- gamebox
|
59
64
|
extensions: []
|
@@ -71,22 +76,28 @@ files:
|
|
71
76
|
- Rakefile
|
72
77
|
- TODO.txt
|
73
78
|
- bin/gamebox
|
74
|
-
- docs/gamebox04_big.png
|
75
79
|
- docs/getting_started.rdoc
|
76
80
|
- docs/logo.png
|
77
81
|
- lib/gamebox.rb
|
78
82
|
- lib/gamebox/actor.rb
|
79
83
|
- lib/gamebox/actor_factory.rb
|
80
84
|
- lib/gamebox/actor_view.rb
|
85
|
+
- lib/gamebox/actors/logo.rb
|
86
|
+
- lib/gamebox/actors/score.rb
|
87
|
+
- lib/gamebox/actors/svg_actor.rb
|
81
88
|
- lib/gamebox/ai/line_of_site.rb
|
82
89
|
- lib/gamebox/ai/polaris.rb
|
83
90
|
- lib/gamebox/ai/two_d_grid_location.rb
|
84
91
|
- lib/gamebox/ai/two_d_grid_map.rb
|
85
|
-
- lib/gamebox/aliasing.rb
|
86
|
-
- lib/gamebox/animated.rb
|
87
92
|
- lib/gamebox/behavior.rb
|
93
|
+
- lib/gamebox/behaviors/animated.rb
|
94
|
+
- lib/gamebox/behaviors/graphical.rb
|
95
|
+
- lib/gamebox/behaviors/layered.rb
|
96
|
+
- lib/gamebox/behaviors/physical.rb
|
97
|
+
- lib/gamebox/behaviors/updatable.rb
|
88
98
|
- lib/gamebox/config_manager.rb
|
89
99
|
- lib/gamebox/console_app.rb
|
100
|
+
- lib/gamebox/data/config/objects.yml
|
90
101
|
- lib/gamebox/data/fonts/Asimov.ttf
|
91
102
|
- lib/gamebox/data/fonts/GAMEBOX_FONTS_GO_HERE
|
92
103
|
- lib/gamebox/data/graphics/GAMEBOX_GRAPHICS_GO_HERE
|
@@ -94,73 +105,70 @@ files:
|
|
94
105
|
- lib/gamebox/data/music/GAMEBOX_MUSIC_GOES_HERE
|
95
106
|
- lib/gamebox/data/sounds/GAMEBOX_SOUND_FX_GO_HERE
|
96
107
|
- lib/gamebox/director.rb
|
108
|
+
- lib/gamebox/event_compat.rb
|
109
|
+
- lib/gamebox/ftor.rb
|
97
110
|
- lib/gamebox/gamebox_application.rb
|
98
111
|
- lib/gamebox/gamebox_generator.rb
|
99
112
|
- lib/gamebox/generators/actor_generator.rb
|
100
|
-
- lib/gamebox/
|
101
|
-
- lib/gamebox/graphical_actor_view.rb
|
102
|
-
- lib/gamebox/inflections.rb
|
103
|
-
- lib/gamebox/inflector.rb
|
113
|
+
- lib/gamebox/generators/view_generator.rb
|
104
114
|
- lib/gamebox/input_manager.rb
|
105
|
-
- lib/gamebox/
|
106
|
-
- lib/gamebox/
|
107
|
-
- lib/gamebox/
|
108
|
-
- lib/gamebox/
|
109
|
-
- lib/gamebox/
|
110
|
-
- lib/gamebox/
|
111
|
-
- lib/gamebox/
|
112
|
-
- lib/gamebox/
|
113
|
-
- lib/gamebox/
|
115
|
+
- lib/gamebox/lib/aliasing.rb
|
116
|
+
- lib/gamebox/lib/diy.rb
|
117
|
+
- lib/gamebox/lib/inflections.rb
|
118
|
+
- lib/gamebox/lib/inflector.rb
|
119
|
+
- lib/gamebox/lib/linked_list.rb
|
120
|
+
- lib/gamebox/lib/metaclass.rb
|
121
|
+
- lib/gamebox/lib/numbers_ext.rb
|
122
|
+
- lib/gamebox/lib/platform.rb
|
123
|
+
- lib/gamebox/lib/publisher_ext.rb
|
124
|
+
- lib/gamebox/lib/sorted_list.rb
|
125
|
+
- lib/gamebox/lib/surface_ext.rb
|
126
|
+
- lib/gamebox/stage.rb
|
127
|
+
- lib/gamebox/stage_manager.rb
|
114
128
|
- lib/gamebox/physical_director.rb
|
115
|
-
- lib/gamebox/
|
129
|
+
- lib/gamebox/physical_stage.rb
|
116
130
|
- lib/gamebox/physics.rb
|
117
|
-
- lib/gamebox/platform.rb
|
118
|
-
- lib/gamebox/publisher_ext.rb
|
119
131
|
- lib/gamebox/resource_manager.rb
|
120
|
-
- lib/gamebox/score.rb
|
121
|
-
- lib/gamebox/sorted_list.rb
|
122
132
|
- lib/gamebox/sound_manager.rb
|
123
|
-
- lib/gamebox/surface_ext.rb
|
124
|
-
- lib/gamebox/svg_actor.rb
|
125
133
|
- lib/gamebox/svg_document.rb
|
126
134
|
- lib/gamebox/tasks/gamebox_tasks.rb
|
127
135
|
- lib/gamebox/templates/actor.erb
|
136
|
+
- lib/gamebox/templates/actor_spec.erb
|
137
|
+
- lib/gamebox/templates/actor_view.erb
|
138
|
+
- lib/gamebox/templates/actor_view_spec.erb
|
128
139
|
- lib/gamebox/templates/template_app/README
|
129
140
|
- lib/gamebox/templates/template_app/Rakefile
|
130
141
|
- lib/gamebox/templates/template_app/config/boot.rb
|
131
142
|
- lib/gamebox/templates/template_app/config/environment.rb
|
132
143
|
- lib/gamebox/templates/template_app/config/game.yml
|
133
|
-
- lib/gamebox/templates/template_app/config/
|
134
|
-
- lib/gamebox/templates/template_app/config/objects.yml
|
144
|
+
- lib/gamebox/templates/template_app/config/stage_config.yml
|
135
145
|
- lib/gamebox/templates/template_app/data/fonts/FONTS_GO_HERE
|
136
146
|
- lib/gamebox/templates/template_app/data/graphics/GRAPHICS_GO_HERE
|
137
147
|
- lib/gamebox/templates/template_app/data/music/MUSIC_GOES_HERE
|
138
148
|
- lib/gamebox/templates/template_app/data/sounds/SOUND_FX_GO_HERE
|
139
149
|
- lib/gamebox/templates/template_app/doc/README_FOR_APP
|
140
150
|
- lib/gamebox/templates/template_app/lib/code_statistics.rb
|
141
|
-
- lib/gamebox/templates/template_app/lib/diy.rb
|
142
151
|
- lib/gamebox/templates/template_app/lib/platform.rb
|
143
152
|
- lib/gamebox/templates/template_app/script/generate
|
144
153
|
- lib/gamebox/templates/template_app/src/app.rb
|
145
|
-
- lib/gamebox/templates/template_app/src/
|
154
|
+
- lib/gamebox/templates/template_app/src/demo_stage.rb
|
146
155
|
- lib/gamebox/templates/template_app/src/game.rb
|
147
156
|
- lib/gamebox/templates/template_app/src/my_actor.rb
|
148
|
-
- lib/gamebox/templates/template_app/
|
149
|
-
- lib/gamebox/templates/test_actor.erb
|
150
|
-
- lib/gamebox/updatable.rb
|
157
|
+
- lib/gamebox/templates/template_app/spec/helper.rb
|
151
158
|
- lib/gamebox/version.rb
|
152
159
|
- lib/gamebox/viewport.rb
|
160
|
+
- lib/gamebox/views/graphical_actor_view.rb
|
153
161
|
- lib/gamebox/wrapped_screen.rb
|
154
162
|
- script/perf_polaris.rb
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
163
|
+
- spec/helper.rb
|
164
|
+
- spec/actor_spec.rb
|
165
|
+
- spec/animated_spec.rb
|
166
|
+
- spec/line_of_site_spec.rb
|
167
|
+
- spec/physical_spec.rb
|
168
|
+
- spec/polaris_spec.rb
|
169
|
+
- spec/viewport_spec.rb
|
162
170
|
has_rdoc: true
|
163
|
-
homepage: http://shawn42.github.com/gamebox
|
171
|
+
homepage: http://shawn42.github.com/gamebox/
|
164
172
|
licenses: []
|
165
173
|
|
166
174
|
post_install_message:
|
@@ -187,11 +195,6 @@ rubyforge_project: gamebox
|
|
187
195
|
rubygems_version: 1.3.3
|
188
196
|
signing_key:
|
189
197
|
specification_version: 3
|
190
|
-
summary:
|
191
|
-
test_files:
|
192
|
-
|
193
|
-
- test/test_animated.rb
|
194
|
-
- test/test_line_of_site.rb
|
195
|
-
- test/test_physical.rb
|
196
|
-
- test/test_polaris.rb
|
197
|
-
- test/test_viewport.rb
|
198
|
+
summary: A game template for building and distributing Rubygame games
|
199
|
+
test_files: []
|
200
|
+
|
data/docs/gamebox04_big.png
DELETED
Binary file
|
data/lib/gamebox/level.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# Levels represent on level of game play. Some games will likely have only one
|
2
|
-
# level. Level is responsible for loading its background, props, and directors.
|
3
|
-
require 'inflector'
|
4
|
-
require 'publisher'
|
5
|
-
require 'director'
|
6
|
-
class Level
|
7
|
-
extend Publisher
|
8
|
-
|
9
|
-
can_fire_anything
|
10
|
-
attr_accessor :director, :resource_manager, :sound_manager,
|
11
|
-
:opts, :viewport, :input_manager
|
12
|
-
|
13
|
-
def initialize(actor_factory, resource_manager, sound_manager, input_manager, viewport, opts={})
|
14
|
-
@director = Director.new
|
15
|
-
@actor_factory = actor_factory
|
16
|
-
@actor_factory.director = @director
|
17
|
-
|
18
|
-
@sound_manager = sound_manager
|
19
|
-
@input_manager = input_manager
|
20
|
-
@resource_manager = resource_manager
|
21
|
-
@viewport = viewport
|
22
|
-
@opts = opts
|
23
|
-
setup
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup
|
27
|
-
end
|
28
|
-
|
29
|
-
def create_actor(type, args={})
|
30
|
-
@actor_factory.build type, self, args
|
31
|
-
end
|
32
|
-
|
33
|
-
def update(time)
|
34
|
-
@director.update time
|
35
|
-
end
|
36
|
-
|
37
|
-
def draw(target,x_off,y_off)
|
38
|
-
end
|
39
|
-
|
40
|
-
# extract all the params from a node that are needed to construct an actor
|
41
|
-
def create_actors_from_svg
|
42
|
-
float_keys = ["x","y"]
|
43
|
-
dynamic_actors ||= {}
|
44
|
-
layer = @svg_doc.find_group_by_label("actors")
|
45
|
-
|
46
|
-
unless layer.nil?
|
47
|
-
# each image in the layer is an actor
|
48
|
-
layer.images.each do |actor_def|
|
49
|
-
klass = actor_def.game_class.to_sym
|
50
|
-
handle = actor_def.game_handle
|
51
|
-
new_opts = {}
|
52
|
-
actor_def.node.attributes.each do |k,v|
|
53
|
-
v = v.to_f if float_keys.include? k
|
54
|
-
new_opts[k.to_sym] = v
|
55
|
-
end
|
56
|
-
|
57
|
-
actor = create_actor klass, new_opts
|
58
|
-
dynamic_actors[handle.to_sym] = actor if handle
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
dynamic_actors
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/lib/gamebox/mode.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'inflector'
|
2
|
-
require 'viewport'
|
3
|
-
# Mode is a state that the game is in. (ie intro mode, multiplayer mode,
|
4
|
-
# single player mode).
|
5
|
-
class Mode
|
6
|
-
extend Publisher
|
7
|
-
can_fire_anything
|
8
|
-
|
9
|
-
attr_accessor :level, :drawables, :resource_manager, :sound_manager
|
10
|
-
def initialize(input_manager, actor_factory, resource_manager, sound_manager, config_manager, levels)
|
11
|
-
@input_manager = input_manager
|
12
|
-
@actor_factory = actor_factory
|
13
|
-
@resource_manager = resource_manager
|
14
|
-
@sound_manager = sound_manager
|
15
|
-
@config_manager = config_manager
|
16
|
-
res = @config_manager[:screen_resolution]
|
17
|
-
|
18
|
-
@viewport = Viewport.new res[0], res[1]
|
19
|
-
@drawables = {}
|
20
|
-
@levels = levels
|
21
|
-
setup
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup
|
25
|
-
end
|
26
|
-
|
27
|
-
def start
|
28
|
-
@level_number = 0
|
29
|
-
clear_drawables
|
30
|
-
@level = build_level @levels[@level_number], nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def next_level
|
34
|
-
@level_number += 1
|
35
|
-
clear_drawables
|
36
|
-
@level = build_level @levels[@level_number], @level
|
37
|
-
end
|
38
|
-
|
39
|
-
def prev_level
|
40
|
-
@level_number -= 1
|
41
|
-
clear_drawables
|
42
|
-
@level = build_level @levels[@level_number], @level
|
43
|
-
end
|
44
|
-
|
45
|
-
def restart_level
|
46
|
-
clear_drawables
|
47
|
-
@level = build_level @levels[@level_number], @level
|
48
|
-
end
|
49
|
-
|
50
|
-
def stop
|
51
|
-
end
|
52
|
-
|
53
|
-
def build_level(level_def, prev_level_instance)
|
54
|
-
level_sym = level_def.keys.first
|
55
|
-
begin
|
56
|
-
require level_sym.to_s+"_level"
|
57
|
-
rescue LoadError => ex
|
58
|
-
puts "Load error: #{ex.inspect}"
|
59
|
-
puts ex.backtrace.join("\n")
|
60
|
-
# maybe we have included it elsewhere
|
61
|
-
end
|
62
|
-
level_klass = ObjectSpace.const_get(Inflector.camelize(level_sym.to_s+"_level"))
|
63
|
-
full_level_def = { :prev_level => prev_level_instance }
|
64
|
-
full_level_def.merge! level_def[level_sym] if level_def[level_sym].is_a? Hash
|
65
|
-
level = level_klass.new @actor_factory, @resource_manager, @sound_manager, @input_manager, @viewport, full_level_def
|
66
|
-
level.when :restart_level do
|
67
|
-
restart_level
|
68
|
-
end
|
69
|
-
level.when :next_level do
|
70
|
-
if @level_number == @levels.size-1
|
71
|
-
fire :next_mode
|
72
|
-
else
|
73
|
-
next_level
|
74
|
-
end
|
75
|
-
end
|
76
|
-
level.when :prev_level do
|
77
|
-
if @level_number == 0
|
78
|
-
fire :prev_mode
|
79
|
-
else
|
80
|
-
prev_level
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
level
|
85
|
-
end
|
86
|
-
|
87
|
-
def update(time)
|
88
|
-
@level.update time if @level
|
89
|
-
@viewport.update time
|
90
|
-
end
|
91
|
-
|
92
|
-
def draw(target)
|
93
|
-
@level.draw target, @viewport.x_offset, @viewport.y_offset
|
94
|
-
|
95
|
-
for parallax_layer in @drawables.keys.sort.reverse
|
96
|
-
pd = @drawables[parallax_layer]
|
97
|
-
for layer in pd.keys.sort
|
98
|
-
for d in pd[layer]
|
99
|
-
trans_x = @viewport.x_offset parallax_layer
|
100
|
-
trans_y = @viewport.y_offset parallax_layer
|
101
|
-
d.draw target, trans_x, trans_y
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def unregister_drawable(drawable)
|
108
|
-
@drawables[drawable.parallax][drawable.layer].delete drawable
|
109
|
-
end
|
110
|
-
|
111
|
-
def clear_drawables
|
112
|
-
@drawables = {}
|
113
|
-
end
|
114
|
-
|
115
|
-
def register_drawable(drawable)
|
116
|
-
layer = drawable.layer
|
117
|
-
parallax = drawable.parallax
|
118
|
-
@drawables[parallax] ||= {}
|
119
|
-
@drawables[parallax][layer] ||= []
|
120
|
-
@drawables[parallax][layer] << drawable
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
data/lib/gamebox/mode_manager.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'inflector'
|
2
|
-
require 'mode'
|
3
|
-
class ModeManager
|
4
|
-
|
5
|
-
constructor :resource_manager, :actor_factory, :input_manager,
|
6
|
-
:sound_manager, :config_manager
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@modes = {}
|
10
|
-
@actor_factory.mode_manager = self
|
11
|
-
modes = @resource_manager.load_config('mode_level_config')[:modes]
|
12
|
-
|
13
|
-
@mode_names = []
|
14
|
-
for mode_hash in modes
|
15
|
-
for mode, levels in mode_hash
|
16
|
-
@mode_names << mode
|
17
|
-
mode_klass_name = "Mode"
|
18
|
-
unless mode == :default
|
19
|
-
mode_klass_name = Inflector.camelize mode.to_s+"Mode"
|
20
|
-
end
|
21
|
-
begin
|
22
|
-
require mode.to_s+"_mode"
|
23
|
-
rescue LoadError
|
24
|
-
# hope it's defined somewhere else
|
25
|
-
end
|
26
|
-
mode_klass = ObjectSpace.const_get mode_klass_name
|
27
|
-
mode_instance = mode_klass.new(@input_manager, @actor_factory, @resource_manager, @sound_manager, @config_manager, levels)
|
28
|
-
mode_instance.when :next_mode do
|
29
|
-
next_mode
|
30
|
-
end
|
31
|
-
mode_instance.when :prev_mode do
|
32
|
-
prev_mode
|
33
|
-
end
|
34
|
-
add_mode mode, mode_instance
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def next_mode
|
40
|
-
index = @mode_names.index @mode
|
41
|
-
if index == @mode_names.size-1
|
42
|
-
puts "last mode, exiting"
|
43
|
-
exit
|
44
|
-
end
|
45
|
-
change_mode_to @mode_names[index+1]
|
46
|
-
end
|
47
|
-
|
48
|
-
def prev_mode
|
49
|
-
index = @mode_names.index @mode
|
50
|
-
if index == 0
|
51
|
-
puts "first mode, exiting"
|
52
|
-
exit
|
53
|
-
end
|
54
|
-
change_mode_to @mode_names[index-1]
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_mode(mode_sym, mode_instance)
|
58
|
-
@modes[mode_sym] = mode_instance
|
59
|
-
@mode = mode_sym unless @mode
|
60
|
-
mode_instance
|
61
|
-
end
|
62
|
-
|
63
|
-
def change_mode_to(mode, *args)
|
64
|
-
@modes[@mode].stop unless @modes[@mode].nil?
|
65
|
-
@mode = mode
|
66
|
-
@modes[@mode].start *args
|
67
|
-
end
|
68
|
-
|
69
|
-
def current_mode
|
70
|
-
@modes[@mode]
|
71
|
-
end
|
72
|
-
|
73
|
-
def update(time)
|
74
|
-
@modes[@mode].update time unless @modes[@mode].nil?
|
75
|
-
end
|
76
|
-
|
77
|
-
def draw(target)
|
78
|
-
@modes[@mode].draw target unless @modes[@mode].nil?
|
79
|
-
end
|
80
|
-
end
|