金庸5加入美女拼图小游戏方法
本帖最后由 美国小玩家 于 2019-7-1 06:40 编辑把脚本名和脚本复制到脚本里
脚本名字
Scene_PT
脚本
#==============================================================================
# ■ 个性化自定义内容
#
#——————————————————————————————————
#
# 是否使用“点歌”功能?如果不会自定义点歌功能,将true改为false即可
# 选了true一定要将Audio\BGM下的歌曲考到自己工程相应文件夹,或者自定义。
$carol3PT_music = true
#——————————————————————————————————
#
# 如果拼图游戏胜利结束,返回时自动打开的开关编号
# 当玩家放弃返回的时候,这个开关不打开
$carol3PT_switch = 1
#——————————————————————————————————
#
# 如果拼图游戏胜利结束时播放的音乐名
$carol3PT_me = "Audio/Me/001-Victory01"
#——————————————————————————————————
#
# 记录步数的变量编号,如果不需要记录步数,设置=0即可。
$carol3PT_steps = 1
#——————————————————————————————————
#
# 前景图编号 & 被拼图编号
#
# 使用说明:
#
# 默认情况下,在调用拼图功能之前,请先使用显示图片的功能显示一张前景图和一张背景图
# 这两张图可以是透明度为0,或者缩得极小,或者显示在屏幕外面,都没有关系(就是说,不用让这两张图出现在屏幕可视范围内,这图不是给玩家看的)
# 程序只是需要读取出这两张图片的名称而已,这样在制作中就不需要动脚本了。
$carol3PT_font = 2 #——前景图
$carol3PT_picture = 1 #——拆散的被拼图
# 然后,使用的时候只需要输入 $scene = Scene_PT.new(x,y) 即可。
#
# 括号内的x,y是切割的刀数,比如$scene = Scene_PT.new(3,3)就是3*3的拼图,$scene = Scene_PT.new(4,4)就是4*4的
# 也可以横纵切割得不一样,比如$scene = Scene_PT.new(4,6),但是这样的图不一定能够
# 保证一定有解,可能分配后就是不可能拼出来。
#
# 如果你只是输入$scene = Scene_PT.new,那就是最简单的3*3拼图
#
# 另外注意:在场景返回后请加一个对话事件,否则在某些RMXP上可能会跳过下面的一段事件。
#———————————————————————————————————————
#
# 是否允许玩家放弃(如果不允许,请一定让玩家拼横纵切割一样的图,否则……)
$carol3PT_draw = true
#———————————————————————————————————————
#
# 被拼图片坐标偏移,根据你自己制作的前景图决定。
$carol3PT_offset_x = 30
$carol3PT_offset_y = 30
#————————————————————————————————————————
#
# 作者的话:
#
# 创作这么一个东西的灵感来源于偶然遇见的拼图游戏(“偶然遇见”是人名,新人别误会)
# 反正正在做网站,也是为了光辉大陆的游戏制作业,于是耗费一天,有了这么个东西
#
#
#————————————————————————————————————————
#==============================================================================
# ■ Scene_SmallPicture
#------------------------------------------------------------------------------
# 处理拼图小图的类
#==============================================================================
class SmallPicture
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :sprite # 拥有的图片
attr_accessor :x # 目前的x坐标
attr_accessor :y # 目前的y坐标
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize(x , y , final_x , final_y )
@sprite = Sprite.new#——拥有的图片
@x=x #——目前x坐标
@y=y #——目前y坐标,这两个可以随时变化
@final_x = final_x#——目标最终x坐标
@final_y = final_y#——目标最终y坐标,初始化后这两个就不可变化了
end
#--------------------------------------------------------------------------
# ● 最终判断功能,已经到位则返回true,否则为false
#--------------------------------------------------------------------------
def judge
if @x==@final_x and @y==@final_y
return true
else
return false
end
end
end
#==============================================================================
# ■ Scene_PT
#------------------------------------------------------------------------------
# 处理拼图的类
#==============================================================================
class Scene_PT
#--------------------------------------------------------------------------
# ● 初始化对像
# menu_index : 命令光标的初期位置
#--------------------------------------------------------------------------
def initialize(max_x=3,max_y=3)
$game_switches[$carol3PT_switch] = false
@offset_x = $carol3PT_offset_x #——偏移x
@offset_y = $carol3PT_offset_y #——偏移y
@max_x = max_x #——纵切刀数
@max_y = max_y #——横切刀数
@smallpicture = []#——可爱的小图们
@randnumbers = [] #——一个随机数组
bit = Bitmap.new("Graphics/Pictures/"+$game_screen.pictures[$carol3PT_picture].name)
@l = bit.width/@max_x #——每格宽度
@h = bit.height/@max_y #——每格高度
bit.dispose
@space_x = max_x-1
@space_y = max_y-1
@update_phase = 1
@last_count = 0
if $carol3PT_steps != 0
$game_variables[$carol3PT_steps] = 0
end
end
#--------------------------------------------------------------------------
# ● 初始化对像
# 生成随机数(晕……我不会生成随机数组,只好自己编一个了)
#--------------------------------------------------------------------------
def randnumbers
for i in 0...@max_x*@max_y-1
thatsOK = false#——判断循环结束后是否已经获得了下一个随机数
for j in 0..30#——如果30次随机不能成功就用另外一种算法,防止运算太久。
tempnumber = rand(@max_x*@max_y-1).to_i#——生成随机数
already = false #——判断是否已经有过这个数字了
for k in 0...@randnumbers.size
if tempnumber == @randnumbers #——逐个寻找
already = true
break
end
end
if already == false
@randnumbers.push(tempnumber)
thatsOK = true
break
end
end
if thatsOK == false#——如果经过随机过程不能成功,这种算法保证OK而已。
for j in 0...@max_x*@max_y-1
already = false
for k in 0...@randnumbers.size
if j==@randnumbers
already = true
break
end
end
if already == false
@randnumbers.push(j)
break
end
end
end
end
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
for i in 0...@max_y
for j in 1..@max_x
if i==@max_y-1 and j==@max_x
break#——右下角留空白
end
#——把编号为i*@max_y+j-1的图放到@randnumbers对应的编号
x = @randnumbers%@max_x
y = @randnumbers/@max_x
@smallpicture.push(SmallPicture.new(x,y,j-1,i))
@smallpicture.sprite.bitmap = Bitmap.new(@l,@h)
@smallpicture.sprite.bitmap.blt(0, 0, Bitmap.new("Graphics/Pictures/"+$game_screen.pictures[$carol3PT_picture].name), Rect.new((j-1)*@l,i*@h,@l,@h))
@smallpicture.sprite.x = x*@l+@offset_x
@smallpicture.sprite.y = y*@h+@offset_y
@smallpicture.sprite.opacity = 0
@smallpicture.sprite.z = 2
$game_system.se_play($data_system.decision_se)
for opacity in 0..5
@smallpicture.sprite.opacity+=51
Graphics.update
end
end
end
end
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
@frontsprite = Sprite.new
@frontsprite.bitmap = Bitmap.new("Graphics/Pictures/"+$game_screen.pictures[$carol3PT_font].name)
@frontsprite.z = 999
Graphics.transition
@backsprite = Sprite.new
@backsprite.bitmap = Bitmap.new("Graphics/Pictures/"+$game_screen.pictures[$carol3PT_picture].name)
@backsprite.x = @offset_x
@backsprite.y = @offset_y
@backsprite.opacity = 0
@backsprite.z = 1
for i in 0..10
@backsprite.opacity += 25
Graphics.update
end
for i in 0..20
Graphics.update
end
for i in 0..20
@backsprite.opacity -= 9
Graphics.update
end
@backsprite.opacity = 70
randnumbers
#——如果在测试的时候自己懒得拼,就把下面这一行最开头的#号去掉。
#@randnumbers =
refresh#————上面都是一些浪费内存和时间的过程,生成窗口放在下面
s1 = "·查看完成图"
s2 = "·重新分布"
s3 = "·放弃这次"
s4 = "·更换背景乐"
#——命令窗口。
if $carol3PT_draw == false
@command_window = Window_Command.new(180,)
else
if $carol3PT_music == true
@command_window = Window_Command.new(180,)
else
@command_window = Window_Command.new(180,)
end
end
@command_window.x = 240
@command_window.y = 160
@command_window.z = 1000
@command_window.back_opacity = 192
@command_window.visible = false
@command_window.active = false
#——下面音乐部分就是你自己定义了,请放在Audio/BGM文件夹下
@music = []
#——以下文件按照在黑暗圣剑传说中的出场命名,实际上来源于RTP、
#——英雄传说、FF10、
@music = "Audio/BGM/BGM (1)"
@music = "Audio/BGM/BGM (2)"
@music = "Audio/BGM/BGM (3)"
@music = "Audio/BGM/BGM (4)"
@music = "Audio/BGM/BGM (5)"
@volume = #——顺次定义音量
@pitch = #——定义音调
@music_window = Window_Command.new(400,["BGM (1)","BGM (2)","BGM (3)","BGM (4)","BGM (5)"])
@music_window.contents_opacity = 0
@music_window.opacity = 0
@music_window.x = 220
@music_window.y = (480-@music_window.height)/2
@music_window.z = 1000
@music_window.active = false
@music_window.visible = false
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@command_window.dispose
for i in 0...@smallpicture.size
@smallpicture.sprite.bitmap.dispose
@smallpicture.sprite.dispose
end
@sprite = nil
@frontsprite.bitmap.dispose
@frontsprite.dispose
@backsprite.bitmap.dispose
@backsprite.dispose
@music_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
case @update_phase #——拼图过程
when 1
if Input.trigger?(Input::B)
@update_phase = 2
$game_system.se_play($data_system.decision_se)
@command_window.visible = true
@command_window.active = true
end
if Input.trigger?(Input::RIGHT)
if @space_x == 0
$game_system.se_play($data_system.buzzer_se)#——演奏冻结SE
else
for i in 0...@smallpicture.size
if @smallpicture.x == @space_x-1 and @smallpicture.y == @space_y
$game_system.se_play($data_system.decision_se)
@smallpicture.x += 1
for j in 0...5
@smallpicture.sprite.x+=@l/5
Graphics.update
end
@smallpicture.sprite.x = @space_x*@l+@offset_x #——为了防止不能整除出错,特地添加这么一行
@space_x -= 1
if $carol3PT_steps != 0
$game_variables[$carol3PT_steps]+=1
end
break
end
end
if victory_judge
Audio.me_play($carol3PT_me, 80, 100)
for i in 0..20
@backsprite.opacity+=13
Graphics.update
end
@update_phase = 5
end
end
end
if Input.trigger?(Input::LEFT)
if @space_x == @max_x-1
$game_system.se_play($data_system.buzzer_se)#——演奏冻结SE
else
for i in 0...@smallpicture.size
if @smallpicture.x == @space_x+1 and @smallpicture.y == @space_y
$game_system.se_play($data_system.decision_se)
@smallpicture.x -= 1
for j in 0...5
@smallpicture.sprite.x-=@l/5
Graphics.update
end
@smallpicture.sprite.x = @space_x*@l+@offset_x #——为了防止不能整除出错,特地添加这么一行
@space_x += 1
if $carol3PT_steps != 0
$game_variables[$carol3PT_steps]+=1
end
break
end
end
if victory_judge
Audio.me_play($carol3PT_me, 80, 100)
for i in 0..20
@backsprite.opacity+=13
Graphics.update
end
@update_phase = 5
end
end
end
if Input.trigger?(Input::DOWN)
if @space_y == 0
$game_system.se_play($data_system.buzzer_se)#——演奏冻结SE
else
for i in 0...@smallpicture.size
if @smallpicture.y == @space_y-1 and @smallpicture.x == @space_x
$game_system.se_play($data_system.decision_se)
@smallpicture.y += 1
for j in 0...5
@smallpicture.sprite.y+=@h/5
Graphics.update
end
@smallpicture.sprite.y = @space_y*@h+@offset_x #——为了防止不能整除出错,特地添加这么一行
@space_y -= 1
if $carol3PT_steps != 0
$game_variables[$carol3PT_steps]+=1
end
break
end
end
if victory_judge
Audio.me_play($carol3PT_me, 80, 100)
for i in 0..20
@backsprite.opacity+=13
Graphics.update
end
@update_phase = 5
end
end
end
if Input.trigger?(Input::UP)
if @space_y == @max_y-1
$game_system.se_play($data_system.buzzer_se)#——演奏冻结SE
else
for i in 0...@smallpicture.size
if @smallpicture.y == @space_y+1 and @smallpicture.x == @space_x
$game_system.se_play($data_system.decision_se)
@smallpicture.y -= 1
for j in 0...5
@smallpicture.sprite.y-=@h/5
Graphics.update
end
@smallpicture.sprite.y = @space_y*@h+@offset_x #——为了防止不能整除出错,特地添加这么一行
@space_y += 1
if $carol3PT_steps != 0
$game_variables[$carol3PT_steps]+=1
end
break
end
end
if victory_judge
Audio.me_play($carol3PT_me, 80, 100)
for i in 0..20
@backsprite.opacity+=13
Graphics.update
end
@update_phase = 5
end
end
end
when 2
update_command_window #——打开选项窗口的时候
when 3
if Input.trigger?(Input::C) or Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
for i in 0...5
@backsprite.opacity -= 20
Graphics.update
end
@command_window.visible = true
@command_window.active = true
for i in 0...5
@backsprite.opacity -= 16
Graphics.update
end
@backsprite.opacity = 70
@backsprite.z = 1
@update_phase = 2
end
when 4 #——选音乐
@music_window.update
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
Audio.bgm_play(@music[@music_window.index],@volume[@music_window.index], @pitch[@music_window.index])
@update_phase = 2
for i in 0...20
@command_window.x +=11
@music_window.opacity -= 14
@music_window.contents_opacity -= 14
Graphics.update
end
@music_window.visible = false
@music_window.active = false
@command_window.active = true
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@update_phase = 2
for i in 0...20
@command_window.x +=11
@music_window.opacity -= 14
@music_window.contents_opacity -= 14
Graphics.update
end
@music_window.visible = false
@music_window.active = false
@command_window.active = true
end
when 5 #——胜利!
@last_count += 1
if @last_count == 100
$game_switches[$carol3PT_switch] = true
$scene = Scene_Map.new
end
if Input.trigger?(Input::B) or Input.trigger?(Input::C)
$game_switches[$carol3PT_switch] = true
$scene = Scene_Map.new
end
end
end#——def update
#--------------------------------------------------------------------------
# ● 选项窗口专用
#--------------------------------------------------------------------------
def update_command_window
@command_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.visible = false
@command_window.active = false
@update_phase = 1
@command_window.index = 0
end
if Input.trigger?(Input::C)
case @command_window.index
when 0
$game_system.se_play($data_system.decision_se)
@backsprite.z = 998
for i in 0...10
@backsprite.opacity+=10
Graphics.update
end
@command_window.visible = false
@command_window.active = false
for i in 0...10
@backsprite.opacity+=10
Graphics.update
end
@update_phase = 3
when 1
@command_window.visible = false
@command_window.active = false
@update_phase = 1
renew
when 2
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
when 3
$game_system.se_play($data_system.decision_se)
@music_window.active = true
@music_window.visible = true
for i in 0...20
@command_window.x -=10
@music_window.opacity += 10
@music_window.contents_opacity += 14
Graphics.update
end
@update_phase = 4
@command_window.active = false
end
end
end
#--------------------------------------------------------------------------
# ● 重新开局(你可以在这里添一些搞笑的东西= =,或者记数,不过不太厚道……)
#--------------------------------------------------------------------------
def renew
@randnumbers = [] #——一个随机数组
for i in 0...@smallpicture.size #——先把原来的东西给清空
@smallpicture.sprite.bitmap.dispose
@smallpicture.sprite.dispose
end
@smallpicture = nil
@smallpicture = [] #——可爱的小图们,回来吧!
Graphics.update
@space_x = @max_x-1
@space_y = @max_y-1
randnumbers
refresh
end
#--------------------------------------------------------------------------
# ● 用来判断胜利的函数,如果已经拼完会返回true
#--------------------------------------------------------------------------
def victory_judge
for pic in @smallpicture
if pic.judge==false
return false
end
end
return true
end
end
下面事件编辑方法
最好把前景用一张透明的,就可以随便改用其它图了
页:
[1]