赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 390 |
最后登录 | 2012-7-22 |
在线时间 | 5 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 5 小时
- 注册时间
- 2008-8-12
- 帖子
- 52
|
6楼
楼主 |
发表于 2009-4-22 21:37:09
|
只看该作者
还是贴出原代码好了...
unless defined? SNSER
module SNSER
#--------------------------------------------------------------------------
# ● 设置路径
#--------------------------------------------------------------------------
PATH_BGM = "Audio/BGM/"
#--------------------------------------------------------------------------
# ● API函数声明
#--------------------------------------------------------------------------
Channel_Pause = Win32API.new("RmSound","Channel_Pause","l","v")
Channel_Resume = Win32API.new("RmSound","Channel_Resume","l","v")
Channel_Stop = Win32API.new("RmSound","Channel_Stop","l","v")
Channel_StopAll = Win32API.new("RmSound","Channel_StopAll","v","v")
Midi_Play = Win32API.new("RmSound","Midi_Play","pi","l")
@@pause = false
#--------------------------------------------------------------------------
# ● 模块函数
#--------------------------------------------------------------------------
module_function
def is_pause(pause)
@@is_pause = pause
end
def bgm_pause?
return $game_system.battle_bgm_pause
end
#--------------------------------------------------------------------------
# ● 暂停Channel
# hChannel :要暂停的Channel句柄。
#--------------------------------------------------------------------------
def chn_pause(hChannel)
Channel_Pause.call(hChannel)
end
#--------------------------------------------------------------------------
# ● 恢复Channel
# hChannel :要恢复的Channel句柄。
#--------------------------------------------------------------------------
def chn_resume(hChannel)
Channel_Resume.call(hChannel)
end
#--------------------------------------------------------------------------
# ● 停止Channel
# hChannel :要停止的Channel句柄。
#--------------------------------------------------------------------------
def chn_stop(hChannel)
Channel_Stop.call(hChannel)
end
#--------------------------------------------------------------------------
# ● 暂停所有Channel
#--------------------------------------------------------------------------
def chn_pause_all
Channel_PauseAll.call
end
#--------------------------------------------------------------------------
# ● 恢复所有Channel
#--------------------------------------------------------------------------
def chn_resume_all
Channel_ResumeAll.call
end
#--------------------------------------------------------------------------
# ● 停止所有Channel
#--------------------------------------------------------------------------
def chn_stop_all
Channel_StopAll.call
end
#--------------------------------------------------------------------------
# ※ Midi
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# ● 播放Midi
# filename :要加载的midi文件名
# loop :如果参数为 0,那么midi播放一次,如果为 1,则一直循环直
# 到播放的 Channel 停止。
#
# return :返回一个Channel的句柄 hChannel,可以用该句柄来控制 。
# 失败返回 0。
#--------------------------------------------------------------------------
def midi_play(filename,loop=1)
if filename != ""
return Midi_Play.call(filename,loop)
end
end
end
end
class << Audio
@@battle_channel = nil
@@map_channel = nil
#--------------------------------------------------------------------------
# ※ BGM
#--------------------------------------------------------------------------
def bgm_play(filename, volume = 80, pitch = 100)
if $game_system.map_bgm_playing == true
if @@map_channel != nil
SNSER.chn_stop(@@map_channel)
end
@@map_channel = SNSER.midi_play(filename+ ".mid")
end
if $game_system.battle_bgm_playing == true
if @@battle_channel != nil
SNSER.chn_stop(@@battle_channel)
end
@@battle_channel = SNSER.midi_play(filename+ ".mid")
end
end
def bgm_stop
if $game_system.map_bgm_playing == false
if @@map_channel.nil?
else
if $game_system.battle_bgm_pause == false
SNSER.chn_stop(@@map_channel)
@@map_channel = nil
end
end
end
if $game_system.battle_bgm_playing == false
if @@battle_channel.nil?
else
SNSER.chn_stop(@@battle_channel)
@@battle_channel = nil
end
end
end
def bgm_pause
if $game_system.battle_bgm_pause == true
if @@map_channel.nil?
else
SNSER.chn_pause(@@map_channel)
end
end
end
def bgm_resume
if $game_system.battle_bgm_pause == false
if @@map_channel.nil?
else
SNSER.chn_resume(@@map_channel)
end
end
end
end
class Game_System
attr_accessor :map_bgm_playing
attr_accessor :battle_bgm_playing
attr_accessor :battle_bgm_pause
alias ori_initialize initialize
def initialize
@battle_bgm_playing = false
@map_bgm_playing = false
@battle_bgm_pause = false
ori_initialize
end
#--------------------------------------------------------------------------
# ● 获取战斗 BGM
#--------------------------------------------------------------------------
def battle_bgm
if @battle_bgm == nil
return $data_system.battle_bgm
else
return @battle_bgm
end
end
#--------------------------------------------------------------------------
# ● 设置战斗 BGM
# battle_bgm : 新的战斗 BGM
#--------------------------------------------------------------------------
def battle_bgm=(battle_bgm)
@battle_bgm = battle_bgm
end
#--------------------------------------------------------------------------
# ● 演奏 BGM
# bgm : 演奏的 BGM
#--------------------------------------------------------------------------
def bgm_play(bgm)
@playing_bgm = bgm
if bgm != nil and bgm.name != ""
Audio.bgm_play("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch)
else
Audio.bgm_stop
end
Graphics.frame_reset
end
end
class Game_Map
#--------------------------------------------------------------------------
# ● BGM / BGS 自动切换
#--------------------------------------------------------------------------
def autoplay
if @map.autoplay_bgm
if SNSER.bgm_pause?
Audio.bgm_resume
else
$game_system.map_bgm_playing = true
$game_system.bgm_play(@map.bgm)
end
end
if @map.autoplay_bgs
$game_system.bgs_play(@map.bgs)
end
end
end
class Scene_Map
#--------------------------------------------------------------------------
# ● 调用战斗
#--------------------------------------------------------------------------
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
# 记忆地图 BGM 停止 BGM
$game_system.map_bgm_playing = false
$game_system.battle_bgm_pause = true
Audio.bgm_pause
$game_system.map_bgm_playing = false
$game_system.battle_bgm_playing = true
# 演奏战斗开始 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
end
class Scene_Battle
#--------------------------------------------------------------------------
# ● 胜负判定
#--------------------------------------------------------------------------
def judge
# 全灭判定是真、并且同伴人数为 0 的情况下
if $game_party.all_dead? or $game_party.actors.size == 0
# 允许失败的情况下
if $game_temp.battle_can_lose
# 还原为战斗开始前的 BGM
#$game_system.bgm_play($game_temp.map_bgm)
$game_system.battle_bgm_playing = false
Audio.bgm_stop
$game_system.battle_bgm_pause = false
Audio.bgm_resume
# 战斗结束
battle_end(2)
# 返回 true
return true
end
# 设置游戏结束标志
$game_temp.gameover = true
# 返回 true
return true
end
# 如果存在任意 1 个敌人就返回 false
for enemy in $game_troop.enemies
if enemy.exist?
return false
end
end
# 开始结束战斗回合 (胜利)
start_phase5
# 返回 true
return true
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 执行战斗事件中的情况下
if $game_system.battle_interpreter.running?
# 刷新解释器
$game_system.battle_interpreter.update
# 强制行动的战斗者不存在的情况下
if $game_temp.forcing_battler == nil
# 执行战斗事件结束的情况下
unless $game_system.battle_interpreter.running?
# 继续战斗的情况下、再执行战斗事件的设置
unless judge
setup_battle_event
end
end
# 如果不是结束战斗回合的情况下
if @phase != 5
# 刷新状态窗口
@status_window.refresh
end
end
end
# 系统 (计时器)、刷新画面
$game_system.update
$game_screen.update
# 计时器为 0 的情况下
if $game_system.timer_working and $game_system.timer == 0
# 中断战斗
$game_temp.battle_abort = true
end
# 刷新窗口
@help_window.update
@party_command_window.update
@actor_command_window.update
@status_window.update
@message_window.update
# 刷新活动块
@spriteset.update
# 处理过渡中的情况下
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
# 显示效果中的情况下
if @spriteset.effect?
return
end
# 游戏结束的情况下
if $game_temp.gameover
# 切换到游戏结束画面
$scene = Scene_Gameover.new
return
end
# 返回标题画面的情况下
if $game_temp.to_title
# 切换到标题画面
$scene = Scene_Title.new
return
end
# 中断战斗的情况下
if $game_temp.battle_abort
# 还原为战斗前的 BGM
# $game_system.bgm_play($game_temp.map_bgm)
$game_system.battle_bgm_playing = false
Audio.bgm_stop
$game_system.battle_bgm_pause = false
Audio.bgm_resume
# 战斗结束
battle_end(1)
return
end
# 等待中的情况下
if @wait_count > 0
# 减少等待计数
@wait_count -= 1
return
end
# 强制行动的角色存在、
# 并且战斗事件正在执行的情况下
if $game_temp.forcing_battler == nil and
$game_system.battle_interpreter.running?
return
end
# 回合分支
case @phase
when 1 # 自由战斗回合
update_phase1
when 2 # 同伴命令回合
update_phase2
when 3 # 角色命令回合
update_phase3
when 4 # 主回合
update_phase4
when 5 # 战斗结束回合
update_phase5
end
end
#--------------------------------------------------------------------------
# ● 画面更新 (同伴指令回合 : 逃跑)
#--------------------------------------------------------------------------
def update_phase2_escape
# 计算敌人速度的平均值
enemies_agi = 0
enemies_number = 0
for enemy in $game_troop.enemies
if enemy.exist?
enemies_agi += enemy.agi
enemies_number += 1
end
end
if enemies_number > 0
enemies_agi /= enemies_number
end
# 计算角色速度的平均值
actors_agi = 0
actors_number = 0
for actor in $game_party.actors
if actor.exist?
actors_agi += actor.agi
actors_number += 1
end
end
if actors_number > 0
actors_agi /= actors_number
end
# 逃跑成功判定
success = rand(100) < 50 * actors_agi / enemies_agi
# 成功逃跑的情况下
if success
# 演奏逃跑 SE
$game_system.se_play($data_system.escape_se)
# 还原为战斗开始前的 BGM
# $game_system.bgm_play($game_temp.map_bgm)
$game_system.battle_bgm_playing = false
Audio.bgm_stop
$game_system.battle_bgm_pause = false
Audio.bgm_resume
# 战斗结束
battle_end(1)
# 逃跑失败的情况下
else
# 清除全体同伴的行动
$game_party.clear_actions
# 开始主回合
start_phase4
end
end
#--------------------------------------------------------------------------
# ● 开始结束战斗回合
#--------------------------------------------------------------------------
def start_phase5
# 转移到回合 5
@phase = 5
# 演奏战斗结束 ME
$game_system.me_play($game_system.battle_end_me)
# 还原为战斗开始前的 BGM
# $game_system.bgm_play($game_temp.map_bgm)
$game_system.battle_bgm_playing = false
Audio.bgm_stop
$game_system.battle_bgm_pause = false
Audio.bgm_resume
# 初始化 EXP、金钱、宝物
exp = 0
gold = 0
treasures = []
# 循环
for enemy in $game_troop.enemies
# 敌人不是隐藏状态的情况下
unless enemy.hidden
# 获得 EXP、增加金钱
exp += enemy.exp
gold += enemy.gold
# 出现宝物判定
if rand(100) < enemy.treasure_prob
if enemy.item_id > 0
treasures.push($data_items[enemy.item_id])
end
if enemy.weapon_id > 0
treasures.push($data_weapons[enemy.weapon_id])
end
if enemy.armor_id > 0
treasures.push($data_armors[enemy.armor_id])
end
end
end
end
# 限制宝物数为 6 个
treasures = treasures[0..5]
# 获得 EXP
for i in 0...$game_party.actors.size
actor = $game_party.actors
if actor.cant_get_exp? == false
last_level = actor.level
actor.exp += exp
if actor.level > last_level
@status_window.level_up(i)
end
end
end
# 获得金钱
$game_party.gain_gold(gold)
# 获得宝物
for item in treasures
case item
when RPG::Item
$game_party.gain_item(item.id, 1)
when RPG::Weapon
$game_party.gain_weapon(item.id, 1)
when RPG::Armor
$game_party.gain_armor(item.id, 1)
end
end
# 生成战斗结果窗口
@result_window = Window_BattleResult.new(exp, gold, treasures)
# 设置等待计数
@phase5_wait_count = 100
end
end |
|