Project1
标题:
角色换装系统主角被npc覆盖问题
[打印本页]
作者:
cloud0001
时间:
2010-7-24 19:25
标题:
角色换装系统主角被npc覆盖问题
我用了角色换装系统,结果发现主角面向上的时候 头部会被npc的脚覆盖,请问这个问题怎么解决?下面是代码~
#==============================================================================
# ■ 角色装备行走图变更 BY:亿万星辰
#------------------------------------------------------------------------------
# 使用了一种特殊的方法来改变行走图,不是更换,而是在原图的基础上继续描绘新的
# 层以实现层的叠加,类似暗黑里的装备帽子以后角色的行走图就多出帽子,装备盾牌以
# 后就会看到角色的左手拿着盾牌。
#
# 介绍:
# 现在默认分为5层,最下为默认的行走图,也就是数据库里角色那里设置的。之后分为头
# 部、身体、左右手4层,也可自行添加,但需要一定的功底,以防备逻辑上的混乱……
#
# 使用说明:
# 全部都是在数据库里设置,对应的武器或防具后逗号追加一个图片文件名即可,此文件
# 放在graphics/characters下,至于图片的绘制,实属虐待美工…… 具体可参考范例里
# 的graphics/characters目录,不过盾牌的图画的不是很合适
#==============================================================================
module RPG
class Weapon
def name
return @name.split(/,/)[0]
end
def part
return @name.split(/,/)[1]
end
end
class Armor
def name
return @name.split(/,/)[0]
end
def part
return @name.split(/,/)[1]
end
end
end
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# 处理主角的类。事件启动的判定、以及地图的滚动等功能。
# 本类的实例请参考 $game_player。
#==============================================================================
class Game_Player < Game_Character
attr_accessor :part_name # 角色 文件名
attr_accessor :turn_z
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super
@turn_z = [0,3,4,1,2] # 优先级,靠后的显示在最前 0主身体 1武器 2盾牌 3身体 4头
@part_name = [
$game_party.actors[0].character_name,
$game_party.actors[0].weapon_id != 0 ? $data_weapons[$game_party.actors[0].weapon_id].part : "",
$game_party.actors[0].armor1_id != 0 ? $data_armors[$game_party.actors[0].armor1_id].part : "",
$game_party.actors[0].armor2_id != 0 ? $data_armors[$game_party.actors[0].armor2_id].part : "",
$game_party.actors[0].armor3_id != 0 ? $data_armors[$game_party.actors[0].armor3_id].part : ""]
end
#--------------------------------------------------------------------------
# ● 面向向下
#--------------------------------------------------------------------------
def turn_down
unless @direction_fix
@direction = 2
@stop_count = 0
@turn_z = [0,3,4,1,2] # 优先级,靠后的显示在最前
end
end
#--------------------------------------------------------------------------
# ● 面向向左
#--------------------------------------------------------------------------
def turn_left
unless @direction_fix
@direction = 4
@stop_count = 0
@turn_z = [1,0,3,4,2] # 优先级,靠后的显示在最前
end
end
#--------------------------------------------------------------------------
# ● 面向向右
#--------------------------------------------------------------------------
def turn_right
unless @direction_fix
@direction = 6
@stop_count = 0
@turn_z = [2,0,3,4,1] # 优先级,靠后的显示在最前
end
end
#--------------------------------------------------------------------------
# ● 面向向上
# (这里感觉不太好处理,有些时候有的图一步在角色主图前,一步在角色主图后,
# 不怎么好处理,只能麻烦美工了……比如范例里的盾牌……)
#--------------------------------------------------------------------------
def turn_up
unless @direction_fix
@direction = 8
@stop_count = 0
@turn_z = [0,1,2,3,4] # 优先级,靠后的显示在最前
end
end
end
#==============================================================================
# ■ Sprite_Character
#------------------------------------------------------------------------------
# 角色显示用脚本。监视 Game_Character 类的实例、
# 自动变化脚本状态。
#==============================================================================
class Sprite_Player < RPG::Sprite
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :part # 角色
#--------------------------------------------------------------------------
# ● 初始化对像
# viewport : 查看端口
# character : 角色 (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, part)
super(viewport)
@part = part
@character = $game_player
self.z += $game_player.turn_z.index(part)
update
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
# 元件 ID、文件名、色相与现在的情况存在差异的情况下
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# 记忆元件 ID 与文件名、色相
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# 元件 ID 为有效值的情况下
pic = @character.part_name[@part]
self.bitmap = RPG::Cache.character(pic, @character.character_hue)
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
# 设置可视状态
self.visible = (not @character.transparent)
# 图形是角色的情况下
if @tile_id == 0
# 设置传送目标的矩形
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# 设置脚本的坐标
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.turn_z.index(part)
# 设置不透明度、合成方式、茂密
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# 动画
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
class Spriteset_Map
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
# 生成显示端口
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# 生成元件地图
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
# 生成远景平面
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
# 生成雾平面
@fog = Plane.new(@viewport1)
@fog.z = 3000
# 生成角色活动块
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Player.new(@viewport1, 0)) # 主体
@character_sprites.push(Sprite_Player.new(@viewport1, 1)) # 武器
@character_sprites.push(Sprite_Player.new(@viewport1, 2)) # 盾牌
@character_sprites.push(Sprite_Player.new(@viewport1, 3)) # 身体
@character_sprites.push(Sprite_Player.new(@viewport1, 4)) # 头
# 生成天气
@weather = RPG::Weather.new(@viewport1)
# 生成图片
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
# 生成计时器块
@timer_sprite = Sprite_Timer.new
# 刷新画面
update
end
end
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# ● 变更装备
# equip_type : 装备类型
# id : 武器 or 防具 ID (0 为解除装备)
#--------------------------------------------------------------------------
def equip(equip_type, id)
case equip_type
when 0 # 武器
if id == 0 or $game_party.weapon_number(id) > 0
$game_party.gain_weapon(@weapon_id, 1)
@weapon_id = id
$game_party.lose_weapon(id, 1)
$game_player.part_name[1] = @weapon_id != 0 ? $data_weapons[@weapon_id].part : ""
end
when 1 # 盾
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor1_id], $data_armors[id])
$game_party.gain_armor(@armor1_id, 1)
@armor1_id = id
$game_party.lose_armor(id, 1)
$game_player.part_name[2] = @armor1_id != 0 ? $data_armors[@armor1_id].part : ""
end
when 2 # 头
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor2_id], $data_armors[id])
$game_party.gain_armor(@armor2_id, 1)
@armor2_id = id
$game_party.lose_armor(id, 1)
$game_player.part_name[3] = @armor2_id != 0 ? $data_armors[@armor2_id].part : ""
end
when 3 # 身体
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor3_id], $data_armors[id])
$game_party.gain_armor(@armor3_id, 1)
@armor3_id = id
$game_party.lose_armor(id, 1)
$game_player.part_name[4] = @armor3_id != 0 ? $data_armors[@armor3_id].part : ""
end
when 4 # 装饰品
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor4_id], $data_armors[id])
$game_party.gain_armor(@armor4_id, 1)
@armor4_id = id
$game_party.lose_armor(id, 1)
end
end
end
end
复制代码
作者:
cloud0001
时间:
2010-7-31 14:29
==========================有米有人知道呀=====================
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1