gamebox 0.2.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -8
- data/Rakefile +13 -37
- data/TODO.txt +27 -27
- data/docs/getting_started.rdoc +2 -2
- data/gamebox.gemspec +33 -191
- data/lib/gamebox.rb +18 -14
- data/lib/gamebox/actor.rb +37 -27
- data/lib/gamebox/actor_factory.rb +4 -5
- data/lib/gamebox/actor_view.rb +8 -0
- data/lib/gamebox/actors/collidable_debugger.rb +2 -2
- data/lib/gamebox/actors/curtain.rb +3 -3
- data/lib/gamebox/actors/emitter.rb +51 -0
- data/lib/gamebox/actors/label.rb +27 -7
- data/lib/gamebox/actors/logo.rb +1 -1
- data/lib/gamebox/actors/spatial_debugger.rb +25 -10
- data/lib/gamebox/arbiter.rb +61 -34
- data/lib/gamebox/behavior.rb +3 -3
- data/lib/gamebox/behaviors/animated.rb +1 -1
- data/lib/gamebox/behaviors/audible.rb +1 -1
- data/lib/gamebox/behaviors/collidable.rb +9 -4
- data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +26 -1
- data/lib/gamebox/behaviors/collidable/circle_collidable.rb +3 -3
- data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
- data/lib/gamebox/behaviors/graphical.rb +30 -4
- data/lib/gamebox/behaviors/layered.rb +1 -1
- data/lib/gamebox/behaviors/physical.rb +113 -30
- data/lib/gamebox/behaviors/timed.rb +33 -0
- data/lib/gamebox/behaviors/updatable.rb +1 -1
- data/lib/gamebox/class_finder.rb +1 -21
- data/lib/gamebox/console_app.rb +33 -31
- data/lib/gamebox/constants.rb +481 -0
- data/lib/gamebox/data/config/objects.yml +7 -0
- data/lib/gamebox/gamebox_application.rb +10 -33
- data/lib/gamebox/gamebox_generator.rb +32 -32
- data/lib/gamebox/input_manager.rb +73 -32
- data/lib/gamebox/lib/inflector.rb +1 -1
- data/lib/gamebox/lib/range_ext.rb +5 -0
- data/lib/gamebox/lib/rect.rb +548 -548
- data/lib/gamebox/lib/sorted_list.rb +1 -1
- data/lib/gamebox/lib/symbol_ext.rb +8 -0
- data/lib/gamebox/physical_director.rb +1 -1
- data/lib/gamebox/physical_stage.rb +3 -3
- data/lib/gamebox/physics.rb +0 -3
- data/lib/gamebox/resource_manager.rb +22 -17
- data/lib/gamebox/sound_manager.rb +3 -2
- data/lib/gamebox/spatial_hash.rb +60 -31
- data/lib/gamebox/spatial_stagehand.rb +30 -6
- data/lib/gamebox/spec/helper.rb +7 -7
- data/lib/gamebox/stage.rb +18 -19
- data/lib/gamebox/stage_manager.rb +33 -23
- data/lib/gamebox/stagehand.rb +3 -0
- data/lib/gamebox/svg_document.rb +1 -1
- data/lib/gamebox/tasks/gamebox_tasks.rake +133 -0
- data/lib/gamebox/templates/actor.erb +0 -2
- data/lib/gamebox/templates/actor_view.erb +1 -3
- data/lib/gamebox/templates/template_app/Gemfile +3 -2
- data/lib/gamebox/templates/template_app/Rakefile +3 -8
- data/lib/gamebox/templates/template_app/config/environment.rb +7 -39
- data/lib/gamebox/templates/template_app/src/demo_stage.rb +1 -2
- data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -3
- data/lib/gamebox/version.rb +2 -2
- data/lib/gamebox/viewport.rb +44 -8
- data/lib/gamebox/views/graphical_actor_view.rb +22 -16
- data/lib/gamebox/wrapped_screen.rb +9 -1
- data/script/perf_spatial_hash.rb +49 -58
- data/script/perf_struct_vs_array.rb +32 -0
- data/spec/actor_factory_spec.rb +61 -0
- data/spec/actor_spec.rb +24 -18
- data/spec/actor_view_spec.rb +51 -6
- data/spec/animated_spec.rb +27 -6
- data/spec/arbiter_spec.rb +12 -24
- data/spec/backstage_spec.rb +1 -1
- data/spec/behavior_spec.rb +3 -3
- data/spec/class_finder_spec.rb +13 -0
- data/spec/collidable_spec.rb +30 -10
- data/spec/emitter_spec.rb +20 -0
- data/spec/helper.rb +5 -21
- data/spec/input_manager_spec.rb +134 -0
- data/spec/label_spec.rb +0 -1
- data/spec/physical_spec.rb +114 -5
- data/spec/resource_manager_spec.rb +1 -2
- data/spec/spatial_hash_spec.rb +23 -7
- data/spec/spatial_stagehand_spec.rb +97 -0
- data/spec/stage_manager_spec.rb +0 -1
- data/spec/stage_spec.rb +2 -2
- data/spec/viewport_spec.rb +92 -48
- metadata +223 -119
- data/.gitignore +0 -11
- data/History.txt +0 -80
- data/VERSION +0 -1
- data/lib/gamebox/event_compat.rb +0 -285
- data/lib/gamebox/lib/diy.rb +0 -371
- data/lib/gamebox/lib/numbers_ext.rb +0 -3
- data/lib/gamebox/tasks/gamebox_tasks.rb +0 -61
- data/load_paths.rb +0 -20
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
|
3
3
|
class CircleCollidable < CollidableShape
|
4
4
|
|
@@ -7,11 +7,11 @@ class CircleCollidable < CollidableShape
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def center_x
|
10
|
-
actor_x
|
10
|
+
actor_x
|
11
11
|
end
|
12
12
|
|
13
13
|
def center_y
|
14
|
-
actor_y
|
14
|
+
actor_y
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
|
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
5
|
class Graphical < Behavior
|
6
6
|
|
7
|
-
attr_accessor :image, :num_x_tiles, :num_y_tiles
|
7
|
+
attr_accessor :image, :num_x_tiles, :num_y_tiles, :rotation
|
8
8
|
def setup
|
9
9
|
|
10
10
|
@image = @actor.resource_manager.load_actor_image @actor
|
@@ -13,9 +13,10 @@ class Graphical < Behavior
|
|
13
13
|
@num_y_tiles = @opts[:num_y_tiles]
|
14
14
|
@num_x_tiles ||= 1
|
15
15
|
@num_y_tiles ||= 1
|
16
|
+
@rotation = 0.0
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
relegates :image, :graphical, :width, :height, :rotation, :rotation=,
|
19
|
+
:scale, :scale=, :x_scale, :y_scale, :x_scale=, :y_scale=
|
19
20
|
end
|
20
21
|
|
21
22
|
def graphical
|
@@ -34,4 +35,29 @@ class Graphical < Behavior
|
|
34
35
|
@tiled
|
35
36
|
end
|
36
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
|
61
|
+
end
|
62
|
+
|
37
63
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
require 'physics'
|
2
|
-
require 'behavior'
|
3
|
-
require 'inflector'
|
4
|
-
require 'publisher'
|
5
|
-
|
6
1
|
# Physical behavior will place your Actor in a physical world.
|
7
2
|
# example:
|
8
3
|
# :physical => {
|
@@ -29,6 +24,7 @@ class Physical < Behavior
|
|
29
24
|
def setup
|
30
25
|
@parts = {}
|
31
26
|
@shapes = []
|
27
|
+
@constraints = []
|
32
28
|
@segments_groups = []
|
33
29
|
|
34
30
|
@moment_of_inertia = @opts[:moment]
|
@@ -41,11 +37,16 @@ class Physical < Behavior
|
|
41
37
|
|
42
38
|
build_secondary_shapes
|
43
39
|
|
40
|
+
|
44
41
|
register
|
42
|
+
warp(vec2(@actor.x,@actor.y))
|
45
43
|
|
46
44
|
# write code here to keep physics and x,y of actor in sync
|
47
45
|
relegates :x, :y, :x=, :y=, :shape, :body, :parts,
|
48
|
-
:rotation, :warp, :segment_groups, :physical
|
46
|
+
:rotation, :warp, :segment_groups, :physical,
|
47
|
+
:pivot, :pin, :spring, :slide, :groove,
|
48
|
+
:rotary_spring, :rotary_limit, :ratchet,
|
49
|
+
:gear, :motor
|
49
50
|
end
|
50
51
|
|
51
52
|
def setup_friction
|
@@ -101,6 +102,8 @@ class Physical < Behavior
|
|
101
102
|
end
|
102
103
|
|
103
104
|
@shapes << @shape
|
105
|
+
|
106
|
+
@body.p = vec2(actor.x,actor.y)
|
104
107
|
end
|
105
108
|
|
106
109
|
def build_secondary_shapes
|
@@ -108,22 +111,37 @@ class Physical < Behavior
|
|
108
111
|
if @opts[:shapes]
|
109
112
|
for obj in @opts[:shapes]
|
110
113
|
for part_name, part_def in obj
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
+
# TODO merge this with build main shape
|
115
|
+
part_shape = nil
|
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
|
121
|
+
|
122
|
+
# TODO pass all physics params to parts (ie u and e)
|
123
|
+
part_shape.u = @friction
|
124
|
+
verts = part_def[:verts].dup
|
125
|
+
verts << part_def[:verts][0]
|
126
|
+
@segments_groups << verts
|
127
|
+
when :circle
|
128
|
+
part_shape = CP::Shape::Circle.new(@body, part_def[:radius], part_def[:offset])
|
129
|
+
else
|
130
|
+
raise "unsupported sub shape type"
|
131
|
+
end
|
114
132
|
part_shape.collision_type = part_name.to_sym
|
115
|
-
# TODO pass all physics params to parts (ie u and e)
|
116
|
-
part_shape.u = @friction
|
117
133
|
@shapes << part_shape
|
118
|
-
|
119
|
-
verts << part_def[:verts][0]
|
120
|
-
@segments_groups << verts
|
134
|
+
# puts @shapes.inspect
|
121
135
|
end
|
122
136
|
end
|
123
137
|
end
|
124
138
|
end
|
125
139
|
|
126
140
|
def register
|
141
|
+
@actor.when :remove_me do
|
142
|
+
cleanup_constraints
|
143
|
+
end
|
144
|
+
|
127
145
|
physical_obj = self
|
128
146
|
if @actor.stage.respond_to? :register_physical_object
|
129
147
|
if @opts[:fixed]
|
@@ -159,7 +177,6 @@ class Physical < Behavior
|
|
159
177
|
else
|
160
178
|
((body.a) * 180.0 / Math::PI + 90) % 360
|
161
179
|
end
|
162
|
-
# rot_deg = rotation.round % 360
|
163
180
|
end
|
164
181
|
|
165
182
|
def warp(new_p)
|
@@ -171,19 +188,85 @@ class Physical < Behavior
|
|
171
188
|
self
|
172
189
|
end
|
173
190
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
265
|
+
|
266
|
+
def cleanup_constraints
|
267
|
+
@constraints.each do |c|
|
268
|
+
@actor.stage.unregister_physical_constraint c
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
189
272
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Timed < Behavior
|
2
|
+
|
3
|
+
def setup
|
4
|
+
actor.when :remove_me do |actor|
|
5
|
+
clear_timers
|
6
|
+
end
|
7
|
+
|
8
|
+
@timers = []
|
9
|
+
relegates :add_timer, :remove_timer
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_timer(name, ms, recurring = true, &block)
|
13
|
+
timer_name = "#{actor.object_id} #{name}"
|
14
|
+
@timers << timer_name
|
15
|
+
actor.stage.add_timer timer_name, ms do
|
16
|
+
block.call
|
17
|
+
actor.stage.remove_timer timer_name unless recurring
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove_timer(name)
|
22
|
+
timer_name = "#{actor.object_id} #{name}"
|
23
|
+
@timers.delete timer_name
|
24
|
+
actor.stage.remove_timer timer_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear_timers
|
28
|
+
@timers.each do |timer_name|
|
29
|
+
actor.stage.remove_timer timer_name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/gamebox/class_finder.rb
CHANGED
@@ -4,27 +4,7 @@ module ClassFinder
|
|
4
4
|
def find(name)
|
5
5
|
klass = nil
|
6
6
|
klass_name = Inflector.camelize(name)
|
7
|
-
|
8
|
-
begin
|
9
|
-
klass = Object.const_get(klass_name)
|
10
|
-
rescue NameError => ex
|
11
|
-
# not there yet
|
12
|
-
log(:warn, ex)
|
13
|
-
begin
|
14
|
-
require "#{name}"
|
15
|
-
rescue LoadError => ex
|
16
|
-
# maybe its included somewhere else
|
17
|
-
log(:warn, ex)
|
18
|
-
ensure
|
19
|
-
begin
|
20
|
-
klass = Object.const_get(klass_name)
|
21
|
-
rescue Exception => ex
|
22
|
-
# leave this alone.. maybe there isnt a NameView
|
23
|
-
log(:warn, ex)
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
7
|
+
klass = Object.const_get(klass_name) rescue
|
28
8
|
|
29
9
|
klass
|
30
10
|
end
|
data/lib/gamebox/console_app.rb
CHANGED
@@ -1,39 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'irb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
if $0 == __FILE__
|
2
|
+
puts "Connecting to game..."
|
3
|
+
require 'irb'
|
4
|
+
require 'irb/completion'
|
5
|
+
module IRB
|
6
|
+
def IRB.start_session(obj)
|
7
|
+
unless $irb
|
8
|
+
IRB.setup nil
|
9
|
+
## maybe set some opts here, as in parse_opts in irb/init.rb?
|
10
|
+
IRB.load_modules
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
+
workspace = WorkSpace.new(obj)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
if @CONF[:SCRIPT] ## normally, set by parse_opts
|
16
|
+
$irb = Irb.new(workspace, @CONF[:SCRIPT])
|
17
|
+
else
|
18
|
+
$irb = Irb.new(workspace)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
@CONF[:IRB_RC].call($irb.context) if @CONF[:IRB_RC]
|
22
|
+
@CONF[:MAIN_CONTEXT] = $irb.context
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
trap("INT") do
|
25
|
+
$irb.signal_handle
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
catch(:IRB_EXIT) do
|
29
|
+
$irb.eval_input
|
30
|
+
end
|
31
|
+
print "\n"
|
31
32
|
|
32
|
-
|
33
|
+
## might want to reset your app's interrupt handler here
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
require 'drb'
|
37
|
-
DRb.start_service
|
38
|
-
game = DRbObject.new nil, "druby://localhost:7373"
|
39
|
-
IRB.start_session game
|
37
|
+
require 'drb'
|
38
|
+
DRb.start_service
|
39
|
+
game = DRbObject.new nil, "druby://localhost:7373"
|
40
|
+
IRB.start_session game
|
41
|
+
end
|
@@ -0,0 +1,481 @@
|
|
1
|
+
enum = 0
|
2
|
+
MOUSE_LEFT = enum += 1
|
3
|
+
MOUSE_MIDDLE = enum += 1
|
4
|
+
MOUSE_RIGHT = enum += 1
|
5
|
+
MOUSE_LMASK = enum += 1
|
6
|
+
MOUSE_MMASK = enum += 1
|
7
|
+
MOUSE_RMASK = enum += 1
|
8
|
+
|
9
|
+
K_UNKNOWN = enum += 1
|
10
|
+
K_FIRST = enum += 1
|
11
|
+
K_BACKSPACE = KbBackspace
|
12
|
+
K_TAB = KbTab
|
13
|
+
K_CLEAR = enum += 1
|
14
|
+
K_RETURN = KbReturn
|
15
|
+
K_PAUSE = enum += 1
|
16
|
+
K_ESCAPE = KbEscape
|
17
|
+
K_SPACE = KbSpace
|
18
|
+
K_EXCLAIM = enum += 1
|
19
|
+
K_QUOTEDBL = enum += 1
|
20
|
+
K_HASH = enum += 1
|
21
|
+
K_DOLLAR = enum += 1
|
22
|
+
K_AMPERSAND = enum += 1
|
23
|
+
K_QUOTE = enum += 1
|
24
|
+
K_LEFTPAREN = enum += 1
|
25
|
+
K_RIGHTPAREN = enum += 1
|
26
|
+
K_ASTERISK = enum += 1
|
27
|
+
K_PLUS = enum += 1
|
28
|
+
K_COMMA = enum += 1
|
29
|
+
K_MINUS = enum += 1
|
30
|
+
K_PERIOD = enum += 1
|
31
|
+
K_SLASH = enum += 1
|
32
|
+
K_0 = Kb0
|
33
|
+
K_1 = Kb1
|
34
|
+
K_2 = Kb2
|
35
|
+
K_3 = Kb3
|
36
|
+
K_4 = Kb4
|
37
|
+
K_5 = Kb5
|
38
|
+
K_6 = Kb6
|
39
|
+
K_7 = Kb7
|
40
|
+
K_8 = Kb8
|
41
|
+
K_9 = Kb9
|
42
|
+
K_COLON = enum += 1
|
43
|
+
K_SEMICOLON = enum += 1
|
44
|
+
K_LESS = enum += 1
|
45
|
+
K_EQUALS = enum += 1
|
46
|
+
K_GREATER = enum += 1
|
47
|
+
K_QUESTION = enum += 1
|
48
|
+
K_AT = enum += 1
|
49
|
+
K_LEFTBRACKET = enum += 1
|
50
|
+
K_BACKSLASH = enum += 1
|
51
|
+
K_RIGHTBRACKET = enum += 1
|
52
|
+
K_CARET = enum += 1
|
53
|
+
K_UNDERSCORE = enum += 1
|
54
|
+
K_BACKQUOTE = enum += 1
|
55
|
+
K_A = KbA
|
56
|
+
K_B = KbB
|
57
|
+
K_C = KbC
|
58
|
+
K_D = KbD
|
59
|
+
K_E = KbE
|
60
|
+
K_F = KbF
|
61
|
+
K_G = KbG
|
62
|
+
K_H = KbH
|
63
|
+
K_I = KbI
|
64
|
+
K_J = KbJ
|
65
|
+
K_K = KbK
|
66
|
+
K_L = KbL
|
67
|
+
K_M = KbM
|
68
|
+
K_N = KbN
|
69
|
+
K_O = KbO
|
70
|
+
K_P = KbP
|
71
|
+
K_Q = KbQ
|
72
|
+
K_R = KbR
|
73
|
+
K_S = KbS
|
74
|
+
K_T = KbT
|
75
|
+
K_U = KbU
|
76
|
+
K_V = KbV
|
77
|
+
K_W = KbW
|
78
|
+
K_X = KbX
|
79
|
+
K_Y = KbY
|
80
|
+
K_Z = KbZ
|
81
|
+
K_DELETE = KbDelete
|
82
|
+
|
83
|
+
K_WORLD_0 = enum += 1
|
84
|
+
K_WORLD_1 = enum += 1
|
85
|
+
K_WORLD_2 = enum += 1
|
86
|
+
K_WORLD_3 = enum += 1
|
87
|
+
K_WORLD_4 = enum += 1
|
88
|
+
K_WORLD_5 = enum += 1
|
89
|
+
K_WORLD_6 = enum += 1
|
90
|
+
K_WORLD_7 = enum += 1
|
91
|
+
K_WORLD_8 = enum += 1
|
92
|
+
K_WORLD_9 = enum += 1
|
93
|
+
K_WORLD_10 = enum += 1
|
94
|
+
K_WORLD_11 = enum += 1
|
95
|
+
K_WORLD_12 = enum += 1
|
96
|
+
K_WORLD_13 = enum += 1
|
97
|
+
K_WORLD_14 = enum += 1
|
98
|
+
K_WORLD_15 = enum += 1
|
99
|
+
K_WORLD_16 = enum += 1
|
100
|
+
K_WORLD_17 = enum += 1
|
101
|
+
K_WORLD_18 = enum += 1
|
102
|
+
K_WORLD_19 = enum += 1
|
103
|
+
K_WORLD_20 = enum += 1
|
104
|
+
K_WORLD_21 = enum += 1
|
105
|
+
K_WORLD_22 = enum += 1
|
106
|
+
K_WORLD_23 = enum += 1
|
107
|
+
K_WORLD_24 = enum += 1
|
108
|
+
K_WORLD_25 = enum += 1
|
109
|
+
K_WORLD_26 = enum += 1
|
110
|
+
K_WORLD_27 = enum += 1
|
111
|
+
K_WORLD_28 = enum += 1
|
112
|
+
K_WORLD_29 = enum += 1
|
113
|
+
K_WORLD_30 = enum += 1
|
114
|
+
K_WORLD_31 = enum += 1
|
115
|
+
K_WORLD_32 = enum += 1
|
116
|
+
K_WORLD_33 = enum += 1
|
117
|
+
K_WORLD_34 = enum += 1
|
118
|
+
K_WORLD_35 = enum += 1
|
119
|
+
K_WORLD_36 = enum += 1
|
120
|
+
K_WORLD_37 = enum += 1
|
121
|
+
K_WORLD_38 = enum += 1
|
122
|
+
K_WORLD_39 = enum += 1
|
123
|
+
K_WORLD_40 = enum += 1
|
124
|
+
K_WORLD_41 = enum += 1
|
125
|
+
K_WORLD_42 = enum += 1
|
126
|
+
K_WORLD_43 = enum += 1
|
127
|
+
K_WORLD_44 = enum += 1
|
128
|
+
K_WORLD_45 = enum += 1
|
129
|
+
K_WORLD_46 = enum += 1
|
130
|
+
K_WORLD_47 = enum += 1
|
131
|
+
K_WORLD_48 = enum += 1
|
132
|
+
K_WORLD_49 = enum += 1
|
133
|
+
K_WORLD_50 = enum += 1
|
134
|
+
K_WORLD_51 = enum += 1
|
135
|
+
K_WORLD_52 = enum += 1
|
136
|
+
K_WORLD_53 = enum += 1
|
137
|
+
K_WORLD_54 = enum += 1
|
138
|
+
K_WORLD_55 = enum += 1
|
139
|
+
K_WORLD_56 = enum += 1
|
140
|
+
K_WORLD_57 = enum += 1
|
141
|
+
K_WORLD_58 = enum += 1
|
142
|
+
K_WORLD_59 = enum += 1
|
143
|
+
K_WORLD_60 = enum += 1
|
144
|
+
K_WORLD_61 = enum += 1
|
145
|
+
K_WORLD_62 = enum += 1
|
146
|
+
K_WORLD_63 = enum += 1
|
147
|
+
K_WORLD_64 = enum += 1
|
148
|
+
K_WORLD_65 = enum += 1
|
149
|
+
K_WORLD_66 = enum += 1
|
150
|
+
K_WORLD_67 = enum += 1
|
151
|
+
K_WORLD_68 = enum += 1
|
152
|
+
K_WORLD_69 = enum += 1
|
153
|
+
K_WORLD_70 = enum += 1
|
154
|
+
K_WORLD_71 = enum += 1
|
155
|
+
K_WORLD_72 = enum += 1
|
156
|
+
K_WORLD_73 = enum += 1
|
157
|
+
K_WORLD_74 = enum += 1
|
158
|
+
K_WORLD_75 = enum += 1
|
159
|
+
K_WORLD_76 = enum += 1
|
160
|
+
K_WORLD_77 = enum += 1
|
161
|
+
K_WORLD_78 = enum += 1
|
162
|
+
K_WORLD_79 = enum += 1
|
163
|
+
K_WORLD_80 = enum += 1
|
164
|
+
K_WORLD_81 = enum += 1
|
165
|
+
K_WORLD_82 = enum += 1
|
166
|
+
K_WORLD_83 = enum += 1
|
167
|
+
K_WORLD_84 = enum += 1
|
168
|
+
K_WORLD_85 = enum += 1
|
169
|
+
K_WORLD_86 = enum += 1
|
170
|
+
K_WORLD_87 = enum += 1
|
171
|
+
K_WORLD_88 = enum += 1
|
172
|
+
K_WORLD_89 = enum += 1
|
173
|
+
K_WORLD_90 = enum += 1
|
174
|
+
K_WORLD_91 = enum += 1
|
175
|
+
K_WORLD_92 = enum += 1
|
176
|
+
K_WORLD_93 = enum += 1
|
177
|
+
K_WORLD_94 = enum += 1
|
178
|
+
K_WORLD_95 = enum += 1
|
179
|
+
|
180
|
+
K_KP0 = enum += 1
|
181
|
+
K_KP1 = enum += 1
|
182
|
+
K_KP2 = enum += 1
|
183
|
+
K_KP3 = enum += 1
|
184
|
+
K_KP4 = enum += 1
|
185
|
+
K_KP5 = enum += 1
|
186
|
+
K_KP6 = enum += 1
|
187
|
+
K_KP7 = enum += 1
|
188
|
+
K_KP8 = enum += 1
|
189
|
+
K_KP9 = enum += 1
|
190
|
+
K_KP_PERIOD = enum += 1
|
191
|
+
K_KP_DIVIDE = enum += 1
|
192
|
+
K_KP_MULTIPLY = enum += 1
|
193
|
+
K_KP_MINUS = enum += 1
|
194
|
+
K_KP_PLUS = enum += 1
|
195
|
+
K_KP_ENTER = enum += 1
|
196
|
+
K_KP_EQUALS = enum += 1
|
197
|
+
|
198
|
+
K_UP = KbUp
|
199
|
+
K_DOWN = KbDown
|
200
|
+
K_RIGHT = KbRight
|
201
|
+
K_LEFT = KbLeft
|
202
|
+
K_INSERT = enum += 1
|
203
|
+
K_HOME = KbHome
|
204
|
+
K_END = KbEnd
|
205
|
+
K_PAGEUP = enum += 1
|
206
|
+
K_PAGEDOWN = enum += 1
|
207
|
+
|
208
|
+
K_F1 = enum += 1
|
209
|
+
K_F2 = enum += 1
|
210
|
+
K_F3 = enum += 1
|
211
|
+
K_F4 = enum += 1
|
212
|
+
K_F5 = enum += 1
|
213
|
+
K_F6 = enum += 1
|
214
|
+
K_F7 = enum += 1
|
215
|
+
K_F8 = enum += 1
|
216
|
+
K_F9 = enum += 1
|
217
|
+
K_F10 = enum += 1
|
218
|
+
K_F11 = enum += 1
|
219
|
+
K_F12 = enum += 1
|
220
|
+
K_F13 = enum += 1
|
221
|
+
K_F14 = enum += 1
|
222
|
+
K_F15 = enum += 1
|
223
|
+
|
224
|
+
K_NUMLOCK = enum += 1
|
225
|
+
K_CAPSLOCK = enum += 1
|
226
|
+
K_SCROLLOCK = enum += 1
|
227
|
+
K_RSHIFT = enum += 1
|
228
|
+
K_LSHIFT = enum += 1
|
229
|
+
K_RCTRL = enum += 1
|
230
|
+
K_LCTRL = enum += 1
|
231
|
+
K_RALT = enum += 1
|
232
|
+
K_LALT = enum += 1
|
233
|
+
K_RMETA = enum += 1
|
234
|
+
K_LMETA = enum += 1
|
235
|
+
K_LSUPER = enum += 1
|
236
|
+
K_RSUPER = enum += 1
|
237
|
+
K_MODE = enum += 1
|
238
|
+
|
239
|
+
K_HELP = enum += 1
|
240
|
+
K_PRINT = enum += 1
|
241
|
+
K_SYSREQ = enum += 1
|
242
|
+
K_BREAK = enum += 1
|
243
|
+
K_MENU = enum += 1
|
244
|
+
K_POWER = enum += 1
|
245
|
+
K_EURO = enum += 1
|
246
|
+
K_LAST = enum += 1
|
247
|
+
|
248
|
+
K_MOD_NONE = enum += 1
|
249
|
+
K_MOD_LSHIFT = enum += 1
|
250
|
+
K_MOD_RSHIFT = enum += 1
|
251
|
+
K_MOD_LCTRL = enum += 1
|
252
|
+
K_MOD_RCTRL = enum += 1
|
253
|
+
K_MOD_LALT = enum += 1
|
254
|
+
K_MOD_RALT = enum += 1
|
255
|
+
K_MOD_LMETA = enum += 1
|
256
|
+
K_MOD_RMETA = enum += 1
|
257
|
+
K_MOD_NUM = enum += 1
|
258
|
+
K_MOD_CAPS = enum += 1
|
259
|
+
K_MOD_MODE = enum += 1
|
260
|
+
K_MOD_RESERVED = enum += 1
|
261
|
+
|
262
|
+
K_MOD_CTRL = enum += 1
|
263
|
+
K_MOD_SHIFT = enum += 1
|
264
|
+
K_MOD_ALT = enum += 1
|
265
|
+
K_MOD_META = enum += 1
|
266
|
+
|
267
|
+
|
268
|
+
# key/mouse event mappings
|
269
|
+
# Hash to translate mouse button sym to string
|
270
|
+
MOUSE2STR = {
|
271
|
+
MOUSE_LEFT => "left",
|
272
|
+
MOUSE_MIDDLE => "middle",
|
273
|
+
MOUSE_RIGHT => "right"
|
274
|
+
}
|
275
|
+
# And to translate the other way...
|
276
|
+
STR2MOUSE = MOUSE2STR.invert()
|
277
|
+
# And allow numbers too (1 = left, so on)...
|
278
|
+
STR2MOUSE[1] = MOUSE_LEFT
|
279
|
+
STR2MOUSE[2] = MOUSE_MIDDLE
|
280
|
+
STR2MOUSE[3] = MOUSE_RIGHT
|
281
|
+
|
282
|
+
# All the keys which have ASCII print values
|
283
|
+
# It is 87 lines from here to the closing }, if you want to skip it...
|
284
|
+
KEY2ASCII = {
|
285
|
+
K_BACKSPACE => "\b",
|
286
|
+
K_TAB => "\t",
|
287
|
+
K_RETURN => "\n", #SDL docs: "\r". Win vs *nix? What about Mac?
|
288
|
+
K_ESCAPE => "^[",
|
289
|
+
K_SPACE => " ",
|
290
|
+
K_EXCLAIM => "!",
|
291
|
+
K_QUOTEDBL => "\"",
|
292
|
+
K_HASH => "#",
|
293
|
+
K_DOLLAR => "$",
|
294
|
+
K_AMPERSAND => "&",
|
295
|
+
K_QUOTE => "\'",
|
296
|
+
K_LEFTPAREN => "(",
|
297
|
+
K_RIGHTPAREN => ")",
|
298
|
+
K_ASTERISK => "*",
|
299
|
+
K_PLUS => "+",
|
300
|
+
K_COMMA => ",",
|
301
|
+
K_MINUS => "-",
|
302
|
+
K_PERIOD => ".",
|
303
|
+
K_SLASH => "/",
|
304
|
+
K_0 => "0",
|
305
|
+
K_1 => "1",
|
306
|
+
K_2 => "2",
|
307
|
+
K_3 => "3",
|
308
|
+
K_4 => "4",
|
309
|
+
K_5 => "5",
|
310
|
+
K_6 => "6",
|
311
|
+
K_7 => "7",
|
312
|
+
K_8 => "8",
|
313
|
+
K_9 => "9",
|
314
|
+
K_COLON => ":",
|
315
|
+
K_SEMICOLON => ";",
|
316
|
+
K_LESS => "<",
|
317
|
+
K_EQUALS => "=",
|
318
|
+
K_GREATER => ">",
|
319
|
+
K_QUESTION => "?",
|
320
|
+
K_AT => "@",
|
321
|
+
K_LEFTBRACKET => "[",
|
322
|
+
K_BACKSLASH => "\\",
|
323
|
+
K_RIGHTBRACKET => "]",
|
324
|
+
K_CARET => "^",
|
325
|
+
K_UNDERSCORE => "_",
|
326
|
+
K_BACKQUOTE => "`",
|
327
|
+
K_A => "a",
|
328
|
+
K_B => "b",
|
329
|
+
K_C => "c",
|
330
|
+
K_D => "d",
|
331
|
+
K_E => "e",
|
332
|
+
K_F => "f",
|
333
|
+
K_G => "g",
|
334
|
+
K_H => "h",
|
335
|
+
K_I => "i",
|
336
|
+
K_J => "j",
|
337
|
+
K_K => "k",
|
338
|
+
K_L => "l",
|
339
|
+
K_M => "m",
|
340
|
+
K_N => "n",
|
341
|
+
K_O => "o",
|
342
|
+
K_P => "p",
|
343
|
+
K_Q => "q",
|
344
|
+
K_R => "r",
|
345
|
+
K_S => "s",
|
346
|
+
K_T => "t",
|
347
|
+
K_U => "u",
|
348
|
+
K_V => "v",
|
349
|
+
K_W => "w",
|
350
|
+
K_X => "x",
|
351
|
+
K_Y => "y",
|
352
|
+
K_Z => "z",
|
353
|
+
K_KP0 => "0",
|
354
|
+
K_KP1 => "1",
|
355
|
+
K_KP2 => "2",
|
356
|
+
K_KP3 => "3",
|
357
|
+
K_KP4 => "4",
|
358
|
+
K_KP5 => "5",
|
359
|
+
K_KP6 => "6",
|
360
|
+
K_KP7 => "7",
|
361
|
+
K_KP8 => "8",
|
362
|
+
K_KP9 => "9",
|
363
|
+
K_KP_PERIOD => ".",
|
364
|
+
K_KP_DIVIDE => "/",
|
365
|
+
K_KP_MULTIPLY => "*",
|
366
|
+
K_KP_MINUS => "-",
|
367
|
+
K_KP_PLUS => "+",
|
368
|
+
K_KP_ENTER => "\n", #again, SDL docs say "\r"
|
369
|
+
K_KP_EQUALS => "=",
|
370
|
+
}
|
371
|
+
|
372
|
+
# And to translate the other way...
|
373
|
+
ASCII2KEY = KEY2ASCII.invert()
|
374
|
+
# accept uppercase letters too, return same as lowercase version:
|
375
|
+
("a".."z").each{ |letter| ASCII2KEY[letter.upcase] = ASCII2KEY[letter] }
|
376
|
+
|
377
|
+
# All the keys that are affected by the Shift key, in lower case
|
378
|
+
# 49 lines from here to the end of the hash
|
379
|
+
KEY2LOWER = {
|
380
|
+
K_QUOTE => "\'",
|
381
|
+
K_COMMA => ",",
|
382
|
+
K_MINUS => "-",
|
383
|
+
K_PERIOD => ".",
|
384
|
+
K_SLASH => "/",
|
385
|
+
K_0 => "0",
|
386
|
+
K_1 => "1",
|
387
|
+
K_2 => "2",
|
388
|
+
K_3 => "3",
|
389
|
+
K_4 => "4",
|
390
|
+
K_5 => "5",
|
391
|
+
K_6 => "6",
|
392
|
+
K_7 => "7",
|
393
|
+
K_8 => "8",
|
394
|
+
K_9 => "9",
|
395
|
+
K_SEMICOLON => ";",
|
396
|
+
K_EQUALS => "=",
|
397
|
+
K_LEFTBRACKET => "[",
|
398
|
+
K_BACKSLASH => "\\",
|
399
|
+
K_RIGHTBRACKET => "]",
|
400
|
+
K_BACKQUOTE => "`",
|
401
|
+
K_A => "a",
|
402
|
+
K_B => "b",
|
403
|
+
K_C => "c",
|
404
|
+
K_D => "d",
|
405
|
+
K_E => "e",
|
406
|
+
K_F => "f",
|
407
|
+
K_G => "g",
|
408
|
+
K_H => "h",
|
409
|
+
K_I => "i",
|
410
|
+
K_J => "j",
|
411
|
+
K_K => "k",
|
412
|
+
K_L => "l",
|
413
|
+
K_M => "m",
|
414
|
+
K_N => "n",
|
415
|
+
K_O => "o",
|
416
|
+
K_P => "p",
|
417
|
+
K_Q => "q",
|
418
|
+
K_R => "r",
|
419
|
+
K_S => "s",
|
420
|
+
K_T => "t",
|
421
|
+
K_U => "u",
|
422
|
+
K_V => "v",
|
423
|
+
K_W => "w",
|
424
|
+
K_X => "x",
|
425
|
+
K_Y => "y",
|
426
|
+
K_Z => "z",
|
427
|
+
}
|
428
|
+
|
429
|
+
# All the keys that are affected by the Shift key, in UPPER case
|
430
|
+
# 49 lines from here to the end of the hash
|
431
|
+
KEY2UPPER = {
|
432
|
+
K_QUOTE => "\"",
|
433
|
+
K_COMMA => "<",
|
434
|
+
K_MINUS => "_",
|
435
|
+
K_PERIOD => ">",
|
436
|
+
K_SLASH => "?",
|
437
|
+
K_0 => ")",
|
438
|
+
K_1 => "!",
|
439
|
+
K_2 => "@",
|
440
|
+
K_3 => "#",
|
441
|
+
K_4 => "$",
|
442
|
+
K_5 => "%",
|
443
|
+
K_6 => "^",
|
444
|
+
K_7 => "&",
|
445
|
+
K_8 => "*",
|
446
|
+
K_9 => "(",
|
447
|
+
K_SEMICOLON => ":",
|
448
|
+
K_EQUALS => "+",
|
449
|
+
K_LEFTBRACKET => "{",
|
450
|
+
K_BACKSLASH => "|",
|
451
|
+
K_RIGHTBRACKET => "}",
|
452
|
+
K_BACKQUOTE => "~",
|
453
|
+
K_A => "A",
|
454
|
+
K_B => "B",
|
455
|
+
K_C => "C",
|
456
|
+
K_D => "D",
|
457
|
+
K_E => "E",
|
458
|
+
K_F => "F",
|
459
|
+
K_G => "G",
|
460
|
+
K_H => "H",
|
461
|
+
K_I => "I",
|
462
|
+
K_J => "J",
|
463
|
+
K_K => "K",
|
464
|
+
K_L => "L",
|
465
|
+
K_M => "M",
|
466
|
+
K_N => "N",
|
467
|
+
K_O => "O",
|
468
|
+
K_P => "P",
|
469
|
+
K_Q => "Q",
|
470
|
+
K_R => "R",
|
471
|
+
K_S => "S",
|
472
|
+
K_T => "T",
|
473
|
+
K_U => "U",
|
474
|
+
K_V => "V",
|
475
|
+
K_W => "W",
|
476
|
+
K_X => "X",
|
477
|
+
K_Y => "Y",
|
478
|
+
K_Z => "Z",
|
479
|
+
}
|
480
|
+
|
481
|
+
|