rubygame 2.2.0-i586-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +201 -0
- data/README +139 -0
- data/ROADMAP +43 -0
- data/Rakefile +409 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/MANIFEST +25 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.o +0 -0
- data/ext/rubygame/rubygame_image.c +108 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +33 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +764 -0
- data/ext/rubygame/rubygame_mixer.h +62 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +209 -0
- data/ext/rubygame/rubygame_shared.h +60 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1147 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame/MANIFEST +12 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color/models/base.rb +106 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/lib/rubygame.rb +41 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +313 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +75 -0
- data/samples/demo_rubygame.rb +284 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- metadata +152 -0
@@ -0,0 +1,265 @@
|
|
1
|
+
# Hotspot, a mixin module to extend an object with custom, named, relative
|
2
|
+
# position offsets.
|
3
|
+
#--
|
4
|
+
# Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
5
|
+
# Copyright (C) 2004-2007 John Croisant
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU Lesser General Public
|
9
|
+
# License as published by the Free Software Foundation; either
|
10
|
+
# version 2.1 of the License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
# Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public
|
18
|
+
# License along with this library; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#++
|
21
|
+
|
22
|
+
module Rubygame
|
23
|
+
|
24
|
+
# *NOTE*: you must require 'rubygame/hotspot' manually to gain access to
|
25
|
+
# Rubygame::Hotspot. It is not imported with Rubygame by default!
|
26
|
+
#
|
27
|
+
# Hotspot is a mixin module to extend an object with "hotspots": custom,
|
28
|
+
# named, relative position offsets. Hotspots can be defined relative to the
|
29
|
+
# origin, to another hotspot, or to the results of a method (via a
|
30
|
+
# 'smart' hotspot).
|
31
|
+
#
|
32
|
+
# There are two types of hotspots, simple and 'smart'.
|
33
|
+
#
|
34
|
+
# Simple hotspots are an Array of three values, an x offset, a y offset,
|
35
|
+
# and the label of another hotspot relative to which this hotspot is defined.
|
36
|
+
# If the last argument is omitted or nil, the hotspot is defined relative
|
37
|
+
# to the true origin (i.e. (0,0), the top-left corner of the Screen).
|
38
|
+
# See #new_hotspot.
|
39
|
+
#
|
40
|
+
# Smart hotspots, or 'smartspots' for short, act as a proxy to the object's
|
41
|
+
# methods. Each time a smartspot is evaluated, it calls the object's method
|
42
|
+
# of the same name as the smartspot, and uses the results of the method as
|
43
|
+
# x and y offsets. Therefore, smartspots only work for methods which:
|
44
|
+
# 1. take no arguments
|
45
|
+
# 2. return an Array with 2 Numeric values (or something else that responds
|
46
|
+
# to #[]
|
47
|
+
#
|
48
|
+
# By adding a smartspot to a Rect, for example, you could define simple
|
49
|
+
# hotspots relative to its Rect#center; then, even if the Rect moves or
|
50
|
+
# changes size, the smartspot will always to evaluate to its true center.
|
51
|
+
# See #new_smartspot.
|
52
|
+
#
|
53
|
+
#--
|
54
|
+
# ((Old documentation/brainstorming))
|
55
|
+
# As an example, consider an object which represents a person's face: eyes,
|
56
|
+
# ears, nose, mouth, etc. You might make a face and define several hotspots
|
57
|
+
# like so:
|
58
|
+
#
|
59
|
+
# myface = Face.new() # Create a new face, with no hotspots.
|
60
|
+
# myface.extend(Hotspot) # Extend myface with hotspot ability.
|
61
|
+
# myface.new_hotspot \ # Define some new hotspots: ...
|
62
|
+
# :nose => [10,5, :center], # the nose, relative to face's center,
|
63
|
+
# :left_eye => [-5,-2, :nose], # the left eye, left and above the nose,
|
64
|
+
# :left_brow => [0,-5, :left_eye], # the left eye-brow, above the left eye.
|
65
|
+
#
|
66
|
+
# Please note that +:center+ is a "virtual" hotspot. When the coordinates of
|
67
|
+
# +:center+ are requested, +myface+'s #center method is called* and the
|
68
|
+
# results used as the coordinates. (* Technically, +myface+ is sent
|
69
|
+
# +:center+, which is not exactly the same as calling #center.)
|
70
|
+
#
|
71
|
+
# Now, suppose we want to find out where :left_brow is, in absolute
|
72
|
+
# coordinates (i.e. relative to the origin). We can do this, even if +myface+
|
73
|
+
# has moved, or the hotspots have been changed:
|
74
|
+
#
|
75
|
+
# myface.left_brow # => [5,-2]
|
76
|
+
# myface.move(20,-12) # moves the face right and up
|
77
|
+
# myface.left_brow # => [25,-14]
|
78
|
+
# myface.new_hotspot \
|
79
|
+
# :left_eye => [-10,3] # redefine the left_eye hotspot
|
80
|
+
# myface.left_brow # => [20,-9]
|
81
|
+
#
|
82
|
+
# Where do [5,-2], [25,-24], and [20,-9] come from? They are the vector sums
|
83
|
+
# of each hotspot in the chain: left_brow, left_eye, nose, and center. See
|
84
|
+
# #hotspot for more information.
|
85
|
+
#++
|
86
|
+
#
|
87
|
+
module Hotspot
|
88
|
+
# :call-seq: def_hotspot label => [x,y,parent]
|
89
|
+
#
|
90
|
+
# Define +label+ as a simple hotspot, a custom reference coordinate
|
91
|
+
# point +x+ pixels to the right and +y+ pixels below the hotspot whose
|
92
|
+
# label is +parent+.
|
93
|
+
# You may omit +parent+, in which case the hotspot will evaluate relative
|
94
|
+
# to the origin, i.e. the top-left corner of the Screen.
|
95
|
+
#
|
96
|
+
# See also #def_smartspot to create a 'smart hotspot'.
|
97
|
+
#
|
98
|
+
# +label+ must be usable as a key in a Hash table. Additionally, if you
|
99
|
+
# want <code>myobject.{label}</code> to work like
|
100
|
+
# <code>myobject.hotspot({label})</code>, +label+ must be a :symbol.
|
101
|
+
#
|
102
|
+
# *IMPORTANT*: Do NOT create circular hotspot chains (e.g. a -> b -> a).
|
103
|
+
# Doing so will raise SystemStackError when #hotspot is asked to evaluate
|
104
|
+
# any hotspot in that chain. Hotspots are not yet smart enough to detect
|
105
|
+
# circular chains.
|
106
|
+
#
|
107
|
+
# Hotspots can be defined in any order, as long as you define all the
|
108
|
+
# hotspots in a chain before that chain is evaluated with #hotspot.
|
109
|
+
#
|
110
|
+
# You may define multiple hotspots simultaneously by separating the
|
111
|
+
# definitions by commas. For example:
|
112
|
+
#
|
113
|
+
# def_hotspot label => [x,y,parent], label2 => [x,y,parent]
|
114
|
+
#
|
115
|
+
# Users of the Rake library will recognize this style of syntax.
|
116
|
+
# It is simply constructing a Hash object and passing it as the
|
117
|
+
# only argument to #new_hotspot. The above code is equivalent to:
|
118
|
+
#
|
119
|
+
# def_hotspot( { label => [x,y,parent], label2 => [x,y,parent] } )
|
120
|
+
def def_hotspot(dfn)
|
121
|
+
@hotspots.update(dfn)
|
122
|
+
rescue NoMethodError => e
|
123
|
+
unless defined? @hotspots
|
124
|
+
@hotspots = Hash.new
|
125
|
+
retry
|
126
|
+
else raise e
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Remove all simple hotspots whose label is included in +*labels+.
|
131
|
+
def undef_hotspot(*labels)
|
132
|
+
labels.flatten.each do |l|
|
133
|
+
@hotspots.delete(l)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# True if +label+ has been defined as a simple hotspot.
|
138
|
+
def defined_hotspot?(label)
|
139
|
+
@hotspots.include? label
|
140
|
+
rescue NoMethodError => e
|
141
|
+
unless defined? @hotspots
|
142
|
+
false
|
143
|
+
else raise e
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# :call-seq: hotspot(label)
|
148
|
+
#
|
149
|
+
# Returns the absolute coordinates represented by the hotspot +label+.
|
150
|
+
# Will return nil if the hotspot (or one of its ancestors) does not exist.
|
151
|
+
#
|
152
|
+
# This method will recursively evaluate the hotspot, it's parent hotspot
|
153
|
+
# (if any), and so on, until a parent-less hotspot or a smartspot is found.
|
154
|
+
#
|
155
|
+
# (*NOTE*: this means that a circular chains (e.g. a -> b -> a)
|
156
|
+
# will keep going around and around until the ruby interpreter
|
157
|
+
# raises SystemStackError!)
|
158
|
+
#
|
159
|
+
# The final value returned by this method will be the vector component sum
|
160
|
+
# of all the hotspots in the chain. For example, if you have this chain:
|
161
|
+
#
|
162
|
+
# :a => [1, 2, :b]
|
163
|
+
# :b => [4, 8, :c]
|
164
|
+
# :c => [16,32]
|
165
|
+
#
|
166
|
+
# the value returned for +:a+ would be [21,42], i.e. [1+4+16, 2+8+32]
|
167
|
+
#--
|
168
|
+
# The x and y arguments are used for recursive accumulation, although
|
169
|
+
# I suppose you could use them to create a temporary offset by giving
|
170
|
+
# something besides zero when you look up a hotspot.
|
171
|
+
#++
|
172
|
+
def hotspot(label,x=0,y=0)
|
173
|
+
a = @hotspots[label]
|
174
|
+
if a[2].nil? # has no parent
|
175
|
+
[x+a[0],y+a[1]]
|
176
|
+
else # has a parent
|
177
|
+
hotspot(a[2],x+a[0],y+a[1])
|
178
|
+
end
|
179
|
+
rescue NoMethodError => e
|
180
|
+
if not(defined? @hotspots)
|
181
|
+
return nil
|
182
|
+
elsif a.nil?
|
183
|
+
smartspot(label,x,y)
|
184
|
+
else raise e
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Define each label in +*labels+ as a smartspot ('smart hotspot').
|
189
|
+
#
|
190
|
+
# To prevent outside objects from abusing hotspots to call arbitrary
|
191
|
+
# methods, a smartspot must be defined for each method before it can be
|
192
|
+
# used as a parent to a hotspot.
|
193
|
+
#
|
194
|
+
# The label must be a :symbol, and it must be identical to the name of the
|
195
|
+
# method to be called.
|
196
|
+
def def_smartspot(*labels)
|
197
|
+
@smartspots += labels.flatten
|
198
|
+
@smartspots.uniq!
|
199
|
+
rescue NoMethodError => e
|
200
|
+
unless defined? @smartspots
|
201
|
+
@smartspots = Array.new
|
202
|
+
retry
|
203
|
+
else raise e
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# Remove all smartspots whose label is included in +*labels+.
|
208
|
+
def undef_smartspot(*labels)
|
209
|
+
@smartspots -= labels.flatten
|
210
|
+
end
|
211
|
+
|
212
|
+
# True if +label+ has been defined as a smartspot.
|
213
|
+
def defined_smartspot?(label)
|
214
|
+
@smartspots.include? label
|
215
|
+
rescue NoMethodError => e
|
216
|
+
unless defined? @smartspots
|
217
|
+
false
|
218
|
+
else raise e
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# :call-seq: smartspot(label)
|
223
|
+
#
|
224
|
+
# Evaluate the smartspot +label+, calling the method of the same name as
|
225
|
+
# +label+. Will return nil if no such smartspot has been defined.
|
226
|
+
#--
|
227
|
+
# The x and y arguments are used for recursive accumulation.
|
228
|
+
#++
|
229
|
+
def smartspot(label,x=0,y=0)
|
230
|
+
if @smartspots.include? label
|
231
|
+
a = self.send(label)
|
232
|
+
[x+a[0],y+a[1]]
|
233
|
+
else
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
rescue NoMethodError => e
|
237
|
+
unless defined? @smartspots
|
238
|
+
nil
|
239
|
+
else raise e
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
#--
|
244
|
+
#
|
245
|
+
# TODO:
|
246
|
+
# Methods for changing the position of the object indirectly,
|
247
|
+
# by saying where the hotspot should be.
|
248
|
+
# You could do this: my_object.foot = [5,3], and if foot was defined
|
249
|
+
# relative to, say, #center, it would set center = [5-x_offset, 3-y_offset]
|
250
|
+
#
|
251
|
+
# It should be recursive to work with chains of hotspots too.
|
252
|
+
#
|
253
|
+
#++
|
254
|
+
|
255
|
+
alias :old_method_missing :method_missing
|
256
|
+
|
257
|
+
def method_missing(symbol,*args)
|
258
|
+
if have_hotspot?(symbol)
|
259
|
+
hotspot(symbol)
|
260
|
+
else old_method_missing(symbol,*args)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# :enddoc:
|
2
|
+
module Rubygame
|
3
|
+
ALL_KEYS = {\
|
4
|
+
K_BACKSPACE => ["\b", "backspace"],\
|
5
|
+
K_TAB => ["\t", "tab"],\
|
6
|
+
K_CLEAR => [nil, "clear"],\
|
7
|
+
K_RETURN => ["\n", "return", "enter"],\
|
8
|
+
K_PAUSE => [nil, "pause"],\
|
9
|
+
K_ESCAPE => ["^[", "escape"],\
|
10
|
+
K_SPACE => [" ", "space"],\
|
11
|
+
K_EXCLAIM => ["!", "exclamation_mark", "exclaim"],\
|
12
|
+
K_QUOTEDBL => ["\"", "double_quote"],\
|
13
|
+
K_HASH => ["#", "hash", "pound", "bang"],\
|
14
|
+
K_DOLLAR => ["$", "dollar"],\
|
15
|
+
K_AMPERSAND => ["&", "ampersand", "and"],\
|
16
|
+
K_QUOTE => ["'", "quote"],\
|
17
|
+
K_LEFTPAREN => ["(", "left_parenthesis", "lparen"],\
|
18
|
+
K_RIGHTPAREN => [")", "right_parenthesis","rparen"],\
|
19
|
+
K_ASTERISK => ["*", "asterisk"],\
|
20
|
+
K_PLUS => ["+", "plus"],\
|
21
|
+
K_COMMA => [",", "comma"],\
|
22
|
+
K_MINUS => ["-", "minus"],\
|
23
|
+
K_PERIOD => [".", "period"],\
|
24
|
+
K_SLASH => ["/", "slash"],\
|
25
|
+
K_0 => ["0", "numberline_0"],\
|
26
|
+
K_1 => ["1", "numberline_1"],\
|
27
|
+
K_2 => ["2", "numberline_2"],\
|
28
|
+
K_3 => ["3", "numberline_3"],\
|
29
|
+
K_4 => ["4", "numberline_4"],\
|
30
|
+
K_5 => ["5", "numberline_5"],\
|
31
|
+
K_6 => ["6", "numberline_6"],\
|
32
|
+
K_7 => ["7", "numberline_7"],\
|
33
|
+
K_8 => ["8", "numberline_8"],\
|
34
|
+
K_9 => ["9", "numberline_9"],\
|
35
|
+
K_COLON => [":", "colon"],\
|
36
|
+
K_SEMICOLON => [";", "semicolon"],\
|
37
|
+
K_LESS => ["<", "less_than"],\
|
38
|
+
K_EQUALS => ["=", "equals"],\
|
39
|
+
K_GREATER => [">", "greater_than"],\
|
40
|
+
K_QUESTION => ["?", "question_mark", "question"],\
|
41
|
+
K_AT => ["@", "at"],\
|
42
|
+
K_LEFTBRACKET => ["[", "left_bracket", "lbracket"],\
|
43
|
+
K_BACKSLASH => ["\\", "backslash"],\
|
44
|
+
K_RIGHTBRACKET => ["]", "right_bracket", "rbracket"],\
|
45
|
+
K_CARET => ["^", "caret"],\
|
46
|
+
K_UNDERSCORE => ["_", "underscore"],\
|
47
|
+
K_BACKQUOTE => ["`", "backquote", "grave"],\
|
48
|
+
K_A => ["a"],\
|
49
|
+
K_B => ["b"],\
|
50
|
+
K_C => ["c"],\
|
51
|
+
K_D => ["d"],\
|
52
|
+
K_E => ["e"],\
|
53
|
+
K_F => ["f"],\
|
54
|
+
K_G => ["g"],\
|
55
|
+
K_H => ["h"],\
|
56
|
+
K_I => ["i"],\
|
57
|
+
K_J => ["j"],\
|
58
|
+
K_K => ["k"],\
|
59
|
+
K_L => ["l"],\
|
60
|
+
K_M => ["m"],\
|
61
|
+
K_N => ["n"],\
|
62
|
+
K_O => ["o"],\
|
63
|
+
K_P => ["p"],\
|
64
|
+
K_Q => ["q"],\
|
65
|
+
K_R => ["r"],\
|
66
|
+
K_S => ["s"],\
|
67
|
+
K_T => ["t"],\
|
68
|
+
K_U => ["u"],\
|
69
|
+
K_V => ["v"],\
|
70
|
+
K_W => ["w"],\
|
71
|
+
K_X => ["x"],\
|
72
|
+
K_Y => ["y"],\
|
73
|
+
K_Z => ["z"],\
|
74
|
+
K_DELETE => [nil, "delete", "del"],\
|
75
|
+
K_KP0 => ["0", "kp0", "keypad_0"],\
|
76
|
+
K_KP1 => ["1", "kp1", "keypad_1"],\
|
77
|
+
K_KP2 => ["2", "kp2", "keypad_2"],\
|
78
|
+
K_KP3 => ["3", "kp3", "keypad_3"],\
|
79
|
+
K_KP4 => ["4", "kp4", "keypad_4"],\
|
80
|
+
K_KP5 => ["5", "kp5", "keypad_5"],\
|
81
|
+
K_KP6 => ["6", "kp6", "keypad_6"],\
|
82
|
+
K_KP7 => ["7", "kp7", "keypad_7"],\
|
83
|
+
K_KP8 => ["8", "kp8", "keypad_8"],\
|
84
|
+
K_KP9 => ["9", "kp9", "keypad_9"],\
|
85
|
+
K_KP_PERIOD => [".", "period", "keypad_period"],\
|
86
|
+
K_KP_DIVIDE => ["/", "divide", "keypad_divide"],\
|
87
|
+
K_KP_MULTIPLY => ["*", "multiply", "keypad_multiply"],\
|
88
|
+
K_KP_MINUS => ["-", "minus", "keypad_minus"],\
|
89
|
+
K_KP_PLUS => ["+", "plus", "keypad_plus"],\
|
90
|
+
K_KP_ENTER => ["\n", "enter", "keypad_enter"],\
|
91
|
+
K_KP_EQUALS => ["=", "equals", "keypad_equals"],\
|
92
|
+
K_UP => [nil, "up"],\
|
93
|
+
K_DOWN => [nil, "down"],\
|
94
|
+
K_RIGHT => [nil, "right"],\
|
95
|
+
K_LEFT => [nil, "left"],\
|
96
|
+
K_INSERT => [nil, "insert", "ins"],\
|
97
|
+
K_HOME => [nil, "home"],\
|
98
|
+
K_END => [nil, "end"],\
|
99
|
+
K_PAGEUP => [nil, "page_up", "pgup"],\
|
100
|
+
K_PAGEDOWN => [nil, "page_down", "pgdn"],\
|
101
|
+
K_F1 => [nil, "f1", "function_1"],\
|
102
|
+
K_F2 => [nil, "f2", "function_2"],\
|
103
|
+
K_F3 => [nil, "f3", "function_3"],\
|
104
|
+
K_F4 => [nil, "f4", "function_4"],\
|
105
|
+
K_F5 => [nil, "f5", "function_5"],\
|
106
|
+
K_F6 => [nil, "f6", "function_6"],\
|
107
|
+
K_F7 => [nil, "f7", "function_7"],\
|
108
|
+
K_F8 => [nil, "f8", "function_8"],\
|
109
|
+
K_F9 => [nil, "f9", "function_9"],\
|
110
|
+
K_F10 => [nil, "f10", "function_10"],\
|
111
|
+
K_F11 => [nil, "f11", "function_11"],\
|
112
|
+
K_F12 => [nil, "f12", "function_12"],\
|
113
|
+
K_F13 => [nil, "f13", "function_13"],\
|
114
|
+
K_F14 => [nil, "f14", "function_14"],\
|
115
|
+
K_F15 => [nil, "f15", "function_15"],\
|
116
|
+
K_NUMLOCK => [nil, "numlock"],\
|
117
|
+
K_CAPSLOCK => [nil, "capslock", "caplock"],\
|
118
|
+
K_SCROLLOCK => [nil, "scroll_lock", "scrollock", "scrolllock"],\
|
119
|
+
K_LSHIFT => [nil, "left_shift", "lshift"],\
|
120
|
+
K_RSHIFT => [nil, "right_shift", "rshift"],\
|
121
|
+
K_LCTRL => [nil, "left_control", "lctrl"],\
|
122
|
+
K_RCTRL => [nil, "right_control", "rctrl"],\
|
123
|
+
K_LALT => [nil, "left_alt", "lalt"],\
|
124
|
+
K_RALT => [nil, "right_alt", "ralt"],\
|
125
|
+
K_LMETA => [nil, "left_meta", "lmeta"],\
|
126
|
+
K_RMETA => [nil, "right_meta", "rmeta"],\
|
127
|
+
K_LSUPER => [nil, "left_super", "lsuper"],\
|
128
|
+
K_RSUPER => [nil, "right_super", "rsuper"],\
|
129
|
+
K_MODE => [nil, "mode"],\
|
130
|
+
K_HELP => [nil, "help"],\
|
131
|
+
K_PRINT => [nil, "print_screen","prt_scr","print"],\
|
132
|
+
K_SYSREQ => [nil, "sysrq", "sysreq", "system_request"],\
|
133
|
+
K_BREAK => [nil, "break"],\
|
134
|
+
K_MENU => [nil, "menu"],\
|
135
|
+
K_POWER => [nil, "power"],\
|
136
|
+
# I have no idea how to get a Euro symbol here!
|
137
|
+
K_EURO => ["\u20ac", "euro"],\
|
138
|
+
# just K_WORLD_0 to K_WORLD_95 after this
|
139
|
+
K_WORLD_0 => [nil, "world_0"],\
|
140
|
+
K_WORLD_1 => [nil, "world_1"],\
|
141
|
+
K_WORLD_2 => [nil, "world_2"],\
|
142
|
+
K_WORLD_3 => [nil, "world_3"],\
|
143
|
+
K_WORLD_4 => [nil, "world_4"],\
|
144
|
+
K_WORLD_5 => [nil, "world_5"],\
|
145
|
+
K_WORLD_6 => [nil, "world_6"],\
|
146
|
+
K_WORLD_7 => [nil, "world_7"],\
|
147
|
+
K_WORLD_8 => [nil, "world_8"],\
|
148
|
+
K_WORLD_9 => [nil, "world_9"],\
|
149
|
+
K_WORLD_10 => [nil, "world_10"],\
|
150
|
+
K_WORLD_11 => [nil, "world_11"],\
|
151
|
+
K_WORLD_12 => [nil, "world_12"],\
|
152
|
+
K_WORLD_13 => [nil, "world_13"],\
|
153
|
+
K_WORLD_14 => [nil, "world_14"],\
|
154
|
+
K_WORLD_15 => [nil, "world_15"],\
|
155
|
+
K_WORLD_16 => [nil, "world_16"],\
|
156
|
+
K_WORLD_17 => [nil, "world_17"],\
|
157
|
+
K_WORLD_18 => [nil, "world_18"],\
|
158
|
+
K_WORLD_19 => [nil, "world_19"],\
|
159
|
+
K_WORLD_20 => [nil, "world_20"],\
|
160
|
+
K_WORLD_21 => [nil, "world_21"],\
|
161
|
+
K_WORLD_22 => [nil, "world_22"],\
|
162
|
+
K_WORLD_23 => [nil, "world_23"],\
|
163
|
+
K_WORLD_24 => [nil, "world_24"],\
|
164
|
+
K_WORLD_25 => [nil, "world_25"],\
|
165
|
+
K_WORLD_26 => [nil, "world_26"],\
|
166
|
+
K_WORLD_27 => [nil, "world_27"],\
|
167
|
+
K_WORLD_28 => [nil, "world_28"],\
|
168
|
+
K_WORLD_29 => [nil, "world_29"],\
|
169
|
+
K_WORLD_30 => [nil, "world_30"],\
|
170
|
+
K_WORLD_31 => [nil, "world_31"],\
|
171
|
+
K_WORLD_32 => [nil, "world_32"],\
|
172
|
+
K_WORLD_33 => [nil, "world_33"],\
|
173
|
+
K_WORLD_34 => [nil, "world_34"],\
|
174
|
+
K_WORLD_35 => [nil, "world_35"],\
|
175
|
+
K_WORLD_36 => [nil, "world_36"],\
|
176
|
+
K_WORLD_37 => [nil, "world_37"],\
|
177
|
+
K_WORLD_38 => [nil, "world_38"],\
|
178
|
+
K_WORLD_39 => [nil, "world_39"],\
|
179
|
+
K_WORLD_40 => [nil, "world_40"],\
|
180
|
+
K_WORLD_41 => [nil, "world_41"],\
|
181
|
+
K_WORLD_41 => [nil, "world_41"],\
|
182
|
+
K_WORLD_42 => [nil, "world_42"],\
|
183
|
+
K_WORLD_43 => [nil, "world_43"],\
|
184
|
+
K_WORLD_44 => [nil, "world_44"],\
|
185
|
+
K_WORLD_45 => [nil, "world_45"],\
|
186
|
+
K_WORLD_46 => [nil, "world_46"],\
|
187
|
+
K_WORLD_47 => [nil, "world_47"],\
|
188
|
+
K_WORLD_48 => [nil, "world_48"],\
|
189
|
+
K_WORLD_49 => [nil, "world_49"],\
|
190
|
+
K_WORLD_50 => [nil, "world_50"],\
|
191
|
+
K_WORLD_51 => [nil, "world_51"],\
|
192
|
+
K_WORLD_52 => [nil, "world_52"],\
|
193
|
+
K_WORLD_53 => [nil, "world_53"],\
|
194
|
+
K_WORLD_54 => [nil, "world_54"],\
|
195
|
+
K_WORLD_55 => [nil, "world_55"],\
|
196
|
+
K_WORLD_56 => [nil, "world_56"],\
|
197
|
+
K_WORLD_57 => [nil, "world_57"],\
|
198
|
+
K_WORLD_58 => [nil, "world_58"],\
|
199
|
+
K_WORLD_59 => [nil, "world_59"],\
|
200
|
+
K_WORLD_60 => [nil, "world_60"],\
|
201
|
+
K_WORLD_61 => [nil, "world_61"],\
|
202
|
+
K_WORLD_62 => [nil, "world_62"],\
|
203
|
+
K_WORLD_63 => [nil, "world_63"],\
|
204
|
+
K_WORLD_64 => [nil, "world_64"],\
|
205
|
+
K_WORLD_65 => [nil, "world_65"],\
|
206
|
+
K_WORLD_66 => [nil, "world_66"],\
|
207
|
+
K_WORLD_67 => [nil, "world_67"],\
|
208
|
+
K_WORLD_68 => [nil, "world_68"],\
|
209
|
+
K_WORLD_69 => [nil, "world_69"],\
|
210
|
+
K_WORLD_70 => [nil, "world_70"],\
|
211
|
+
K_WORLD_71 => [nil, "world_71"],\
|
212
|
+
K_WORLD_72 => [nil, "world_72"],\
|
213
|
+
K_WORLD_73 => [nil, "world_73"],\
|
214
|
+
K_WORLD_74 => [nil, "world_74"],\
|
215
|
+
K_WORLD_75 => [nil, "world_75"],\
|
216
|
+
K_WORLD_76 => [nil, "world_76"],\
|
217
|
+
K_WORLD_77 => [nil, "world_77"],\
|
218
|
+
K_WORLD_78 => [nil, "world_78"],\
|
219
|
+
K_WORLD_79 => [nil, "world_79"],\
|
220
|
+
K_WORLD_80 => [nil, "world_80"],\
|
221
|
+
K_WORLD_81 => [nil, "world_81"],\
|
222
|
+
K_WORLD_82 => [nil, "world_82"],\
|
223
|
+
K_WORLD_83 => [nil, "world_83"],\
|
224
|
+
K_WORLD_84 => [nil, "world_84"],\
|
225
|
+
K_WORLD_85 => [nil, "world_85"],\
|
226
|
+
K_WORLD_86 => [nil, "world_86"],\
|
227
|
+
K_WORLD_87 => [nil, "world_87"],\
|
228
|
+
K_WORLD_88 => [nil, "world_88"],\
|
229
|
+
K_WORLD_89 => [nil, "world_89"],\
|
230
|
+
K_WORLD_90 => [nil, "world_90"],\
|
231
|
+
K_WORLD_91 => [nil, "world_91"],\
|
232
|
+
K_WORLD_92 => [nil, "world_92"],\
|
233
|
+
K_WORLD_93 => [nil, "world_93"],\
|
234
|
+
K_WORLD_94 => [nil, "world_94"],\
|
235
|
+
K_WORLD_95 => [nil, "world_95"],\
|
236
|
+
}
|
237
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#--
|
2
|
+
# Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
# Copyright (C) 2004-2007 John Croisant
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#++
|
19
|
+
|
20
|
+
require "rubygame"
|
21
|
+
|
22
|
+
module Rubygame
|
23
|
+
|
24
|
+
# *NOTE*: you must require 'rubygame/mediabag' manually to gain access to
|
25
|
+
# Rubygame::MediaBag. It is not imported with Rubygame by default!
|
26
|
+
#
|
27
|
+
# A Hash-like class which will load and retain media files (images and
|
28
|
+
# sounds), so that the file can be loaded once, but used many times.
|
29
|
+
#
|
30
|
+
# The first time a file is requested with the #[] method,that file will be
|
31
|
+
# loaded into memory. All subsequent requests for the same file will return
|
32
|
+
# a reference to the already-loaded version. Ideally, objects should not
|
33
|
+
# have to know whether or not the image has been loaded or not.
|
34
|
+
class MediaBag
|
35
|
+
@@image_ext = %W{bmp gif jpg lbm pcx png pnm ppm pgm pbm tga tif xcf xpm}
|
36
|
+
@@sound_ext = %W{wav}
|
37
|
+
|
38
|
+
def initialize()
|
39
|
+
@media = Hash.new
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return a reference to the stored value for key.
|
43
|
+
# If there is no value for key, automatically attempt to load key
|
44
|
+
# as a filename (guessing the file type based on its extension)
|
45
|
+
#
|
46
|
+
def [](key)
|
47
|
+
@media[key] or load(key)
|
48
|
+
rescue Rubygame::SDLError
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# Load the file, but only if it has not been previously loaded.
|
53
|
+
def load(filename)
|
54
|
+
@media[filename] or store( filename, load_file(filename) )
|
55
|
+
end
|
56
|
+
|
57
|
+
# Store value as key, but only if there is no previous value.
|
58
|
+
def store(key,value)
|
59
|
+
@media[key] ||= value
|
60
|
+
end
|
61
|
+
|
62
|
+
# Forcibly (re)load the file, replacing the previous version in memory
|
63
|
+
# (if any).
|
64
|
+
def force_load(filename)
|
65
|
+
force_store( filename, load_file(filename) )
|
66
|
+
end
|
67
|
+
|
68
|
+
# Forcibly store value as key, replacing the previous value (if any).
|
69
|
+
def force_store(key,value)
|
70
|
+
@media[key] = value
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_file(filename)
|
74
|
+
case File::extname(filename).downcase[1..-1]
|
75
|
+
when *(@@image_ext)
|
76
|
+
return load_image(filename)
|
77
|
+
when *(@@sound_ext)
|
78
|
+
return load_sound(filename)
|
79
|
+
else
|
80
|
+
raise(ArgumentError,"Unrecognized file extension `%s': %s"%
|
81
|
+
[File::extname(filename), filename])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_image(filename)
|
86
|
+
return Rubygame::Surface.load_image(filename)
|
87
|
+
end
|
88
|
+
|
89
|
+
def load_sound(filename)
|
90
|
+
return Rubygame::Mixer::Sample.load_audio(filename)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|