gamebox 0.3.4 → 0.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +38 -0
- data/Rakefile +1 -10
- data/TODO.txt +6 -6
- data/app_generators/gamebox_generator.rb +95 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/.gitignore +0 -0
- data/app_generators/templates/Gemfile +7 -0
- data/app_generators/templates/NEXT_STEPS.txt +1 -0
- data/{lib/gamebox/templates/template_app/README → app_generators/templates/README.rdoc} +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/Rakefile +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/config/boot.rb +0 -0
- data/app_generators/templates/config/environment.rb +30 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/config/game.yml +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/fonts/FONTS_GO_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/graphics/GRAPHICS_GO_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/music/MUSIC_GOES_HERE +0 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/data/sounds/SOUND_FX_GO_HERE +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_spec.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_view.erb +0 -0
- data/{lib/gamebox/templates → app_generators/templates/script}/actor_view_spec.erb +0 -0
- data/app_generators/templates/script/generate +12 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/spec/helper.rb +0 -0
- data/app_generators/templates/src/actors/player.rb +8 -0
- data/{lib/gamebox/templates/template_app → app_generators/templates}/src/app.rb +0 -0
- data/app_generators/templates/src/demo_stage.rb +7 -0
- data/bin/gamebox +8 -70
- data/component_generators/actor_generator.rb +17 -0
- data/docs/CODE_REVIEW +1 -1
- data/docs/REFACTOR_NOTES.txt +25 -0
- data/docs/getting_started.rdoc +1 -1
- data/gamebox.gemspec +7 -4
- data/lib/gamebox.rb +6 -3
- data/lib/gamebox/actors/collidable_debugger.rb +13 -15
- data/lib/gamebox/actors/curtain.rb +44 -43
- data/lib/gamebox/actors/emitter.rb +3 -42
- data/lib/gamebox/actors/fps.rb +13 -6
- data/lib/gamebox/actors/label.rb +42 -34
- data/lib/gamebox/actors/logo.rb +2 -4
- data/lib/gamebox/actors/score.rb +37 -27
- data/lib/gamebox/actors/svg_actor.rb +45 -32
- data/lib/gamebox/behaviors/animated.rb +39 -59
- data/lib/gamebox/behaviors/audible.rb +14 -14
- data/lib/gamebox/behaviors/collidable.rb +65 -36
- data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +2 -3
- data/lib/gamebox/behaviors/collidable/collidable_shape.rb +6 -4
- data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
- data/lib/gamebox/behaviors/emitting.rb +48 -0
- data/lib/gamebox/behaviors/graphical.rb +22 -56
- data/lib/gamebox/behaviors/layered.rb +8 -21
- data/lib/gamebox/behaviors/physical.rb +202 -213
- data/lib/gamebox/behaviors/positioned.rb +16 -0
- data/lib/gamebox/behaviors/projectile.rb +15 -0
- data/lib/gamebox/behaviors/visible.rb +16 -0
- data/lib/gamebox/core/aabb_helpers.rb +61 -0
- data/lib/gamebox/core/aabb_node.rb +118 -0
- data/lib/gamebox/core/aabb_tree.rb +137 -0
- data/lib/gamebox/core/actor.rb +102 -0
- data/lib/gamebox/core/actor_factory.rb +56 -0
- data/lib/gamebox/core/actor_view.rb +63 -0
- data/lib/gamebox/core/actor_view_factory.rb +40 -0
- data/lib/gamebox/{arbiter.rb → core/arbiter.rb} +31 -34
- data/lib/gamebox/{backstage.rb → core/backstage.rb} +0 -0
- data/lib/gamebox/core/behavior.rb +64 -0
- data/lib/gamebox/core/behavior_factory.rb +56 -0
- data/lib/gamebox/{class_finder.rb → core/class_finder.rb} +0 -0
- data/lib/gamebox/{config_manager.rb → core/config_manager.rb} +1 -1
- data/lib/gamebox/core/configuration.rb +39 -0
- data/lib/gamebox/core/core.rb +30 -0
- data/lib/gamebox/core/deprecated.rb +15 -0
- data/lib/gamebox/{director.rb → core/director.rb} +6 -11
- data/lib/gamebox/core/font_style.rb +26 -0
- data/lib/gamebox/core/font_style_factory.rb +11 -0
- data/lib/gamebox/core/game.rb +19 -0
- data/lib/gamebox/{hooked_gosu_window.rb → core/hooked_gosu_window.rb} +12 -6
- data/lib/gamebox/{input_manager.rb → core/input_manager.rb} +106 -99
- data/lib/gamebox/core/physics.rb +22 -0
- data/lib/gamebox/{physical_stage.rb → core/physics_manager.rb} +36 -30
- data/lib/gamebox/{resource_manager.rb → core/resource_manager.rb} +19 -18
- data/lib/gamebox/{sound_manager.rb → core/sound_manager.rb} +9 -7
- data/lib/gamebox/{stage.rb → core/stage.rb} +42 -80
- data/lib/gamebox/{stage_manager.rb → core/stage_manager.rb} +46 -53
- data/lib/gamebox/{stagehand.rb → core/stagehand.rb} +0 -0
- data/lib/gamebox/{svg_document.rb → core/svg_document.rb} +0 -0
- data/lib/gamebox/core/timer_manager.rb +50 -0
- data/lib/gamebox/{viewport.rb → core/viewport.rb} +2 -3
- data/lib/gamebox/{wrapped_screen.rb → core/wrapped_screen.rb} +12 -19
- data/lib/gamebox/gamebox_application.rb +7 -15
- data/lib/gamebox/lib/evented_attributes.rb +51 -0
- data/lib/gamebox/{ftor.rb → lib/ftor.rb} +0 -0
- data/lib/gamebox/lib/min_max_helpers.rb +10 -0
- data/lib/gamebox/lib/rect.rb +112 -54
- data/lib/gamebox/lib/yoda.rb +46 -0
- data/lib/gamebox/spec/helper.rb +317 -12
- data/lib/gamebox/stagehands/spatial_tree_stagehand.rb +61 -0
- data/lib/gamebox/version.rb +8 -3
- data/lib/gamebox/views/graphical_actor_view.rb +22 -29
- data/script/perf_aabb.rb +56 -0
- data/script/perf_array_access.rb +16 -0
- data/script/perf_collisions.rb +37 -18
- data/script/perf_struct_vs_array.rb +7 -7
- data/spec/acceptance/animation_spec.rb +65 -0
- data/spec/acceptance/basic_actor_lifecycle_spec.rb +92 -0
- data/spec/acceptance/built_in_collision_handling_spec.rb +55 -0
- data/spec/acceptance/chipmunk_collision_handling_spec.rb +83 -0
- data/spec/acceptance/fps_actor_spec.rb +40 -0
- data/spec/acceptance/pausing_spec.rb +61 -0
- data/spec/acceptance/timer_usage_spec.rb +53 -0
- data/spec/actors/emitter_spec.rb +5 -0
- data/spec/{label_spec.rb → actors/label_spec.rb} +1 -1
- data/spec/behaviors/animated_spec.rb +85 -0
- data/spec/behaviors/collidable_spec.rb +134 -0
- data/spec/{physical_spec.rb → behaviors/physical_spec.rb} +2 -1
- data/spec/behaviors/positioned_spec.rb +6 -0
- data/spec/behaviors/projectile_spec.rb +6 -0
- data/spec/core/aabb_tree_spec.rb +109 -0
- data/spec/core/actor_factory_spec.rb +44 -0
- data/spec/core/actor_spec.rb +78 -0
- data/spec/core/actor_view_spec.rb +53 -0
- data/spec/{arbiter_spec.rb → core/arbiter_spec.rb} +29 -30
- data/spec/core/backstage_spec.rb +37 -0
- data/spec/core/behavior_factory_spec.rb +50 -0
- data/spec/core/behavior_spec.rb +8 -0
- data/spec/core/configuration_spec.rb +8 -0
- data/spec/core/core_spec.rb +13 -0
- data/spec/core/font_style_factory_spec.rb +17 -0
- data/spec/core/font_style_spec.rb +41 -0
- data/spec/core/hooked_gosu_window_spec.rb +75 -0
- data/spec/core/input_manager_spec.rb +285 -0
- data/spec/core/physics_manager_spec.rb +11 -0
- data/spec/core/resource_manager_spec.rb +12 -0
- data/spec/core/stage_manager_spec.rb +140 -0
- data/spec/core/stage_spec.rb +73 -0
- data/spec/core/timer_manager_spec.rb +89 -0
- data/spec/{viewport_spec.rb → core/viewport_spec.rb} +6 -3
- data/spec/core/wrapped_screen_spec.rb +26 -0
- data/spec/fixtures/game.yml +7 -0
- data/spec/fixtures/snelpling/idle/1.png +0 -0
- data/spec/fixtures/snelpling/jump/1.png +0 -0
- data/spec/fixtures/snelpling/jump/2.png +0 -0
- data/spec/fixtures/snelpling/jump/3.png +0 -0
- data/spec/helper.rb +8 -0
- data/spec/{class_finder_spec.rb → lib/class_finder_spec.rb} +2 -1
- data/spec/stagehands/spatial_tree_stagehand_spec.rb +19 -0
- data/spec/views/graphical_actor_view_spec.rb +116 -0
- metadata +343 -144
- data/README.txt +0 -34
- data/lib/gamebox/actor.rb +0 -179
- data/lib/gamebox/actor_factory.rb +0 -57
- data/lib/gamebox/actor_view.rb +0 -44
- data/lib/gamebox/actors/spatial_debugger.rb +0 -62
- data/lib/gamebox/behavior.rb +0 -70
- data/lib/gamebox/behaviors/timed.rb +0 -33
- data/lib/gamebox/behaviors/updatable.rb +0 -12
- data/lib/gamebox/console_app.rb +0 -41
- data/lib/gamebox/gamebox_generator.rb +0 -32
- data/lib/gamebox/generators/actor_generator.rb +0 -43
- data/lib/gamebox/generators/view_generator.rb +0 -42
- data/lib/gamebox/physical_director.rb +0 -17
- data/lib/gamebox/physics.rb +0 -32
- data/lib/gamebox/spatial_bucket.rb +0 -9
- data/lib/gamebox/spatial_hash.rb +0 -194
- data/lib/gamebox/spatial_stagehand.rb +0 -80
- data/lib/gamebox/templates/template_app/Gemfile +0 -6
- data/lib/gamebox/templates/template_app/config/environment.rb +0 -23
- data/lib/gamebox/templates/template_app/config/stage_config.yml +0 -2
- data/lib/gamebox/templates/template_app/script/generate +0 -7
- data/lib/gamebox/templates/template_app/src/demo_stage.rb +0 -11
- data/lib/gamebox/templates/template_app/src/game.rb +0 -19
- data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -14
- data/script/perf_spatial_hash.rb +0 -64
- data/spec/actor_factory_spec.rb +0 -61
- data/spec/actor_spec.rb +0 -71
- data/spec/actor_view_spec.rb +0 -61
- data/spec/animated_spec.rb +0 -83
- data/spec/backstage_spec.rb +0 -45
- data/spec/behavior_spec.rb +0 -28
- data/spec/collidable_spec.rb +0 -135
- data/spec/emitter_spec.rb +0 -20
- data/spec/input_manager_spec.rb +0 -134
- data/spec/resource_manager_spec.rb +0 -13
- data/spec/spatial_hash_spec.rb +0 -119
- data/spec/spatial_stagehand_spec.rb +0 -93
- data/spec/stage_manager_spec.rb +0 -25
- data/spec/stage_spec.rb +0 -65
data/docs/getting_started.rdoc
CHANGED
data/gamebox.gemspec
CHANGED
@@ -19,12 +19,14 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_dependency "gosu"
|
22
|
-
s.add_dependency "constructor"
|
23
22
|
s.add_dependency "publisher"
|
24
|
-
s.add_dependency "
|
23
|
+
s.add_dependency "conject", ">= 0.0.5"
|
25
24
|
s.add_dependency "tween"
|
25
|
+
s.add_dependency "activesupport", '3.0.0'
|
26
|
+
s.add_dependency "i18n"
|
27
|
+
s.add_dependency "rubigen"
|
26
28
|
s.add_dependency "require_all"
|
27
|
-
s.add_dependency "kvo"
|
29
|
+
s.add_dependency "kvo", ">= 0.0.2"
|
28
30
|
|
29
31
|
s.add_development_dependency "pry", '~>0.9.7'
|
30
32
|
s.add_development_dependency "pry-remote"
|
@@ -35,6 +37,7 @@ Gem::Specification.new do |s|
|
|
35
37
|
s.add_development_dependency "rspec"
|
36
38
|
s.add_development_dependency "rake"
|
37
39
|
s.add_development_dependency "polaris"
|
38
|
-
|
40
|
+
s.add_development_dependency "simplecov"
|
41
|
+
s.add_development_dependency "chipmunk"
|
39
42
|
end
|
40
43
|
|
data/lib/gamebox.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
GAMEBOX_PATH = File.join(File.dirname(__FILE__),"gamebox/")
|
2
|
-
require '
|
3
|
-
require 'constructor'
|
2
|
+
require 'conject'
|
4
3
|
require 'kvo'
|
5
4
|
require 'tween'
|
6
5
|
require 'gosu'
|
@@ -19,5 +18,9 @@ begin
|
|
19
18
|
rescue LoadError
|
20
19
|
end
|
21
20
|
|
21
|
+
require "#{GAMEBOX_PATH}/version.rb"
|
22
22
|
require 'require_all'
|
23
|
-
|
23
|
+
directory_load_order = %w(lib core actors behaviors views stagehands)
|
24
|
+
directory_load_order.each do |dir|
|
25
|
+
require_all "#{GAMEBOX_PATH}/#{dir}/**/*.rb"
|
26
|
+
end
|
@@ -1,27 +1,25 @@
|
|
1
|
+
Actor.define :collidable_debugger do
|
2
|
+
has_behaviors :collider_container
|
3
|
+
end
|
1
4
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@actor = opts[:collider]
|
9
|
-
@actor.when :remove_me do
|
10
|
-
remove_self
|
5
|
+
Behavior.define :collider_container do
|
6
|
+
setup do
|
7
|
+
actor.has_attributes collider: actor.opts[:collider]
|
8
|
+
actor.collider.when :remove do
|
9
|
+
actor.remove
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
|
14
|
+
ActorView.define :collidable_debugger_view do
|
17
15
|
|
18
|
-
|
16
|
+
configure do
|
19
17
|
@color = Color::WHITE
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
collider =
|
24
|
-
case collider.
|
20
|
+
draw do |target,x_off,y_off,z|
|
21
|
+
collider = actor.collider
|
22
|
+
case collider.shape_type
|
25
23
|
when :circle
|
26
24
|
target.draw_circle x_off+collider.center_x, y_off+collider.center_y, collider.radius, @color, z
|
27
25
|
else
|
@@ -1,57 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class CurtainView < ActorView
|
6
|
-
def draw(target,x_off,y_off,z)
|
7
|
-
target.fill 0,0,1024,800, [0,0,0,@actor.height], z
|
1
|
+
ActorView.define :curtain_view do
|
2
|
+
draw do |target,x_off,y_off,z|
|
3
|
+
target.fill 0,0,1024,800, [0,0,0,actor.height], z
|
8
4
|
end
|
9
5
|
end
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
can_fire :curtain_up, :curtain_down
|
7
|
+
FULL_CURTAIN = 255
|
8
|
+
NO_CURTAIN = 0
|
15
9
|
|
16
|
-
|
10
|
+
Behavior.define :curtain_operator do
|
11
|
+
requires :director
|
12
|
+
setup do
|
13
|
+
actor.has_attributes duration_in_ms: 1000
|
14
|
+
actor.has_attributes dir: :down
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
FULL_CURTAIN = 255
|
21
|
-
NO_CURTAIN = 0
|
22
|
-
def setup
|
23
|
-
@duration_in_ms = @opts[:duration]
|
24
|
-
@duration_in_ms ||= 1000
|
25
|
-
|
26
|
-
case @opts[:dir]
|
16
|
+
case actor.dir
|
27
17
|
when :up
|
28
|
-
|
29
|
-
|
18
|
+
height = FULL_CURTAIN
|
19
|
+
actor.dir = -1
|
30
20
|
when :down
|
31
|
-
|
32
|
-
|
21
|
+
height = NO_CURTAIN
|
22
|
+
actor.dir = 1
|
33
23
|
end
|
34
|
-
end
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
actor.has_attributes height: height
|
26
|
+
director.when :update do |time|
|
27
|
+
update time
|
28
|
+
end
|
29
|
+
end
|
41
30
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
31
|
+
helpers do
|
32
|
+
# Update curtain height 0-255 (alpha)
|
33
|
+
def update(time)
|
34
|
+
perc_change = time.to_f/actor.duration_in_ms
|
35
|
+
amount = FULL_CURTAIN * perc_change * actor.dir
|
36
|
+
actor.height += amount.floor
|
37
|
+
|
38
|
+
if actor.height < 0
|
39
|
+
actor.height = 0
|
40
|
+
if actor.alive
|
41
|
+
actor.emit :curtain_up
|
42
|
+
actor.remove
|
43
|
+
end
|
44
|
+
elsif actor.height > 255
|
45
|
+
actor.height = 255
|
46
|
+
if actor.alive
|
47
|
+
actor.emit :curtain_down
|
48
|
+
actor.remove
|
49
|
+
end
|
53
50
|
end
|
54
51
|
end
|
55
|
-
|
56
52
|
end
|
57
53
|
end
|
54
|
+
|
55
|
+
Actor.define :curtain do
|
56
|
+
has_behavior layered: 99_999
|
57
|
+
has_behavior :curtain_operator
|
58
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# actor used for particle emissions
|
2
|
+
Actor.define :emitter do
|
4
3
|
# options:
|
5
4
|
# delay: ms to wait between creating more particles
|
6
5
|
# particle_actor: actor to spawn as particle
|
@@ -9,43 +8,5 @@ class Emitter < Actor
|
|
9
8
|
# spawn_variance: dist in pixels to spawn away from emitter (default -10..10)
|
10
9
|
# location_tween: tween object that will be used to move the emitter (optional)
|
11
10
|
# follow: actor to follow (optional)
|
12
|
-
|
13
|
-
@variance = opts[:spawn_variance] || (-10..10)
|
14
|
-
|
15
|
-
spawn_timer = "#{self.object_id}_spawn"
|
16
|
-
self.when :remove_me do
|
17
|
-
stage.remove_timer spawn_timer
|
18
|
-
end
|
19
|
-
stage.add_timer spawn_timer, opts[:delay] do
|
20
|
-
spawn_particle
|
21
|
-
end
|
22
|
-
ttl = opts[:ttl]
|
23
|
-
if ttl
|
24
|
-
suicide_timer = "#{self.object_id}_ttl"
|
25
|
-
stage.add_timer suicide_timer, ttl do
|
26
|
-
stage.remove_timer suicide_timer
|
27
|
-
remove_self
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
target = opts[:follow]
|
32
|
-
if target
|
33
|
-
self.x = target.x
|
34
|
-
self.y = target.y
|
35
|
-
target.when :x_changed do
|
36
|
-
self.x = target.x
|
37
|
-
end
|
38
|
-
target.when :y_changed do
|
39
|
-
self.y = target.y
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def spawn_particle
|
46
|
-
spawn_x = self.x + @variance.sample
|
47
|
-
spawn_y = self.y + @variance.sample
|
48
|
-
|
49
|
-
spawn opts[:particle_actor], {x: spawn_x, y: spawn_y}.merge(opts[:particle_opts])
|
50
|
-
end
|
11
|
+
has_behavior :emitting
|
51
12
|
end
|
data/lib/gamebox/actors/fps.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
Behavior.define :fps_label_updater do
|
2
|
+
requires :director, :stage
|
3
|
+
setup do
|
4
|
+
@label = stage.create_actor :label, actor.attributes
|
5
|
+
director.when :update do |time|
|
6
|
+
@label.text = Gosu.fps
|
7
|
+
end
|
6
8
|
end
|
7
|
-
|
9
|
+
react_to do |msg, *args|
|
10
|
+
@label.remove if msg == :remove
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Actor.define :fps do
|
14
|
+
has_behavior :fps_label_updater
|
8
15
|
end
|
data/lib/gamebox/actors/label.rb
CHANGED
@@ -1,43 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
Behavior.define :label_stuff do
|
2
|
+
requires_behaviors :positioned
|
3
|
+
requires :font_style_factory
|
4
|
+
|
5
|
+
setup do
|
6
|
+
# will define attributes and set their values if no one else has
|
7
|
+
actor.has_attributes text: "",
|
8
|
+
font_size: 30,
|
9
|
+
font_name: "Asimov.ttf",
|
10
|
+
color: [250,250,250,255],
|
11
|
+
width: 0,
|
12
|
+
height: 0,
|
13
|
+
layer: 1
|
14
|
+
|
15
|
+
|
16
|
+
font_style = font_style_factory.build actor.font_name, actor.font_size, actor.color
|
17
|
+
actor.has_attributes font_style: font_style
|
18
|
+
|
19
|
+
actor.when :font_size_changed do
|
20
|
+
actor.font_style.reload
|
21
|
+
recalculate_size
|
22
|
+
end
|
23
|
+
actor.when :font_name_changed do
|
24
|
+
actor.font_style.reload
|
25
|
+
recalculate_size
|
26
|
+
end
|
27
|
+
actor.when :text_changed do
|
28
|
+
recalculate_size
|
29
|
+
end
|
19
30
|
|
20
|
-
@text ||= ""
|
21
|
-
@size ||= 30
|
22
|
-
font_name ||= "Asimov.ttf"
|
23
|
-
@color ||= [250,250,250,255]
|
24
|
-
layer = opts[:layer]
|
25
|
-
layered.layer = layer
|
26
|
-
|
27
|
-
@font = resource_manager.load_font font_name, @size
|
28
31
|
end
|
29
32
|
|
30
|
-
|
31
|
-
|
33
|
+
helpers do
|
34
|
+
def recalculate_size
|
35
|
+
actor.width = actor.font_style.calc_width actor.text
|
36
|
+
actor.height = actor.font_style.height
|
37
|
+
end
|
32
38
|
end
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
Actor.define :label do
|
42
|
+
has_behavior layered: 1
|
43
|
+
has_behavior :label_stuff
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
view do
|
46
|
+
draw do |target,x_off,y_off,z|
|
47
|
+
target.print actor.text, actor.x, actor.y, z, actor.font_style
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
end
|
data/lib/gamebox/actors/logo.rb
CHANGED
data/lib/gamebox/actors/score.rb
CHANGED
@@ -1,37 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
text = @actor.score.to_s
|
4
|
-
text = '0'*(6-text.size)+text
|
1
|
+
define_behavior :score_keeper do
|
2
|
+
requires :backstage, :stage
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
setup do
|
5
|
+
clear if score.nil?
|
6
|
+
# TODO helper for "attached subactor"
|
7
|
+
label = stage.create_actor(:label, actor.attributes)
|
8
|
+
actor.has_attributes label: label
|
9
|
+
actor.when :position_changed do
|
10
|
+
actor.label.x = actor.x
|
11
|
+
actor.label.y = actor.y
|
12
|
+
end
|
13
|
+
actor.when :remove_me do
|
14
|
+
label.remove
|
15
|
+
end
|
16
|
+
update_text
|
17
|
+
reacts_with :subtract, :add
|
10
18
|
end
|
11
|
-
end
|
12
|
-
class Score < Actor
|
13
19
|
|
14
|
-
|
20
|
+
helpers do
|
21
|
+
def score
|
22
|
+
backstage[:score]
|
23
|
+
end
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
def clear
|
26
|
+
backstage[:score] = 0
|
27
|
+
end
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
def add(amount)
|
30
|
+
backstage[:score] += amount
|
31
|
+
update_text
|
32
|
+
end
|
23
33
|
|
24
|
-
|
25
|
-
|
26
|
-
|
34
|
+
def subtract(amount)
|
35
|
+
backstage[:score] -= amount
|
36
|
+
update_text
|
37
|
+
end
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
def update_text
|
40
|
+
actor.label.text = score
|
41
|
+
end
|
31
42
|
end
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
45
|
+
define_actor :score do
|
46
|
+
has_behavior :score_keeper, layered: 999
|
37
47
|
end
|