- 注册时间
- 2009-2-22
- 最后登录
- 2010-5-3
⑦老手
- 积分
- 6346
|
发表于 2009-5-1 18:53:11
|
显示全部楼层
一共六个脚本,都放在main前。试试
不是我做的,我找的。
#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
# 显示存档以及读档画面、保存文件的窗口。
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :filename # 文件名
attr_reader :selected # 选择状态
#--------------------------------------------------------------------------
# ● 初始化对像
# file_index : 存档文件的索引 (0~3)
# filename : 文件名
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % 4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
@file_index = file_index
@filename = $user_name + "/Save#{@file_index + 1}.rxdata"
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@game_system = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
file.close
end
refresh
@selected = false
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# 描绘文件编号
self.contents.font.color = normal_color
name = "文件 #{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# 存档文件存在的情况下
if @file_exist
# 描绘角色
for i in 0...@characters.size
bitmap = RPG::Cache.character(@characters[0], @characters[1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
end
# 描绘游戏时间
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(4, 8, 600, 32, time_string, 2)
# 描绘时间标记
self.contents.font.color = normal_color
time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
self.contents.draw_text(4, 40, 600, 32, time_string, 2)
end
end
#--------------------------------------------------------------------------
# ● 设置选择状态
# selected : 新的选择状态 (true=选择 false=不选择)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
class Scene_New_User
MAXNUM = 9
# -------------------------
def main
@edit_window = Window_NameEdit.new(MAXNUM)
@input_window = Window_NameInput.new
@alert_window = Window_Base.new(188, 208, 264, 64)
@alert_window.contents = Bitmap.new(228, 32)
@alert_window.contents.font.name = "黑体"
@alert_window.contents.font.size = 24
@alert_window.z = 1001
@alert_window.visible = false
c1 = " English"
c2 = " ひらがな"
c3 = " 输入中文"
c4 = " 空格"
c5 = " 退格"
c6 = " 默认姓名"
c7 = " 确定"
commands = [c1, c2, c3, c4, c5, c6, c7]
@command_window = Window_NameCommand.new(160, commands)
@input_window.active = false
@input_window.visible = true
@command_window.index = 0
@command_window.visible = true
@command_window.active = true
@command_window.x = 0
@command_window.y = 128
@command_window.z = 1000
@alert_count = 0
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@edit_window.dispose
@input_window.dispose
@command_window.dispose
@alert_window.dispose
end
# -------------------------
def update
@edit_window.update
@input_window.update
@command_window.update
@alert_window.update
if @alert_window.visible == true && @alert_count > 0
@alert_count -= 1
if @alert_count <= 0
@command_window.active = true
@alert_window.visible = false
end
return
end
if @input_window.active == false
@command_window.active = true
end
if @command_window.active == false
@input_window.active = true
end
if Input.repeat?(Input::B) && @input_window.active == true
if @edit_window.index == 0
return
else
$game_system.se_play($data_system.cancel_se)
@edit_window.back
end
end
if Input.repeat?(Input::B) && @command_window.active == true
$game_system.se_play($data_system.buzzer_se)
return
end
if Input.trigger?(Input::C)
if @command_window.active == true
case @command_window.index
when 0
$game_system.se_play($data_system.decision_se)
@input_window.mode = 1
@input_window.refresh
@command_window.active = false
@input_window.active = true
@input_window.index = 0
return
when 1
$game_system.se_play($data_system.decision_se)
@input_window.mode = 2
@input_window.refresh
@command_window.active = false
@input_window.active = true
@input_window.index = 0
return
when 2
$game_system.se_play($data_system.decision_se)
@input_window.mode = 3
@input_window.refresh
@command_window.active = false
@input_window.active = true
@input_window.index = 0
return
when 3
if @edit_window.index < MAXNUM
$game_system.se_play($data_system.decision_se)
@edit_window.add(" ")
else
$game_system.se_play($data_system.buzzer_se)
end
return
when 4
$game_system.se_play($data_system.decision_se)
@edit_window.back
return
when 5
$game_system.se_play($data_system.decision_se)
@edit_window.restore_default
return
when 6
unless $all_user.include?(@edit_window.name.split("\\n")[0])
if @edit_window.name == ""
$game_system.se_play($data_system.buzzer_se)
@alert_window.visible = true
@command_window.active = false
@alert_window.contents.draw_text(0, 0, 228, 32, "你必须输入一个名字")
@alert_count = 60
return
end
$game_system.se_play($data_system.decision_se)
$user_name = @edit_window.name.split("\\n")[0]
$all_user[0] = $user_name
$all_user.unshift($user_name)
Dir.mkdir($user_name)
f = File.open("Users.1012","w")
for name in $all_user
f.write(name)
f.write("\\n")
end
f.close
$game_system.se_play($data_system.decision_se)
$scene = Scene_Title.new
else
$game_system.se_play($data_system.buzzer_se)
@alert_window.visible = true
@command_window.active = false
@alert_window.contents.draw_text(0, 0, 228, 32, "你输入的名字已存在")
@alert_count = 60
end
return
end
end
if @edit_window.index == MAXNUM &&
@input_window.active == true
$game_system.se_play($data_system.buzzer_se)
return
end
if @input_window.character == "" && @input_window.active == true
$game_system.se_play($data_system.buzzer_se)
return
end
if @input_window.character != nil && @input_window.active == true &&
@edit_window.index <= MAXNUM
$game_system.se_play($data_system.decision_se)
if @input_window.mode == 1
@edit_window.char_type[@edit_window.index] = 1
else
@edit_window.char_type[@edit_window.index] = 2
end
@edit_window.add(@input_window.character)
end
return
end
end
end
class Window_NameEdit < Window_Base
# ---------------------------
attr_accessor :char_type
attr_reader :name
attr_reader :index
# ---------------------------
def initialize(max_char = 9)
super(0, 0, 640, 128)
self.contents = Bitmap.new(width - 32, height - 32)
@name = ""
@max_char = max_char
@char_type = []
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array
@char_type = 1
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
# ---------------------------
def restore_default
@name = @default_name
for i in 0..@default_name.size
@char_type = 1
end
@index = @name.split(//).size
refresh
update_cursor_rect
end
# ---------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
# ---------------------------
def back
if @index > 0
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array
end
@index -= 1
refresh
update_cursor_rect
end
end
# ---------------------------
def refresh
self.contents.clear
name_array = @name.split(//)
for i in 0...@max_char
c = name_array
if c == nil
c = "_"
end
x = 320 - @max_char * 14 + i * 28
if @char_type == 1
self.contents.font.name = "黑体"
self.contents.font.size = 24
else
self.contents.font.name = "黑体"
self.contents.font.size = 22
end
self.contents.draw_text(x, 32, 28, 32, c, 1)
end
end
# ---------------------------
def update_cursor_rect
x = 320 - @max_char * 14 + @index * 28
self.cursor_rect.set(x, 32, 28, 32)
end
# ---------------------------
def update
super
update_cursor_rect
end
end
class Window_NameInput < Window_Base
# ----------------------------------
attr_accessor :mode
# ----------------------------------
ENGLISH_TABLE =
[
"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
" ","Q","R","S","T",
"U","V","W","X","Y",
"Z","","","","",
"0","1","2","3","4",
"5", "6" ,"7", "8" ,"9",
"","","","","",
"a", "b" ,"c", "d" ,"e",
"f","g","h","i","j",
"k","l","m","n","o",
"p","q","r","s","t",
"u","v","w","x","y",
"z","","","","",
".",",","?","!","/",
"\\\\","<",">",";",":",
"","", "" , "" , "" ,
"@","#","$","%","^",
"&","*","(",")","",
"[","]","'","\\"","~",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"", "" ,"", "" ,"",
"","","","","",
]
HIRAGANA_TABLE =
[
"あ","い","う","え","お",
"か","き","く","け","こ",
"さ","し","す","せ","そ",
"た","ち","つ","て","と",
"な","に","ぬ","ね","の",
"は","ひ","ふ","へ","ほ",
"ま","み","む","め","も",
"や", "" ,"ゆ", "" ,"よ",
"ら","り","る","れ","ろ",
"わ", "" ,"を", "" ,"ん",
"が","ぎ","ぐ","げ","ご",
"ざ","じ","ず","ぜ","ぞ",
"だ","ぢ","づ","で","ど",
"ば","び","ぶ","べ","ぼ",
"ぱ","ぴ","ぷ","ぺ","ぽ",
"ゃ","ゅ","ょ","っ","ゎ",
"ぁ","ぃ","ぅ","ぇ","ぉ",
"ー","・", "" , "" , "" ,
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
]
KATAKANA_TABLE =
[
"赵","钱","孙","李","百",
"周","吴","郑","王","家",
"需","要","什","么","姓",
"文","字","请","自","己",
"去","填","加",",","只",
"要","替","换","现","有",
"文","字","即","可","。",
"你","也" ,"可", "以" ,"把",
"日","文","英","文","改",
"成","中" ,"文", "," ,"常",
"用","汉","字","基","本",
"也","就","够","用","了",
"文","字","太","多","玩",
"家","也","不","会","有",
"心","思","去","找","·",
"","","","","",
"","","","","",
"","","", "" , "" ,
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
"","","","","",
]
# ----------------------------------
def initialize
super(160, 128, 480, 352)
self.contents = Bitmap.new(width - 32, height - 32)
self.active = false
@index = -1
@mode = 1
refresh
update_cursor_rect
end
# ----------------------------------
def index=(value)
@index = value
update_cursor_rect
end
#--------------------------------------
def character
if @mode == 1
return ENGLISH_TABLE[@index]
elsif @mode == 2
return HIRAGANA_TABLE[@index]
else
return KATAKANA_TABLE[@index]
end
end
# ----------------------------------
def refresh
self.contents.clear
for i in 0..134
x = 4 + i / 5 / 9 * 152 + i % 5 * 28
y = i / 5 % 9 * 32
if @mode == 1
self.contents.font.name = "黑体"
self.contents.font.size = 24
self.contents.draw_text(x, y, 28, 32, ENGLISH_TABLE, 1)
elsif @mode == 2
self.contents.font.name = "黑体"
self.contents.font.size = 22
self.contents.draw_text(x, y, 28, 32, HIRAGANA_TABLE, 1)
else
self.contents.font.name = "黑体"
self.contents.font.size = 22
self.contents.draw_text(x, y, 28, 32, KATAKANA_TABLE, 1)
end
end
end
# ----------------------------------
def update_cursor_rect
if self.active == false
self.cursor_rect.empty
else
x = 4 + @index / 5 / 9 * 152 + @index % 5 * 28
y = @index / 5 % 9 * 32
self.cursor_rect.set(x, y, 28, 32)
end
end
# ----------------------------------
def update
super
if @index >= 0 && @index <= 134
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
if @index % 5 == 4
if @index < 94
@index += 41
end
else
@index += 1
end
end
if Input.repeat?(Input: EFT)
$game_system.se_play($data_system.cursor_se)
if @index % 5 == 0
if @index < 45
self.active = false
@index = -999
return
else
@index -= 41
end
else
@index -= 1
end
end
if Input.repeat?(Input: OWN)
$game_system.se_play($data_system.cursor_se)
if @index % 45 < 40
@index += 5
end
end
if Input.repeat?(Input::UP)
if Input.trigger?(Input::UP) or @index % 45 >= 5
$game_system.se_play($data_system.cursor_se)
if @index % 45 >= 5
@index -= 5
end
end
end
end
update_cursor_rect
end
end
class Window_NameCommand < Window_Command
# -------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
if i == 1 or i == 2
font = 1
self.contents.font.name = "黑体"
self.contents.font.size = 22
else
font = 0
self.contents.font.name = "黑体"
self.contents.font.size = 24
end
draw_item(i, normal_color, font)
end
end
# -------------------------------
def draw_item(index, color, f)
if f == 0
self.contents.font.color = color
self.contents.font.name = "黑体"
self.contents.font.size = 24
else
self.contents.font.name = "黑体"
self.contents.font.size = 22
end
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
end
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
# 处理标题画面的类。
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# ● 住处理
#--------------------------------------------------------------------------
def main
# 战斗测试的情况下
if $BTEST
battle_test
return
end
# 生成标题图形
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# 生成命令窗口
s1 = "新游戏"
s2 = "继续"
s3 = "退出"
s4 = "这不是我"
@command_window = Window_Command.new(192, [s1, s2, s3, s4])
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
w = @command_window.contents.text_size($user_name).width
user_window = Window_Base.new(0, 0, 128 + w, 64)
user_window.contents = Bitmap.new(w + 96, 32)
user_window.contents.draw_text(0, 0, w + 96, 32, "您好," + $user_name, 1)
# 判定继续的有效性
# 存档文件一个也不存在的时候也调查
# 有効为 @continue_enabled 为 true、無効为 false
@continue_enabled = false
for i in 0..3
if FileTest.exist?($user_name + "/Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# 继续为有效的情况下、光标停止在继续上
# 无效的情况下、继续的文字显示为灰色
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# 演奏标题 BGM
$game_system.bgm_play($data_system.title_bgm)
# 停止演奏 ME、BGS
Audio.me_stop
Audio.bgs_stop
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面被切换就中断循环
if $scene != self
break
end
end
# 装备过渡
Graphics.freeze
# 释放命令窗口
@command_window.dispose
user_window.dispose
# 释放标题图形
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新命令窗口
@command_window.update
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 命令窗口的光标位置的分支
case @command_window.index
when 0 # 新游戏
command_new_game
when 1 # 继续
command_continue
when 2 # 退出
command_shutdown
when 3 # 换人
command_changeplayer
end
end
end
#--------------------------------------------------------------------------
# ● 命令 : 新游戏
#--------------------------------------------------------------------------
def command_new_game
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 停止 BGM
Audio.bgm_stop
# 重置测量游戏时间用的画面计数器
Graphics.frame_count = 0
# 生成各种游戏对像
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# 设置初期同伴位置
$game_party.setup_starting_members
# 设置初期位置的地图
$game_map.setup($data_system.start_map_id)
# 主角向初期位置移动
$game_player.moveto($data_system.start_x, $data_system.start_y)
# 刷新主角
$game_player.refresh
# 执行地图设置的 BGM 与 BGS 的自动切换
$game_map.autoplay
# 刷新地图 (执行并行事件)
$game_map.update
# 切换地图画面
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ● 命令 : 继续
#--------------------------------------------------------------------------
def command_continue
# 继续无效的情况下
unless @continue_enabled
# 演奏无效 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 切换到读档画面
$scene = Scene_Load.new
end
#--------------------------------------------------------------------------
# ● 命令 : 退出
#--------------------------------------------------------------------------
def command_shutdown
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# BGM、BGS、ME 的淡入淡出
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# 退出
$scene = nil
end
#--------------------------------------------------------------------------
# ● 命令 : 换人
#--------------------------------------------------------------------------
def command_changeplayer
$scene = Scene_ChangePlayer.new
end
#--------------------------------------------------------------------------
# ● 战斗测试
#--------------------------------------------------------------------------
def battle_test
# 载入数据库 (战斗测试用)
$data_actors = load_data("Data/BT_Actors.rxdata")
$data_classes = load_data("Data/BT_Classes.rxdata")
$data_skills = load_data("Data/BT_Skills.rxdata")
$data_items = load_data("Data/BT_Items.rxdata")
$data_weapons = load_data("Data/BT_Weapons.rxdata")
$data_armors = load_data("Data/BT_Armors.rxdata")
$data_enemies = load_data("Data/BT_Enemies.rxdata")
$data_troops = load_data("Data/BT_Troops.rxdata")
$data_states = load_data("Data/BT_States.rxdata")
$data_animations = load_data("Data/BT_Animations.rxdata")
$data_tilesets = load_data("Data/BT_Tilesets.rxdata")
$data_common_events = load_data("Data/BT_CommonEvents.rxdata")
$data_system = load_data("Data/BT_System.rxdata")
# 重置测量游戏时间用的画面计数器
Graphics.frame_count = 0
# 生成各种游戏对像
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# 设置战斗测试用同伴
$game_party.setup_battle_test_members
# 设置队伍 ID、可以逃走标志、战斗背景
$game_temp.battle_troop_id = $data_system.test_troop_id
$game_temp.battle_can_escape = true
$game_map.battleback_name = $data_system.battleback_name
# 演奏战斗开始 BGM
$game_system.se_play($data_system.battle_start_se)
# 演奏战斗 BGM
$game_system.bgm_play($game_system.battle_bgm)
# 切换到战斗画面
$scene = Scene_Battle.new
end
end |
|