赞 | 0 |
VIP | 157 |
好人卡 | 6 |
积分 | 1 |
经验 | 113829 |
最后登录 | 2014-1-16 |
在线时间 | 26 小时 |
Lv1.梦旅人 B
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 26 小时
- 注册时间
- 2007-8-26
- 帖子
- 3693
|
- #==============================================================================
- # ■ Game_Picture
- #------------------------------------------------------------------------------
- # 处理图片的类。本类在类 Game_Screen ($game_screen)
- # 的内部使用。
- #==============================================================================
- $gd = true
- # 图片固定开关
- class Game_Picture
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :number # 图片编号
- attr_reader :name # 文件名
- attr_reader :origin # 原点
- attr_reader :x # X 坐标
- attr_reader :y # Y 坐标
- attr_reader :zoom_x # X 方向放大率
- attr_reader :zoom_y # Y 方向放大率
- attr_reader :opacity # 不透明度
- attr_reader :blend_type # 合成方式
- attr_reader :tone # 色调
- attr_reader :angle # 旋转角度
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # number : 图片编号
- #--------------------------------------------------------------------------
- def initialize(number)
- @number = number
- @name = ""
- @origin = 0
- @x = 0.0
- @y = 0.0
- @zoom_x = 100.0
- @zoom_y = 100.0
- @opacity = 255.0
- @blend_type = 1
- @duration = 0
- @target_x = @x
- @target_y = @y
- @target_zoom_x = @zoom_x
- @target_zoom_y = @zoom_y
- @target_opacity = @opacity
- @tone = Tone.new(0, 0, 0, 0)
- @tone_target = Tone.new(0, 0, 0, 0)
- @tone_duration = 0
- @angle = 0
- @rotate_speed = 0
- end
- #--------------------------------------------------------------------------
- # ● 显示图片
- # name : 文件名
- # origin : 原点
- # x : X 坐标
- # y : Y 坐标
- # zoom_x : X 方向放大率
- # zoom_y : Y 方向放大率
- # opacity : 不透明度
- # blend_type : 合成方式
- #--------------------------------------------------------------------------
- def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
- @name = name
- @origin = origin
- @x = x.to_f
- @y = y.to_f
- @zoom_x = zoom_x.to_f
- @zoom_y = zoom_y.to_f
- @opacity = opacity.to_f
- @blend_type = blend_type
- @duration = 0
- @target_x = @x
- @target_y = @y
- @target_zoom_x = @zoom_x
- @target_zoom_y = @zoom_y
- @target_opacity = @opacity
- @tone = Tone.new(0, 0, 0, 0)
- @tone_target = Tone.new(0, 0, 0, 0)
- @tone_duration = 0
- @angle = 0
- @rotate_speed = 0
- end
- #--------------------------------------------------------------------------
- # ● 移动图片
- # duration : 时间
- # origin : 原点
- # x : X 坐标
- # y : Y 坐标
- # zoom_x : X 方向放大率
- # zoom_y : Y 方向放大率
- # opacity : 不透明度
- # blend_type : 合成方式
- #--------------------------------------------------------------------------
- def move(duration, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
- @duration = duration
- @origin = origin
- @target_x = x.to_f
- @target_y = y.to_f
- @target_zoom_x = zoom_x.to_f
- @target_zoom_y = zoom_y.to_f
- @target_opacity = opacity.to_f
- @blend_type = blend_type
- end
- #--------------------------------------------------------------------------
- # ● 更改旋转速度
- # speed : 旋转速度
- #--------------------------------------------------------------------------
- def rotate(speed)
- @rotate_speed = speed
- end
- #--------------------------------------------------------------------------
- # ● 开始更改色调
- # tone : 色调
- # duration : 时间
- #--------------------------------------------------------------------------
- def start_tone_change(tone, duration)
- @tone_target = tone.clone
- @tone_duration = duration
- if @tone_duration == 0
- @tone = @tone_target.clone
- end
- end
- #--------------------------------------------------------------------------
- # ● 消除图片
- #--------------------------------------------------------------------------
- def erase
- @name = ""
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
-
- @real_x = @x * 128
- @real_y = @y * 128
- if @duration >= 1
- d = @duration
- @x = (@x * (d - 1) + @target_x) / d
- @y = (@y * (d - 1) + @target_y) / d
- @zoom_x = (@zoom_x * (d - 1) + @target_zoom_x) / d
- @zoom_y = (@zoom_y * (d - 1) + @target_zoom_y) / d
- @opacity = (@opacity * (d - 1) + @target_opacity) / d
- @duration -= 1
- end
- if @tone_duration >= 1
- d = @tone_duration
- @tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
- @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
- @tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
- @tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
- @tone_duration -= 1
- end
- if @rotate_speed != 0
- @angle += @rotate_speed / 2.0
- while @angle < 0
- @angle += 360
- end
- @angle %= 360
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取画面 X 坐标
- #--------------------------------------------------------------------------
- def screen_x
- # 通过实际坐标和地图的显示位置来求得画面坐标
- return (@real_x - $game_map.display_x + 3) / 4 + 16
- end
- #--------------------------------------------------------------------------
- # ● 获取画面 Y 坐标
- #--------------------------------------------------------------------------
- def screen_y
- return (@real_y - $game_map.display_y + 3) / 4 + 32
- end
- end
- #==============================================================================
- # ■ Sprite_Picture
- #------------------------------------------------------------------------------
- # 显示图片用的活动块。Game_Picture 类的实例监视、
- # 活动块状态的自动变化。
- #==============================================================================
- class Sprite_Picture < Sprite
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # viewport : 显示端口
- # picture : 图片 (Game_Picture)
- #--------------------------------------------------------------------------
- def initialize(viewport, picture)
- super(viewport)
- @picture = picture
- update
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- if self.bitmap != nil
- self.bitmap.dispose
- end
- super
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- # 图片的文件名与当前的情况有差异的情况下
- if @picture_name != @picture.name
- # 将文件名记忆到实例变量
- @picture_name = @picture.name
- # 文件名不为空的情况下
- if @picture_name != ""
- # 获取图片图形
- self.bitmap = RPG::Cache.picture(@picture_name)
- end
- end
- # 文件名是空的情况下
- if @picture_name == ""
- # 将活动块设置为不可见
- self.visible = false
- return
- end
- # 将活动块设置为可见
- self.visible = true
- # 设置传送原点
- if @picture.origin == 0
- self.ox = 0
- self.oy = 0
- else
- self.ox = self.bitmap.width / 2
- self.oy = self.bitmap.height / 2
- end
- # 设置活动块的坐标
-
- if $gd
- self.x = @picture.x
- self.y = @picture.y
- else
- self.x = @picture.screen_x
- self.y = @picture.screen_y
-
- self.z = @picture.number
- # 设置放大率、不透明度、合成方式
- self.zoom_x = @picture.zoom_x / 100.0
- self.zoom_y = @picture.zoom_y / 100.0
- self.opacity = @picture.opacity
- self.blend_type = @picture.blend_type
- # 设置旋转角度、色调
- self.angle = @picture.angle
- self.tone = @picture.tone
- end
- end
复制代码 |
|