注册会员 登录
Project1 返回首页

汪汪的个人空间 https://rpg.blue/?171386 [收藏] [复制] [分享] [RSS]

日志

【xp】即时录像的脚本(修改)

已有 61 次阅读2015-4-14 22:33 |个人分类:脚本·修改·整合·胡编

#==============================================================================
# ■ 即时录像脚本
#------------------------------------------------------------------------------
# 根据 66rpg 中 雷欧纳德 先生 的 脚本 更改 
# 原脚本如下:
# 仿魔兽的replay(录象?) - RPG Maker 技术区 - 66RPG - Powered by Discuz!
# http://rm.66rpg.com/forum.php?mod=viewthread&tid=38520
#------------------------------------------------------------------------------
#  $record.reca(i)   录制(i)开始 
#  $record.recz(i)   录制(i)结束
#  $record.recl(i)   播放(i)录像
#  bug 未知,下次更新未知。。。。。。。
#==============================================================================


#==============================================================================
# ■ Kernel
#------------------------------------------------------------------------------
#  Kernel模块。
#==============================================================================

module Kernel
  #--------------------------------------------------------------------------
  # ● 别名
  #--------------------------------------------------------------------------
  if @rand_redef.nil?
    alias rand_old rand
    @rand_redef = true
  end
  
  #--------------------------------------------------------------------------
  # ● 重定义
  #--------------------------------------------------------------------------
  def rand(max)
    if $record != nil and $record.mode == "播放"
      $record.key = $record.pop if $record.key == nil
      if $record.key == false
        $record.key = nil
      end
      keys = ["@dir4","@dir8","@press","@trigger","@repeat"]
      if keys.include?($record.key[0]) 
        $record.key = nil
      end
      if $record.key[0] == "@rand"
        result  = $record.key[1]
      end
      $record.key = nil
      return result
    end
    result = rand_old(max)
    if $record != nil and $record.mode == "录制"
      Input.deal_repeat_key
      $record.push(["@rand",result])
    end
    return result
  end

end

#==============================================================================
# ■ Input
#------------------------------------------------------------------------------
#  Input模块。
#==============================================================================

module Input
  #--------------------------------------------------------------------------
  # ● 记录
  #--------------------------------------------------------------------------
  @press = method("press?") if @press.nil?
  @trigger = method("trigger?") if @trigger.nil?
  @repeat = method("repeat?") if @repeat.nil?
  @dir4 = method("dir4") if @dir4.nil?
  @dir8 = method("dir8") if @dir8.nil?
  @ss = nil
  #--------------------------------------------------------------------------
  # ● 作用函数
  #--------------------------------------------------------------------------
  module_function
  
  #--------------------------------------------------------------------------
  # ● 记数
  #--------------------------------------------------------------------------
  @counts = 0
  
  #--------------------------------------------------------------------------
  # ● 处理重复键
  #--------------------------------------------------------------------------
  def deal_repeat_key
    return if @counts == 0
    $record.push(false,@counts)
    @counts = 0
  end
  
  #--------------------------------------------------------------------------
  # ● 通常
  #--------------------------------------------------------------------------
  def common(kind,num = nil)
    if $record != nil and $record.mode == "播放"
      $record.key = $record.pop if $record.key == nil
      return  if $record.key == nil
      if $record.key == false
        $record.key = nil 
        return 
      end
      if $record.key[0] == "@rand"
        return 
      end
      if  kind == $record.key[0]
        if num == $record.key[1]
          result = $record.key[2]
          $record.key = nil
          return result
        end
      end
      return
    end
    if ["@dir4","@dir8"].include?(kind) 
      result = eval(kind).call
      if $record != nil and $record.mode == "录制"
        if result != 0
          self.deal_repeat_key
          $record.push([kind,nil,result])
        else
          @counts += 1
        end
      end
    elsif ["@press","@trigger","@repeat"].include?(kind)
      result = eval(kind).call(num)
      if $record != nil and $record.mode == "录制"
        if result
          self.deal_repeat_key
          $record.push([kind,num,result])
        else
          @counts += 1
        end
      end
    end
    return result
  end
  
  #--------------------------------------------------------------------------
  # ● 重定义 press?
  #--------------------------------------------------------------------------
  def press?(num)
    return self.common("@press",num)
  end
  
  #--------------------------------------------------------------------------
  # ● 重定义 trigger?
  #--------------------------------------------------------------------------
  def trigger?(num)
    return self.common("@trigger",num)
  end
  
  #--------------------------------------------------------------------------
  # ● 重定义 repeat?
  #--------------------------------------------------------------------------
  def repeat?(num)
    return self.common("@repeat",num)
  end
  #--------------------------------------------------------------------------
  # ● 重定义 dir4
  #--------------------------------------------------------------------------
  def dir4
    return self.common("@dir4")
  end
  #--------------------------------------------------------------------------
  # ● 重定义 dir8
  #--------------------------------------------------------------------------
  def dir8
    return self.common("@dir8")
  end
  
end

#==============================================================================
# ■ Sub_Hash
#------------------------------------------------------------------------------
#  Hash的子类。
#==============================================================================

class Sub_Hash < Hash
  
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def initialize
    @pos = 0
  end
  
  #--------------------------------------------------------------------------
  # ● push
  #--------------------------------------------------------------------------
  def push(value)
    self[@pos] = value
    @pos += 1
  end
  
  #--------------------------------------------------------------------------
  # ● shift
  #--------------------------------------------------------------------------
  def shift
    result = self[@pos]
    @pos += 1
    return result
  end
  
  #--------------------------------------------------------------------------
  # ● 更改位置
  #--------------------------------------------------------------------------
  def pos=(pos)
    @pos = pos
  end
  
  #--------------------------------------------------------------------------
  # ● 判断
  #--------------------------------------------------------------------------
  def empty?
    return @pos == self.size
  end
  
end
    
#==============================================================================
# ■ Record
#------------------------------------------------------------------------------
#  录制的类。
#==============================================================================

class Record
  
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :mode
  attr_accessor :key
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def initialize
    @mode = "空"
    @infos = {}
    @replay = Sub_Hash.new  
    @key =nil 
    Dir.mkdir("Record") if !FileTest.directory?("Record")

  end
  
  #--------------------------------------------------------------------------
  # ● 开始录制
  #--------------------------------------------------------------------------
  def start
    #if [email protected]
    @mode = "录制"
    #end
  end
  

  
  #--------------------------------------------------------------------------
  # ● push 推进  录像记录方法
  #--------------------------------------------------------------------------
  def push(value,num = 1)
    @infos.each_key {|key| @infos[key].push([value,num]) }
  end
  

  
  #--------------------------------------------------------------------------
  # ●清空内容
  #--------------------------------------------------------------------------
  def clear
    @mode = "空"
    @infos = {}
    @replay = Sub_Hash.new  
    @recnum=nil
    @key =nil 
  end
  

  
  #--------------------------------------------------------------------------
  # ● 开始 写入录像数据
  #--------------------------------------------------------------------------
  def  reca(num=0)
    if @mode != "播放"
      @infos[num] = Sub_Hash.new
      rec={}
      rec[1] = recsave
      save_data(rec,"Record/record#{num}.rxdata")
      #开始录制
      start   
    end
  end
 
  #--------------------------------------------------------------------------
  # ● 结束 写入录像数据
  #--------------------------------------------------------------------------
  def recz(num=0)
    if $record != nil and $record.mode == "录制"
      rec=load_data("Record/record#{num}.rxdata")
      rec[2]= @infos[num]
      save_data(rec,"Record/record#{num}.rxdata")
      @infos.delete(num) 
    end
  end
  
  #--------------------------------------------------------------------------
  # ● 读取 录像数据
  #--------------------------------------------------------------------------
  def recl(num=0)
    if @mode != "播放"
      if @recnum == num or num == nil  
      # @renume 归 nil ,回到 读取录像点 时使用,保证不会重复触发
        @recnum = nil
      else
      # 记录num ,回到 读取录像点 时使用
        @recnum = num
      # 读取 录像 
        rec = load_data("Record/record#{num}.rxdata")
      # 写入 读取录像点 到录像
        rec[3] = recsave
        save_data(rec,"Record/record#{num}.rxdata")
      # 载入 录像开始点
        recload(rec[1])
      # 载入 录像
        @replay = rec[2] 
      #开始播放
        play 
      end
    end
  end
   
  #--------------------------------------------------------------------------
  # ● 开始播放
  #--------------------------------------------------------------------------
  def play
    @infos={}
    @replay = Sub_Hash.new if @replay == nil
    @mode = "播放" 
    @replay.pos = 0
    @counts = 0
    @kind = nil
    @key = nil
  end
   
  #--------------------------------------------------------------------------
  # ● pop 出现   录像读取方法
  #--------------------------------------------------------------------------
  def pop
    if @replay.empty?
      self.finish
      return
    end
    if @counts == 0
      result = @replay.shift
      @counts = result[1]
      @counts -= 1
      @kind = result[0] 
      return @kind
    else
      @counts -= 1
      return @kind
    end
  end
    
   
  #--------------------------------------------------------------------------
  # ● 播放结束
  #--------------------------------------------------------------------------
  def finish
    @mode = "空"
    p '播放结束'
    rec = load_data("Record/record#{@recnum}.rxdata")
    recload(rec[3])
    start
  end
  
  
  #--------------------------------------------------------------------------
  # ● 存档
  #--------------------------------------------------------------------------
  def recsave
    save = []
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    save[0]=characters
    save[1]=Graphics.frame_count
    $game_system.magic_number = $data_system.magic_number
    save[2]=$game_system
    save[3]=$game_switches
    save[4]=$game_variables
    save[5]=$game_self_switches
    save[6]=$game_screen
    save[7]=$game_actors
    save[8]=$game_party
    save[9]=$game_troop
    save[10]=$game_map
    save[11]=$game_player
    return save
  end
    
  
  #--------------------------------------------------------------------------
  # ● 读档
  #--------------------------------------------------------------------------
    
  def recload(load)
    characters           = load[0]
    Graphics.frame_count = load[1]
    $game_system         = load[2]
    $game_switches       = load[3]
    $game_variables      = load[4]
    $game_self_switches  = load[5]
    $game_screen         = load[6]
    $game_actors         = load[7]
    $game_party          = load[8]
    $game_troop          = load[9]
    $game_map            = load[10]
    $game_player         = load[11]
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh
    # 还原 BGM、BGS
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    # 刷新地图 (执行并行事件)
    $game_map.update 
    # 切换到地图画面
    $scene = Scene_Map.new
  end   
   
end

$record = Record.new


鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-10 05:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部