#============================================================================
# ■ Plane
#----------------------------------------------------------------------------
# 处理平面的类(DKRM追定义)
# 主要用于处理超出640*480分辨率的远景图和雾图形
#============================================================================
class Plane
#--------------------------------------------------------------------------
# ● 初始化定义
#--------------------------------------------------------------------------
def initialize(v = Viewport.new(0, 0, 640, 480))
@x = 0
@y = 0
@z = 0
@ox = 0
@oy = 0
@ox2 = 0
@oy2 = 0
@rect = v.rect
@zoom_x = 1.0
@zoom_y = 1.0
@bitmap = nil
@contents = Sprite.new
@n_w = 1
@n_h = 1
@visible = true
@tone = Tone.new(0, 0, 0, 0)
[url=home.php?mod=space&uid=10453]@color[/url] = Color.new(255,255,255,0)
@blend_type = 0
[url=home.php?mod=space&uid=316553]@opacity[/url] = 255
@dispose = false
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
@contents.x = @x
@contents.y = @y
@contents.ox = @ox2
@contents.oy = @oy2
@contents.opacity = [url=home.php?mod=space&uid=316553]@opacity[/url]
@contents.visible = @visible
@contents.tone = @tone
@contents.blend_type = @blend_type
@contents.z = @z
end
#--------------------------------------------------------------------------
# ● 装载图形(bitmap)
#--------------------------------------------------------------------------
def bitmap=(bitmap)
if @disposed
raise(RGSSError,"disposed window")
else
@bitmap = bitmap
count_wh
update
end
end
#--------------------------------------------------------------------------
# ● 图形
#--------------------------------------------------------------------------
def bitmap
return if @bitmap != nil
end
#--------------------------------------------------------------------------
# ● X 坐标(x)
#--------------------------------------------------------------------------
def x=(x)
if @disposed
raise(RGSSError,"disposed window")
else
@x = x
update
end
end
def x
return @x
end
#--------------------------------------------------------------------------
# ● Y 坐标(y)
#--------------------------------------------------------------------------
def y=(y)
if @disposed
raise(RGSSError,"disposed window")
else
@y = y
update
end
end
def y
return @y
end
#--------------------------------------------------------------------------
# ● Z 坐标(z)
#--------------------------------------------------------------------------
def z=(z)
if @disposed
raise(RGSSError,"disposed window")
else
@z = z
update
end
end
def z
return @z
end
#--------------------------------------------------------------------------
# ● X 漂移量(ox)
#--------------------------------------------------------------------------
def ox=(ox)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap != nil
@ox = ox
@ox2 = ox % (@bitmap.width * @zoom_x).to_i
update
end
end
end
def ox
return @ox
end
#--------------------------------------------------------------------------
# ● Y 漂移量(oy)
#--------------------------------------------------------------------------
def oy=(oy)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap != nil
@oy = oy
@oy2 = oy % (@bitmap.height * @zoom_y).to_i
update
end
end
end
def oy
return @oy
end
#--------------------------------------------------------------------------
# ● X 方向缩放(zoom_x)
#--------------------------------------------------------------------------
def zoom_x=(zx)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_x != zx
@zoom_x = zx
count_wh
end
update
end
end
def zoom_x
return @zoom_x
end
#--------------------------------------------------------------------------
# ● Y 方向缩放(zoom_y)
#--------------------------------------------------------------------------
def zoom_y=(zy)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_y != zy
@zoom_y = zy
count_wh
end
update
end
end
def zoom_y
return @zoom_y
end
#--------------------------------------------------------------------------
# ● 不透明度(opacity)
#--------------------------------------------------------------------------
def opacity=(op)
if @disposed
raise(RGSSError,"disposed window")
else
[url=home.php?mod=space&uid=316553]@opacity[/url] = op
update
end
end
def opacity
return @opacity
end
#--------------------------------------------------------------------------
# ● 颜色叠加(color)
#--------------------------------------------------------------------------
def color=(c)
if @disposed
raise(RGSSError,"disposed window")
else
[url=home.php?mod=space&uid=10453]@color[/url] = c
update
end
end
def color
return @color
end
#--------------------------------------------------------------------------
# ● 色调(tone)
#--------------------------------------------------------------------------
def tone=(tone)
if @disposed
raise(RGSSError,"disposed window")
else
@tone = tone
update
end
end
def tone
return @tone
end
#--------------------------------------------------------------------------
# ● 是否可见(visible)
#--------------------------------------------------------------------------
def visible=(v)
if @disposed
raise(RGSSError,"disposed window")
else
@visible = v
update
end
end
def visible
return @visible
end
#--------------------------------------------------------------------------
# ● 叠加模式(blend_type)
#--------------------------------------------------------------------------
def blend_type=(bt)
if @disposed
raise(RGSSError,"disposed window")
else
@blend_type = bt
update
end
end
def blend_type
return @blend_type
end
#--------------------------------------------------------------------------
# ● 释放内存(dispose)
#--------------------------------------------------------------------------
def dispose
return if @dispose
@dispose = true
@contents.bitmap.dispose if @contents.bitmap != nil
@contents.bitmap = nil
@contents.dispose if @contents != nil
@contents = nil
@bitmap.dispose if @bitmap != nil
@bitmap = nil
end
#--------------------------------------------------------------------------
# ● 检测释放(dispose?)
#--------------------------------------------------------------------------
def dispose?
@dispose
end
#--------------------------------------------------------------------------
# ● 计算Plane的长宽与精灵排布(count_wh)
#--------------------------------------------------------------------------
def count_wh
if @bitmap != nil
@n_w = @rect.width / (@bitmap.width * @zoom_x).to_i + 3
@n_h = @rect.height / (@bitmap.height * @zoom_y).to_i + 3
h = @n_h * (@bitmap.height * @zoom_y).to_i
w = @n_w * (@bitmap.width * @zoom_x).to_i
if @contents.bitmap == nil
@contents.bitmap = Bitmap.new(w, h)
end
@contents.bitmap.clear
for x in 0..@n_w
for y in 0..@n_h
rect = Rect.new(0,0,@bitmap.width,@bitmap.height)
dest_rect = Rect.new(x * @bitmap.width * @zoom_x,\
y * @bitmap.height * @zoom_y,@bitmap.width * @zoom_x,\
@bitmap.height * @zoom_y)
@contents.bitmap.stretch_blt(dest_rect, @bitmap, rect)
end
end
end
end
end