幻耶 发表于 2010-5-31 14:21:09

求对事件绕圈脚本的速度优化!

以下脚本的功能是让一个事件围绕主角转圈子,但是对游戏速度影响比较大,在我的电脑上测试游戏,不用此脚本帧数34左右,用了帧数8左右,相差二十几帧,又不想放弃这个效果。。求速度优化!


比如让33号事件绕主角转圈:
运行$game_map.events.rotation($game_player, 96, 6)
$game_player是围绕的对象
96是半径
6是绕圈的速度



class Game_Character
alias :plus_initialize :initialize
alias :plus_screen_x :screen_x
alias :plus_screen_y :screen_y
alias :plus_screen_z :screen_z
def initialize(*avgc)
plus_initialize(*avgc)
@rotating = false # 旋转中?
@rotation_object = nil # 围绕的对象
@rotation_radius = 0 # 旋转半径
@rotation_speed = 0 # 旋转速度
@rotation_count = 0 # 旋转计数
end
# rotating?
def rotating?
return @rotating
end
# object : Game_Character
# radius : Int
def rotation(object, radius, speed)
@rotation_object = object
@rotation_radius = radius
@rotation_speed = speed
@rotating = true
end
def stop_rotation
@rotating = false
@rotation_object = nil
@rotation_radius = 0
@rotation_speed = 0
@rotation_count = 0
end
def update_rotating
@rotation_count += @rotation_speed
end
def rota_screen_x
return @rotation_object.screen_x + Math.cos(@rotation_count * Math::PI / 180) * @rotation_radius
end
def rota_screen_y
return @rotation_object.screen_y + Math.sin(@rotation_count * Math::PI / 180) * @rotation_radius
end
def rota_screen_z
return 9999
end
#--------------------------------------------------------------------------
# ● 获取画面 X 坐标
#--------------------------------------------------------------------------
def screen_x
if rotating?
rota_screen_x
else
plus_screen_x
end
end
#--------------------------------------------------------------------------
# ● 获取画面 Y 坐标
#--------------------------------------------------------------------------
def screen_y
if rotating?
rota_screen_y
else
plus_screen_y
end
end
#--------------------------------------------------------------------------
# ● 获取画面 Z 坐标
# height : 角色的高度
#--------------------------------------------------------------------------
def screen_z(height = 0)
if rotating?
rota_screen_z
else
plus_screen_z(height)
end
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 跳跃中、移动中、停止中的分支
if jumping?
update_jump
elsif moving?
update_move
elsif rotating?
update_rotating
else
update_stop
end



# 动画计数超过最大值的情况下
# ※最大值等于基本值减去移动速度 * 1 的值
if @anime_count > 18 - @move_speed * 2
# 停止动画为 OFF 并且在停止中的情况下
if not @step_anime and @stop_count > 0
# 还原为原来的图形
@pattern = @original_pattern
# 停止动画为 ON 并且在移动中的情况下
else
# 更新图形
@pattern = (@pattern + 1) % 4
end
# 清除动画计数
@anime_count = 0
end
# 等待中的情况下
if @wait_count > 0
# 减少等待计数
@wait_count -= 1
return
end
# 强制移动路线的场合
if @move_route_forcing
# 自定义移动
move_type_custom
return
end
# 事件执行待机中并且为锁定状态的情况下
if @starting or lock?
# 不做规则移动
return
end

# 如果停止计数超过了一定的值(由移动频度算出)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# 移动类型分支
case @move_type
when 1 # 随机
move_type_random
when 2 # 接近
move_type_toward_player
when 3 # 自定义
move_type_custom
end
end

# 环绕魔法的命中调用公共事件判定
for i in 1..20
next if $game_self_switches[[$game_map.map_id,i,"C"]] == true or !$game_map.events.name.include?("敌人")
if ($game_map.events.screen_x - $game_map.events.screen_x).abs <= 10 and ($game_map.events.screen_y - $game_map.events.screen_y).abs <= 10
$game_map.events.animation_id = 300
end
end

end
end
页: [1]
查看完整版本: 求对事件绕圈脚本的速度优化!