本帖最后由 RyanBern 于 2014-10-25 21:03 编辑
2L已经说明,必须要记录打败敌人的数量,这点可以在$game_system里面开一个Hash表(和2L不同,这里用的是Hash表而不是数组,这是模仿游戏存储道具的数据结构设定)。然后就是在每次战斗结束后对此Hash表进行操作即可。然后就是敌人战斗图的显示,可以利用$data_enemies[id].batter_name来获取战斗图名字。下面是一个简易的窗口,由于战斗图大小各异,所以请保证战斗图大小一致,否则会引起排版错乱。这里默认战斗图是100*100。
不知道你用的什么办法计算最终得到金钱的数量的,只能做到这一步了。战斗结束时自动记录敌人,打开这个界面后,按Esc退出金钱自动会增加。
我这里没有闪退的问题,不知道你改了哪里。
#=============================================================================== # ■ Scene_赏金系统 #------------------------------------------------------------------------------- # 处理赏金画面的类 #=============================================================================== class Scene_赏金系统 #-------------------------------------------------------------------------- # ● 主处理 #-------------------------------------------------------------------------- def main @sprite=Sprite.new @sprite.bitmap=RPG::Cache.picture("赏金背景") @enemy_window = Window_Enemy.new Graphics.transition loop do Graphics.update Input.update # 如果切换画面就中断循环 update if $scene != self break end end # 准备过渡 Graphics.freeze @sprite.dispose @enemy_window.dispose end def update if Input.trigger?(Input::B) $game_system.clear_defeated $game_party.gain_gold($kklt) $kklt = 0 $scene = Scene_Map.new return end end end #============================================================================== class Game_System alias rb_initialize_20141025 initialize def initialize @defeated_enemies = {} rb_initialize_20141025 end def defeated_enemy_number(enemy_id) return @defeated_enemies[enemy_id] == nil ? 0 : @defeated_enemies[enemy_id] end def defeated_enemy_number_add(enemy_id, n) @defeated_enemies[enemy_id] = [defeated_enemy_number(enemy_id) + n, 0].max end def clear_defeated @defeated_enemies = {} end end #============================================================================== class Window_Enemy < Window_Base def initialize super(0, 0, 480, 480) self.contents = Bitmap.new(width - 32, height - 32) self.opacity = 0 refresh end def refresh self.contents.clear @data = [] (1...$data_enemies.size).each do |i| if $game_system.defeated_enemy_number(i) > 0 @data.push($data_enemies[i]) end end self.contents.font.size = 36 @data.each_with_index do |enemy, i| x = 4 + i % 2 * 240 y = i / 2 * 100 bitmap = RPG::Cache.battler(enemy.battler_name, enemy.battler_hue) self.contents.blt(x, y, bitmap, Rect.new(0,0,100,100)) self.contents.draw_text(x + 104, y, 100, 100, "×" + $game_system.defeated_enemy_number(enemy.id).to_s, 2) end self.contents.draw_text(0, 400, 400-32, 64, $kklt.to_s + "G", 2) end end class Scene_Battle alias rb_battle_end battle_end def battle_end(result) if result == 0 $game_troop.enemies.each do |enemy| $game_system.defeated_enemy_number_add(enemy.id, 1) end end rb_battle_end(result) end end
#===============================================================================
# ■ Scene_赏金系统
#-------------------------------------------------------------------------------
# 处理赏金画面的类
#===============================================================================
class Scene_赏金系统
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
@sprite=Sprite.new
@sprite.bitmap=RPG::Cache.picture("赏金背景")
@enemy_window = Window_Enemy.new
Graphics.transition
loop do
Graphics.update
Input.update
# 如果切换画面就中断循环
update
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
@sprite.dispose
@enemy_window.dispose
end
def update
if Input.trigger?(Input::B)
$game_system.clear_defeated
$game_party.gain_gold($kklt)
$kklt = 0
$scene = Scene_Map.new
return
end
end
end
#==============================================================================
class Game_System
alias rb_initialize_20141025 initialize
def initialize
@defeated_enemies = {}
rb_initialize_20141025
end
def defeated_enemy_number(enemy_id)
return @defeated_enemies[enemy_id] == nil ? 0 : @defeated_enemies[enemy_id]
end
def defeated_enemy_number_add(enemy_id, n)
@defeated_enemies[enemy_id] = [defeated_enemy_number(enemy_id) + n, 0].max
end
def clear_defeated
@defeated_enemies = {}
end
end
#==============================================================================
class Window_Enemy < Window_Base
def initialize
super(0, 0, 480, 480)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
refresh
end
def refresh
self.contents.clear
@data = []
(1...$data_enemies.size).each do |i|
if $game_system.defeated_enemy_number(i) > 0
@data.push($data_enemies[i])
end
end
self.contents.font.size = 36
@data.each_with_index do |enemy, i|
x = 4 + i % 2 * 240
y = i / 2 * 100
bitmap = RPG::Cache.battler(enemy.battler_name, enemy.battler_hue)
self.contents.blt(x, y, bitmap, Rect.new(0,0,100,100))
self.contents.draw_text(x + 104, y, 100, 100, "×" + $game_system.defeated_enemy_number(enemy.id).to_s, 2)
end
self.contents.draw_text(0, 400, 400-32, 64, $kklt.to_s + "G", 2)
end
end
class Scene_Battle
alias rb_battle_end battle_end
def battle_end(result)
if result == 0
$game_troop.enemies.each do |enemy|
$game_system.defeated_enemy_number_add(enemy.id, 1)
end
end
rb_battle_end(result)
end
end
|