gamebox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/History.txt +18 -0
  2. data/Manifest.txt +85 -0
  3. data/README.txt +33 -0
  4. data/Rakefile +42 -0
  5. data/TODO.txt +29 -0
  6. data/bin/gamebox +49 -0
  7. data/docs/gamebox04_big.png +0 -0
  8. data/docs/getting_started.rdoc +99 -0
  9. data/docs/logo.png +0 -0
  10. data/lib/gamebox.rb +6 -0
  11. data/lib/gamebox/actor.rb +143 -0
  12. data/lib/gamebox/actor_factory.rb +64 -0
  13. data/lib/gamebox/actor_view.rb +35 -0
  14. data/lib/gamebox/ai/line_of_site.rb +61 -0
  15. data/lib/gamebox/ai/polaris.rb +107 -0
  16. data/lib/gamebox/ai/two_d_grid_location.rb +21 -0
  17. data/lib/gamebox/ai/two_d_grid_map.rb +77 -0
  18. data/lib/gamebox/aliasing.rb +16 -0
  19. data/lib/gamebox/animated.rb +84 -0
  20. data/lib/gamebox/behavior.rb +16 -0
  21. data/lib/gamebox/config_manager.rb +22 -0
  22. data/lib/gamebox/console_app.rb +39 -0
  23. data/lib/gamebox/data/fonts/Asimov.ttf +0 -0
  24. data/lib/gamebox/data/fonts/GAMEBOX_FONTS_GO_HERE +0 -0
  25. data/lib/gamebox/data/graphics/GAMEBOX_GRAPHICS_GO_HERE +0 -0
  26. data/lib/gamebox/data/graphics/logo.png +0 -0
  27. data/lib/gamebox/data/music/GAMEBOX_MUSIC_GOES_HERE +0 -0
  28. data/lib/gamebox/data/sounds/GAMEBOX_SOUND_FX_GO_HERE +0 -0
  29. data/lib/gamebox/director.rb +47 -0
  30. data/lib/gamebox/gamebox_application.rb +77 -0
  31. data/lib/gamebox/graphical.rb +24 -0
  32. data/lib/gamebox/graphical_actor_view.rb +31 -0
  33. data/lib/gamebox/inflections.rb +52 -0
  34. data/lib/gamebox/inflector.rb +278 -0
  35. data/lib/gamebox/input_manager.rb +104 -0
  36. data/lib/gamebox/layered.rb +34 -0
  37. data/lib/gamebox/level.rb +64 -0
  38. data/lib/gamebox/linked_list.rb +137 -0
  39. data/lib/gamebox/logo.rb +11 -0
  40. data/lib/gamebox/metaclass.rb +6 -0
  41. data/lib/gamebox/mode.rb +123 -0
  42. data/lib/gamebox/mode_manager.rb +80 -0
  43. data/lib/gamebox/numbers_ext.rb +3 -0
  44. data/lib/gamebox/physical.rb +139 -0
  45. data/lib/gamebox/physical_director.rb +17 -0
  46. data/lib/gamebox/physical_level.rb +89 -0
  47. data/lib/gamebox/physics.rb +27 -0
  48. data/lib/gamebox/publisher_ext.rb +13 -0
  49. data/lib/gamebox/resource_manager.rb +122 -0
  50. data/lib/gamebox/score.rb +35 -0
  51. data/lib/gamebox/sorted_list.rb +59 -0
  52. data/lib/gamebox/sound_manager.rb +84 -0
  53. data/lib/gamebox/surface_ext.rb +37 -0
  54. data/lib/gamebox/svg_actor.rb +55 -0
  55. data/lib/gamebox/svg_document.rb +160 -0
  56. data/lib/gamebox/template_app/README +30 -0
  57. data/lib/gamebox/template_app/Rakefile +20 -0
  58. data/lib/gamebox/template_app/config/boot.rb +5 -0
  59. data/lib/gamebox/template_app/config/environment.rb +29 -0
  60. data/lib/gamebox/template_app/config/game.yml +6 -0
  61. data/lib/gamebox/template_app/config/mode_level_config.yml +3 -0
  62. data/lib/gamebox/template_app/config/objects.yml +29 -0
  63. data/lib/gamebox/template_app/data/fonts/FONTS_GO_HERE +0 -0
  64. data/lib/gamebox/template_app/data/graphics/GRAPHICS_GO_HERE +0 -0
  65. data/lib/gamebox/template_app/data/music/MUSIC_GOES_HERE +0 -0
  66. data/lib/gamebox/template_app/data/sounds/SOUND_FX_GO_HERE +0 -0
  67. data/lib/gamebox/template_app/doc/README_FOR_APP +1 -0
  68. data/lib/gamebox/template_app/lib/code_statistics.rb +107 -0
  69. data/lib/gamebox/template_app/lib/diy.rb +371 -0
  70. data/lib/gamebox/template_app/lib/platform.rb +16 -0
  71. data/lib/gamebox/template_app/src/app.rb +8 -0
  72. data/lib/gamebox/template_app/src/demo_level.rb +20 -0
  73. data/lib/gamebox/template_app/src/game.rb +22 -0
  74. data/lib/gamebox/template_app/src/my_actor.rb +17 -0
  75. data/lib/gamebox/version.rb +10 -0
  76. data/lib/gamebox/viewport.rb +81 -0
  77. data/lib/gamebox/wrapped_screen.rb +15 -0
  78. data/script/perf_polaris.rb +36 -0
  79. data/test/helper.rb +25 -0
  80. data/test/test_actor.rb +38 -0
  81. data/test/test_animated.rb +64 -0
  82. data/test/test_line_of_site.rb +14 -0
  83. data/test/test_physical.rb +26 -0
  84. data/test/test_polaris.rb +193 -0
  85. data/test/test_viewport.rb +116 -0
  86. metadata +188 -0
@@ -0,0 +1,18 @@
1
+ === 0.0.1 / 2009-06-19
2
+
3
+ * Gamebox lives!
4
+ * got game generation working in ruby 1.8
5
+ * initial objects built
6
+ * Actor/ActorViews (game objects)
7
+ * Director manages actors
8
+ * Level manages directors, backgrounds, level goals
9
+ * Mode manages level loading and order
10
+ * Behavior system for adding behaviors to actors (ie physical to put an actor into a physical space)
11
+ * Loading of Levels from an SVG file
12
+ * Polaris A* path finder
13
+ * Lots more to come!
14
+ * examples to show how to use it
15
+ * netris
16
+ * roids
17
+ * rague
18
+ * nario
@@ -0,0 +1,85 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ TODO.txt
6
+ bin/gamebox
7
+ docs/gamebox04_big.png
8
+ docs/getting_started.rdoc
9
+ docs/logo.png
10
+ lib/gamebox.rb
11
+ lib/gamebox/actor.rb
12
+ lib/gamebox/actor_factory.rb
13
+ lib/gamebox/actor_view.rb
14
+ lib/gamebox/ai/line_of_site.rb
15
+ lib/gamebox/ai/polaris.rb
16
+ lib/gamebox/ai/two_d_grid_location.rb
17
+ lib/gamebox/ai/two_d_grid_map.rb
18
+ lib/gamebox/aliasing.rb
19
+ lib/gamebox/animated.rb
20
+ lib/gamebox/behavior.rb
21
+ lib/gamebox/config_manager.rb
22
+ lib/gamebox/console_app.rb
23
+ lib/gamebox/data/fonts/Asimov.ttf
24
+ lib/gamebox/data/fonts/GAMEBOX_FONTS_GO_HERE
25
+ lib/gamebox/data/graphics/GAMEBOX_GRAPHICS_GO_HERE
26
+ lib/gamebox/data/graphics/logo.png
27
+ lib/gamebox/data/music/GAMEBOX_MUSIC_GOES_HERE
28
+ lib/gamebox/data/sounds/GAMEBOX_SOUND_FX_GO_HERE
29
+ lib/gamebox/director.rb
30
+ lib/gamebox/gamebox_application.rb
31
+ lib/gamebox/graphical.rb
32
+ lib/gamebox/graphical_actor_view.rb
33
+ lib/gamebox/inflections.rb
34
+ lib/gamebox/inflector.rb
35
+ lib/gamebox/input_manager.rb
36
+ lib/gamebox/layered.rb
37
+ lib/gamebox/level.rb
38
+ lib/gamebox/linked_list.rb
39
+ lib/gamebox/logo.rb
40
+ lib/gamebox/metaclass.rb
41
+ lib/gamebox/mode.rb
42
+ lib/gamebox/mode_manager.rb
43
+ lib/gamebox/numbers_ext.rb
44
+ lib/gamebox/physical.rb
45
+ lib/gamebox/physical_director.rb
46
+ lib/gamebox/physical_level.rb
47
+ lib/gamebox/physics.rb
48
+ lib/gamebox/publisher_ext.rb
49
+ lib/gamebox/resource_manager.rb
50
+ lib/gamebox/score.rb
51
+ lib/gamebox/sorted_list.rb
52
+ lib/gamebox/sound_manager.rb
53
+ lib/gamebox/surface_ext.rb
54
+ lib/gamebox/svg_actor.rb
55
+ lib/gamebox/svg_document.rb
56
+ lib/gamebox/template_app/README
57
+ lib/gamebox/template_app/Rakefile
58
+ lib/gamebox/template_app/config/boot.rb
59
+ lib/gamebox/template_app/config/environment.rb
60
+ lib/gamebox/template_app/config/game.yml
61
+ lib/gamebox/template_app/config/mode_level_config.yml
62
+ lib/gamebox/template_app/config/objects.yml
63
+ lib/gamebox/template_app/data/fonts/FONTS_GO_HERE
64
+ lib/gamebox/template_app/data/graphics/GRAPHICS_GO_HERE
65
+ lib/gamebox/template_app/data/music/MUSIC_GOES_HERE
66
+ lib/gamebox/template_app/data/sounds/SOUND_FX_GO_HERE
67
+ lib/gamebox/template_app/doc/README_FOR_APP
68
+ lib/gamebox/template_app/lib/code_statistics.rb
69
+ lib/gamebox/template_app/lib/diy.rb
70
+ lib/gamebox/template_app/lib/platform.rb
71
+ lib/gamebox/template_app/src/app.rb
72
+ lib/gamebox/template_app/src/demo_level.rb
73
+ lib/gamebox/template_app/src/game.rb
74
+ lib/gamebox/template_app/src/my_actor.rb
75
+ lib/gamebox/version.rb
76
+ lib/gamebox/viewport.rb
77
+ lib/gamebox/wrapped_screen.rb
78
+ script/perf_polaris.rb
79
+ test/helper.rb
80
+ test/test_actor.rb
81
+ test/test_animated.rb
82
+ test/test_line_of_site.rb
83
+ test/test_physical.rb
84
+ test/test_polaris.rb
85
+ test/test_viewport.rb
@@ -0,0 +1,33 @@
1
+ = gamebox
2
+
3
+ * http://shawn42.github.com/gamebox/
4
+
5
+ == DESCRIPTION:
6
+
7
+ A game template for building and distributing Rubygame games. See docs/getting_started.rdoc for help getting started.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Quickly generate a game and have it up and running.
12
+
13
+ == SYNOPSIS:
14
+
15
+ A game template for building and distributing Rubygame games.
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * Rubygame (its dependancies, SDL)
20
+ * constructor gem
21
+ * publisher gem
22
+ * bacon (for gamebox tests)
23
+ * algorithms gem (optional for line of site and A*)
24
+
25
+ == INSTALL:
26
+
27
+ * gem install gamebox; gamebox my_cool_game
28
+
29
+ == LICENSE:
30
+
31
+ (GPLv2)
32
+
33
+ Copyright (c) 2009 Shawn Anderson
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+
4
+ module Gamebox
5
+ VERSION = '0.0.1'
6
+ end
7
+ Hoe.new('gamebox', Gamebox::VERSION) do |p|
8
+ p.developer('Shawn Anderson', 'shawn42@gmail.com')
9
+ p.author = "Shawn Anderson"
10
+ p.description = "Framework for building and distributing games using Rubygame"
11
+ p.email = 'shawn42@gmail.com'
12
+ p.summary = "Framework for building and distributing games using Rubygame"
13
+ p.url = "http://shawn42.github.com/gamebox"
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.remote_rdoc_dir = '' # Release to root
16
+ p.extra_deps << ['constructor']
17
+ p.extra_deps << ['publisher']
18
+ p.extra_deps << ['bacon']
19
+ if p.extra_rdoc_files
20
+ p.extra_rdoc_files << 'docs/getting_started.rdoc'
21
+ end
22
+ end
23
+
24
+ STATS_DIRECTORIES = [
25
+ %w(Source lib/)
26
+ ].collect { |name, dir| [ name, "#{dir}" ] }.select { |name, dir| File.directory?(dir) }
27
+
28
+ desc "Report code statistics (KLOCs, etc) from the application"
29
+ task :stats do
30
+ require 'code_statistics'
31
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
32
+ end
33
+
34
+ desc "Run all the strips of bacon"
35
+ task :bacon do
36
+ # sh "bacon -Ilib:test --automatic --quiet"
37
+ sh "bacon -Ilib:test --automatic "
38
+ end
39
+
40
+ task :test => :bacon
41
+
42
+ # vim: syntax=Ruby
@@ -0,0 +1,29 @@
1
+ planned features:
2
+ change Polaris to return partial path when step max is reached
3
+ update physical objects to use chipmunk_object.rb
4
+ allow for repeating actors (tiles)
5
+ allow overriding of animation timing
6
+ make complex Phyiscal behaviors (made up by a group of shapes/bodies pinned together?)
7
+ physical objects should have bodies and shapes body/shape should be shorthand for bodies.first/shapes.first
8
+ - add basic generator for things like actors/levels/etc with tests
9
+ - solidify rdocs (including tutorial)
10
+ SVGS
11
+ create a DynamicPhysicalActor that can be built from external verts
12
+ add while key down K_UP callback?
13
+ add nice actor debugging
14
+ add Extra; actor with a short time to live (TTL); useful for special effects (maybe as a behavior)
15
+ add some kind of fade in/out for actors w/ smooth interpolation
16
+
17
+ static deployment bundles (crate)
18
+ ruby
19
+ SDL
20
+ rubygame
21
+ possible features:
22
+ AI
23
+ state machine
24
+ rule based
25
+ optional GUI via rubygoo
26
+ particle system? ParticleGroupActor?
27
+ network manager
28
+ highscore upload system
29
+ gamebox server (content server?)
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("INT") { puts; exit }
4
+
5
+ require File.dirname(__FILE__) + '/../lib/gamebox/version'
6
+ if %w(--version -v).include? ARGV.first
7
+ puts "Gamebox #{Gamebox::VERSION::STRING}"
8
+ exit(0)
9
+ end
10
+
11
+ begin
12
+ require 'ftools'
13
+ fklass = File
14
+ rescue LoadError
15
+ require 'fileutils'
16
+ fklass = FileUtils
17
+ end
18
+
19
+ PROJECT_NAME = ARGV[0]
20
+ TARGET_DIR = File.expand_path(Dir.pwd + "/" + PROJECT_NAME)
21
+ SOURCE_DIR = File.expand_path(File.dirname(__FILE__) + "/../lib/gamebox")
22
+
23
+ Dir.mkdir(TARGET_DIR)
24
+
25
+ # Generate the directory structure for the new application
26
+ # Gems does not pull in empty directories so template_app only
27
+ # contains populated directories
28
+ Dir.mkdir(TARGET_DIR + "/config")
29
+ Dir.mkdir(TARGET_DIR + "/data")
30
+ Dir.mkdir(TARGET_DIR + "/data/graphics")
31
+ Dir.mkdir(TARGET_DIR + "/data/sound")
32
+ Dir.mkdir(TARGET_DIR + "/data/music")
33
+ Dir.mkdir(TARGET_DIR + "/doc")
34
+ Dir.mkdir(TARGET_DIR + "/lib")
35
+ Dir.mkdir(TARGET_DIR + "/script")
36
+ Dir.mkdir(TARGET_DIR + "/src")
37
+ Dir.mkdir(TARGET_DIR + "/test")
38
+
39
+ Dir.chdir(SOURCE_DIR + "/template_app")
40
+ Dir.glob("**/*").each do |file|
41
+ puts "#{file} => #{TARGET_DIR + "/" + file}"
42
+ if File.directory?(file)
43
+ target_dir = TARGET_DIR + "/" + file
44
+ Dir.mkdir(target_dir) unless File.exists? target_dir
45
+ else
46
+ fklass.copy(file, TARGET_DIR + "/" + file)
47
+ end
48
+ end
49
+
Binary file
@@ -0,0 +1,99 @@
1
+ = Getting started with Gamebox
2
+
3
+ == Purpose
4
+
5
+ Why use Gamebox? Gamebox was designed to spring board game development. It allows the developer to define business rules about a game very quickly without having to worry about resource loading, sound/music management, creating windows, or messing with viewports. Gamebox allows you to define a game's business rules within minutes.
6
+
7
+ The driving idea behind Gamebox is to provide the ability to have as many of the basic common pieces of a 2D game at the developers disposal from the beginning.
8
+
9
+ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing competitions and second, to allow me to write simple educational games for my kid(s).
10
+
11
+ == Installation
12
+
13
+ - gem install gamebox
14
+ - or tar from http://shawn42.github.com/gamebox
15
+ - or git pull from git://github.com/shawn42/gamebox.git
16
+
17
+ == Game Creation
18
+
19
+ - gamebox zapper
20
+ - this will create the directory structure and needed files to get a basic actor up on the screen
21
+ zapper
22
+ |-- README
23
+ |-- Rakefile
24
+ |-- config
25
+ | |-- boot.rb
26
+ | |-- environment.rb
27
+ | |-- game.yml
28
+ | |-- mode_level_config.yml
29
+ | `-- objects.yml
30
+ |-- data
31
+ | |-- fonts
32
+ | | `-- FONTS_GO_HERE
33
+ | |-- graphics
34
+ | | `-- GRAPHICS_GO_HERE
35
+ | |-- music
36
+ | | `-- MUSIC_GOES_HERE
37
+ | |-- sound
38
+ | `-- sounds
39
+ | `-- SOUND_FX_GO_HERE
40
+ |-- doc
41
+ | `-- README_FOR_APP
42
+ |-- lib
43
+ | |-- code_statistics.rb
44
+ | |-- diy.rb
45
+ | `-- platform.rb
46
+ |-- script
47
+ |-- src
48
+ | |-- app.rb
49
+ | |-- demo_level.rb
50
+ | |-- game.rb
51
+ | `-- my_actor.rb
52
+ `-- test
53
+ - you now have a runnable gamebox game
54
+
55
+ cd zapper
56
+ ruby src/app.rb
57
+
58
+ == Actors to the Stage
59
+
60
+ An Actor is the base class for any game object. A building, the player, the score, the bullet are all examples of actors. Actors can even be invisible. Any number of Behavior s can be added to an Actor to define how it will react to the world via the Actor.has_behaviors method.
61
+
62
+ So Actors sound fun, how do I get one? That's where the ActorFactory comes in. In your Level class (demo_level.rb by default) you can use the create_actor helper method as shown below.
63
+
64
+ @score = create_actor :score, :x => 10, :y => 10
65
+
66
+ This call will return an instance of the Score class (the first arg is the symbolized version of the classname). The ActorFactory will try to require the symbolized class name for you. It will also create the view for the actor and register it to be drawn. Which view is instantiated depends on the actor requested. The factory will always look for a class named the same as the actor with View on the end. So the actor Score will look for ScoreView. If ScoreView does not exist, a generic view class will be used based on the behaviors of the actor. Each ActorView class is constructed with a reference to the actor it is displaying. See ActorFactor#build for more details.
67
+
68
+ That's great, but how do I tell my actors what to do? They can register for events of course! A common place for this is in your actor's setup method. Here is an example from the roids example.
69
+
70
+ input_manager.reg KeyDownEvent, K_SPACE do
71
+ shoot
72
+ end
73
+
74
+ == Sound
75
+
76
+ There are two ways to play sounds in Gamebox. From your level you can simple access the SoundManager via the @sound_manager instance variable. From your actors, you can play sounds via the play_sound helper method.
77
+
78
+ # music
79
+ sound_manager.play_music :overworld
80
+
81
+ # sounds
82
+ sound_manager.play_sound :death
83
+
84
+ or
85
+
86
+ # from an actor
87
+ play_sound :jump
88
+
89
+ == Resources
90
+
91
+ All file loading is handled by the ResourceManager. It handles loading images, sounds, fonts, config files, and even svg files. The resource manager caches images based on their name and fonts based on their name/size pair. Example usage from the ScoreView class:
92
+
93
+ font = @mode.resource_manager.load_font 'Asimov.ttf', 30
94
+
95
+ == Behaviors
96
+ == Levels
97
+ == Modes
98
+ == Physics
99
+ == SVG Levels
Binary file
@@ -0,0 +1,6 @@
1
+ $: << File.dirname(__FILE__)+"/gamebox"
2
+
3
+ # TODO or I could include all my files here... ug
4
+ GAMEBOX_PATH = File.join(File.dirname(__FILE__),"gamebox/")
5
+ require 'gamebox_application'
6
+
@@ -0,0 +1,143 @@
1
+ require 'publisher'
2
+ # Actor represent a game object.
3
+ # Actors can have behaviors added and removed from them. Such as :physical or :animated.
4
+ # They are created and hooked up to their optional View class in Level#create_actor.
5
+ class Actor
6
+ extend Publisher
7
+ can_fire_anything
8
+
9
+ attr_accessor :behaviors, :x, :y, :level, :input_manager,
10
+ :resource_manager, :alive, :opts, :sound_manager, :visible
11
+
12
+
13
+ def initialize(opts={}) # :nodoc:
14
+ @opts = opts
15
+ @x = @opts[:x]
16
+ @y = @opts[:y]
17
+ @x ||= 0
18
+ @y ||= 0
19
+ @level = opts[:level]
20
+ @input_manager = opts[:input]
21
+ @sound_manager = opts[:sound]
22
+ @resource_manager = opts[:resources]
23
+ @alive = true
24
+
25
+ @behaviors = {}
26
+ # add our classes behaviors
27
+ class_behaviors = self.class.behaviors.dup
28
+ for behavior in class_behaviors
29
+ is behavior
30
+ end
31
+ setup
32
+ end
33
+
34
+ # Called at the end of actor/behavior initialization. To be defined by the
35
+ # child class.
36
+ def setup
37
+ end
38
+
39
+ # Is the actor still alive?
40
+ def alive?
41
+ @alive
42
+ end
43
+
44
+ # Tells the actor's Director that he wants to be removed; and unsubscribes
45
+ # the actor from all input events.
46
+ def remove_self
47
+ @alive = false
48
+ fire :remove_me
49
+ @input_manager.unsubscribe_all self
50
+ end
51
+
52
+ # Does this actor have this behavior?
53
+ def is?(behavior_sym)
54
+ !@behaviors[behavior_sym].nil?
55
+ end
56
+
57
+ # Adds the given behavior to the actor. Takes a symbol or a Hash.
58
+ # act.is(:shootable) or act.is(:shootable => {:range=>3})
59
+ # this will create a new instance of Shootable and pass
60
+ # :range=>3 to it
61
+ # Actor#is does try to require 'shootable' but will not throw an error if shootable cannot be required.
62
+ def is(behavior_def)
63
+ behavior_sym = behavior_def.is_a?(Hash) ? behavior_def.keys.first : behavior_def
64
+ behavior_opts = behavior_def.is_a?(Hash) ? behavior_def.values.first : {}
65
+ begin
66
+ require behavior_sym.to_s;
67
+ rescue LoadError
68
+ # maybe its included somewhere else
69
+ end
70
+ klass = Object.const_get Inflector.camelize(behavior_sym)
71
+ @behaviors[behavior_sym] = klass.new self, behavior_opts
72
+ end
73
+
74
+ # removed the behavior from the actor.
75
+ def is_no_longer(behavior_sym)
76
+ @behaviors.delete behavior_sym
77
+ end
78
+
79
+ # Calls update on all the actor's behaviors.
80
+ def update_behaviors(time)
81
+ for behavior in @behaviors.values
82
+ behavior.update time
83
+ end
84
+ end
85
+
86
+ # Creates a new actor and returns it. (This actor will automatically be added to the Director.
87
+ def spawn(type, args={})
88
+ @level.create_actor type, args
89
+ end
90
+
91
+ # Plays a sound via the SoundManager. See SoundManager for
92
+ # details on how to "define" sounds.
93
+ def play_sound(*args)
94
+ @sound_manager.play_sound *args
95
+ end
96
+
97
+ # Stops a sound via the SoundManager.
98
+ def stop_sound(*args)
99
+ @sound_manager.stop_sound *args
100
+ end
101
+
102
+ # to be defined in child class
103
+ def update(time)
104
+ # TODO maybe use a callback list for child classes
105
+ update_behaviors time
106
+ end
107
+
108
+ def hide
109
+ fire :hide_me if visible?
110
+ @visible = false
111
+ end
112
+
113
+ def show
114
+ fire :show_me unless visible?
115
+ @visible = true
116
+ end
117
+
118
+ def visible?
119
+ @visible
120
+ end
121
+
122
+ # magic
123
+ metaclass.instance_eval do
124
+ define_method( :behaviors ) do
125
+ @behaviors ||= []
126
+ end
127
+ define_method( :has_behaviors ) do |*args|
128
+ @behaviors ||= []
129
+ for a in args
130
+ if a.is_a? Hash
131
+ for k,v in a
132
+ h = {}
133
+ h[k]=v
134
+ @behaviors << h
135
+ end
136
+ else
137
+ @behaviors << a
138
+ end
139
+ end
140
+ @behaviors
141
+ end
142
+ end
143
+ end