设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
Project1 查看内容

用脚本简化的地图明雷遇敌系统

2007-5-16 00:00| 发布者: 柳柳| 查看: 8354| 评论: 0|原作者: kevin5408

摘要:     作者 kevin5408 版本 没有 相关网址 点此进入讨论贴 范例工程 没有   内容 這個系統,是模擬 仙劍奇俠傳的地圖遇敵模式。基本上怪物會在地圖上出現,當玩家處碰/
 
 

作者

kevin5408

版本

没有

相关网址

点此进入讨论贴

范例工程

没有


 

内容

這個系統,是模擬 仙劍奇俠傳的地圖遇敵模式。
基本上怪物會在地圖上出現,當玩家處碰/或是被處碰到才會進入戰鬥
(目前戰鬥系統還是以RMXP預設為主)
可能有人會認為,這個功能用事件內建功能就可以達成。在此是利用腳本整合,並且有些
特殊的地方。
1.比如1號地圖上有 史萊姆、蜘蛛、蛇 三類的敵人。
如果運用事件來作,可能事件的圖案就很難達到完善
(地圖上事件是史萊姆,結果一開打竟然是蛇。)
這個腳本他可以把你再[地圖設定]內所加入的怪物,直接轉換到地圖上直接顯示
你的地圖設定有三類的怪,那地圖上絕對不會顯示出第四類...
並且,地圖上顯示史萊姆,進入戰鬥就是跟史萊姆作戰,不會打錯敵人.

2.大幅簡化開發者的怪物設定上的困難度。
如果以事件內建功能來製作,不同的怪物你必許指定不同的圖案外,進入戰鬥這指令
還得再另外的去設定。
這個腳本很簡單,只要在事件名稱上輸入[敵人]。其他欄位都不用管
(你也可以設定他的移動速度/頻率)
系統自動會幫你轉換地圖上因該出現的敵人。開發者只要把這敵人事件放到想要放的位置即可。

目前唯一的BUG無法克服:
設計時地圖上所有[事件ID]必須[連號]
也就是有5個事件,那麼這事件ID必須為1.2.3.4.5
不可以為 1.2.3.4.6 會出現異常錯誤。

目前這系統有修改到 Scene_Battler 4 這腳本些許功能(主要是判斷戰鬥勝利的模組)
因此可能會與部分戰鬥腳本衝突。但是..要修改非常簡單...
因為只是在 Scene_Battler 4 內增加幾個變數而已。


補充,因為使用繁體,所以可能再事件名稱的判斷上會出現問題。
可以看到整個程式碼後找到下面這段修改。

if $game_map.events[i].name == "敵人"


這敵人請改為簡體,事件名稱使用簡體的[敵人]即可。

#------------------------------------------------------------------
#●怪物事件隨機圖示變化設計模組-主要控制
#--------------------------------------------------------------------
def new_battle_module
  # 遇敵列表不為空的情況下
  if $game_map.encounter_list != []
    # 不是在事件執行中或者禁止遇敵中
    unless $game_system.map_interpreter.running? or
           $game_system.encounter_disabled
      # 確定隊伍
       for i in 1 .. $game_map.events.size
         if $game_map.events[i].name == "敵人"
           if $game_map.events[i].character_name == ""#避免怪物持續刷新,設置一個break的條件

 
 

 脚本

 #-------------------------------------------------------------------------------------
#超!遇敵系統
#coding by Kevin Chang
#==============================================================================
# ■ Game_Event
#------------------------------------------------------------------------------
#  處理事件的程式。條件判斷、事件頁的切換、並行處理、執行事件功能
#     在 Game_Map 的內部使用。
#==============================================================================
module RPG #新增name定義,作用於抓取事件名稱欄位值
 class Event
   def initialize(x, y)
     @id = 0
     @name = ""
     @x = x
     @y = y
     @pages = [RPG::Event::Page.new]
   end
   attr_accessor :id
   attr_accessor :name
   attr_accessor :x
   attr_accessor :y
   attr_accessor :pages
 end
end
class Game_Event < Game_Character
 #--------------------------------------------------------------------------
 # ● 定義實例變量
 #--------------------------------------------------------------------------
 attr_accessor   :trigger                  # 目標(改為可讀寫)
 attr_reader   :list                     # 執行內容
 attr_reader   :starting                 # 啟動中標誌
 attr_accessor :name                  #取得事件名稱
 attr_accessor :character_name #改變事件圖形為可讀寫
 attr_accessor :auto_fight   #敵人事件處碰啟動戰鬥設定
 attr_accessor :move_type          #移動方式讓 $game_map.events[event_id].move_type = ? 來設定
 #--------------------------------------------------------------------------
 # ● 初始化對像
 #     map_id : 地圖 ID
 #     event  : 事件 (RPG::Event)
 #--------------------------------------------------------------------------
 def initialize(map_id, event)
   super()
   @map_id = map_id
   @event = event
   @id = @event.id
   @erased = false
   @starting = false
   @through = true
   @name = @event.name #取得事件名稱
   @character_name =""#改變事件圖形為可讀寫
   @auto_fight = false #敵人事件接觸自動戰鬥
   @move_type = 0 #移動方式 讓 $game_map.events[event_id].move_type = ? 來設定
   #改變敵人事件的移動方法 0.不動 1.隨機 2.接近 4.自訂AI
   # 初期位置的移動
   moveto(@event.x, @event.y)
   refresh
 end
   #--------------------------------------------------------------------------
 # ● 接觸事件啟動判定
 #--------------------------------------------------------------------------
 def check_event_trigger_touch(x, y)
   # 事件執行中的情況下
   if $game_system.map_interpreter.running?
     return
   end
   # 目標為 [與事件接觸] 以及和主角坐標一致的情況下
   if @trigger == 2 and x == $game_player.x and y == $game_player.y
     # 除跳躍中以外的情況、啟動判定就是正面的事件
     if not jumping? and not over_trigger?
       @auto_fight = true
            start
      else
       @auto_fight = false
     end
   end
 end
 #--------------------------------------------------------------------------
 # ● 自動事件啟動判定
 #--------------------------------------------------------------------------
 def check_event_trigger_auto
   # 目標為 [與事件接觸] 以及和主角坐標一致的情況下
   if @trigger == 2 and @x == $game_player.x and @y == $game_player.y
     # 除跳躍中以外的情況、啟動判定就是同位置的事件
     if not jumping? and over_trigger?
       @auto_fight = true
       start
     else
       @auto_fight = false
     end
   end
   # 目標是 [自動執行] 的情況下
   if @trigger == 3
     start
   end
 end
end

#==============================================================================
# ■ Game_Character (分割定義 2)
#------------------------------------------------------------------------------
#  處理角色的程式。本程式作為 Game_Player 與 Game_Event
#     的超級程式使用。
#==============================================================================

class Game_Character
 #--------------------------------------------------------------------------
 # ● 移動類型 : 接近
 #--------------------------------------------------------------------------
 def move_type_toward_player
   # 求得與主角坐標的差
   sx = @x - $game_player.x
   sy = @y - $game_player.y
   # 求得差的絕對值
   abs_sx = sx > 0 ? sx : -sx
   abs_sy = sy > 0 ? sy : -sy
   # 如果縱橫共計離開 20 個元件
   if sx + sy >= 5#修正敵人警戒距離
     # 隨機
     move_random
     return
   end
   # 隨機 0~5 的分支
   case rand(6)
   when 0..3  # 接近主角
     move_toward_player
   when 4  # 隨機
     move_random
   when 5  # 前進一步
     move_forward
   end
 end
end

#===========================================================
#==============================================================================
# ■ Scene_Map
#------------------------------------------------------------------------------
#  處理地圖畫面的程式。
#==============================================================================

class Scene_Map
 #--------------------------------------------------------------------------
 # ● 主處理
 #--------------------------------------------------------------------------
 $enemy_event_arry = [] #存放敵人事件的事件編號對應的敵人隊伍id(troop_id)
 $e_event_id = []#存放屬於敵人事件的事件id
 def main  
@a = 0
   # 生成活動塊
   @spriteset = Spriteset_Map.new
   # 生成訊息窗口
   @message_window = Window_Message.new
   # 執行過渡
   Graphics.transition
   # 主循環
   loop do    
     new_battle_module #呼叫新版遇敵系統
     # 刷新遊戲畫面
     Graphics.update
     # 刷新輸入訊息
     Input.update
     # 刷新畫面
     update
     # 如果畫面切換的話就中斷循環
     if $scene != self
       break
     end
   end
   # 準備過渡
   Graphics.freeze
   # 釋放活動塊
   @spriteset.dispose
   # 釋放訊息窗口
   @message_window.dispose
   # 標題畫面切換中的情況下
   if $scene.is_a?(Scene_Title)
     # 淡入淡出畫面
     Graphics.transition
     Graphics.freeze
   end
 end
 #------------------------------------------------------------------
 #●怪物事件隨機圖示變化設計模組-主要控制
 #--------------------------------------------------------------------
 def new_battle_module
   # 遇敵列表不為空的情況下
   if $game_map.encounter_list != []
     # 不是在事件執行中或者禁止遇敵中
     unless $game_system.map_interpreter.running? or
            $game_system.encounter_disabled
       # 確定隊伍
        for i in 1 .. $game_map.events.size
          if $game_map.events[i].name == "敵人"
            if $game_map.events[i].character_name == ""#避免怪物持續刷新,設置一個break的條件
            $game_map.events[i].character_name = rand_enemies_character_name#改變敵人事件的圖片
            $enemy_event_arry[i] = $enemy_event_id#將獲取的troop_id 存放到敵人事件陣列內
            $e_event_id[@a] = i
           @a += 1
            $game_map.events[i].trigger = 2 #自動改為接觸啟動事件
            $game_map.events[i].move_type = 2
            #改變敵人事件的移動方法 0.不動 1.隨機 2.接近
            # 隊伍有效的話
            else
              break
            end#if 避免怪物持續刷新,設置一個break的條件
          end
      end#end for
   end #unless
 end#if 遇敵列表不為空的情況下
end#module  
 #--------------------------------------------------------------------
 #●怪物事件隨機圖示變化設計模組-戰鬥圖獲取
 #--------------------------------------------------------------------
 def rand_enemies_character_name
        n = rand($game_map.encounter_list.size)#亂數取得地圖敵人列表數量
        troop_id = $game_map.encounter_list[n]#亂數帶入敵人隊伍ID內,由敵人列表隨機取出一隊伍
        troop = $data_troops[troop_id]#將隨機敵人隊伍資料存放到 troop 變數內
        $enemy_event_id = troop_id
        i =  rand(troop.members.size) #由troop隊伍資料內 隨機抽出一個敵人隊員
        enemy_character_name = $data_enemies[troop.members[i].enemy_id].battler_name
        #抽出的隨機敵人隊員,與data_enemies去比對出對應的怪物戰鬥圖,把戰鬥圖名稱取出
         return enemy_character_name #回傳戰鬥圖名稱
 end
 #--------------------------------------------------------------------------
 # ● 刷新畫面
 #--------------------------------------------------------------------------
 def update
   # 循環
   loop do
     # 按照地圖、實例、主角的順序刷新
     # (本更新順序不會在的滿足事件的執行條件下成為給予角色瞬間移動
     #  的機會的重要原素)
     $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
   # 遊戲結束的情況下
   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
     # 執行過渡
     if $game_temp.transition_name == ""
       Graphics.transition(20)
     else
       Graphics.transition(40, "Graphics/Transitions/" +
         $game_temp.transition_name)
     end
   end
   # 顯示訊息窗口中的情況下
   if $game_temp.message_window_showing
     return
   end
   # 遇敵列表不為空的情況下且敵人事件 auto_fight 為true
   for i in $e_event_id
   if $game_map.encounter_list != [] and $game_map.events[i].auto_fight == true
     $event_id_on_time = i #把正在進行戰鬥的 event_id 取出,以便後面呼叫使用
     # 不是在事件執行中或者禁止遇敵中
     unless $game_system.map_interpreter.running? or
            $game_system.encounter_disabled
       # 確定隊伍
       troop_id = $enemy_event_arry[i]
       # 隊伍有效的話
       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
   end #for
   # 按下 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 $DEBUG and 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
end
#==============================================================================
# ■ Scene_Battle (分割定義 2)
#------------------------------------------------------------------------------
#  處理戰鬥畫面的程式。
#==============================================================================

class Scene_Battle
 #--------------------------------------------------------------------------
 # ● 畫面更新 (結束戰鬥回合)
 #--------------------------------------------------------------------------
 def update_phase5
   # 等待計數大于 0 的情況下
   if @phase5_wait_count > 0
     # 減少等待計數
     @phase5_wait_count -= 1
     # 等待計數為 0 的情況下
     if @phase5_wait_count == 0
       # 顯示結果窗口
       @result_window.visible = true
       # 清除主回合標誌
       $game_temp.battle_main_phase = false
       # 刷新狀態窗口
       @status_window.refresh
     end
     return
   end
   # 按下 C 鍵的情況下
   if Input.trigger?(Input::C)
     # 戰鬥結束
     $game_map.events[$event_id_on_time].name = "死亡"
     $game_map.events[$event_id_on_time].auto_fight = false
     $game_map.events[$event_id_on_time].trigger = 0
     $game_map.events[$event_id_on_time].erase
     battle_end(0)
   end
 end
end
 
 

教程的通用说明

本站发布的教程,大多经过一些测试,应该都能够实现相应功能。但不保证所有的教程都是最优化的制作方法。

相关问题,点击发布贴进行讨论。谢谢您的鼓励与支持。


鲜花
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-2-21 21:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部