查看: 2559|回复: 3

[已经解决] 存档的问题

[复制链接]
梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
回帖
317
发表于 2014-10-13 14:40:26 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
我想把档位限制为一个。保存的时候默认第一个位置。读取的时候默认读取第一个位置.标题[继续]情况下,直接读取默认存档
梦石
0
星屑
105
在线时间
297 小时
注册时间
2009-1-7
回帖
155
发表于 2014-10-13 16:10:56 | 显示全部楼层
Scene_Load类的initialize方法:
  1.   def initialize
  2.     # 再生成临时对像
  3.     $game_temp = Game_Temp.new
  4.     # 选择存档时间最新的文件
  5.     $game_temp.last_file_index = 0
  6.     latest_time = Time.at(0)
  7.     for i in 0..3
  8.       filename = make_filename(i)
  9.       if FileTest.exist?(filename)
  10.         file = File.open(filename, "r")
  11.         if file.mtime > latest_time
  12.           latest_time = file.mtime
  13.           $game_temp.last_file_index = i
  14.         end
  15.         file.close
  16.       end
  17.     end
  18.     super("要载入哪个文件?")
  19.   end
复制代码
不要循环直接设置成0或者1怎么样?
游戏群组:https://rpg.blue/forum.php?mod=group&fid=565在这里你可以看到我在制作游戏过程中分享的内容。
回复

使用道具 举报

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
回帖
317
 楼主| 发表于 2014-10-13 16:31:01 | 显示全部楼层
timiesea 发表于 2014-10-13 16:10
Scene_Load类的initialize方法:不要循环直接设置成0或者1怎么样?

存档的时候默认呢
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2014-10-13 22:45:07 | 显示全部楼层
档位一个……,意思就是不考虑选择喽。
把这些替换原有差不多就可以了。缺点嘛{:8_460:}
存档时确定一下就存上了……容易误存
  1. #==============================================================================
  2. # ■ Scene_Title
  3. #------------------------------------------------------------------------------
  4. #  处理标题画面的类。
  5. #==============================================================================

  6. class Scene_Title
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     # 战斗测试的情况下
  12.     if $BTEST
  13.       battle_test
  14.       return
  15.     end
  16.     # 载入数据库
  17.     $data_actors        = load_data("Data/Actors.rxdata")
  18.     $data_classes       = load_data("Data/Classes.rxdata")
  19.     $data_skills        = load_data("Data/Skills.rxdata")
  20.     $data_items         = load_data("Data/Items.rxdata")
  21.     $data_weapons       = load_data("Data/Weapons.rxdata")
  22.     $data_armors        = load_data("Data/Armors.rxdata")
  23.     $data_enemies       = load_data("Data/Enemies.rxdata")
  24.     $data_troops        = load_data("Data/Troops.rxdata")
  25.     $data_states        = load_data("Data/States.rxdata")
  26.     $data_animations    = load_data("Data/Animations.rxdata")
  27.     $data_tilesets      = load_data("Data/Tilesets.rxdata")
  28.     $data_common_events = load_data("Data/CommonEvents.rxdata")
  29.     $data_system        = load_data("Data/System.rxdata")
  30.     # 生成系统对像
  31.     $game_system = Game_System.new
  32.     # 生成标题图形
  33.     @sprite = Sprite.new
  34.     @sprite.bitmap = RPG::Cache.title($data_system.title_name)
  35.     # 生成命令窗口
  36.     s1 = "新游戏"
  37.     s2 = "继续"
  38.     s3 = "退出"
  39.     @command_window = Window_Command.new(192, [s1, s2, s3])
  40.     @command_window.back_opacity = 160
  41.     @command_window.x = 320 - @command_window.width / 2
  42.     @command_window.y = 288
  43.     # 判定继续的有效性
  44.     # 存档文件一个也不存在的时候也调查
  45.     # 有効为 @continue_enabled 为 true、无效为 false
  46.     @continue_enabled = false
  47.    
  48.       if FileTest.exist?("Save1.rxdata")
  49.         @continue_enabled = true
  50.       end
  51.       
  52.     # 继续为有效的情况下、光标停止在继续上
  53.     # 无效的情况下、继续的文字显示为灰色
  54.     if @continue_enabled
  55.       @command_window.index = 1
  56.     else
  57.       @command_window.disable_item(1)
  58.     end
  59.     # 演奏标题 BGM
  60.     $game_system.bgm_play($data_system.title_bgm)
  61.     # 停止演奏 ME、BGS
  62.     Audio.me_stop
  63.     Audio.bgs_stop
  64.     # 执行过渡
  65.     Graphics.transition
  66.     # 主循环
  67.     loop do
  68.       # 刷新游戏画面
  69.       Graphics.update
  70.       # 刷新输入信息
  71.       Input.update
  72.       # 刷新画面
  73.       update
  74.       # 如果画面被切换就中断循环
  75.       if $scene != self
  76.         break
  77.       end
  78.     end
  79.     # 装备过渡
  80.     Graphics.freeze
  81.     # 释放命令窗口
  82.     @command_window.dispose
  83.     # 释放标题图形
  84.     @sprite.bitmap.dispose
  85.     @sprite.dispose
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 刷新画面
  89.   #--------------------------------------------------------------------------
  90.   def update
  91.     # 刷新命令窗口
  92.     @command_window.update
  93.     # 按下 C 键的情况下
  94.     if Input.trigger?(Input::C)
  95.       # 命令窗口的光标位置的分支
  96.       case @command_window.index
  97.       when 0  # 新游戏
  98.         command_new_game
  99.       when 1  # 继续
  100.         command_continue
  101.       when 2  # 退出
  102.         command_shutdown
  103.       end
  104.     end
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● 命令 : 新游戏
  108.   #--------------------------------------------------------------------------
  109.   def command_new_game
  110.     # 演奏确定 SE
  111.     $game_system.se_play($data_system.decision_se)
  112.     # 停止 BGM
  113.     Audio.bgm_stop
  114.     # 重置测量游戏时间用的画面计数器
  115.     Graphics.frame_count = 0
  116.     # 生成各种游戏对像
  117.     $game_temp          = Game_Temp.new
  118.     $game_system        = Game_System.new
  119.     $game_switches      = Game_Switches.new
  120.     $game_variables     = Game_Variables.new
  121.     $game_self_switches = Game_SelfSwitches.new
  122.     $game_screen        = Game_Screen.new
  123.     $game_actors        = Game_Actors.new
  124.     $game_party         = Game_Party.new
  125.     $game_troop         = Game_Troop.new
  126.     $game_map           = Game_Map.new
  127.     $game_player        = Game_Player.new
  128.     # 设置初期同伴位置
  129.     $game_party.setup_starting_members
  130.     # 设置初期位置的地图
  131.     $game_map.setup($data_system.start_map_id)
  132.     # 主角向初期位置移动
  133.     $game_player.moveto($data_system.start_x, $data_system.start_y)
  134.     # 刷新主角
  135.     $game_player.refresh
  136.     # 执行地图设置的 BGM 与 BGS 的自动切换
  137.     $game_map.autoplay
  138.     # 刷新地图 (执行并行事件)
  139.     $game_map.update
  140.     # 切换地图画面
  141.     $scene = Scene_Map.new
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # ● 命令 : 继续
  145.   #--------------------------------------------------------------------------
  146.   def command_continue
  147.     # 继续无效的情况下
  148.     unless @continue_enabled
  149.       # 演奏无效 SE
  150.       $game_system.se_play($data_system.buzzer_se)
  151.       return
  152.     end
  153.     # 演奏确定 SE
  154.     $game_system.se_play($data_system.decision_se)
  155.     # 切换到读档画面

  156.    
  157.     file = File.open("Save1.rxdata", "rb")
  158.         # 读取描绘存档文件用的角色数据
  159.     characters = Marshal.load(file)
  160.     # 读取测量游戏时间用画面计数
  161.     Graphics.frame_count = Marshal.load(file)
  162.     # 读取各种游戏对像
  163.     $game_system        = Marshal.load(file)
  164.     $game_switches      = Marshal.load(file)
  165.     $game_variables     = Marshal.load(file)
  166.     $game_self_switches = Marshal.load(file)
  167.     $game_screen        = Marshal.load(file)
  168.     $game_actors        = Marshal.load(file)
  169.     $game_party         = Marshal.load(file)
  170.     $game_troop         = Marshal.load(file)
  171.     $game_map           = Marshal.load(file)
  172.     $game_player        = Marshal.load(file)
  173.     # 魔法编号与保存时有差异的情况下
  174.     # (加入编辑器的编辑过的数据)
  175.     if $game_system.magic_number != $data_system.magic_number
  176.       # 重新装载地图
  177.       $game_map.setup($game_map.map_id)
  178.       $game_player.center($game_player.x, $game_player.y)
  179.     end
  180.     # 刷新同伴成员
  181.     $game_party.refresh
  182.     file.close
  183.     # 还原 BGM、BGS
  184.     $game_system.bgm_play($game_system.playing_bgm)
  185.     $game_system.bgs_play($game_system.playing_bgs)
  186.     # 刷新地图 (执行并行事件)
  187.     $game_map.update
  188.     # 切换到地图画面
  189.     $scene = Scene_Map.new

  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● 命令 : 退出
  193.   #--------------------------------------------------------------------------
  194.   def command_shutdown
  195.     # 演奏确定 SE
  196.     $game_system.se_play($data_system.decision_se)
  197.     # BGM、BGS、ME 的淡入淡出
  198.     Audio.bgm_fade(800)
  199.     Audio.bgs_fade(800)
  200.     Audio.me_fade(800)
  201.     # 退出
  202.     $scene = nil
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # ● 战斗测试
  206.   #--------------------------------------------------------------------------
  207.   def battle_test
  208.     # 载入数据库 (战斗测试用)
  209.     $data_actors        = load_data("Data/BT_Actors.rxdata")
  210.     $data_classes       = load_data("Data/BT_Classes.rxdata")
  211.     $data_skills        = load_data("Data/BT_Skills.rxdata")
  212.     $data_items         = load_data("Data/BT_Items.rxdata")
  213.     $data_weapons       = load_data("Data/BT_Weapons.rxdata")
  214.     $data_armors        = load_data("Data/BT_Armors.rxdata")
  215.     $data_enemies       = load_data("Data/BT_Enemies.rxdata")
  216.     $data_troops        = load_data("Data/BT_Troops.rxdata")
  217.     $data_states        = load_data("Data/BT_States.rxdata")
  218.     $data_animations    = load_data("Data/BT_Animations.rxdata")
  219.     $data_tilesets      = load_data("Data/BT_Tilesets.rxdata")
  220.     $data_common_events = load_data("Data/BT_CommonEvents.rxdata")
  221.     $data_system        = load_data("Data/BT_System.rxdata")
  222.     # 重置测量游戏时间用的画面计数器
  223.     Graphics.frame_count = 0
  224.     # 生成各种游戏对像
  225.     $game_temp          = Game_Temp.new
  226.     $game_system        = Game_System.new
  227.     $game_switches      = Game_Switches.new
  228.     $game_variables     = Game_Variables.new
  229.     $game_self_switches = Game_SelfSwitches.new
  230.     $game_screen        = Game_Screen.new
  231.     $game_actors        = Game_Actors.new
  232.     $game_party         = Game_Party.new
  233.     $game_troop         = Game_Troop.new
  234.     $game_map           = Game_Map.new
  235.     $game_player        = Game_Player.new
  236.     # 设置战斗测试用同伴
  237.     $game_party.setup_battle_test_members
  238.     # 设置队伍 ID、可以逃走标志、战斗背景
  239.     $game_temp.battle_troop_id = $data_system.test_troop_id
  240.     $game_temp.battle_can_escape = true
  241.     $game_map.battleback_name = $data_system.battleback_name
  242.     # 演奏战斗开始 BGM
  243.     $game_system.se_play($data_system.battle_start_se)
  244.     # 演奏战斗 BGM
  245.     $game_system.bgm_play($game_system.battle_bgm)
  246.     # 切换到战斗画面
  247.     $scene = Scene_Battle.new
  248.   end
  249. end
复制代码



  1. #==============================================================================
  2. # ■ Scene_Menu
  3. #------------------------------------------------------------------------------
  4. #  处理菜单画面的类。
  5. #==============================================================================

  6. class Scene_Menu
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     menu_index : 命令光标的初期位置
  10.   #--------------------------------------------------------------------------
  11.   def initialize(menu_index = 0)
  12.     @menu_index = menu_index
  13.   end
  14.   #--------------------------------------------------------------------------
  15.   # ● 主处理
  16.   #--------------------------------------------------------------------------
  17.   def main
  18.     # 生成命令窗口
  19.     s1 = $data_system.words.item
  20.     s2 = $data_system.words.skill
  21.     s3 = $data_system.words.equip
  22.     s4 = "状态"
  23.     s5 = "存档"
  24.     s6 = "结束游戏"
  25.     @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
  26.     @command_window.index = @menu_index
  27.     # 同伴人数为 0 的情况下
  28.     if $game_party.actors.size == 0
  29.       # 物品、特技、装备、状态无效化
  30.       @command_window.disable_item(0)
  31.       @command_window.disable_item(1)
  32.       @command_window.disable_item(2)
  33.       @command_window.disable_item(3)
  34.     end
  35.     # 禁止存档的情况下
  36.     if $game_system.save_disabled
  37.       # 存档无效
  38.       @command_window.disable_item(4)
  39.     end
  40.     # 生成游戏时间窗口
  41.     @playtime_window = Window_PlayTime.new
  42.     @playtime_window.x = 0
  43.     @playtime_window.y = 224
  44.     # 生成步数窗口
  45.     @steps_window = Window_Steps.new
  46.     @steps_window.x = 0
  47.     @steps_window.y = 320
  48.     # 生成金钱窗口
  49.     @gold_window = Window_Gold.new
  50.     @gold_window.x = 0
  51.     @gold_window.y = 416
  52.     # 生成状态窗口
  53.     @status_window = Window_MenuStatus.new
  54.     @status_window.x = 160
  55.     @status_window.y = 0
  56.     # 执行过渡
  57.     Graphics.transition
  58.     # 主循环
  59.     loop do
  60.       # 刷新游戏画面
  61.       Graphics.update
  62.       # 刷新输入信息
  63.       Input.update
  64.       # 刷新画面
  65.       update
  66.       # 如果切换画面就中断循环
  67.       if $scene != self
  68.         break
  69.       end
  70.     end
  71.     # 准备过渡
  72.     Graphics.freeze
  73.     # 释放窗口
  74.     @command_window.dispose
  75.     @playtime_window.dispose
  76.     @steps_window.dispose
  77.     @gold_window.dispose
  78.     @status_window.dispose
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # ● 刷新画面
  82.   #--------------------------------------------------------------------------
  83.   def update
  84.     # 刷新窗口
  85.     @command_window.update
  86.     @playtime_window.update
  87.     @steps_window.update
  88.     @gold_window.update
  89.     @status_window.update
  90.     # 命令窗口被激活的情况下: 调用 update_command
  91.     if @command_window.active
  92.       update_command
  93.       return
  94.     end
  95.     # 状态窗口被激活的情况下: 调用 update_status
  96.     if @status_window.active
  97.       update_status
  98.       return
  99.     end
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 刷新画面 (命令窗口被激活的情况下)
  103.   #--------------------------------------------------------------------------
  104.   def update_command
  105.     # 按下 B 键的情况下
  106.     if Input.trigger?(Input::B)
  107.       # 演奏取消 SE
  108.       $game_system.se_play($data_system.cancel_se)
  109.       # 切换的地图画面
  110.       $scene = Scene_Map.new
  111.       return
  112.     end
  113.     # 按下 C 键的情况下
  114.     if Input.trigger?(Input::C)
  115.       # 同伴人数为 0、存档、游戏结束以外的场合
  116.       if $game_party.actors.size == 0 and @command_window.index < 4
  117.         # 演奏冻结 SE
  118.         $game_system.se_play($data_system.buzzer_se)
  119.         return
  120.       end
  121.       # 命令窗口的光标位置分支
  122.       case @command_window.index
  123.       when 0  # 物品
  124.         # 演奏确定 SE
  125.         $game_system.se_play($data_system.decision_se)
  126.         # 切换到物品画面
  127.         $scene = Scene_Item.new
  128.       when 1  # 特技
  129.         # 演奏确定 SE
  130.         $game_system.se_play($data_system.decision_se)
  131.         # 激活状态窗口
  132.         @command_window.active = false
  133.         @status_window.active = true
  134.         @status_window.index = 0
  135.       when 2  # 装备
  136.         # 演奏确定 SE
  137.         $game_system.se_play($data_system.decision_se)
  138.         # 激活状态窗口
  139.         @command_window.active = false
  140.         @status_window.active = true
  141.         @status_window.index = 0
  142.       when 3  # 状态
  143.         # 演奏确定 SE
  144.         $game_system.se_play($data_system.decision_se)
  145.         # 激活状态窗口
  146.         @command_window.active = false
  147.         @status_window.active = true
  148.         @status_window.index = 0
  149.       when 4  # 存档
  150.         # 禁止存档的情况下
  151.         if $game_system.save_disabled
  152.           # 演奏冻结 SE
  153.           $game_system.se_play($data_system.buzzer_se)
  154.           return
  155.         end
  156.         # 演奏确定 SE
  157.         $game_system.se_play($data_system.decision_se)
  158.         # 切换到存档画面
  159.           file = File.open( "Save1.rxdata", "wb")
  160.           characters = []
  161.           for i in 0...$game_party.actors.size
  162.              actor = $game_party.actors[i]
  163.           characters.push([actor.character_name, actor.character_hue])
  164.           end
  165.           # 写入描绘存档文件用的角色数据
  166.             Marshal.dump(characters, file)
  167.           # 写入测量游戏时间用画面计数
  168.           Marshal.dump(Graphics.frame_count, file)
  169.           # 增加 1 次存档次数
  170.           $game_system.save_count += 1
  171.           # 保存魔法编号
  172.           # (将编辑器保存的值以随机值替换)
  173.           $game_system.magic_number = $data_system.magic_number
  174.           # 写入各种游戏对像
  175.           Marshal.dump($game_system, file)
  176.           Marshal.dump($game_switches, file)
  177.           Marshal.dump($game_variables, file)
  178.           Marshal.dump($game_self_switches, file)
  179.           Marshal.dump($game_screen, file)
  180.           Marshal.dump($game_actors, file)
  181.           Marshal.dump($game_party, file)
  182.           Marshal.dump($game_troop, file)
  183.           Marshal.dump($game_map, file)
  184.           Marshal.dump($game_player, file)
  185.           file.close
  186.       when 5  # 游戏结束
  187.         # 演奏确定 SE
  188.         $game_system.se_play($data_system.decision_se)
  189.         # 切换到游戏结束画面
  190.         $scene = Scene_End.new
  191.       end
  192.       return
  193.     end
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # ● 刷新画面 (状态窗口被激活的情况下)
  197.   #--------------------------------------------------------------------------
  198.   def update_status
  199.     # 按下 B 键的情况下
  200.     if Input.trigger?(Input::B)
  201.       # 演奏取消 SE
  202.       $game_system.se_play($data_system.cancel_se)
  203.       # 激活命令窗口
  204.       @command_window.active = true
  205.       @status_window.active = false
  206.       @status_window.index = -1
  207.       return
  208.     end
  209.     # 按下 C 键的情况下
  210.     if Input.trigger?(Input::C)
  211.       # 命令窗口的光标位置分支
  212.       case @command_window.index
  213.       when 1  # 特技
  214.         # 本角色的行动限制在 2 以上的情况下
  215.         if $game_party.actors[@status_window.index].restriction >= 2
  216.           # 演奏冻结 SE
  217.           $game_system.se_play($data_system.buzzer_se)
  218.           return
  219.         end
  220.         # 演奏确定 SE
  221.         $game_system.se_play($data_system.decision_se)
  222.         # 切换到特技画面
  223.         $scene = Scene_Skill.new(@status_window.index)
  224.       when 2  # 装备
  225.         # 演奏确定 SE
  226.         $game_system.se_play($data_system.decision_se)
  227.         # 切换的装备画面
  228.         $scene = Scene_Equip.new(@status_window.index)
  229.       when 3  # 状态
  230.         # 演奏确定 SE
  231.         $game_system.se_play($data_system.decision_se)
  232.         # 切换到状态画面
  233.         $scene = Scene_Status.new(@status_window.index)
  234.       end
  235.       return
  236.     end
  237.   end
  238. end
复制代码

评分

参与人数 1梦石 +1 收起 理由
RyanBern + 1 认可答案,代码还可更精简些

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部