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
@@ -2,62 +2,28 @@
|
|
2
2
|
# keeps track of an image for you based on the actor's class
|
3
3
|
# by default it expects images to be:
|
4
4
|
# data/graphics/classname.png
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
image.width
|
28
|
-
end
|
29
|
-
|
30
|
-
def height
|
31
|
-
image.height
|
32
|
-
end
|
33
|
-
|
34
|
-
def tiled?
|
35
|
-
@tiled
|
36
|
-
end
|
37
|
-
|
38
|
-
def scale
|
39
|
-
@scale || 1
|
40
|
-
end
|
41
|
-
|
42
|
-
def scale=(s)
|
43
|
-
@scale = s
|
44
|
-
end
|
45
|
-
|
46
|
-
def x_scale
|
47
|
-
@x_scale || scale
|
48
|
-
end
|
49
|
-
|
50
|
-
def x_scale=(xs)
|
51
|
-
@x_scale = xs
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def y_scale
|
56
|
-
@y_scale || scale
|
57
|
-
end
|
58
|
-
|
59
|
-
def y_scale=(ys)
|
60
|
-
@y_scale = ys
|
5
|
+
Behavior.define :graphical do
|
6
|
+
|
7
|
+
requires :resource_manager
|
8
|
+
setup do
|
9
|
+
image = resource_manager.load_actor_image(actor)
|
10
|
+
scale = @opts[:scale] || 1,
|
11
|
+
actor.has_attributes( image: image,
|
12
|
+
width: image.width,
|
13
|
+
height: image.height,
|
14
|
+
tiled: @opts[:tiled],
|
15
|
+
view: @opts[:view] || :graphical_actor_view,
|
16
|
+
num_x_tiles: @opts[:num_x_tiles] || 1,
|
17
|
+
num_y_tiles: @opts[:num_y_tiles] || 1,
|
18
|
+
scale: scale,
|
19
|
+
x_scale: @opts[:x_scale] || scale,
|
20
|
+
y_scale: @opts[:y_scale] || scale,
|
21
|
+
rotation: 0.0 )
|
22
|
+
|
23
|
+
actor.when :image_changed do |old, new|
|
24
|
+
actor.width = new.width
|
25
|
+
actor.height = new.height
|
26
|
+
end
|
61
27
|
end
|
62
28
|
|
63
29
|
end
|
@@ -2,33 +2,20 @@
|
|
2
2
|
# Keeps track of the layer that something is to be drawn on.
|
3
3
|
# By default it sets everything to layer 0 and parallax layer of
|
4
4
|
# 1.
|
5
|
-
|
5
|
+
Behavior.define :layered do
|
6
6
|
|
7
|
-
|
8
|
-
def setup
|
7
|
+
setup do
|
9
8
|
if @opts.is_a? Hash
|
10
|
-
|
11
|
-
|
9
|
+
layer = @opts[:layer]
|
10
|
+
parallax = @opts[:parallax]
|
12
11
|
else
|
13
|
-
|
12
|
+
layer = @opts
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
layer ||= 0
|
16
|
+
parallax ||= 1
|
18
17
|
|
19
|
-
|
20
|
-
:layered
|
18
|
+
actor.has_attributes layer: layer, parallax: parallax
|
21
19
|
end
|
22
20
|
|
23
|
-
def layered
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def parallax=(new_parallax)
|
28
|
-
@parallax = new_parallax
|
29
|
-
end
|
30
|
-
|
31
|
-
def layer=(new_layer)
|
32
|
-
@layer = new_layer
|
33
|
-
end
|
34
21
|
end
|
@@ -10,25 +10,25 @@
|
|
10
10
|
# :friction => 0.4,
|
11
11
|
# :moment => Float::INFINITY,
|
12
12
|
# :verts => [[-15,-20],[-15,20],[15,20],[15,-20]]}
|
13
|
-
|
14
|
-
attr_accessor :shapes, :body, :opts, :parts, :segments_groups
|
15
|
-
|
16
|
-
def shape
|
17
|
-
if @shapes
|
18
|
-
@shapes.first
|
19
|
-
else
|
20
|
-
@shape
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup
|
25
|
-
@parts = {}
|
26
|
-
@shapes = []
|
27
|
-
@constraints = []
|
28
|
-
@segments_groups = []
|
13
|
+
Behavior.define :physical do
|
29
14
|
|
15
|
+
requires :physics_manager, :director
|
16
|
+
setup do
|
30
17
|
@moment_of_inertia = @opts[:moment]
|
31
18
|
|
19
|
+
actor.has_attributes x: 0, y: 0
|
20
|
+
|
21
|
+
actor.has_attributes :x, :y, :shape, :shapes, :body,
|
22
|
+
:rotation, :segment_groups, :constraints,
|
23
|
+
:pivot, :pin, :spring, :slide, :groove,
|
24
|
+
:rotary_spring, :rotary_limit, :ratchet,
|
25
|
+
:gear, :motor
|
26
|
+
|
27
|
+
actor.shapes = []
|
28
|
+
actor.constraints = []
|
29
|
+
actor.segment_groups = []
|
30
|
+
|
31
|
+
|
32
32
|
build_main_shape
|
33
33
|
setup_main_collisions
|
34
34
|
setup_position
|
@@ -37,235 +37,224 @@ class Physical < Behavior
|
|
37
37
|
|
38
38
|
build_secondary_shapes
|
39
39
|
|
40
|
-
|
41
40
|
register
|
42
|
-
warp(vec2(@actor.x,@actor.y))
|
43
41
|
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:rotary_spring, :rotary_limit, :ratchet,
|
49
|
-
:gear, :motor
|
50
|
-
end
|
42
|
+
# TODO use positioned?
|
43
|
+
actor.when :position_changed do
|
44
|
+
actor.body.p = vec2(actor.x, actor.y)
|
45
|
+
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
director.when :update do |time|
|
48
|
+
actor.x = actor.body.p.x
|
49
|
+
actor.y = actor.body.p.y
|
50
|
+
actor.rotation = rotation
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
@elasticity = @opts[:elasticity]
|
60
|
-
@elasticity ||= 0.1
|
61
|
-
@shape.e = @elasticity
|
62
|
-
end
|
53
|
+
warp(vec2(actor.x,actor.y))
|
63
54
|
|
64
|
-
|
65
|
-
@collision_type = @opts[:collision_group]
|
66
|
-
@collision_type ||=
|
67
|
-
Inflector.underscore(@actor.class).to_sym
|
68
|
-
@shape.collision_type = @collision_type
|
55
|
+
reacts_with :warp
|
69
56
|
end
|
70
57
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@shape.body.p = vec2(start_x,start_y)
|
58
|
+
helpers do
|
59
|
+
def setup_friction
|
60
|
+
@friction = @opts[:friction]
|
61
|
+
@friction ||= 0.4
|
62
|
+
actor.shape.u = @friction
|
63
|
+
end
|
78
64
|
|
79
|
-
|
65
|
+
def setup_elasticity
|
66
|
+
@elasticity = @opts[:elasticity]
|
67
|
+
@elasticity ||= 0.1
|
68
|
+
actor.shape.e = @elasticity
|
69
|
+
end
|
80
70
|
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
def setup_main_collisions
|
72
|
+
@collision_type = @opts[:collision_group]
|
73
|
+
@collision_type ||= actor.actor_type
|
74
|
+
actor.shape.collision_type = @collision_type
|
75
|
+
end
|
84
76
|
|
85
|
-
|
86
|
-
|
87
|
-
|
77
|
+
def setup_position
|
78
|
+
actor.body.a = @opts[:angle] if @opts[:angle]
|
79
|
+
start_x = @opts[:x]
|
80
|
+
start_y = @opts[:y]
|
81
|
+
start_x ||= actor.x
|
82
|
+
start_y ||= actor.y
|
83
|
+
actor.shape.body.p = vec2(start_x,start_y)
|
88
84
|
|
89
|
-
|
90
|
-
@body = CP::Body.new(@mass, @moment_of_inertia)
|
91
|
-
@shape = CP::Shape::Circle.new(@body, @radius, ZERO_VEC_2)
|
85
|
+
end
|
92
86
|
|
93
|
-
|
94
|
-
|
87
|
+
def build_main_shape
|
88
|
+
@mass = @opts[:mass]
|
89
|
+
@mass ||= Float::INFINITY
|
95
90
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
verts = @opts[:verts].dup
|
100
|
-
verts << @opts[:verts][0]
|
101
|
-
@segments_groups << verts
|
102
|
-
end
|
91
|
+
case @opts[:shape]
|
92
|
+
when :circle
|
93
|
+
@radius = @opts[:radius]
|
103
94
|
|
104
|
-
|
95
|
+
@moment_of_inertia ||= @opts[:fixed] ? Float::INFINITY : CP::moment_for_circle(@mass, @radius, 0, ZERO_VEC_2)
|
96
|
+
actor.body = CP::Body.new(@mass, @moment_of_inertia)
|
97
|
+
actor.shape = CP::Shape::Circle.new(actor.body, @radius, ZERO_VEC_2)
|
105
98
|
|
106
|
-
|
107
|
-
|
99
|
+
when :poly
|
100
|
+
shape_array = @opts[:verts].collect{|v| vec2(v[0],v[1])}
|
108
101
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
case part_def[:shape]
|
117
|
-
when :poly
|
118
|
-
part_shape_array = part_def[:verts].collect{|v| vec2(v[0],v[1])}
|
119
|
-
part_shape = CP::Shape::Poly.new(@body, part_shape_array, part_def[:offset])
|
120
|
-
part_shape.collision_type = part_name.to_sym
|
102
|
+
@moment_of_inertia ||= @opts[:fixed] ? Float::INFINITY : CP::moment_for_poly(@mass, shape_array, ZERO_VEC_2)
|
103
|
+
actor.body = CP::Body.new(@mass, @moment_of_inertia)
|
104
|
+
actor.shape = CP::Shape::Poly.new(actor.body, shape_array, ZERO_VEC_2)
|
105
|
+
verts = @opts[:verts].dup
|
106
|
+
verts << @opts[:verts][0]
|
107
|
+
actor.segment_groups << verts
|
108
|
+
end
|
121
109
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
110
|
+
actor.shape.actor = actor
|
111
|
+
actor.shapes << actor.shape
|
112
|
+
|
113
|
+
actor.body.p = vec2(actor.x,actor.y)
|
114
|
+
end
|
115
|
+
|
116
|
+
def build_secondary_shapes
|
117
|
+
|
118
|
+
if @opts[:shapes]
|
119
|
+
for obj in @opts[:shapes]
|
120
|
+
for part_name, part_def in obj
|
121
|
+
# TODO merge this with build main shape
|
122
|
+
part_shape = nil
|
123
|
+
case part_def[:shape]
|
124
|
+
when :poly
|
125
|
+
part_shape_array = part_def[:verts].collect{|v| vec2(v[0],v[1])}
|
126
|
+
part_shape = CP::Shape::Poly.new(actor.body, part_shape_array, part_def[:offset])
|
127
|
+
part_shape.collision_type = part_name.to_sym
|
128
|
+
|
129
|
+
# TODO pass all physics params to parts (ie u and e)
|
130
|
+
part_shape.u = @friction
|
131
|
+
verts = part_def[:verts].dup
|
132
|
+
verts << part_def[:verts][0]
|
133
|
+
actor.segment_groups << verts
|
134
|
+
when :circle
|
135
|
+
part_shape = CP::Shape::Circle.new(actor.body, part_def[:radius], part_def[:offset])
|
136
|
+
else
|
137
|
+
raise "unsupported sub shape type"
|
138
|
+
end
|
139
|
+
part_shape.collision_type = part_name.to_sym
|
140
|
+
part_shape.actor = actor
|
141
|
+
actor.shapes << part_shape
|
131
142
|
end
|
132
|
-
part_shape.collision_type = part_name.to_sym
|
133
|
-
@shapes << part_shape
|
134
|
-
# puts @shapes.inspect
|
135
143
|
end
|
136
144
|
end
|
137
145
|
end
|
138
|
-
end
|
139
146
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
147
|
+
def register
|
148
|
+
actor.when :remove_me do
|
149
|
+
cleanup_constraints
|
150
|
+
end
|
144
151
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
if physics_manager
|
153
|
+
if @opts[:fixed]
|
154
|
+
physics_manager.register_physical_object actor, true
|
155
|
+
else
|
156
|
+
physics_manager.register_physical_object actor
|
157
|
+
end
|
149
158
|
else
|
150
|
-
|
159
|
+
raise "physical actor in a non-physical stage!"
|
151
160
|
end
|
152
|
-
else
|
153
|
-
raise "physical actor in a non-physical stage!"
|
154
161
|
end
|
155
|
-
end
|
156
162
|
|
157
|
-
def x
|
158
|
-
body.p.x
|
159
|
-
end
|
160
163
|
|
161
|
-
def y
|
162
|
-
body.p.y
|
163
|
-
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
def rotation
|
174
|
-
# TODO hack!! why do poly's not work the same?
|
175
|
-
if opts[:shape] == :poly
|
176
|
-
((body.a-1.57) * 180.0 / Math::PI + 90) % 360
|
177
|
-
else
|
178
|
-
((body.a) * 180.0 / Math::PI + 90) % 360
|
165
|
+
def rotation
|
166
|
+
if opts[:shape] == :poly
|
167
|
+
((actor.body.a-1.57) * 180.0 / Math::PI + 90) % 360
|
168
|
+
else
|
169
|
+
((actor.body.a) * 180.0 / Math::PI + 90) % 360
|
170
|
+
end
|
179
171
|
end
|
180
|
-
end
|
181
172
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
def physical
|
188
|
-
self
|
189
|
-
end
|
190
|
-
|
191
|
-
def pivot(my_anchor, other_physical, other_anchor)
|
192
|
-
pivot = CP::Constraint::PivotJoint.new(physical.body, other_physical.body, my_anchor, other_anchor)
|
193
|
-
@actor.stage.register_physical_constraint pivot
|
194
|
-
@constraints << pivot
|
195
|
-
pivot
|
196
|
-
end
|
197
|
-
|
198
|
-
def pin(my_anchor, other_physical, other_anchor)
|
199
|
-
pin = CP::Constraint::PinJoint.new(physical.body, other_physical.physical.body, my_anchor, other_anchor)
|
200
|
-
@actor.stage.register_physical_constraint pin
|
201
|
-
@constraints << pin
|
202
|
-
pin
|
203
|
-
end
|
204
|
-
|
205
|
-
def spring(my_anchor, other_physical, other_anchor, rest_length, stiffness, damping)
|
206
|
-
spring = CP::Constraint::DampedSpring.new(physical.body,other_physical.body,
|
207
|
-
my_anchor,other_anchor, rest_length, stiffness, damping)
|
208
|
-
@actor.stage.register_physical_constraint spring
|
209
|
-
@constraints << spring
|
210
|
-
spring
|
211
|
-
end
|
212
|
-
|
213
|
-
def slide(my_anchor, other_physical, other_anchor, min_distance, max_distance)
|
214
|
-
slide = CP::Constraint::SlideJoint.new(physical.body, other_physical.body, my_anchor, other_anchor, min_distance, max_distance)
|
215
|
-
@actor.stage.register_physical_constraint slide
|
216
|
-
@constraints << slide
|
217
|
-
slide
|
218
|
-
end
|
219
|
-
|
220
|
-
def groove(groove_start, groove_end, other_physical, other_anchor)
|
221
|
-
groove = CP::Constraint::GrooveJoint.new(physical.body, other_physical.body, groove_start, groove_end, other_anchor)
|
222
|
-
@actor.stage.register_physical_constraint groove
|
223
|
-
@constraints << groove
|
224
|
-
groove
|
225
|
-
end
|
226
|
-
|
227
|
-
#
|
228
|
-
# All of these rotary joint types expect angles in radians.
|
229
|
-
#
|
230
|
-
|
231
|
-
def rotary_spring(other_physical, rest_angle, stiffness, damping)
|
232
|
-
rotary_spring = CP::Constraint::DampedRotarySpring.new(physical.body, other_physical.body, rest_angle, stiffness, damping)
|
233
|
-
@actor.stage.register_physical_constraint rotary_spring
|
234
|
-
@constraints << rotary_spring
|
235
|
-
rotary_spring
|
236
|
-
end
|
237
|
-
|
238
|
-
def rotary_limit(other_physical, min_angle, max_angle)
|
239
|
-
rotary_limit = CP::Constraint::RotaryLimitJoint.new(physical.body, other_physical.body, min_angle, max_angle)
|
240
|
-
@actor.stage.register_physical_constraint rotary_limit
|
241
|
-
@constraints << rotary_limit
|
242
|
-
rotary_limit
|
243
|
-
end
|
244
|
-
|
245
|
-
def ratchet(other_physical, phase, ratchet)
|
246
|
-
ratchet_joint = CP::Constraint::RatchetJoint.new(physical.body, other_physical.body, phase, ratchet)
|
247
|
-
@actor.stage.register_physical_constraint ratchet_joint
|
248
|
-
@constraints << ratchet_joint
|
249
|
-
ratchet_joint
|
250
|
-
end
|
251
|
-
|
252
|
-
def gear(other_physical, phase, ratio)
|
253
|
-
gear = CP::Constraint::GearJoint.new(physical.body, other_physical.body, phase, ratio)
|
254
|
-
@actor.stage.register_physical_constraint gear
|
255
|
-
@constraints << gear
|
256
|
-
gear
|
257
|
-
end
|
258
|
-
|
259
|
-
def motor(other_physical, rate)
|
260
|
-
motor = CP::Constraint::SimpleMotor.new(physical.body, other_physical.body, rate)
|
261
|
-
@actor.stage.register_physical_constraint motor
|
262
|
-
@constraints << motor
|
263
|
-
motor
|
264
|
-
end
|
173
|
+
def warp(new_p)
|
174
|
+
actor.body.p = new_p
|
175
|
+
physics_manager.space.rehash_static if opts[:fixed]
|
176
|
+
end
|
265
177
|
|
266
|
-
|
267
|
-
|
268
|
-
|
178
|
+
# TODO use react_to to handle these requests?
|
179
|
+
# def pivot(my_anchor, other_physical, other_anchor)
|
180
|
+
# pivot = CP::Constraint::PivotJoint.new(actor.body, other_physical.actor.body, my_anchor, other_anchor)
|
181
|
+
# physics_manager.register_physical_constraint pivot
|
182
|
+
# actor.constraints << pivot
|
183
|
+
# pivot
|
184
|
+
# end
|
185
|
+
|
186
|
+
# def pin(my_anchor, other_physical, other_anchor)
|
187
|
+
# pin = CP::Constraint::PinJoint.new(actor.body, other_physical.physical.body, my_anchor, other_anchor)
|
188
|
+
# physics_manager.register_physical_constraint pin
|
189
|
+
# actor.constraints << pin
|
190
|
+
# pin
|
191
|
+
# end
|
192
|
+
|
193
|
+
# def spring(my_anchor, other_physical, other_anchor, rest_length, stiffness, damping)
|
194
|
+
# spring = CP::Constraint::DampedSpring.new(body,other_physical.body,
|
195
|
+
# my_anchor,other_anchor, rest_length, stiffness, damping)
|
196
|
+
# physics_manager.register_physical_constraint spring
|
197
|
+
# actor.constraints << spring
|
198
|
+
# spring
|
199
|
+
# end
|
200
|
+
|
201
|
+
# def slide(my_anchor, other_physical, other_anchor, min_distance, max_distance)
|
202
|
+
# slide = CP::Constraint::SlideJoint.new(actor.body, other_physical.body, my_anchor, other_anchor, min_distance, max_distance)
|
203
|
+
# physics_manager.register_physical_constraint slide
|
204
|
+
# actor.constraints << slide
|
205
|
+
# slide
|
206
|
+
# end
|
207
|
+
|
208
|
+
# def groove(groove_start, groove_end, other_physical, other_anchor)
|
209
|
+
# groove = CP::Constraint::GrooveJoint.new(actor.body, other_physical.body, groove_start, groove_end, other_anchor)
|
210
|
+
# physics_manager.register_physical_constraint groove
|
211
|
+
# actor.constraints << groove
|
212
|
+
# groove
|
213
|
+
# end
|
214
|
+
|
215
|
+
# #
|
216
|
+
# # All of these rotary joint types expect angles in radians.
|
217
|
+
# #
|
218
|
+
|
219
|
+
# def rotary_spring(other_physical, rest_angle, stiffness, damping)
|
220
|
+
# rotary_spring = CP::Constraint::DampedRotarySpring.new(actor.body, other_physical.body, rest_angle, stiffness, damping)
|
221
|
+
# physics_manager.register_physical_constraint rotary_spring
|
222
|
+
# actor.constraints << rotary_spring
|
223
|
+
# rotary_spring
|
224
|
+
# end
|
225
|
+
|
226
|
+
# def rotary_limit(other_physical, min_angle, max_angle)
|
227
|
+
# rotary_limit = CP::Constraint::RotaryLimitJoint.new(actor.body, other_physical.body, min_angle, max_angle)
|
228
|
+
# physics_manager.register_physical_constraint rotary_limit
|
229
|
+
# actor.constraints << rotary_limit
|
230
|
+
# rotary_limit
|
231
|
+
# end
|
232
|
+
|
233
|
+
# def ratchet(other_physical, phase, ratchet)
|
234
|
+
# ratchet_joint = CP::Constraint::RatchetJoint.new(actor.body, other_physical.body, phase, ratchet)
|
235
|
+
# physics_manager.register_physical_constraint ratchet_joint
|
236
|
+
# actor.constraints << ratchet_joint
|
237
|
+
# ratchet_joint
|
238
|
+
# end
|
239
|
+
|
240
|
+
# def gear(other_physical, phase, ratio)
|
241
|
+
# gear = CP::Constraint::GearJoint.new(actor.body, other_physical.body, phase, ratio)
|
242
|
+
# physics_manager.register_physical_constraint gear
|
243
|
+
# actor.constraints << gear
|
244
|
+
# gear
|
245
|
+
# end
|
246
|
+
|
247
|
+
# def motor(other_physical, rate)
|
248
|
+
# motor = CP::Constraint::SimpleMotor.new(actor.body, other_physical.body, rate)
|
249
|
+
# physics_manager.register_physical_constraint motor
|
250
|
+
# actor.constraints << motor
|
251
|
+
# motor
|
252
|
+
# end
|
253
|
+
|
254
|
+
def cleanup_constraints
|
255
|
+
actor.constraints.each do |c|
|
256
|
+
physics_manager.unregister_physical_constraint c
|
257
|
+
end
|
269
258
|
end
|
270
259
|
end
|
271
260
|
|