openrgss 0.1.1-x86-mingw32 → 0.1.2-x86-mingw32
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/lib/openrgss.rb +19 -0
- data/lib/openrgss/audio.rb +109 -0
- data/lib/openrgss/bitmap.rb +255 -0
- data/lib/openrgss/color.rb +106 -0
- data/lib/openrgss/font.rb +106 -0
- data/lib/openrgss/graphics.rb +150 -0
- data/lib/openrgss/input.rb +141 -0
- data/lib/openrgss/plane.rb +102 -0
- data/lib/openrgss/rect.rb +78 -0
- data/lib/openrgss/rgss.rb +302 -0
- data/lib/openrgss/rgsserror.rb +7 -0
- data/lib/openrgss/rgssreset.rb +7 -0
- data/lib/openrgss/sprite.rb +135 -0
- data/lib/openrgss/table.rb +51 -0
- data/lib/openrgss/tilemap.rb +686 -0
- data/lib/openrgss/tone.rb +95 -0
- data/lib/openrgss/viewport.rb +82 -0
- data/lib/openrgss/window.rb +303 -0
- data/lib/rgss.rb +1 -0
- metadata +21 -2
@@ -0,0 +1,78 @@
|
|
1
|
+
class Rect
|
2
|
+
|
3
|
+
# The x-coordinate of the rectangle's upper left corner.
|
4
|
+
attr_accessor :x
|
5
|
+
|
6
|
+
# The y-coordinate of the rectangle's upper left corner.
|
7
|
+
attr_accessor :y
|
8
|
+
|
9
|
+
# The rectangle's width.
|
10
|
+
attr_accessor :width
|
11
|
+
|
12
|
+
# The rectangle's height.
|
13
|
+
attr_accessor :height
|
14
|
+
|
15
|
+
# :call-seq:
|
16
|
+
# Rect.new(x, y, width, height)
|
17
|
+
# Rect.new
|
18
|
+
#
|
19
|
+
# Creates a new Rect object.
|
20
|
+
#
|
21
|
+
# The default values when no arguments are specified are (0, 0, 0, 0).
|
22
|
+
|
23
|
+
def initialize(x=0, y=0, width=0, height=0)
|
24
|
+
set(x, y, width, height)
|
25
|
+
end
|
26
|
+
|
27
|
+
# :call-seq:
|
28
|
+
# set(x, y, width, height)
|
29
|
+
# set(rect)
|
30
|
+
#
|
31
|
+
# Sets all parameters at once.
|
32
|
+
#
|
33
|
+
# The second format copies all the components from a separate Rect object.
|
34
|
+
|
35
|
+
def set(x, y=0, width=0, height=0)
|
36
|
+
if x.is_a? Rect
|
37
|
+
rect = x
|
38
|
+
@x = rect.x
|
39
|
+
@y = rect.y
|
40
|
+
@width = rect.width
|
41
|
+
@height = rect.height
|
42
|
+
else
|
43
|
+
@x = x
|
44
|
+
@y = y
|
45
|
+
@width = width
|
46
|
+
@height = height
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
"(#{x}, #{y}, #{width}, #{height})"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets all components to 0.
|
55
|
+
def empty
|
56
|
+
set(0, 0, 0, 0)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Vergleichsmethode
|
60
|
+
def == other
|
61
|
+
if other.kind_of?(Rect) then
|
62
|
+
x == other.x && y == other.y && width == other.width && height == other.height
|
63
|
+
else
|
64
|
+
raise TypeError.new("Can't convert #{other.class} to Rect")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Serialisiert das Objekt
|
69
|
+
def _dump limit
|
70
|
+
[x, y, width, height].pack("iiii")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Deserialisiert das Objekt
|
74
|
+
def self._load str
|
75
|
+
new(*str.unpack("iiii"))
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'sdl'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
# The following built-in functions are defined in RGSS.
|
5
|
+
|
6
|
+
module RGSS
|
7
|
+
|
8
|
+
Log = Logger.new(STDOUT)
|
9
|
+
@resources = []
|
10
|
+
@load_path = []
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# 标题
|
14
|
+
attr_accessor :title
|
15
|
+
|
16
|
+
# get_file的读取路径,目录字符串的数组
|
17
|
+
attr_accessor :load_path
|
18
|
+
|
19
|
+
# get_file的自动补全扩展名,以点开头的扩展名字符串的数组
|
20
|
+
attr_accessor :load_ext
|
21
|
+
|
22
|
+
# 屏幕上显示的资源,Drawable的数组
|
23
|
+
attr_accessor :resources
|
24
|
+
|
25
|
+
# 显示帧率
|
26
|
+
attr_accessor :show_fps
|
27
|
+
|
28
|
+
def title=(title) # :NODOC:
|
29
|
+
@title = title
|
30
|
+
SDL::WM.set_caption(title, title)
|
31
|
+
end
|
32
|
+
|
33
|
+
# 在load_path指定的目录中查找文件,会自动补全Autoload_Extname里指定的扩展面给,默认为 .png, .jpg, .gif, .bmp, .ogg, .wma, .mp3, .wav, .mid
|
34
|
+
#
|
35
|
+
# 在Audio和Bitmap的内部自动调用
|
36
|
+
#
|
37
|
+
# 如果找不到文件,将返回filename本身
|
38
|
+
|
39
|
+
def get_file(filename)
|
40
|
+
([nil] + RGSS.load_path).each do |directory|
|
41
|
+
([''] + load_ext).each do |extname|
|
42
|
+
path = File.expand_path filename + extname, directory
|
43
|
+
if File.exist? path
|
44
|
+
return path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
filename
|
49
|
+
end
|
50
|
+
|
51
|
+
# 初始化RGSS引擎,将会在rgss_main内部自动调用
|
52
|
+
|
53
|
+
def init
|
54
|
+
SDL.init SDL::INIT_EVERYTHING
|
55
|
+
Graphics.entity = SDL::Screen.open(Graphics.width, Graphics.height, 0, SDL::HWSURFACE|SDL::HWPALETTE)
|
56
|
+
SDL::Mixer.open(SDL::Mixer::DEFAULT_FREQUENCY, SDL::Mixer::DEFAULT_FORMAT, SDL::Mixer::DEFAULT_CHANNELS, 1536)
|
57
|
+
SDL::TTF.init
|
58
|
+
self.title = @title
|
59
|
+
end
|
60
|
+
|
61
|
+
# 指定是否显示帧率
|
62
|
+
|
63
|
+
def show_fps=(show_fps)
|
64
|
+
if show_fps
|
65
|
+
SDL::WM.set_caption("#{title} - #{Graphics.real_fps}fps", title)
|
66
|
+
else
|
67
|
+
SDL::WM.set_caption(title, title)
|
68
|
+
end
|
69
|
+
|
70
|
+
@show_fps = show_fps
|
71
|
+
end
|
72
|
+
|
73
|
+
# 引擎的更新,将在Graphics.update和Input.update的内部自动调用
|
74
|
+
|
75
|
+
def update
|
76
|
+
if @show_fps and @fps != Graphics.real_fps
|
77
|
+
SDL::WM.set_caption("#{title} - #{Graphics.real_fps}fps", title)
|
78
|
+
@fps = Graphics.real_fps
|
79
|
+
end
|
80
|
+
|
81
|
+
while event = SDL::Event.poll
|
82
|
+
case event
|
83
|
+
when SDL::Event::Quit
|
84
|
+
exit
|
85
|
+
when SDL::Event::KeyDown, SDL::Event::KeyUp
|
86
|
+
Input.events << event
|
87
|
+
else #when
|
88
|
+
#Log.debug "unhandled event: #{event}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
self.load_ext = ['.png', '.jpg', '.gif', '.bmp', '.ogg', '.wma', '.mp3', '.wav', '.mid']
|
94
|
+
self.load_path = []
|
95
|
+
# Evaluates the provided block one time only.
|
96
|
+
#
|
97
|
+
# Detects a reset within a block with a press of the F12 key and returns to the beginning if reset.
|
98
|
+
# rgss_main { SceneManager.run }
|
99
|
+
|
100
|
+
def rgss_main
|
101
|
+
RGSS.init
|
102
|
+
begin
|
103
|
+
yield
|
104
|
+
rescue RGSSReset
|
105
|
+
RGSS.resources.clear
|
106
|
+
retry
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Stops script execution and only repeats screen refreshing. Defined for use in script introduction.
|
111
|
+
#
|
112
|
+
# Equivalent to the following.
|
113
|
+
#
|
114
|
+
# loop { Graphics.update }
|
115
|
+
|
116
|
+
def rgss_stop
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# Loads the data file indicated by filename and restores the object.
|
121
|
+
#
|
122
|
+
# $data_actors = load_data("Data/Actors.rvdata2")
|
123
|
+
#
|
124
|
+
# This function is essentially the same as:
|
125
|
+
#
|
126
|
+
# File.open(filename, "rb") { |f|
|
127
|
+
# obj = Marshal.load(f)
|
128
|
+
# }
|
129
|
+
#
|
130
|
+
# However, it differs in that it can load files from within encrypted archives.
|
131
|
+
|
132
|
+
def load_data(filename)
|
133
|
+
File.open(filename, "rb") { |f|
|
134
|
+
obj = Marshal.load(f)
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
# Saves the object obj to the data file indicated by filename.
|
139
|
+
#
|
140
|
+
# save_data($data_actors, "Data/Actors.rvdata2")
|
141
|
+
#
|
142
|
+
# This function is the same as:
|
143
|
+
# File.open(filename, "wb") { |f|
|
144
|
+
# Marshal.dump(obj, f)
|
145
|
+
# }
|
146
|
+
|
147
|
+
def save_data(obj, filename)
|
148
|
+
File.open(filename, "wb") { |f|
|
149
|
+
Marshal.dump(obj, f)
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Outputs the arguments to the message box. If a non-string object has been supplied as an argument, it will be converted into a string with to_s and output.
|
154
|
+
#
|
155
|
+
# Returns nil.
|
156
|
+
#
|
157
|
+
# <b>(Not Implemented in OpenRGSS)</b>
|
158
|
+
def msgbox(*args)
|
159
|
+
if RUBY_PLATFORM['mingw'] or RUBY_PLATFORM['mswin']
|
160
|
+
require 'dl'
|
161
|
+
@@msgbox = DL.dlopen('user32')['MessageBoxA', 'ILSSI']
|
162
|
+
msgbox.call(0, args.collect{|arg|arg.to_s}.join("\n"), title, 0)
|
163
|
+
else
|
164
|
+
puts args
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Outputs obj to the message box in a human-readable format. Identical to the following code (see Object#inspect):
|
169
|
+
#
|
170
|
+
# msgbox obj.inspect, "\n", obj2.inspect, "\n", ...
|
171
|
+
#
|
172
|
+
# Returns nil.
|
173
|
+
#
|
174
|
+
# <b>(Not Implemented in OpenRGSS)</b>
|
175
|
+
def msgbox_p(*args)
|
176
|
+
msgbox args.collect{|obj|obj.inspect}.join("\n")
|
177
|
+
end
|
178
|
+
|
179
|
+
module Drawable
|
180
|
+
attr_accessor :x, :y, :viewport, :created_at
|
181
|
+
attr_reader :z, :visible
|
182
|
+
|
183
|
+
def initialize(viewport=nil)
|
184
|
+
@created_at = Time.now
|
185
|
+
@viewport = viewport
|
186
|
+
self.visible = @visible
|
187
|
+
end
|
188
|
+
|
189
|
+
def viewport=(viewport)
|
190
|
+
@viewport = viewport
|
191
|
+
self.visible = @visible
|
192
|
+
end
|
193
|
+
|
194
|
+
def >(v)
|
195
|
+
return false if self.viewport.nil?&&v.viewport
|
196
|
+
unless (v.viewport.nil?)
|
197
|
+
return false if self.viewport.z<v.viewport.z
|
198
|
+
return false if self.viewport.z==v.viewport.z and self.viewport.created_at<v.viewport.created_at
|
199
|
+
end
|
200
|
+
return false if self.z<v.z
|
201
|
+
return false if self.z==v.z and self.y<v.y
|
202
|
+
return false if self.z==v.z and self.y==v.y and self.created_at<v.created_at
|
203
|
+
return true
|
204
|
+
end
|
205
|
+
|
206
|
+
#$a=0
|
207
|
+
def <=>(v)
|
208
|
+
#print $a+=1
|
209
|
+
return 1 if (self>v)
|
210
|
+
return -1
|
211
|
+
end
|
212
|
+
|
213
|
+
def z=(z)
|
214
|
+
return if z==@z
|
215
|
+
@z = z
|
216
|
+
|
217
|
+
self.visible = true if @visible and !@disposed
|
218
|
+
end
|
219
|
+
|
220
|
+
def y=(y)
|
221
|
+
return if y==@y
|
222
|
+
@y = y
|
223
|
+
# RGSS.resources.sort
|
224
|
+
self.visible = true if @visible and !@disposed
|
225
|
+
end
|
226
|
+
|
227
|
+
def disposed?
|
228
|
+
@disposed
|
229
|
+
end
|
230
|
+
|
231
|
+
def dispose
|
232
|
+
@disposed = true
|
233
|
+
RGSS.resources.delete self
|
234
|
+
end
|
235
|
+
|
236
|
+
def visible=(visible)
|
237
|
+
#if @visible
|
238
|
+
# RGSS.resources.delete self
|
239
|
+
#end
|
240
|
+
@visible = visible
|
241
|
+
RGSS.resources.delete self unless @visible
|
242
|
+
if @visible
|
243
|
+
RGSS.resources.delete self
|
244
|
+
RGSS.resources<< self
|
245
|
+
# RGSS.resources.sort
|
246
|
+
end
|
247
|
+
=begin
|
248
|
+
if @visible
|
249
|
+
RGSS.resources.each_with_index { |resource, index|
|
250
|
+
|
251
|
+
#TODO: 简化逻辑
|
252
|
+
if resource.viewport
|
253
|
+
resource_viewport_z = resource.viewport.z
|
254
|
+
resource_viewport_y = resource.viewport.y
|
255
|
+
else
|
256
|
+
resource_viewport_z = 0
|
257
|
+
resource_viewport_y = 0
|
258
|
+
end
|
259
|
+
if self.viewport
|
260
|
+
self_viewport_z = self.viewport.z
|
261
|
+
self_viewport_y = self.viewport.y
|
262
|
+
else
|
263
|
+
self_viewport_z = 0
|
264
|
+
self_viewport_y = 0
|
265
|
+
end
|
266
|
+
|
267
|
+
return RGSS.resources.insert(index-1, self) if (
|
268
|
+
if self_viewport_z == resource_viewport_z
|
269
|
+
if self_viewport_y == resource_viewport_y
|
270
|
+
if (self.viewport.nil? and resource.viewport) or (self.viewport and resource.viewport and self.viewport.created_at < resource.viewport.created_at)
|
271
|
+
true
|
272
|
+
elsif (self.viewport and resource.viewport.nil?) or (self.viewport and resource.viewport and self.viewport.created_at > resource.viewport.created_at)
|
273
|
+
false
|
274
|
+
elsif self.z == resource.z
|
275
|
+
if self.y == resource.y
|
276
|
+
self.created_at < resource.created_at
|
277
|
+
else
|
278
|
+
self.y < resource.y
|
279
|
+
end
|
280
|
+
else
|
281
|
+
self.y < resource.y
|
282
|
+
end
|
283
|
+
else
|
284
|
+
self_viewport_y < resource_viewport_y
|
285
|
+
end
|
286
|
+
else
|
287
|
+
self_viewport_z < resource_viewport_z
|
288
|
+
end
|
289
|
+
)
|
290
|
+
|
291
|
+
}
|
292
|
+
RGSS.resources += [self]
|
293
|
+
end
|
294
|
+
=end
|
295
|
+
end
|
296
|
+
|
297
|
+
def draw(destination=Graphics)
|
298
|
+
raise NotImplementedError
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# The sprite class. Sprites are the basic concept used to display characters and other objects on the game screen.
|
2
|
+
|
3
|
+
class Sprite
|
4
|
+
# Refers to the bitmap (Bitmap) used for the sprite's starting point.
|
5
|
+
attr_accessor :bitmap
|
6
|
+
|
7
|
+
# The box (Rect) taken from a bitmap.
|
8
|
+
attr_accessor :src_rect
|
9
|
+
|
10
|
+
|
11
|
+
# Refers to the viewport (Viewport) associated with the sprite.
|
12
|
+
attr_accessor :viewport
|
13
|
+
|
14
|
+
# The x-coordinate of the sprite's starting point.
|
15
|
+
attr_accessor :ox
|
16
|
+
|
17
|
+
# The y-coordinate of the sprite's starting point.
|
18
|
+
attr_accessor :oy
|
19
|
+
|
20
|
+
# The sprite's x-axis zoom level. 1.0 denotes actual pixel size.
|
21
|
+
attr_accessor :zoom_x
|
22
|
+
|
23
|
+
# The sprite's y-axis zoom level. 1.0 denotes actual pixel size.
|
24
|
+
attr_accessor :zoom_y
|
25
|
+
|
26
|
+
# The sprite's angle of rotation. Specifies up to 360 degrees of counterclockwise rotation. However, drawing a rotated sprite is time-consuming, so avoid overuse.
|
27
|
+
attr_accessor :angle
|
28
|
+
|
29
|
+
# Defines the amplitude, frequency, speed, and phase of the wave effect. A raster scroll effect is achieved by using a sinusoidal function to draw the sprite with each line's horizontal position slightly different from the last.
|
30
|
+
#
|
31
|
+
# wave_amp is the wave amplitude and wave_length is the wave frequency, and each is specified by a number of pixels.
|
32
|
+
#
|
33
|
+
# wave_speed specifies the speed of the wave animation. The default is 360, and the larger the value, the faster the effect.
|
34
|
+
#
|
35
|
+
# wave_phase specifies the phase of the top line of the sprite using an angle of up to 360 degrees. This is updated each time the update method is called. It is not necessary to use this property unless it is required for two sprites to have their wave effects synchronized.
|
36
|
+
attr_accessor :wave_amp
|
37
|
+
attr_accessor :wave_length
|
38
|
+
attr_accessor :wave_speed
|
39
|
+
attr_accessor :wave_phase
|
40
|
+
|
41
|
+
# A flag denoting the sprite has been flipped horizontally. If TRUE, the sprite will be drawn flipped. The default is false.
|
42
|
+
attr_accessor :mirror
|
43
|
+
|
44
|
+
# The bush depth and opacity of a sprite. This can be used to represent a situation such as the character's legs being hidden by bushes.
|
45
|
+
#
|
46
|
+
# For bush_depth, the number of pixels for the bush section is specified. The default value is 0.
|
47
|
+
#
|
48
|
+
# For bush_opacity, the opacity of the bush section from 0 to 255 is specified. Out-of-range values will be corrected automatically. The default value is 128.
|
49
|
+
#
|
50
|
+
# The bush_opacity value will be multiplied by opacity. For example, if both opacity and bush_opacity are set to 128, it will be handled as a transparency on # top of a transparency, for an actual opacity of 64.
|
51
|
+
attr_accessor :bush_depth
|
52
|
+
attr_accessor :bush_opacity
|
53
|
+
|
54
|
+
# The sprite's opacity (0-255). Out-of-range values are automatically corrected.
|
55
|
+
attr_accessor :opacity
|
56
|
+
|
57
|
+
# The sprite's blending mode (0: normal, 1: addition, 2: subtraction).
|
58
|
+
attr_accessor :blend_type
|
59
|
+
|
60
|
+
# The color (Color) to be blended with the sprite. Alpha values are used in the blending ratio.
|
61
|
+
#
|
62
|
+
# Handled separately from the color blended into a flash effect. However, the color with the higher alpha value when displayed will have the higher priority when blended.
|
63
|
+
attr_accessor :color
|
64
|
+
|
65
|
+
# The sprite's color tone (Tone).
|
66
|
+
attr_accessor :tone
|
67
|
+
|
68
|
+
include RGSS::Drawable
|
69
|
+
|
70
|
+
# Creates a new sprite object. Specifies a viewport (Viewport) when necessary.
|
71
|
+
|
72
|
+
def initialize(viewport=nil)
|
73
|
+
@src_rect = Rect.new(0, 0, 0, 0)
|
74
|
+
@x = 0
|
75
|
+
@y = 0
|
76
|
+
@z = 0
|
77
|
+
@ox = 0
|
78
|
+
@oy = 0
|
79
|
+
@zoom_x = 1
|
80
|
+
@zoom_y = 1
|
81
|
+
@angle = 0
|
82
|
+
@src_rect = Rect.new
|
83
|
+
@color = Color.new
|
84
|
+
@tone = Tone.new
|
85
|
+
@opacity = 255
|
86
|
+
@visible = true
|
87
|
+
super(viewport)
|
88
|
+
end
|
89
|
+
|
90
|
+
def bitmap=(bitmap)
|
91
|
+
@src_rect.set(0, 0, bitmap.width, bitmap.height) if bitmap
|
92
|
+
@bitmap = bitmap
|
93
|
+
end
|
94
|
+
|
95
|
+
# Begins flashing the sprite. duration specifies the number of frames flashing will last.
|
96
|
+
#
|
97
|
+
# If color is set to nil, the sprite will disappear while flashing.
|
98
|
+
|
99
|
+
def flash(color, duration)
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Advances the sprite flash or wave phase. As a general rule, this method is called once per frame.
|
104
|
+
#
|
105
|
+
# It is not necessary to call this if a flash or wave is not needed.
|
106
|
+
|
107
|
+
def update
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# Gets the width of the sprite. Equivalent to src_rect.width.
|
112
|
+
def width
|
113
|
+
bitmap.width
|
114
|
+
end
|
115
|
+
|
116
|
+
# Gets the height of the sprite. Equivalent to src_rect.height.
|
117
|
+
def height
|
118
|
+
bitmap.height
|
119
|
+
end
|
120
|
+
|
121
|
+
def draw(destination=Graphics)
|
122
|
+
return unless bitmap and opacity > 0
|
123
|
+
|
124
|
+
base_x = @x-@ox
|
125
|
+
base_y = @y-@oy
|
126
|
+
if viewport
|
127
|
+
destination.entity.set_clip_rect(viewport.rect.x, viewport.rect.y, viewport.rect.width, viewport.rect.height)
|
128
|
+
base_x += viewport.rect.x - viewport.ox
|
129
|
+
base_y += viewport.rect.y - viewport.oy
|
130
|
+
end
|
131
|
+
|
132
|
+
SDL::Surface.blit(@bitmap.entity, @src_rect.x, @src_rect.y, @src_rect.width, @src_rect.height, destination.entity, base_x, base_y)
|
133
|
+
destination.entity.set_clip_rect(0, 0, destination.width, destination.height) if viewport
|
134
|
+
end
|
135
|
+
end
|