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
@@ -0,0 +1,30 @@
|
|
1
|
+
module Gamebox
|
2
|
+
# Returns the global configuration object
|
3
|
+
def self.configuration
|
4
|
+
@configuration ||= Configuration.new
|
5
|
+
@configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield configuration if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def define_behavior(name, &blk)
|
13
|
+
Behavior.define name, &blk
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_actor(name, &blk)
|
17
|
+
Actor.define name, &blk
|
18
|
+
end
|
19
|
+
|
20
|
+
def define_actor_view(name, &blk)
|
21
|
+
ActorView.define name, &blk
|
22
|
+
end
|
23
|
+
|
24
|
+
# module_function :define_behavior, :define_actor, :define_actor_view
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# EEK... dirty?
|
30
|
+
include Gamebox
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Actor
|
2
|
+
def self.inherited(klass)
|
3
|
+
log "Cannot extend #{self} anymore #{klass}"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
class Behavior
|
7
|
+
def self.inherited(klass)
|
8
|
+
log "Cannot extend #{self} anymore #{klass}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class ActorView
|
12
|
+
def self.inherited(klass)
|
13
|
+
log "Cannot extend #{self} anymore #{klass}"
|
14
|
+
end
|
15
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Directors manage actors.
|
2
2
|
class Director
|
3
|
+
extend Publisher
|
4
|
+
can_fire_anything
|
3
5
|
attr_accessor :actors
|
4
6
|
|
5
7
|
def initialize
|
@@ -16,7 +18,7 @@ class Director
|
|
16
18
|
actor.when :remove_me do
|
17
19
|
remove_actor actor
|
18
20
|
end
|
19
|
-
actor_added actor
|
21
|
+
fire :actor_added, actor
|
20
22
|
actor
|
21
23
|
end
|
22
24
|
|
@@ -24,12 +26,6 @@ class Director
|
|
24
26
|
@dead_actors << actor
|
25
27
|
end
|
26
28
|
|
27
|
-
def actor_removed(actor)
|
28
|
-
end
|
29
|
-
|
30
|
-
def actor_added(actor)
|
31
|
-
end
|
32
|
-
|
33
29
|
def empty?
|
34
30
|
@actors.empty?
|
35
31
|
end
|
@@ -50,11 +46,10 @@ class Director
|
|
50
46
|
def update(time)
|
51
47
|
for act in @dead_actors
|
52
48
|
@actors.delete act
|
53
|
-
actor_removed act
|
49
|
+
fire :actor_removed, act
|
54
50
|
end
|
55
51
|
@dead_actors = []
|
56
|
-
|
57
|
-
|
58
|
-
end
|
52
|
+
time_in_seconds = time / 1000.to_f
|
53
|
+
fire :update, time, time_in_seconds
|
59
54
|
end
|
60
55
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
class FontStyle
|
3
|
+
construct_with :resource_manager
|
4
|
+
|
5
|
+
attr_accessor :font, :name, :size, :color, :x_scale, :y_scale
|
6
|
+
def configure(name, size, color, x_scale, y_scale)
|
7
|
+
@name = name
|
8
|
+
@size = size
|
9
|
+
@color = color
|
10
|
+
@x_scale = x_scale
|
11
|
+
@y_scale = y_scale
|
12
|
+
reload
|
13
|
+
end
|
14
|
+
|
15
|
+
def calc_width(text)
|
16
|
+
@font.text_width text
|
17
|
+
end
|
18
|
+
|
19
|
+
def height
|
20
|
+
@font.height
|
21
|
+
end
|
22
|
+
|
23
|
+
def reload
|
24
|
+
@font = resource_manager.load_font name, size
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class FontStyleFactory
|
2
|
+
construct_with :this_object_context
|
3
|
+
|
4
|
+
def build(name, size, color, x_scale=1, y_scale=1)
|
5
|
+
this_object_context.in_subcontext do |style_context|
|
6
|
+
style_context["font_style"].tap do |style|
|
7
|
+
style.configure name, size, color, x_scale, y_scale
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Game
|
2
|
+
|
3
|
+
# BTW: we have extra deps to make sure they are all built at game construction time
|
4
|
+
construct_with :wrapped_screen, :input_manager, :sound_manager,
|
5
|
+
:stage_manager
|
6
|
+
|
7
|
+
def configure
|
8
|
+
stage_manager.change_stage_to stage_manager.default_stage
|
9
|
+
end
|
10
|
+
|
11
|
+
def update(time)
|
12
|
+
stage_manager.update time
|
13
|
+
end
|
14
|
+
|
15
|
+
def draw
|
16
|
+
stage_manager.draw wrapped_screen
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
require 'publisher'
|
2
|
-
|
3
|
-
class HookedGosuWindow < Window
|
4
|
-
extend Publisher
|
5
|
-
can_fire :update, :draw, :button_down, :button_up
|
6
|
-
|
2
|
+
module GosuWindowAPI
|
7
3
|
def initialize(width, height, fullscreen)
|
8
4
|
super(width, height, fullscreen)
|
9
5
|
end
|
10
6
|
|
11
7
|
def update
|
12
8
|
millis = Gosu::milliseconds
|
13
|
-
@last_millis ||=
|
9
|
+
@last_millis ||= 0
|
14
10
|
fire :update, (millis - @last_millis)
|
15
11
|
@last_millis = millis
|
16
12
|
end
|
@@ -27,4 +23,14 @@ class HookedGosuWindow < Window
|
|
27
23
|
def button_up(id)
|
28
24
|
fire :button_up, id
|
29
25
|
end
|
26
|
+
|
27
|
+
attr_accessor :needs_cursor
|
28
|
+
alias :needs_cursor? :needs_cursor
|
29
|
+
end
|
30
|
+
|
31
|
+
class HookedGosuWindow < Window
|
32
|
+
include GosuWindowAPI
|
33
|
+
extend Publisher
|
34
|
+
can_fire :update, :draw, :button_down, :button_up
|
35
|
+
|
30
36
|
end
|
@@ -26,111 +26,28 @@ class InputManager
|
|
26
26
|
UP_EVENTS = [:mouse_up, :keyboard_up, :game_pad_up]
|
27
27
|
|
28
28
|
attr_accessor :window
|
29
|
-
|
29
|
+
construct_with :config_manager, :wrapped_screen
|
30
30
|
|
31
31
|
# Sets up the clock and main event loop. You should never call this method,
|
32
|
-
# as this class should be initialized by
|
33
|
-
def
|
34
|
-
@window = @wrapped_screen.screen
|
35
|
-
|
36
|
-
auto_quit = @config_manager[:auto_quit]
|
37
|
-
@auto_quit = instance_eval(auto_quit) if auto_quit
|
38
|
-
|
32
|
+
# as this class should be initialized by conject.
|
33
|
+
def initialize
|
39
34
|
@hooks = {}
|
40
35
|
@non_id_hooks = {}
|
41
36
|
@down_ids = {}
|
42
|
-
end
|
43
|
-
|
44
|
-
# This gets called from game app and sets up all the
|
45
|
-
# events. (also shows the window)
|
46
|
-
def main_loop(game)
|
47
37
|
|
48
|
-
|
49
|
-
_handle_event button_id, :up
|
50
|
-
end
|
51
|
-
@window.when :button_down do |button_id|
|
52
|
-
_handle_event button_id, :down
|
53
|
-
end
|
54
|
-
|
55
|
-
@window.when :update do |millis|
|
56
|
-
|
57
|
-
if @uses_mouse
|
58
|
-
@last_mouse_x ||= mouse_x
|
59
|
-
@last_mouse_y ||= mouse_y
|
60
|
-
|
61
|
-
x_diff = @last_mouse_x - mouse_x
|
62
|
-
y_diff = @last_mouse_y - mouse_y
|
63
|
-
|
64
|
-
unless x_diff < 0.1 && x_diff > -0.1 && y_diff < 0.1 && y_diff > -0.1
|
65
|
-
_handle_event nil, :motion
|
66
|
-
|
67
|
-
@last_mouse_x = mouse_x
|
68
|
-
@last_mouse_y = mouse_y
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
game.update millis
|
73
|
-
end
|
74
|
-
@window.when :draw do
|
75
|
-
game.draw
|
76
|
-
end
|
77
|
-
|
78
|
-
@window.show
|
38
|
+
setup
|
79
39
|
end
|
80
40
|
|
81
|
-
def
|
82
|
-
@window
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
@down_ids.delete gosu_id
|
87
|
-
end
|
88
|
-
|
89
|
-
event_data = nil
|
90
|
-
mouse_dragged = false
|
91
|
-
|
92
|
-
callback_key = action
|
93
|
-
if gosu_id.nil?
|
94
|
-
event_type = :mouse_motion
|
95
|
-
callback_key = :mouse_motion
|
96
|
-
@mouse_dragging = true if @mouse_down
|
97
|
-
event_data = [mouse_x, mouse_y]
|
98
|
-
elsif gosu_id >= MsRangeBegin && gosu_id <= MsRangeEnd
|
99
|
-
event_type = :mouse
|
100
|
-
event_data = [mouse_x, mouse_y]
|
101
|
-
if action == :up
|
102
|
-
# callback_key = :mouse_up
|
103
|
-
@mouse_down = false
|
104
|
-
mouse_dragged = true if @mouse_dragging
|
105
|
-
@mouse_dragging = false
|
106
|
-
else
|
107
|
-
# callback_key = :mouse_down
|
108
|
-
@mouse_down = true
|
109
|
-
@last_click_x = mouse_x
|
110
|
-
@last_click_y = mouse_y
|
111
|
-
end
|
112
|
-
elsif gosu_id >= KbRangeBegin && gosu_id <= KbRangeEnd
|
113
|
-
event_type = :keyboard
|
114
|
-
elsif gosu_id >= GpRangeBegin && gosu_id <= GpRangeEnd
|
115
|
-
event_type = :game_pad
|
116
|
-
end
|
117
|
-
|
118
|
-
# single threaded.. keep same event
|
119
|
-
@event ||= {}
|
120
|
-
@event[:type] = event_type
|
121
|
-
@event[:id] = gosu_id
|
122
|
-
@event[:action] = action
|
123
|
-
@event[:callback_key] = callback_key
|
124
|
-
@event[:data] = event_data
|
125
|
-
|
126
|
-
fire_event(@event)
|
41
|
+
def setup
|
42
|
+
@window = wrapped_screen.screen
|
43
|
+
auto_quit = config_manager[:auto_quit]
|
44
|
+
@auto_quit = instance_eval(auto_quit) if auto_quit
|
45
|
+
end
|
127
46
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
fire_event(@event)
|
133
|
-
end
|
47
|
+
def show
|
48
|
+
# Does not return, Gosu uses this to pop up the window
|
49
|
+
# This must be last in the method
|
50
|
+
@window.show
|
134
51
|
end
|
135
52
|
|
136
53
|
def fire_event(event)
|
@@ -151,13 +68,13 @@ class InputManager
|
|
151
68
|
end
|
152
69
|
end
|
153
70
|
end
|
154
|
-
|
71
|
+
|
155
72
|
non_id_event_hooks = @non_id_hooks[event[:callback_key]]
|
156
73
|
if non_id_event_hooks
|
157
74
|
for callback in non_id_event_hooks
|
158
75
|
callback.call event
|
159
76
|
end
|
160
|
-
end
|
77
|
+
end
|
161
78
|
end
|
162
79
|
|
163
80
|
# registers a block to be called when matching events are pulled from the SDL queue.
|
@@ -228,7 +145,7 @@ class InputManager
|
|
228
145
|
end
|
229
146
|
end
|
230
147
|
end
|
231
|
-
|
148
|
+
|
232
149
|
for key in @non_id_hooks.keys.dup
|
233
150
|
@non_id_hooks[key].delete_if do |block|
|
234
151
|
eval('self',block.binding).equal?(listener)
|
@@ -268,10 +185,100 @@ class InputManager
|
|
268
185
|
@paused_non_id_hooks = nil
|
269
186
|
end
|
270
187
|
|
188
|
+
def register(game)
|
189
|
+
@window.when :button_up do |button_id|
|
190
|
+
handle_event button_id, :up
|
191
|
+
end
|
192
|
+
@window.when :button_down do |button_id|
|
193
|
+
handle_event button_id, :down
|
194
|
+
end
|
195
|
+
|
196
|
+
@window.when :update do |millis|
|
197
|
+
|
198
|
+
if @uses_mouse
|
199
|
+
@last_mouse_x ||= mouse_x
|
200
|
+
@last_mouse_y ||= mouse_y
|
201
|
+
|
202
|
+
x_diff = @last_mouse_x - mouse_x
|
203
|
+
y_diff = @last_mouse_y - mouse_y
|
204
|
+
|
205
|
+
unless x_diff < 0.1 && x_diff > -0.1 && y_diff < 0.1 && y_diff > -0.1
|
206
|
+
handle_event nil, :motion
|
207
|
+
|
208
|
+
@last_mouse_x = mouse_x
|
209
|
+
@last_mouse_y = mouse_y
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
game.update millis
|
214
|
+
end
|
215
|
+
@window.when :draw do
|
216
|
+
game.draw
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
271
220
|
private
|
221
|
+
|
222
|
+
def handle_event(gosu_id, action) #:nodoc:
|
223
|
+
@window.close if @auto_quit && gosu_id == @auto_quit
|
224
|
+
if action == :down
|
225
|
+
@down_ids[gosu_id] = true
|
226
|
+
else
|
227
|
+
@down_ids.delete gosu_id
|
228
|
+
end
|
229
|
+
|
230
|
+
event_data = nil
|
231
|
+
mouse_dragged = false
|
232
|
+
|
233
|
+
callback_key = action
|
234
|
+
if gosu_id.nil?
|
235
|
+
event_type = :mouse_motion
|
236
|
+
callback_key = :mouse_motion
|
237
|
+
@mouse_dragging = true if @mouse_down
|
238
|
+
event_data = [mouse_x, mouse_y]
|
239
|
+
elsif gosu_id >= MsRangeBegin && gosu_id <= MsRangeEnd
|
240
|
+
event_type = :mouse
|
241
|
+
event_data = [mouse_x, mouse_y]
|
242
|
+
if action == :up
|
243
|
+
# callback_key = :mouse_up
|
244
|
+
@mouse_down = false
|
245
|
+
mouse_dragged = true if @mouse_dragging
|
246
|
+
@mouse_dragging = false
|
247
|
+
else
|
248
|
+
# callback_key = :mouse_down
|
249
|
+
@mouse_down = true
|
250
|
+
@last_click_x = mouse_x
|
251
|
+
@last_click_y = mouse_y
|
252
|
+
end
|
253
|
+
elsif gosu_id >= KbRangeBegin && gosu_id <= KbRangeEnd
|
254
|
+
event_type = :keyboard
|
255
|
+
elsif gosu_id >= GpRangeBegin && gosu_id <= GpRangeEnd
|
256
|
+
event_type = :game_pad
|
257
|
+
end
|
258
|
+
|
259
|
+
# single threaded.. keep same event
|
260
|
+
@event ||= {}
|
261
|
+
@event[:type] = event_type
|
262
|
+
@event[:id] = gosu_id
|
263
|
+
@event[:action] = action
|
264
|
+
@event[:callback_key] = callback_key
|
265
|
+
@event[:data] = event_data
|
266
|
+
|
267
|
+
fire_event(@event)
|
268
|
+
|
269
|
+
if mouse_dragged
|
270
|
+
drag_data = {:to => [mouse_x, mouse_y], :from => [@last_click_x, @last_click_y]}
|
271
|
+
@event[:data] = drag_data
|
272
|
+
@event[:callback_key] = :mouse_drag
|
273
|
+
fire_event(@event)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
272
278
|
def mouse_x
|
273
279
|
@window.mouse_x
|
274
280
|
end
|
281
|
+
|
275
282
|
def mouse_y
|
276
283
|
@window.mouse_y
|
277
284
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
if defined? CP
|
2
|
+
ZERO_VEC_2 = vec2(0,0) unless defined? ZERO_VEC_2
|
3
|
+
def vec2(*args)
|
4
|
+
CP::Vec2.new *args
|
5
|
+
end
|
6
|
+
|
7
|
+
class CP::Shape::Circle
|
8
|
+
attr_accessor :actor
|
9
|
+
end
|
10
|
+
class CP::Shape::Poly
|
11
|
+
attr_accessor :actor
|
12
|
+
end
|
13
|
+
class CP::Shape::Segment
|
14
|
+
attr_accessor :actor
|
15
|
+
end
|
16
|
+
|
17
|
+
else
|
18
|
+
ZERO_VEC_2 = Ftor.new(0,0)
|
19
|
+
def vec2(*args)
|
20
|
+
Ftor.new *args
|
21
|
+
end
|
22
|
+
end
|