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
data/lib/gamebox/version.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
module Gamebox
|
2
2
|
module VERSION #:nodoc:
|
3
3
|
MAJOR = 0
|
4
|
-
MINOR =
|
5
|
-
TINY =
|
4
|
+
MINOR = 4
|
5
|
+
TINY = 0
|
6
|
+
RC = 1
|
6
7
|
|
7
|
-
|
8
|
+
if RC > 0
|
9
|
+
ARRAY = [MAJOR, MINOR, TINY, "rc#{RC}"]
|
10
|
+
else
|
11
|
+
ARRAY = [MAJOR, MINOR, TINY]
|
12
|
+
end
|
8
13
|
STRING = ARRAY.join('.')
|
9
14
|
end
|
10
15
|
end
|
@@ -1,47 +1,40 @@
|
|
1
1
|
|
2
|
+
ActorView.define :graphical_actor_view do
|
3
|
+
|
4
|
+
draw do |target, x_off, y_off, z|
|
5
|
+
img = actor.do_or_do_not(:image)
|
6
|
+
return if img.nil?
|
2
7
|
|
3
|
-
class GraphicalActorView < ActorView
|
4
|
-
def draw(target, x_off, y_off, z)
|
5
8
|
x = actor.x
|
6
9
|
y = actor.y
|
7
10
|
|
8
11
|
offset_x = x+x_off
|
9
12
|
offset_y = y+y_off
|
10
13
|
|
11
|
-
|
12
|
-
return if img.nil?
|
13
|
-
|
14
|
-
alpha = actor.respond_to?(:alpha) ? actor.alpha : 0xFF
|
14
|
+
alpha = actor.do_or_do_not(:alpha) || 0xFF
|
15
15
|
color = Color.new(alpha,0xFF,0xFF,0xFF)
|
16
16
|
|
17
|
+
x_scale = actor.do_or_do_not(:x_scale) || 1
|
18
|
+
y_scale = actor.do_or_do_not(:y_scale) || 1
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
# TODO add ? ableness to actor attributes
|
21
|
+
if actor.do_or_do_not(:tiled)
|
22
|
+
x_tiles = actor.num_x_tiles
|
23
|
+
y_tiles = actor.num_y_tiles
|
21
24
|
img_w = img.width
|
22
25
|
img_h = img.height
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if graphical_behavior && graphical_behavior.tiled?
|
28
|
-
x_tiles = graphical_behavior.num_x_tiles
|
29
|
-
y_tiles = graphical_behavior.num_y_tiles
|
30
|
-
img_w = img.width
|
31
|
-
img_h = img.height
|
32
|
-
x_tiles.times do |col|
|
33
|
-
y_tiles.times do |row|
|
34
|
-
# TODO why is there a nasty black line between these that jitters?
|
35
|
-
img.draw_rot offset_x+col*img_w, offset_y+row*img_h, z, actor.rotation, x_scale, y_scale
|
36
|
-
end
|
26
|
+
x_tiles.times do |col|
|
27
|
+
y_tiles.times do |row|
|
28
|
+
# TODO why is there a nasty black line between these that jitters?
|
29
|
+
img.draw_rot offset_x+col*img_w, offset_y+row*img_h, z, actor.rotation, x_scale, y_scale
|
37
30
|
end
|
31
|
+
end
|
32
|
+
else
|
33
|
+
if actor.respond_to? :rotation
|
34
|
+
rot = actor.rotation || 0.0
|
35
|
+
img.draw_rot offset_x, offset_y, z, rot, 0.5, 0.5, x_scale, y_scale, color
|
38
36
|
else
|
39
|
-
|
40
|
-
rot = actor.rotation || 0.0
|
41
|
-
img.draw_rot offset_x, offset_y, z, rot, 0.5, 0.5, x_scale, y_scale, color
|
42
|
-
else
|
43
|
-
img.draw offset_x, offset_y, z, x_scale, y_scale, color
|
44
|
-
end
|
37
|
+
img.draw offset_x, offset_y, z, x_scale, y_scale, color
|
45
38
|
end
|
46
39
|
end
|
47
40
|
end
|
data/script/perf_aabb.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require '../lib/gamebox'
|
3
|
+
|
4
|
+
class BoxedActor
|
5
|
+
include Kvo
|
6
|
+
kvo_attr_accessor :x, :y
|
7
|
+
attr_accessor :w, :h
|
8
|
+
|
9
|
+
can_fire_anything
|
10
|
+
|
11
|
+
def initialize(x,y,w,h)
|
12
|
+
@kvo_x = x
|
13
|
+
@kvo_y = y
|
14
|
+
@w = w
|
15
|
+
@h = h
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
require 'perftools'
|
20
|
+
PerfTools::CpuProfiler.start("/tmp/perf.txt")
|
21
|
+
|
22
|
+
|
23
|
+
NUM = 1_000
|
24
|
+
# Benchmark.bm(60) do |b|
|
25
|
+
# b.report("full") do
|
26
|
+
tree = SpatialTreeStagehand.new :thing, :thing
|
27
|
+
|
28
|
+
thing = BoxedActor.new 1, 2, 3, 4
|
29
|
+
tree.add thing
|
30
|
+
things = []
|
31
|
+
100.times do |i|
|
32
|
+
t = BoxedActor.new i, i, i, i
|
33
|
+
things << t
|
34
|
+
tree.add t
|
35
|
+
end
|
36
|
+
|
37
|
+
NUM.times do
|
38
|
+
it = BoxedActor.new 1, 2, 3, 4
|
39
|
+
tree.add it
|
40
|
+
|
41
|
+
thing.x + 1
|
42
|
+
things[20..40].each do |t|
|
43
|
+
t.x += rand(40)-20
|
44
|
+
end
|
45
|
+
|
46
|
+
tree.neighbors_of thing do
|
47
|
+
end
|
48
|
+
tree.remove it
|
49
|
+
end
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
|
53
|
+
PerfTools::CpuProfiler.stop
|
54
|
+
# be pprof.rb --text /tmp/perf.txt
|
55
|
+
|
56
|
+
|
data/script/perf_collisions.rb
CHANGED
@@ -3,25 +3,22 @@ $: << File.dirname(__FILE__)+"/../lib/gamebox"
|
|
3
3
|
require 'gamebox'
|
4
4
|
|
5
5
|
|
6
|
-
NUM_RUNS =
|
7
|
-
PROFILE =
|
6
|
+
NUM_RUNS = 1000
|
7
|
+
PROFILE = false
|
8
|
+
class FakeInput
|
9
|
+
def unsubscribe_all(*args);end
|
10
|
+
end
|
8
11
|
|
9
12
|
def run
|
10
13
|
config = {
|
11
14
|
screen_resolution: [800,600]
|
12
15
|
}
|
13
16
|
|
14
|
-
|
17
|
+
fake_input = FakeInput.new
|
18
|
+
af = ActorFactory.new input_manager: fake_input, wrapped_screen: :wrapped_screen
|
15
19
|
af.director = FakeUpdate.new
|
16
20
|
stage = Stage.new :input_manager, af, :resource_manager, :sound_manager, config, :backstage, {}
|
17
21
|
|
18
|
-
things = []
|
19
|
-
20.times do |i|
|
20
|
-
5.times do |j|
|
21
|
-
things << stage.spawn(:thinger, x: i*40, y: j*40)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
22
|
Benchmark.bm(60) do |b|
|
26
23
|
b.report("update loop") do
|
27
24
|
|
@@ -31,16 +28,38 @@ def run
|
|
31
28
|
require 'perftools'
|
32
29
|
PerfTools::CpuProfiler.start("/tmp/gamebox_perf.txt")
|
33
30
|
end
|
31
|
+
things = []
|
32
|
+
200.times do |i|
|
33
|
+
50.times do |j|
|
34
|
+
things << stage.spawn(:thinger, x: i*40, y: j*40)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
34
38
|
|
39
|
+
stage.on_collision_of :thinger, :thinger do |a,b|
|
40
|
+
# no op, just want something to call
|
41
|
+
end
|
35
42
|
runs.times do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
# move some around
|
44
|
+
dist = 10
|
45
|
+
[0,2,5,7,13,19].each do |i|
|
46
|
+
thing = things[i]
|
47
|
+
thing.x = thing.x + dist
|
48
|
+
thing.y = thing.y + dist
|
49
|
+
end
|
50
|
+
|
51
|
+
stage.update(20)
|
52
|
+
|
53
|
+
[0,2,5,7,13,19].each do |i|
|
54
|
+
thing = things[i]
|
55
|
+
thing.x = thing.x - dist
|
56
|
+
thing.y = thing.y - dist
|
57
|
+
end
|
58
|
+
stage.update(20)
|
59
|
+
|
60
|
+
to_kill = things.pop
|
61
|
+
things << stage.spawn(:thinger, x: to_kill.x, y: to_kill.y)
|
62
|
+
to_kill.remove_self
|
44
63
|
stage.update(20)
|
45
64
|
#
|
46
65
|
# puts "\nGARBAGE COLLECTION"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
|
3
3
|
# Point = Struct.new :x, :y
|
4
|
-
class Point
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
# class Point
|
5
|
+
# attr_accessor :x, :y
|
6
|
+
# def initialize(x,y)
|
7
|
+
# @x = x
|
8
|
+
# @y = y
|
9
|
+
# end
|
10
|
+
# end
|
11
11
|
NUM = 10_000_000
|
12
12
|
Benchmark.bm(60) do |b|
|
13
13
|
b.report("array") do
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Using animation", acceptance: true do
|
4
|
+
|
5
|
+
let!(:snelpling_idle_png) { mock_image('snelpling/idle/1.png') }
|
6
|
+
let!(:snelpling_jump_1_png) { mock_image('snelpling/jump/1.png') }
|
7
|
+
let!(:snelpling_jump_2_png) { mock_image('snelpling/jump/2.png') }
|
8
|
+
let!(:snelpling_jump_3_png) { mock_image('snelpling/jump/3.png') }
|
9
|
+
|
10
|
+
define_behavior :jump_on_j do
|
11
|
+
requires :input_manager
|
12
|
+
setup do
|
13
|
+
input_manager.reg :down, KbJ do
|
14
|
+
actor.action = :jump
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
define_actor_view :snelpling_view do
|
19
|
+
draw do |target, x_off, y_off, z|
|
20
|
+
actor.image.draw #offset_x, offset_y, z, x_scale, y_scale, color
|
21
|
+
end
|
22
|
+
end
|
23
|
+
define_actor :snelpling do
|
24
|
+
has_behavior :jump_on_j
|
25
|
+
has_behavior :animated
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'animates correctly' do
|
29
|
+
game.stage do |stage| # instance of TestingStage
|
30
|
+
create_actor :snelpling
|
31
|
+
end
|
32
|
+
|
33
|
+
see_actor_attrs :snelpling,
|
34
|
+
action: :idle,
|
35
|
+
image: snelpling_idle_png
|
36
|
+
|
37
|
+
draw
|
38
|
+
see_image_drawn snelpling_idle_png
|
39
|
+
|
40
|
+
update 60
|
41
|
+
draw
|
42
|
+
see_image_drawn snelpling_idle_png
|
43
|
+
|
44
|
+
press_key KbJ
|
45
|
+
draw
|
46
|
+
|
47
|
+
see_image_drawn snelpling_jump_1_png
|
48
|
+
update 60
|
49
|
+
draw
|
50
|
+
|
51
|
+
see_image_drawn snelpling_jump_2_png
|
52
|
+
update 60
|
53
|
+
draw
|
54
|
+
|
55
|
+
see_image_drawn snelpling_jump_3_png
|
56
|
+
update 60
|
57
|
+
draw
|
58
|
+
|
59
|
+
see_image_drawn snelpling_jump_1_png
|
60
|
+
|
61
|
+
pending "add callback checks?"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "The basic life cycle of an actor", acceptance: true do
|
4
|
+
before do
|
5
|
+
Gamebox.configure do |config|
|
6
|
+
config.config_path = "spec/fixtures/"
|
7
|
+
config.music_path = "spec/fixtures/"
|
8
|
+
config.sound_path = "spec/fixtures/"
|
9
|
+
config.stages = [:testing]
|
10
|
+
end
|
11
|
+
|
12
|
+
Conject.instance_variable_set '@default_object_context', nil
|
13
|
+
HookedGosuWindow.stubs(:new).returns(gosu)
|
14
|
+
end
|
15
|
+
let(:gosu) { MockGosuWindow.new }
|
16
|
+
let!(:mc_bane_png) { mock_image('mc_bane.png') }
|
17
|
+
|
18
|
+
define_behavior :shooty do |beh|
|
19
|
+
beh.requires :director
|
20
|
+
beh.setup do
|
21
|
+
actor.has_attribute :bullets, opts[:bullets]
|
22
|
+
director.when :update do |time|
|
23
|
+
actor.bullets -= time
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
define_behavior :death_on_d do
|
29
|
+
requires :input_manager
|
30
|
+
# TODO can we rename this to configure?
|
31
|
+
setup do
|
32
|
+
input_manager.reg :up, KbD do
|
33
|
+
actor.remove
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
define_actor_view :mc_bane_view do
|
39
|
+
requires :resource_manager # needs these injected
|
40
|
+
configure do
|
41
|
+
@image = resource_manager.load_actor_image(actor)
|
42
|
+
end
|
43
|
+
|
44
|
+
draw do |target, x_off, y_off, z|
|
45
|
+
# TODO TRACK THESE DRAWINGS
|
46
|
+
@image.draw #offset_x, offset_y, z, x_scale, y_scale, color
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# no code is allowed in the actor!
|
51
|
+
# all done through behaviors
|
52
|
+
define_actor :mc_bane do
|
53
|
+
has_behavior shooty: { bullets: 50 }
|
54
|
+
has_behavior :death_on_d
|
55
|
+
# actor.has_behavior :graphical
|
56
|
+
|
57
|
+
# FEATURE REQUEST
|
58
|
+
# actor.has_view do |view|
|
59
|
+
# view.uses :resource_manager
|
60
|
+
# view.configure do
|
61
|
+
# end
|
62
|
+
|
63
|
+
# view.draw do |target, x_off, y_off, z|
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
it 'creates an actor from within stage with the correct behaviors and updates' do
|
70
|
+
# going for a capybara style "page" reference for the game
|
71
|
+
game.stage do |stage| # instance of TestingStage
|
72
|
+
create_actor :mc_bane, x: 250, y: 400
|
73
|
+
end
|
74
|
+
see_actor_attrs :mc_bane, bullets: 50
|
75
|
+
|
76
|
+
update 10
|
77
|
+
see_image_not_drawn mc_bane_png
|
78
|
+
|
79
|
+
draw
|
80
|
+
see_image_drawn mc_bane_png
|
81
|
+
|
82
|
+
see_actor_attrs :mc_bane, bullets: 40
|
83
|
+
game.should have_actor(:mc_bane)
|
84
|
+
|
85
|
+
release_key KbD
|
86
|
+
|
87
|
+
# should have removed himself
|
88
|
+
game.should_not have_actor(:mc_bane)
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Using gamebox's built in collision handling", acceptance: true do
|
4
|
+
|
5
|
+
define_actor :frickin_laser do
|
6
|
+
has_behavior :projectile
|
7
|
+
has_behavior collidable: {shape: :polygon, points: [[0,0],[10,7],[20,10]]}
|
8
|
+
end
|
9
|
+
|
10
|
+
define_actor :alien do
|
11
|
+
has_behavior collidable: {shape: :circle, radius: 10}
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'shows that two overlapping objects collide' do
|
15
|
+
#scope cheatzys
|
16
|
+
laser = nil
|
17
|
+
alien = nil
|
18
|
+
game.stage do |stage| # instance of TestingStage
|
19
|
+
laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 5, vel_y: 1
|
20
|
+
alien = create_actor :alien, x: 0, y: 0
|
21
|
+
on_collision_of :frickin_laser, :alien do |collision_laser, collision_alien|
|
22
|
+
@collision_laser = collision_laser
|
23
|
+
@collision_alien = collision_alien
|
24
|
+
end
|
25
|
+
end
|
26
|
+
see_stage_ivars collision_laser: nil, collision_alien: nil
|
27
|
+
update 1
|
28
|
+
# TODO not sure about this one..
|
29
|
+
update 1
|
30
|
+
see_stage_ivars collision_laser: laser, collision_alien: alien
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'shows that an object in motion can collide' do
|
34
|
+
laser = nil
|
35
|
+
alien = nil
|
36
|
+
game.stage do |stage| # instance of TestingStage
|
37
|
+
laser = create_actor :frickin_laser, x: 0, y: 0, vel_x: 5, vel_y: 0
|
38
|
+
alien = create_actor :alien, x: 31, y: 0
|
39
|
+
on_collision_of :frickin_laser, :alien do |collision_laser, collision_alien|
|
40
|
+
@collision_laser = collision_laser
|
41
|
+
@collision_alien = collision_alien
|
42
|
+
end
|
43
|
+
end
|
44
|
+
see_stage_ivars collision_laser: nil, collision_alien: nil
|
45
|
+
# now the laser moved and will be checked for collisions _next_ update
|
46
|
+
update 1
|
47
|
+
# trigger the next round of collision detection
|
48
|
+
update 2000
|
49
|
+
# TODO not sure about this one..
|
50
|
+
update 1
|
51
|
+
see_stage_ivars collision_laser: laser, collision_alien: alien
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|