gamebox 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Rakefile +17 -15
- data/TODO.txt +4 -0
- data/docs/getting_started.rdoc +41 -0
- data/lib/gamebox/actor.rb +3 -1
- data/lib/gamebox/actor_factory.rb +2 -2
- data/lib/gamebox/actor_view.rb +0 -2
- data/lib/gamebox/ai/two_d_grid_map.rb +4 -0
- data/lib/gamebox/graphical_actor_view.rb +3 -1
- data/lib/gamebox/input_manager.rb +15 -12
- data/lib/gamebox/svg_actor.rb +1 -7
- metadata +4 -4
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.3.0'
|
2
3
|
require 'hoe'
|
3
4
|
|
4
5
|
module Gamebox
|
5
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.2'
|
6
7
|
end
|
7
|
-
Hoe.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if
|
20
|
-
|
8
|
+
Hoe.new 'gamebox' do |spec|
|
9
|
+
spec.developer('Shawn Anderson', 'shawn42@gmail.com')
|
10
|
+
spec.author = "Shawn Anderson"
|
11
|
+
spec.description = "Framework for building and distributing games using Rubygame"
|
12
|
+
spec.email = 'shawn42@gmail.com'
|
13
|
+
spec.summary = "Framework for building and distributing games using Rubygame"
|
14
|
+
spec.url = "http://shawn42.github.com/gamebox"
|
15
|
+
spec.version = Gamebox::VERSION
|
16
|
+
spec.changes = spec.paragraphs_of('History.txt', 2..3).join("\n\n")
|
17
|
+
spec.extra_deps << ['constructor']
|
18
|
+
spec.extra_deps << ['publisher']
|
19
|
+
spec.extra_deps << ['bacon']
|
20
|
+
if spec.extra_rdoc_files
|
21
|
+
spec.extra_rdoc_files << 'docs/getting_started.rdoc'
|
21
22
|
end
|
23
|
+
spec.remote_rdoc_dir = ' ' # Release to root
|
22
24
|
end
|
23
25
|
|
24
26
|
STATS_DIRECTORIES = [
|
data/TODO.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
planned features:
|
2
|
+
create an :updatable behavior for actors that wish to be updated (to remove unnecessarily calling update)
|
3
|
+
- add auto_update_actors method to Level?
|
4
|
+
allow easy pausing of game and physics
|
5
|
+
- fire :pause event w/ a new Director of actors?
|
2
6
|
change Polaris to return partial path when step max is reached
|
3
7
|
update physical objects to use chipmunk_object.rb
|
4
8
|
allow for repeating actors (tiles)
|
data/docs/getting_started.rdoc
CHANGED
@@ -13,6 +13,12 @@ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing com
|
|
13
13
|
- gem install gamebox
|
14
14
|
- or tar from http://shawn42.github.com/gamebox
|
15
15
|
- or git pull from git://github.com/shawn42/gamebox.git
|
16
|
+
- required gems
|
17
|
+
- hoe
|
18
|
+
- rubygame (all of its dependencies)
|
19
|
+
- constructor
|
20
|
+
- publisher
|
21
|
+
- bacon for unit tests
|
16
22
|
|
17
23
|
== Game Creation
|
18
24
|
|
@@ -93,6 +99,41 @@ All file loading is handled by the ResourceManager. It handles loading images,
|
|
93
99
|
font = @mode.resource_manager.load_font 'Asimov.ttf', 30
|
94
100
|
|
95
101
|
== Behaviors
|
102
|
+
|
103
|
+
Behaviors are designed to allow you to build Actors from previously built chunks of code. Lets look at the built in Animated behavior.
|
104
|
+
class SuperHero < Actor
|
105
|
+
has_behaviors :animated, :updatable
|
106
|
+
end
|
107
|
+
|
108
|
+
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.
|
109
|
+
|
110
|
+
zapper/
|
111
|
+
`-- data
|
112
|
+
`-- graphics
|
113
|
+
`-- super_hero
|
114
|
+
|-- flying
|
115
|
+
| |-- 1.png
|
116
|
+
| |-- 2.png
|
117
|
+
| |-- ...
|
118
|
+
| `-- 8.png
|
119
|
+
|-- idle
|
120
|
+
| `-- 1.png
|
121
|
+
`-- walking
|
122
|
+
|-- 1.png
|
123
|
+
`-- 2.png
|
124
|
+
|
125
|
+
Here we can see that the SuperHere class has three actions (flying, walking, idle). These actions will be set by calling action= on your Actor.
|
126
|
+
|
127
|
+
batman = create_actor :super_hero
|
128
|
+
batman.action = :flying
|
129
|
+
|
130
|
+
The animation will cycle through all the numbered png files for the current action. To stop animating you simple call stop_animating.
|
131
|
+
|
132
|
+
batman.stop_animating
|
133
|
+
|
134
|
+
|
135
|
+
Animated and Updatable are just two behaviors available in Gamebox. Other include graphical, layered, and physical. You can easily add your own game specific behaviors by extending Behavior. (see Wanderer in rague example).
|
136
|
+
|
96
137
|
== Levels
|
97
138
|
== Modes
|
98
139
|
== Physics
|
data/lib/gamebox/actor.rb
CHANGED
@@ -7,7 +7,8 @@ class Actor
|
|
7
7
|
can_fire_anything
|
8
8
|
|
9
9
|
attr_accessor :behaviors, :x, :y, :level, :input_manager,
|
10
|
-
:resource_manager, :alive, :opts, :sound_manager, :visible
|
10
|
+
:resource_manager, :alive, :opts, :sound_manager, :visible,
|
11
|
+
:director
|
11
12
|
|
12
13
|
|
13
14
|
def initialize(opts={}) # :nodoc:
|
@@ -20,6 +21,7 @@ class Actor
|
|
20
21
|
@input_manager = opts[:input]
|
21
22
|
@sound_manager = opts[:sound]
|
22
23
|
@resource_manager = opts[:resources]
|
24
|
+
@director = opts[:director]
|
23
25
|
@alive = true
|
24
26
|
|
25
27
|
@behaviors = {}
|
@@ -42,6 +42,7 @@ class ActorFactory
|
|
42
42
|
:level => level,
|
43
43
|
:input => @input_manager,
|
44
44
|
:sound => @sound_manager,
|
45
|
+
:director => @director,
|
45
46
|
:resources => level.resource_manager
|
46
47
|
}
|
47
48
|
merged_opts = basic_opts.merge(opts)
|
@@ -56,8 +57,7 @@ class ActorFactory
|
|
56
57
|
end
|
57
58
|
view_klass.new @mode_manager.current_mode, model if view_klass
|
58
59
|
|
59
|
-
|
60
|
-
@director.add_actor model
|
60
|
+
model.show unless opts[:hide]
|
61
61
|
|
62
62
|
return model
|
63
63
|
end
|
data/lib/gamebox/actor_view.rb
CHANGED
@@ -6,8 +6,10 @@ class GraphicalActorView < ActorView
|
|
6
6
|
x = @actor.x
|
7
7
|
y = @actor.y
|
8
8
|
img = @actor.image
|
9
|
+
return if img.nil?
|
9
10
|
|
10
|
-
if @actor.is? :animated or
|
11
|
+
#if @actor.is? :animated or
|
12
|
+
if @actor.is? :physical
|
11
13
|
w,h = *img.size
|
12
14
|
x = x-w/2
|
13
15
|
y = y-h/2
|
@@ -3,6 +3,12 @@ class InputManager
|
|
3
3
|
extend Publisher
|
4
4
|
can_fire :key_up, :event_received
|
5
5
|
|
6
|
+
MOUSE_BUTTON_LOOKUP = {
|
7
|
+
1 => :left,
|
8
|
+
2 => :middle,
|
9
|
+
3 => :right,
|
10
|
+
}
|
11
|
+
|
6
12
|
attr_accessor :hooks
|
7
13
|
|
8
14
|
def initialize
|
@@ -55,10 +61,14 @@ class InputManager
|
|
55
61
|
fire :event_received, event
|
56
62
|
|
57
63
|
event_hooks = @hooks[event.class]
|
58
|
-
|
59
|
-
if
|
60
|
-
|
61
|
-
|
64
|
+
id = event.key if event.respond_to? :key
|
65
|
+
id ||= MOUSE_BUTTON_LOOKUP[event.button] if event.respond_to? :button
|
66
|
+
unless id.nil?
|
67
|
+
event_action_hooks = event_hooks[id] if event_hooks
|
68
|
+
if event_action_hooks
|
69
|
+
for callback in event_action_hooks
|
70
|
+
callback.call event
|
71
|
+
end
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
@@ -86,14 +96,7 @@ class InputManager
|
|
86
96
|
@hooks[event_class] ||= {}
|
87
97
|
for event_id in event_ids
|
88
98
|
@hooks[event_class][event_id] ||= []
|
89
|
-
if block_given?
|
90
|
-
@hooks[event_class][event_id].delete block
|
91
|
-
else
|
92
|
-
# for blocks in @hooks[event_class][event_id]
|
93
|
-
# listener = eval("self", block.binding)
|
94
|
-
# @hooks[event_class][event_id].delete block if listener == id
|
95
|
-
# end
|
96
|
-
end
|
99
|
+
@hooks[event_class][event_id].delete block if block_given?
|
97
100
|
end
|
98
101
|
end
|
99
102
|
alias unreg unregister_hook
|
data/lib/gamebox/svg_actor.rb
CHANGED
@@ -15,7 +15,7 @@ class SvgActor < Actor
|
|
15
15
|
|
16
16
|
my_layer = @svg_doc.find_group_by_label(@name.to_s)
|
17
17
|
build_from_vertices my_layer.path.vertices
|
18
|
-
|
18
|
+
hide unless my_layer.path.visible?
|
19
19
|
end
|
20
20
|
|
21
21
|
def build_from_vertices(vertices)
|
@@ -36,16 +36,10 @@ class SvgActor < Actor
|
|
36
36
|
@level.space.add_static_shape(seg)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
def visible?
|
41
|
-
@visible
|
42
|
-
end
|
43
|
-
|
44
39
|
end
|
45
40
|
|
46
41
|
class SvgActorView < ActorView
|
47
42
|
def draw(target,x_off,y_off)
|
48
|
-
return unless @actor.visible?
|
49
43
|
@actor.segments.each do |seg|
|
50
44
|
p1 = seg[0]
|
51
45
|
p2 = seg[1]
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Anderson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 2.3.1
|
54
54
|
version:
|
55
55
|
description: Framework for building and distributing games using Rubygame
|
56
56
|
email: shawn42@gmail.com
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
requirements: []
|
176
176
|
|
177
177
|
rubyforge_project: gamebox
|
178
|
-
rubygems_version: 1.3.
|
178
|
+
rubygems_version: 1.3.3
|
179
179
|
signing_key:
|
180
180
|
specification_version: 3
|
181
181
|
summary: Framework for building and distributing games using Rubygame
|