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 +2 -0
- data/docs/getting_started.rdoc +50 -44
- data/lib/gamebox/actors/label.rb +5 -1
- data/lib/gamebox/behaviors/collidable.rb +5 -5
- data/lib/gamebox/behaviors/graphical.rb +1 -0
- data/lib/gamebox/core/aabb_tree.rb +4 -2
- data/lib/gamebox/core/actor.rb +19 -5
- data/lib/gamebox/core/actor_factory.rb +4 -0
- data/lib/gamebox/core/actor_view_factory.rb +1 -0
- data/lib/gamebox/core/director.rb +5 -37
- data/lib/gamebox/core/resource_manager.rb +1 -2
- data/lib/gamebox/core/sound_manager.rb +8 -0
- data/lib/gamebox/version.rb +1 -1
- data/spec/acceptance/basic_actor_lifecycle_spec.rb +2 -0
- metadata +2 -2
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?
|
data/docs/getting_started.rdoc
CHANGED
@@ -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
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
56
|
+
rake
|
64
57
|
|
65
58
|
== Actors to the Stage
|
66
59
|
|
67
|
-
An
|
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
|
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 =
|
64
|
+
@score = create_actor :score, x: 10, y: 10
|
72
65
|
|
73
|
-
This call will return an instance of
|
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?
|
68
|
+
That's great, but how do I tell my actors what to do? By defining their behaviors!
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
107
|
-
|
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/
|
data/lib/gamebox/actors/label.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
@@ -38,8 +38,10 @@ class AABBTree
|
|
38
38
|
|
39
39
|
def remove(item)
|
40
40
|
leaf = @items.delete item
|
41
|
-
|
42
|
-
|
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)
|
data/lib/gamebox/core/actor.rb
CHANGED
@@ -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
|
-
|
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
|
-
@
|
35
|
-
@
|
8
|
+
@paused_subscriptions = @subscriptions
|
9
|
+
@subscriptions = {}
|
36
10
|
end
|
37
11
|
|
38
12
|
def unpause
|
39
|
-
unless @
|
40
|
-
@
|
41
|
-
@
|
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
|
-
|
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
|
data/lib/gamebox/version.rb
CHANGED
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.
|
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-
|
14
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: gosu
|