gamebox 0.4.0.rc1 → 0.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/TODO.txt CHANGED
@@ -1,4 +1,6 @@
1
1
  TAKE YOUR PICK:
2
+ - add define_style that defines a bucket of behaviors
3
+ - add helper for has_required_attributes on an actor from a behavior (checking that opts for the behavior has said key)
2
4
  - move all classes into Gamebox module
3
5
  - collision detection performance for tiles?
4
6
  - collision detection honoring rotation?
@@ -6,7 +6,7 @@ Why use Gamebox? Gamebox was designed to spring board game development. It allow
6
6
 
7
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
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).
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 kids.
10
10
 
11
11
  == Installation
12
12
 
@@ -14,6 +14,7 @@ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing com
14
14
  - or tar from http://shawn42.github.com/gamebox
15
15
  - or git pull from git://github.com/shawn42/gamebox.git
16
16
  - required gems
17
+ - rake
17
18
  - bundler
18
19
  - gosu
19
20
  - conject
@@ -25,58 +26,50 @@ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing com
25
26
  - gamebox zapper
26
27
  - this will create the directory structure and needed files to get a basic actor up on the screen
27
28
  zapper
28
- |-- README
29
- |-- Rakefile
30
- |-- config
31
- | |-- boot.rb
32
- | |-- environment.rb
33
- | |-- game.yml
34
- | |-- gamebox_generator_version.yml
35
- | `-- stage_config.yml
36
- |-- data
37
- | |-- fonts
38
- | | `-- FONTS_GO_HERE
39
- | |-- graphics
40
- | | `-- GRAPHICS_GO_HERE
41
- | |-- music
42
- | | `-- MUSIC_GOES_HERE
43
- | `-- sounds
44
- | `-- SOUND_FX_GO_HERE
45
- |-- doc
46
- | `-- README_FOR_APP
47
- |-- lib
48
- | |-- code_statistics.rb
49
- | `-- platform.rb
50
- |-- script
51
- | `-- generate
52
- |-- spec
53
- | `-- helper.rb
54
- `-- src
55
- |-- app.rb
56
- |-- demo_stage.rb
57
- |-- game.rb
58
- `-- my_actor.rb
29
+ ├── Gemfile
30
+ ├── README.rdoc
31
+ ├── Rakefile
32
+ ├── config
33
+ │   ├── boot.rb
34
+ │   ├── environment.rb
35
+ │   └── game.yml
36
+ ├── data
37
+ │   ├── fonts
38
+ │   │   └── FONTS_GO_HERE
39
+ │   ├── graphics
40
+ │   │   └── GRAPHICS_GO_HERE
41
+ │   ├── music
42
+ │   │   └── MUSIC_GOES_HERE
43
+ │   └── sounds
44
+ │   └── SOUND_FX_GO_HERE
45
+ ├── spec
46
+ │   └── helper.rb
47
+ └── src
48
+ ├── actors
49
+ │   └── player.rb
50
+ ├── app.rb
51
+ └── demo_stage.rb
59
52
 
60
53
  - you now have a runnable gamebox game
61
54
 
62
55
  cd zapper
63
- ruby src/app.rb
56
+ rake
64
57
 
65
58
  == Actors to the Stage
66
59
 
67
- 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.
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 behaviors can be added to an actor to define how it will react to the world via the define_actor method. Actors are simply buckets of data and behaviors. The interactions with system are all driven by their behaviors.
68
61
 
69
- So Actors sound fun, how do I get one? That's where the ActorFactory comes in. In your Stage class (demo_stage.rb by default) you can use the spawn helper method as shown below.
62
+ So Actors sound fun, how do I get one? That's where the ActorFactory comes in. In your Stage class (demo_stage.rb by default) you can use the create_actor helper method as shown below.
70
63
 
71
- @score = spawn :score, :x => 10, :y => 10
64
+ @score = create_actor :score, x: 10, y: 10
72
65
 
73
- This call will return an instance of the Score class (the first arg is the symbolized version of the classname). 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.
66
+ This call will return an instance of a score (the first arg is the symbolized version of the actor type). 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 view named the same as the actor with _view on the end. So the actor score will look for score_view. If score_view does not exist, a generic view class will be used based on the behaviors of the actor. Each view is constructed with a reference to the actor it is displaying. See ActorFactor#build for more details.
74
67
 
75
- 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.
68
+ That's great, but how do I tell my actors what to do? By defining their behaviors!
76
69
 
77
- input_manager.reg KeyDownEvent, K_SPACE do
78
- shoot
79
- end
70
+ define_actor :score do
71
+ has_behaviors :positioned, :score_keeping
72
+ end
80
73
 
81
74
  == Sound
82
75
 
@@ -92,7 +85,7 @@ or
92
85
 
93
86
  # from an actor
94
87
  has_behavior :audible
95
- play_sound :jump
88
+ actor.react_to :play_sound, :jump
96
89
 
97
90
  == Resources
98
91
 
@@ -103,10 +96,23 @@ All file loading is handled by the ResourceManager. It handles loading images,
103
96
  == Behaviors
104
97
 
105
98
  Behaviors are designed to allow you to build Actors from previously built chunks of code. Lets look at the built in Animated behavior.
106
- class SuperHero < Actor
107
- has_behaviors :animated, :updatable
99
+ define_behavior :shooting do
100
+ requires :input_manager
101
+ setup do
102
+ input_manager.reg :down, KbSpace do
103
+ shoot
104
+ end
105
+ end
106
+
107
+ helpers do
108
+ def shoot
109
+ # shoot
110
+ end
111
+ end
108
112
  end
109
113
 
114
+
115
+
110
116
  This snippet show us that our Actor wants to be updated on every gameloop and that it wants to be animated. Gamebox favors convention over configuration. This means that there are default locations and setting for most things. They can be overridden but you are not required to do so. The animated behavior assumes that your animated images are in a directory structure based on the Actor's underscored name and its current action.
111
117
 
112
118
  zapper/
@@ -17,6 +17,7 @@ Behavior.define :label_stuff do
17
17
  actor.has_attributes font_style: font_style
18
18
 
19
19
  actor.when :font_size_changed do
20
+ actor.font_style.size = actor.font_size
20
21
  actor.font_style.reload
21
22
  recalculate_size
22
23
  end
@@ -27,6 +28,9 @@ Behavior.define :label_stuff do
27
28
  actor.when :text_changed do
28
29
  recalculate_size
29
30
  end
31
+ actor.when :color_changed do
32
+ actor.font_style.color = actor.color
33
+ end
30
34
 
31
35
  end
32
36
 
@@ -39,7 +43,7 @@ Behavior.define :label_stuff do
39
43
  end
40
44
 
41
45
  Actor.define :label do
42
- has_behavior layered: 1
46
+ has_attributes layered: 1
43
47
  has_behavior :label_stuff
44
48
 
45
49
  view do
@@ -52,14 +52,14 @@ Behavior.define :collidable do
52
52
 
53
53
  stage.register_collidable actor
54
54
 
55
- reacts_with :remove, :position_changed
56
- end
57
-
58
- helpers do
59
- def remove
55
+ actor.when :remove_me do
60
56
  stage.unregister_collidable actor
61
57
  end
62
58
 
59
+ reacts_with :position_changed
60
+ end
61
+
62
+ helpers do
63
63
  def position_changed
64
64
  shape = actor.shape
65
65
  shape.recalculate_collidable_cache
@@ -4,6 +4,7 @@
4
4
  # data/graphics/classname.png
5
5
  Behavior.define :graphical do
6
6
 
7
+ requires_behaviors :layered
7
8
  requires :resource_manager
8
9
  setup do
9
10
  image = resource_manager.load_actor_image(actor)
@@ -38,8 +38,10 @@ class AABBTree
38
38
 
39
39
  def remove(item)
40
40
  leaf = @items.delete item
41
- @root = @root.remove_subtree leaf if leaf
42
- clear_cached_collisions leaf
41
+ if leaf
42
+ @root = @root.remove_subtree leaf
43
+ clear_cached_collisions leaf
44
+ end
43
45
  end
44
46
 
45
47
  def update(item)
@@ -9,9 +9,8 @@ class Actor
9
9
  construct_with :this_object_context
10
10
  public :this_object_context
11
11
 
12
- has_attribute :alive
13
-
14
12
  def initialize
13
+ has_attribute :alive
15
14
  @behaviors = {}
16
15
  end
17
16
 
@@ -58,7 +57,6 @@ class Actor
58
57
  end
59
58
 
60
59
  # TODO should this live somewhere else?
61
- # TODO should we support "inheritance" of components?
62
60
  class << self
63
61
 
64
62
  def define(actor_type, opts={}, &blk)
@@ -71,6 +69,12 @@ class Actor
71
69
  if view_blk
72
70
  ActorView.define "#{actor_type}_view".to_sym, &view_blk
73
71
  end
72
+
73
+ behavior_blk = definition.behavior_blk
74
+ if behavior_blk
75
+ Behavior.define actor_type, &behavior_blk
76
+ definition.has_behavior actor_type
77
+ end
74
78
  end
75
79
 
76
80
  def definitions
@@ -80,7 +84,7 @@ class Actor
80
84
  end
81
85
 
82
86
  class ActorDefinition
83
- attr_accessor :behaviors, :attributes, :view_blk
87
+ attr_accessor :behaviors, :attributes, :view_blk, :behavior_blk
84
88
  def initialize
85
89
  @behaviors = []
86
90
  @attributes = []
@@ -93,10 +97,20 @@ class Actor
93
97
  end
94
98
  alias has_behavior has_behaviors
95
99
 
96
- # TODO spec view helper on actor def
100
+ def has_attributes(*attributes)
101
+ attributes.each do |att|
102
+ @attributes << att
103
+ end
104
+ end
105
+ alias has_behavior has_behaviors
106
+
97
107
  def view(&blk)
98
108
  @view_blk = blk
99
109
  end
110
+
111
+ def behavior(&blk)
112
+ @behavior_blk = blk
113
+ end
100
114
  end
101
115
 
102
116
  end
@@ -18,6 +18,10 @@ class ActorFactory
18
18
  raise "#{actor} not found in Actor.definitions" if actor_definition.nil?
19
19
  model.configure(merged_opts)
20
20
 
21
+ actor_definition.attributes.each do |attr|
22
+ model.has_attributes attr
23
+ end
24
+
21
25
  actor_definition.behaviors.each do |behavior|
22
26
  beh_opts = {}
23
27
  beh_key = behavior
@@ -8,6 +8,7 @@ class ActorViewFactory
8
8
  def build(actor, opts={})
9
9
  # TODO have animated, graphical, physical set a view attr on actor
10
10
  view_klass = opts[:view] || actor.do_or_do_not(:view) || "#{actor.actor_type}_view"
11
+
11
12
  view_definition = ActorView.definitions[view_klass.to_sym]
12
13
  view = nil
13
14
  if view_definition
@@ -4,51 +4,19 @@ class Director
4
4
  can_fire_anything
5
5
  attr_accessor :actors
6
6
 
7
- def initialize
8
- @actors = []
9
- @dead_actors = []
10
- setup
11
- end
12
-
13
- def setup
14
- end
15
-
16
- def add_actor(actor)
17
- @actors << actor
18
- actor.when :remove_me do
19
- remove_actor actor
20
- end
21
- fire :actor_added, actor
22
- actor
23
- end
24
-
25
- def remove_actor(actor)
26
- @dead_actors << actor
27
- end
28
-
29
- def empty?
30
- @actors.empty?
31
- end
32
-
33
7
  def pause
34
- @paused_actors = @actors
35
- @actors = []
8
+ @paused_subscriptions = @subscriptions
9
+ @subscriptions = {}
36
10
  end
37
11
 
38
12
  def unpause
39
- unless @paused_actors.nil?
40
- @actors.each{|actor| actor.remove_self }
41
- @actors = @paused_actors
42
- @paused_actors = nil
13
+ unless @paused_subscriptions.nil?
14
+ @subscriptions = @paused_subscriptions
15
+ @paused_subscriptions = nil
43
16
  end
44
17
  end
45
18
 
46
19
  def update(time)
47
- for act in @dead_actors
48
- @actors.delete act
49
- fire :actor_removed, act
50
- end
51
- @dead_actors = []
52
20
  time_in_seconds = time / 1000.to_f
53
21
  fire :update, time, time_in_seconds
54
22
  end
@@ -41,8 +41,7 @@ class ResourceManager
41
41
  # -------------
42
42
  #
43
43
  def load_tile_set(actor, action)
44
- actor_dir = Inflector.underscore(actor.class)
45
- tileset_name = "#{actor_dir}/#{action}.png"
44
+ tileset_name = "#{actor.actor_type}/#{action}.png"
46
45
  tileset = load_image tileset_name
47
46
 
48
47
  action_imgs = []
@@ -78,6 +78,14 @@ class SoundManager
78
78
  @music[what].stop if @music[what]
79
79
  end
80
80
  end
81
+
82
+ # pause the music file that is passed in.
83
+ # pause_music :foo
84
+ def pause_music(what)
85
+ if @enabled
86
+ @music[what].pause if @music[what]
87
+ end
88
+ end
81
89
 
82
90
  # stops the sound that is passed in.
83
91
  # stop_sound :foo
@@ -3,7 +3,7 @@ module Gamebox
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
5
  TINY = 0
6
- RC = 1
6
+ RC = 2
7
7
 
8
8
  if RC > 0
9
9
  ARRAY = [MAJOR, MINOR, TINY, "rc#{RC}"]
@@ -88,5 +88,7 @@ describe "The basic life cycle of an actor", acceptance: true do
88
88
  game.should_not have_actor(:mc_bane)
89
89
 
90
90
  end
91
+
92
+ it 'uses default values from actor definition'
91
93
  end
92
94
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc1
4
+ version: 0.4.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-05-08 00:00:00.000000000 Z
14
+ date: 2012-05-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gosu