Project1

标题: 【不是创意的创意】只读开关 [打印本页]

作者: 精灵使者    时间: 2012-9-11 16:50
标题: 【不是创意的创意】只读开关
本帖最后由 精灵使者 于 2017-10-9 00:59 编辑
  1. #==============================================================================
  2. # ■ 只允许读的开关
  3. # 控制 $write_able来控制$temp_switches是否存入存档。
  4. # 使用$temp_switches作为游戏里开关变量。
  5. #==============================================================================
  6. class Window_SaveFile < Window_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● 定义实例变量
  9.   #--------------------------------------------------------------------------
  10.   attr_reader   :filename                 # 文件名
  11.   attr_reader   :selected                 # 选择状态
  12.   #--------------------------------------------------------------------------
  13.   # ● 初始化对像
  14.   #     file_index : 存档文件的索引 (0~3)
  15.   #     filename   : 文件名
  16.   #--------------------------------------------------------------------------
  17.   def initialize(file_index, filename)
  18.     super(0, 64 + file_index % 4 * 104, 640, 104)
  19.     self.contents = Bitmap.new(width - 32, height - 32)
  20.     @file_index = file_index
  21.     @filename = "Save#{@file_index + 1}.rxdata"
  22.     @time_stamp = Time.at(0)
  23.     @file_exist = FileTest.exist?(@filename)
  24.     if @file_exist
  25.       file = File.open(@filename, "r")
  26.       @switches = Marshal.load(file) #读取已经初始化过的$switches并读入存档。
  27.       @time_stamp = file.mtime
  28.       @characters = Marshal.load(file)
  29.       @frame_count = Marshal.load(file)
  30.       @game_system = Marshal.load(file)
  31.       @game_switches = Marshal.load(file)
  32.       @game_variables = Marshal.load(file)
  33.       @total_sec = @frame_count / Graphics.frame_rate
  34.       file.close
  35.     end
  36.     refresh
  37.     @selected = false
  38.   end
  39. end

  40. #==============================================================================
  41. # ■ Scene_Save
  42. #------------------------------------------------------------------------------
  43. #  处理存档画面的类。
  44. #==============================================================================

  45. class Scene_Save < Scene_File
  46.   def write_save_data(file)
  47.     #switches 开关初始化并存档
  48.     @switches = false if @switches.nil?
  49.     #当可写变量打开时,写入游戏开关存档
  50.    if $write_able
  51.      @switches = $temp_switches
  52.      $write_able = false
  53.    end
  54.        Marshal.dump(@switches, file)
  55.     # 生成描绘存档文件用的角色图形
  56.     characters = []
  57.     for i in 0...$game_party.actors.size
  58.       actor = $game_party.actors[i]
  59.       characters.push([actor.character_name, actor.character_hue])
  60.     end
  61.     # 写入描绘存档文件用的角色数据
  62.     Marshal.dump(characters, file)
  63.     # 写入测量游戏时间用画面计数
  64.     Marshal.dump(Graphics.frame_count, file)
  65.     # 增加 1 次存档次数
  66.     $game_system.save_count += 1
  67.     # 保存魔法编号
  68.     # (将编辑器保存的值以随机值替换)
  69.     $game_system.magic_number = $data_system.magic_number
  70.     # 写入各种游戏对像
  71.     Marshal.dump($game_system, file)
  72.     Marshal.dump($game_switches, file)
  73.     Marshal.dump($game_variables, file)
  74.     Marshal.dump($game_self_switches, file)
  75.     Marshal.dump($game_screen, file)
  76.     Marshal.dump($game_actors, file)
  77.     Marshal.dump($game_party, file)
  78.     Marshal.dump($game_troop, file)
  79.     Marshal.dump($game_map, file)
  80.     Marshal.dump($game_player, file)
  81.   end
  82. end
  83. #==============================================================================
  84. # ■ Scene_Load
  85. #------------------------------------------------------------------------------
  86. #  处理读档画面的类。
  87. #==============================================================================

  88. class Scene_Load < Scene_File
  89.   def read_save_data(file)
  90.     @switches = Marshal.load(file) #读取已经初始化过的$switches并读入存档。
  91.     $temp_switches = @switches
  92.     # 读取描绘存档文件用的角色数据
  93.     characters = Marshal.load(file)
  94.     # 读取测量游戏时间用画面计数
  95.     Graphics.frame_count = Marshal.load(file)
  96.     # 读取各种游戏对像
  97.     $game_system        = Marshal.load(file)
  98.     $game_switches      = Marshal.load(file)
  99.     $game_variables     = Marshal.load(file)
  100.     $game_self_switches = Marshal.load(file)
  101.     $game_screen        = Marshal.load(file)
  102.     $game_actors        = Marshal.load(file)
  103.     $game_party         = Marshal.load(file)
  104.     $game_troop         = Marshal.load(file)
  105.     $game_map           = Marshal.load(file)
  106.     $game_player        = Marshal.load(file)
  107.     # 魔法编号与保存时有差异的情况下
  108.     # (加入编辑器的编辑过的数据)
  109.     if $game_system.magic_number != $data_system.magic_number
  110.       # 重新装载地图
  111.       $game_map.setup($game_map.map_id)
  112.       $game_player.center($game_player.x, $game_player.y)
  113.     end
  114.     # 刷新同伴成员
  115.     $game_party.refresh
  116.   end
  117. end


  118. class Scene_Title
  119.   #--------------------------------------------------------------------------
  120.   # ● 命令 : 新游戏
  121.   #--------------------------------------------------------------------------
  122.   def command_new_game
  123.     # 演奏确定 SE
  124.     $game_system.se_play($data_system.decision_se)
  125.     # 停止 BGM
  126.     Audio.bgm_stop
  127.     # 重置测量游戏时间用的画面计数器
  128.     Graphics.frame_count = 0
  129.     # 生成各种游戏对像
  130.     $temp_switches      = false
  131.     $game_temp          = Game_Temp.new
  132.     $game_system        = Game_System.new
  133.     $game_switches      = Game_Switches.new
  134.     $game_variables     = Game_Variables.new
  135.     $game_self_switches = Game_SelfSwitches.new
  136.     $game_screen        = Game_Screen.new
  137.     $game_actors        = Game_Actors.new
  138.     $game_party         = Game_Party.new
  139.     $game_troop         = Game_Troop.new
  140.     $game_map           = Game_Map.new
  141.     $game_player        = Game_Player.new
  142.     # 设置初期同伴位置
  143.     $game_party.setup_starting_members
  144.     # 设置初期位置的地图
  145.     $game_map.setup($data_system.start_map_id)
  146.     # 主角向初期位置移动
  147.     $game_player.moveto($data_system.start_x, $data_system.start_y)
  148.     # 刷新主角
  149.     $game_player.refresh
  150.     # 执行地图设置的 BGM 与 BGS 的自动切换
  151.     $game_map.autoplay
  152.     # 刷新地图 (执行并行事件)
  153.     $game_map.update
  154.     # 切换地图画面
  155.     $scene = Scene_Map.new
  156.   end
  157. end
复制代码


顾名思义,只允许读的开关。除非打开$write_able这个开关,否则$temp_switches不会存入存档。
这个可以做一些匪夷所思的东西用……
作者: satgo1546    时间: 2012-9-11 19:16
果然是匪夷所思的东西……
可是我到现在都还没看懂这是什么意思,是指$temp_switches是只能读的吗?
还是别的什么……





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1