这是一个可以让新手交流研究用的脚本,因为脚本比较简单。。。
此脚本必须用到另外一个脚本——全键盘脚本。范例工程里面已经有全键盘脚本了
效果就是在地图上点击一个键直接弹出一个菜单,然后通过上下键移动光标选择项目。
效果图:
弹出时有个移动的效果
RUBY 代码
- #=============================================================================
- #弹出菜单脚本.西瓜版V0.1
- #作者:伊吹西瓜(朱鹭子)
- #此脚本为学习用原创的脚本,程序如有雷同(不包括效果),纯属巧合。
- #转载如果可以的话保留一下该信息吧。
- #应援幻想天空:[url]http://www.rpgsky.net/forum.php[/url]
- #=============================================================================
- #-----------------------------------------------------------------------------
- #●弹出菜单窗口
- #-----------------------------------------------------------------------------
- class Window_Mapcd < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化窗口
- #--------------------------------------------------------------------------
- def initialize
- super(640, 0, 200, 480)
- self.contents = Bitmap.new(width - 32, height - 32)
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- #self.windowskin = RPG::Cache.windowskin("")
- @dtcd1 = Bitmap.new("Graphics/Pictures/Equip.png")
- rect1 = Rect.new(0,0,80,132)
- self.contents.blt(0, 0, @dtcd1, rect1)
- @dtcd2 = Bitmap.new("Graphics/Pictures/magic.png")
- rect2 = Rect.new(0,0,80,132)
- self.contents.blt(0, 120, @dtcd2, rect2)
- @dtcd3 = Bitmap.new("Graphics/Pictures/target.png")
- rect3 = Rect.new(0,0,80,132)
- self.contents.blt(0, 240, @dtcd3, rect3)
- @dtcd4 = Bitmap.new("Graphics/Pictures/caidan.png")
- rect4 = Rect.new(0,0,80,132)
- self.contents.blt(0, 360, @dtcd4, rect4)
- end
- end
- #-----------------------------------------------------------------------------
- #●弹出菜单的鼠标
- #-----------------------------------------------------------------------------
- class Window_MapSb < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化窗口
- #--------------------------------------------------------------------------
- def initialize
- super(540, 20, 100,132)
- self.contents = Bitmap.new(width - 32, height - 32)
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.windowskin = RPG::Cache.windowskin("")
- @shubiao = Bitmap.new("Graphics/Pictures/shubiao.png")
- shubiao = Rect.new(0,0,200,132)
- self.contents.blt(0, 0, @shubiao, shubiao)
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #------------------------------------------------------------------------------
- # 处理地图画面的类。
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # ● 主处理
- #--------------------------------------------------------------------------
- def main
- $mune = 0
- $sbwz = 1 #这个是菜单栏目的数量
- # 生成活动块
- @spriteset = Spriteset_Map.new
- # 生成信息窗口
- @message_window = Window_Message.new
- #生成弹出菜单
- @mapcd_window = Window_Mapcd.new
- @mapcd_window.z = 10001
- #生成弹出鼠标
- @mapsb_window = Window_MapSb.new
- @mapsb_window.visible = false
- @mapsb_window.z = 10004
- tempBitmap = Sprite.new
- tempBitmap.bitmap = Bitmap.new(640,480)
- tempBitmap.bitmap.fill_rect(0, 0, 640, 480, Color.new(0,0,0,255))
- # 执行过渡
- Graphics.transition(0)
- for i in0..10
- tempBitmap.opacity-=25
- Graphics.update
- end
- tempBitmap.bitmap.dispose
- tempBitmap.dispose
- # 主循环
- loopdo
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- if$mune == 0#如果菜单弹出来的话,默认键盘无效,否则可能会发生冲突
- Input.update
- end
- Keyboard.update
- if$mune == 1 #判定菜单是否弹出来
- if Keyboard.trigger?(Keyboard::VK_ESCAPE)
- Audio.se_play("Audio/SE/005-System05",80,100)
- if$mune == 1
- $mune = 0
- elsif$mune == 0
- $mune = 1
- end
- end
- if Keyboard.trigger?(Keyboard::VK_UP)
- Audio.se_play("Audio/SE/005-System05",80,100)
- @mapsb_window.y -= 120
- $sbwz -= 1
- if@mapsb_window.y < 20
- @mapsb_window.y = 380
- $sbwz = 4
- end
- end
- if Keyboard.trigger?(Keyboard::VK_DOWN)
- Audio.se_play("Audio/SE/005-System05",80,100)
- @mapsb_window.y += 120
- $sbwz += 1
- if@mapsb_window.y > 380
- @mapsb_window.y = 20
- $sbwz = 1
- end
- end
- if Keyboard.trigger?(Keyboard::VK_RETURN)
- Audio.se_play("Audio/SE/005-System05",80,100)
- case$sbwz
- when1
- $scene = Scene_Equip.new
- when2
- $scene = Scene_Skill.new
- when3
- $scene = Scene_Item.new
- when4
- $scene = Scene_Menu.new
- end
- end
- end
- # 刷新画面
- update
- # 如果画面切换的话就中断循环
- if Keyboard.trigger?(Keyboard::VK_M)
- Audio.se_play("Audio/SE/005-System05",80,100)
- if$mune == 1
- $mune = 0
- elsif$mune == 0
- $mune = 1
- end
- end
- if$scene != self
- break
- end
- end
- # 标题画面切换中的情况下
- if$scene.is_a?(Scene_Title)
- @message_window.dispose
- tempBitmap = Sprite.new
- tempBitmap.bitmap = Bitmap.new(640,480)
- tempBitmap.bitmap.fill_rect(0, 0, 640,480, Color.new(0,0,0,255))
- tempBitmap.opacity = 0
- for i in0..25
- tempBitmap.opacity +=11
- Graphics.update
- end
- tempBitmap.bitmap.dispose
- tempBitmap.dispose
- Graphics.transition(0)
- @spriteset.dispose
- else
- @message_window.dispose
- @mapcd_window.dispose
- @mapsb_window.dispose
- @spriteset.dispose
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- if$mune == 1
- if@mapcd_window.x != 440
- @mapcd_window.x -= 10
- end
- end
- if$mune == 0
- if@mapcd_window.x != 640
- @mapcd_window.x += 10
- end
- end
- if@mapcd_window.x == 440
- @mapsb_window.visible = true
- else
- @mapsb_window.visible = false
- $sbwz = 1
- @mapsb_window.y = 20
- end
- @mapcd_window.update
- # 循环
- loopdo
- # 按照地图、实例、主角的顺序刷新
- # (本更新顺序不会在的满足事件的执行条件下成为给予角色瞬间移动
- # 的机会的重要因素)
- $game_map.update
- $game_system.map_interpreter.update
- $game_player.update
- # 系统 (计时器)、画面刷新
- $game_system.update
- $game_screen.update
- # 如果主角在场所移动中就中断循环
- unless$game_temp.player_transferring
- break
- end
- # 执行场所移动
- transfer_player
- # 处理过渡中的情况下、中断循环
- if$game_temp.transition_processing
- break
- end
- end
- # 刷新活动块
- @spriteset.update
- # 刷新信息窗口
- @message_window.update
- # 刷新弹出窗口
- @mapcd_window.update
- # 刷新鼠标
- @mapsb_window.update
- # 游戏结束的情况下
- if$game_temp.gameover
- # 切换的游戏结束画面
- $scene = Scene_Gameover.new
- return
- end
- # 返回标题画面的情况下
- if$game_temp.to_title
- # 切换到标题画面
- $scene = Scene_Title.new
- return
- end
- # 处理过渡中的情况下
- if$game_temp.transition_processing
- # 清除过渡处理中标志
- $game_temp.transition_processing = false
- # 执行过渡
- Graphics.transition(0)
- end
- # 显示信息窗口中的情况下
- if$game_temp.message_window_showing
- return
- end
- # 遇敌计数为 0 且、且遇敌列表不为空的情况下
- if$game_player.encounter_count == 0and$game_map.encounter_list != []
- # 不是在事件执行中或者禁止遇敌中
- unless$game_system.map_interpreter.running? or
- $game_system.encounter_disabled
- # 确定队伍
- n = rand($game_map.encounter_list.size)
- troop_id = $game_map.encounter_list[n]
- # 队伍有效的话
- if$data_troops[troop_id] != nil
- # 设置调用战斗标志
- $game_temp.battle_calling = true
- $game_temp.battle_troop_id = troop_id
- $game_temp.battle_can_escape = true
- $game_temp.battle_can_lose = false
- $game_temp.battle_proc = nil
- end
- end
- end
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 不是在事件执行中或菜单禁止中
- unless$game_system.map_interpreter.running? or
- $game_system.menu_disabled
- # 设置菜单调用标志以及 SE 演奏
- $game_temp.menu_calling = true
- $game_temp.menu_beep = true
- end
- end
- # 调试模式为 ON 并且按下 F9 键的情况下
- if$DEBUGand Input.press?(Input::F9)
- # 设置调用调试标志
- $game_temp.debug_calling = true
- end
- # 不在主角移动中的情况下
- unless$game_player.moving?
- # 执行各种画面的调用
- if$game_temp.battle_calling
- call_battle
- elsif$game_temp.shop_calling
- call_shop
- elsif$game_temp.name_calling
- call_name
- elsif$game_temp.menu_calling
- call_menu
- elsif$game_temp.save_calling
- call_save
- elsif$game_temp.debug_calling
- call_debug
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 调用战斗
- #--------------------------------------------------------------------------
- def call_battle
- # 清除战斗调用标志
- $game_temp.battle_calling = false
- # 清除菜单调用标志
- $game_temp.menu_calling = false
- $game_temp.menu_beep = false
- # 生成遇敌计数
- $game_player.make_encounter_count
- # 记忆地图 BGM 、停止 BGM
- $game_temp.map_bgm = $game_system.playing_bgm
- $game_system.bgm_stop
- # 演奏战斗开始 SE
- $game_system.se_play($data_system.battle_start_se)
- # 演奏战斗 BGM
- $game_system.bgm_play($game_system.battle_bgm)
- # 矫正主角姿势
- $game_player.straighten
- # 切换到战斗画面
- $scene = Scene_Battle.new
- end
- #--------------------------------------------------------------------------
- # ● 调用商店
- #--------------------------------------------------------------------------
- def call_shop
- # 清除商店调用标志
- $game_temp.shop_calling = false
- # 矫正主角姿势
- $game_player.straighten
- # 切换到商店画面
- $scene = Scene_Shop.new
- end
- #--------------------------------------------------------------------------
- # ● 调用名称输入
- #--------------------------------------------------------------------------
- def call_name
- # 清除商店调用名称输入标志
- $game_temp.name_calling = false
- # 矫正主角姿势
- $game_player.straighten
- # 切换到名称输入画面
- $scene = Scene_Name.new
- end
- #--------------------------------------------------------------------------
- # ● 调用菜单
- #--------------------------------------------------------------------------
- def call_menu
- =begin
- # 清除商店调用菜单标志
- $game_temp.menu_calling = false
- # 已经设置了菜单 SE 演奏标志的情况下
- if $game_temp.menu_beep
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- # 清除菜单演奏 SE 标志
- $game_temp.menu_beep = false
- end
- # 矫正主角姿势
- $game_player.straighten
- # 切换到菜单画面
- $scene = Scene_Menu.new
- =end
- end
- #--------------------------------------------------------------------------
- # ● 调用存档
- #--------------------------------------------------------------------------
- def call_save
- # 矫正主角姿势
- $game_player.straighten
- # 切换到存档画面
- $scene = Scene_Save.new
- end
- #--------------------------------------------------------------------------
- # ● 调用调试
- #--------------------------------------------------------------------------
- def call_debug
- # 清除商店调用调试标志
- $game_temp.debug_calling = false
- # 演奏确定 SE
- $game_system.se_play($data_system.decision_se)
- # 矫正主角姿势
- $game_player.straighten
- # 切换到调试画面
- $scene = Scene_Debug.new
- end
- #--------------------------------------------------------------------------
- # ● 主角的场所移动
- #--------------------------------------------------------------------------
- def transfer_player
- # 清除主角场所移动调试标志
- $game_temp.player_transferring = false
- # 移动目标与现在的地图有差异的情况下
- if$game_map.map_id != $game_temp.player_new_map_id
- # 设置新地图
- $game_map.setup($game_temp.player_new_map_id)
- end
- # 设置主角位置
- $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
- # 设置主角朝向
- case$game_temp.player_new_direction
- when2 # 下
- $game_player.turn_down
- when4 # 左
- $game_player.turn_left
- when6 # 右
- $game_player.turn_right
- when8 # 上
- $game_player.turn_up
- end
- # 矫正主角姿势
- $game_player.straighten
- # 刷新地图 (执行并行事件)
- $game_map.update
- # 在生成活动块
- @spriteset.dispose
- @spriteset = Spriteset_Map.new
- # 处理过渡中的情况下
- if$game_temp.transition_processing
- # 清除过渡处理中标志
- $game_temp.transition_processing = false
- # 执行过渡
- $_t_Bitmap=Sprite.new
- $_t_Bitmap.bitmap = Bitmap.new(640,480)
- $_t_Bitmap.bitmap.fill_rect(0,0,640,480,Color.new(0,0,0,255))
- Graphics.transition(0)
- for i in0..10
- $_t_Bitmap.opacity-=26
- Graphics.update
- end
- $_t_Bitmap.bitmap.dispose
- $_t_Bitmap.dispose
- end
- # 执行地图设置的 BGM、BGS 的自动切换
- $game_map.autoplay
- # 设置画面
- Graphics.frame_reset
- # 刷新输入信息
- Input.update
- end
- end
复制代码
范例工程:
本帖来自P1论坛作者伊吹西瓜,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:
https://rpg.blue/forum.php?mod=viewthread&tid=252259 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。