| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2024-3-20 |
| 在线时间 | 62 小时 |
- 梦石
- 0
- 星屑
- 143
- 在线时间
- 62 小时
- 注册时间
- 2015-5-24
- 回帖
- 44
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 梦想始终会醒 于 2017-7-25 15:56 编辑
研究了半天还是不知从哪下手.特来6R求助.
我把Bitmap位图代码无论放在脚本哪个位置都会发生错误
小弟把希望寄托在6R了,希望有前辈解答.
@芯☆淡茹水 @guoxiaomi
小地图代码.
小地图代码#==============================================================================
# ■ 修改小地图一般属性
#==============================================================================
module Micro_Map
X = 70 # X坐标
Y = 50 # Y坐标
WIDTH = 500 # 宽度
HEIGHT = 380 # 高度
OPACITY = 200 # 窗口透明度
CONTENTS_OPACITY = 255 # 地图透明度
OPEN_LIST = 60 # 寻路路径检索数(设置30哪里寻路速度很快,只是路径有点奇怪!)
TYPE = 2 # 寻路类型(1==四方向,2==八方向)
KEY = true # 鼠标单击可以寻路开关
FOG = false # 雾景图开关
PANORAMA = true # 全景图开关
POS = true # 坐标NPC窗口开关
PANORAMA_KEY = false # 仅仅用远景图做地图无元件的情况下打开此开关,可以快速载入。
# 使用时请确认你是否有【双远景脚本】或【三远景脚本】
# 并且地图块大小由你的地图图片【宽】与【高】 / 32 得到,这样坐标才能标准,
# 你的地图也标准显示。
end
#==============================================================================
# ■ Game_Character
#------------------------------------------------------------------------------
# 处理角色的类。本类作为 Game_Player 类与 Game_Event
# 类的超级类使用。
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :move_speed
attr_accessor :move_key
attr_accessor :through
end
#==============================================================================
# ■ Game_Event
#------------------------------------------------------------------------------
# 处理事件的类。条件判断、事件页的切换、并行处理、执行事件功能
# 在 Game_Map 类的内部使用。
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# ● 取得名字
#--------------------------------------------------------------------------
def name
return @event.name
end
end
#==============================================================================
# ■ Window_Micromap
#------------------------------------------------------------------------------
# 显示小地图的窗口。
#==============================================================================
class Window_Micromap < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :visible_key
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
super(Micro_Map::X,Micro_Map::Y,Micro_Map::WIDTH,Micro_Map::HEIGHT)
self.contents = Bitmap.new(width - 32, height- 32)
self.opacity = Micro_Map::OPACITY
self.contents_opacity = Micro_Map::CONTENTS_OPACITY
self.visible = false
@visible_key = true
if Micro_Map::TYPE == 2
@Find = Find_Path_8.new
else
@find = Find_Path_4.new
end
self.z = 9000
@actor = nil
@event = nil
@path = []
@route = []
@array = []
@step = 1
@wait_count = 6 - $game_player.move_speed
@path_count = 0
@window_pos = Window_Mini_Pos.new
refresh
end
#--------------------------------------------------------------------------
# ● 设置窗口大小
#--------------------------------------------------------------------------
def key(k)
@visible_key = k
$game_player.move_key = !k
return
end
#--------------------------------------------------------------------------
# ● 设置窗口大小
#--------------------------------------------------------------------------
def set(x,y,w,h)
self.x = x
self.y = y
self.width = w
self.height = h
self.contents = Bitmap.new(width - 32, height- 32)
refresh
end
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def setup
@path = []
@route = []
@array = []
@path_count = 0
@mini_map = Sprite.new
@mini_map.visible = false
@mini_map.bitmap = Bitmap.new($game_map.width * 32,$game_map.height * 32)
@stdx = ((self.width - 32) * 1.00 / $game_map.width * 1.00)
@stdy = ((self.height - 32) * 1.00 / $game_map.height * 1.00)
@path_line = Sprite.new
@path_line.z = 9997
@path_line.x = self.x
@path_line.y = self.y
@path_line.bitmap = Bitmap.new(self.width, self.height)
end
#--------------------------------------------------------------------------
# ● 释放位图
#--------------------------------------------------------------------------
def dispose
@mini_map.dispose
@path_line.bitmap.dispose
@path_line.dispose
@window_pos.dispose
if @actor != nil
@actor.dispose
end
if @event != nil
@event.dispose
end
if @tilemap != nil
@tilemap.dispose
end
end
#--------------------------------------------------------------------------
# ● 描绘地图
# stretch_blt(dest_rect, src_bitmap, src_rect[, opacity])
# 传送 src_bitmap 的矩形 src_rect(Rect)到该位图的矩形 dest_rect(Rect)。
# opacity 指定其不透明度,范围为 0 ~ 255。
# 0~383 --- 自动元件
# > 383 --- 基本元件
#--------------------------------------------------------------------------
def draw_map
@mini_map.bitmap.clear
if Micro_Map::PANORAMA == true
# 描绘远景平面
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
@panorama_bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
dest_rect = Rect.new(0,0,32*$game_map.width,32*$game_map.height)
@mini_map.bitmap.stretch_blt(dest_rect,@panorama_bitmap,@panorama_bitmap.rect)
end
# 描绘元件
@tilemap = Sprite.new
@tilemap.visible = false
@tilemap.bitmap = RPG::Cache.tileset($game_map.tileset_name)
if Micro_Map::PANORAMA_KEY == false
for mx in 0...$game_map.width
for my in 0...$game_map.height
for ml in 0..2
id = $game_map.data[mx,my,ml]
# 如果是自动元件
if id <= 383 && id != 0
if id.between?(48*1,48*1+47)
num = 0
elsif id.between?(48*2,48*2+47)
num = 1
elsif id.between?(48*3,48*3+47)
num = 2
elsif id.between?(48*4,48*4+47)
num = 3
elsif id.between?(48*5,48*5+47)
num = 4
elsif id.between?(48*6,48*6+47)
num = 5
elsif id.between?(48*7,48*7+47)
num = 6
end
src_bitmap = RPG::Cache.autotile($game_map.autotile_names[num])
src_rect = Rect.new(32,80,32,32)
tw = 32
th = 32
tx = mx*tw
ty = my*th
dest_rect = Rect.new(tx,ty,tw,th)
@mini_map.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
else # 否则是基本元件
src_bitmap = @tilemap.bitmap
row = ((id - 384) / 8)
column = (id - 384 - 8 * row)
sx = column * 32
sy = row * 32
src_rect = Rect.new(sx,sy,32,32)
tw = 32
th = 32
tx = mx*tw
ty = my*th
dest_rect = Rect.new(tx,ty,tw,th)
@mini_map.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
end
end
end
end
end
# 转换为窗口地图
src_bitmap = @mini_map.bitmap
src_rect = @mini_map.bitmap.rect
dest_rect = Rect.new(0,0,self.width - 32,self.height - 32)
self.contents.stretch_blt(dest_rect,src_bitmap,src_rect)
self.contents.blur(1, 20)
if Micro_Map::FOG == true
# 描绘雾平面
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
@fog_bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
dest_rect = Rect.new(0,0,32*$game_map.width,32*$game_map.height)
self.contents.stretch_blt(dest_rect,@fog_bitmap,@fog_bitmap.rect,50)
end
end
#--------------------------------------------------------------------------
# ● 描绘主角
#--------------------------------------------------------------------------
def draw_actor
if @actor != nil
@actor.dispose
@actor = Sprite.new
@actor.x = self.x
@actor.y = self.y
@actor.visible = self.visible
@actor.bitmap = Bitmap.new(self.width-8, self.height-16)
@actor.z = 9997
else
@actor = Sprite.new
@actor.x = self.x
@actor.y = self.y
@actor.visible = self.visible
@actor.bitmap = Bitmap.new(self.width-8, self.height-16)
@actor.z = 9997
@actor.bitmap.blur(1, 20)
end
@actor.bitmap.clear
src_bitmap = RPG::Cache.picture("小地图指示图")
src_rect = Rect.new(0,0,src_bitmap.width/3,src_bitmap.height)
tx = ($game_player.x*@stdx).floor + 16
ty = ($game_player.y*@stdy).floor + 16
tw = 6
th = 6
dest_rect = Rect.new(tx,ty,tw,th)
@actor.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
end
#--------------------------------------------------------------------------
# ● 描绘事件
#--------------------------------------------------------------------------
def draw_event
if @event != nil
@event.dispose
@event = Sprite.new
@event.x = self.x
@event.y = self.y
@event.visible = self.visible
@event.bitmap = Bitmap.new(self.width - 8, self.height - 16)
@event.z = 9997
else
@event = Sprite.new
@event.x = self.x
@event.y = self.y
@event.visible = self.visible
@event.bitmap = Bitmap.new(self.width - 8, self.height - 16)
@event.z = 9997
@event.bitmap.blur(1, 20)
end
@event.bitmap.clear
for e in $game_map.events.values
if !e.name.include?("★")
next
end
src_bitmap = RPG::Cache.picture("小地图指示图")
src_rect = Rect.new(12,0,src_bitmap.width/3,src_bitmap.height)
tx = (e.x*@stdx).floor + 16
ty = (e.y*@stdy).floor + 16
tw = 6
th = 6
dest_rect = Rect.new(tx,ty,tw,th)
@event.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
end
end
#--------------------------------------------------------------------------
# ● 描绘路径
#--------------------------------------------------------------------------
def draw_path
nx = $game_player.x
ny = $game_player.y
nt = 0
src_bitmap = RPG::Cache.picture("小地图指示图")
src_rect = Rect.new(24,0,src_bitmap.width/3,src_bitmap.height)
loop do
tw = 6
th = 6
tx = (nx*@stdx).floor + 16
ty = (ny*@stdy).floor + 16
dest_rect = Rect.new(tx,ty,tw,th)
case @path[nt]
when 1
nt += 1
nx -= 1
ny += 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 2
nt += 1
ny += 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 3
nt += 1
nx += 1
ny += 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 4
nt += 1
nx -= 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 6
nt += 1
nx += 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 7
nt += 1
nx -= 1
ny -= 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 8
nt += 1
ny -= 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when 9
nt += 1
nx += 1
ny -= 1
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
when nil
@path_line.bitmap.stretch_blt(dest_rect,src_bitmap,src_rect)
@path_line.bitmap.blur(1, 20)
break
end
end
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
setup
draw_map
draw_actor
draw_event
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
@path_line.visible = false
end
#--------------------------------------------------------------------------
# ● 获取目的路径
# 寻路算法不够完美所以采取切割探寻法
#--------------------------------------------------------------------------
def get_mini_position
mouse_x, mouse_y = Mouse.get_mouse_pos
if Mouse.trigger?(Mouse::LEFT) && self.visible == true && Micro_Map::KEY == true
@path = []
@route = []
@array = []
@path_count = 0
@path_line.bitmap.clear
mx = [[0,(((mouse_x-self.x) / @stdx)-0.4).floor].max,$game_map.width-1].min
my = [[0,(((mouse_y-self.y) / @stdy)-0.4).floor].max,$game_map.height-1].min
if [mx,my] == [$game_player.x,$game_player.y]
return
end
if $game_player.passable?(mx,my,0) == false
return
end
nx = $game_player.x
ny = $game_player.y
tx = mx
ty = my
for i in 0..$game_map.width
for j in 0..$game_map.height
if $game_player.passable?(i,j,5)
tp = [i,j]
break
end
end
end
object_route = @find.find_short_path(tx,ty,tp[0],tp[1])
step = [0]
for i in step
if object_route == []
return
end
@route = @find.find_short_path(nx,ny,tx,ty)
@array = exchange_path([nx,ny],@route)
if @array != []
if @array[@array.size-1] != [mx,my]
# 接下去搜索
nx = @array[@array.size-1][0]
ny = @array[@array.size-1][1]
tx = mx
ty = my
step.push(i+1)
else
for s in @route
@path += s
end
end
end
end
draw_path
@step = 2 if @path != []
return
end
end
#--------------------------------------------------------------------------
# ● 开始分析路径
#--------------------------------------------------------------------------
def analyse_path
if @wait_count > 0
@wait_count -= 1
return
end
mouse_x, mouse_y = Mouse.get_mouse_pos
if Mouse.trigger?(Mouse::LEFT) && self.visible == true && Micro_Map::KEY == true
@path = []
@route = []
@array = []
@path_count = 0
@path_line.bitmap.clear
mx = [[0,(((mouse_x-self.x) / @stdx)-0.4).floor].max,$game_map.width-1].min
my = [[0,(((mouse_y-self.y) / @stdy)-0.4).floor].max,$game_map.height-1].min
if [mx,my] == [$game_player.x,$game_player.y]
return
end
if $game_player.passable?(mx,my,0) == false
return
end
nx = $game_player.x
ny = $game_player.y
tx = mx
ty = my
for i in 0..$game_map.width
for j in 0..$game_map.height
if $game_player.passable?(i,j,5)
tp = [i,j]
break
end
end
end
object_route = @find.find_short_path(tx,ty,tp[0],tp[1])
step = [0]
for i in step
if object_route == []
return
end
@route = @find.find_short_path(nx,ny,tx,ty)
@array = exchange_path([nx,ny],@route)
if @array != []
if @array[@array.size-1] != [mx,my]
nx = @array[@array.size-1][0]
ny = @array[@array.size-1][1]
tx = mx
ty = my
step.push(i+1)
else
for s in @route
@path += s
end
end
end
end
draw_path
@path_count = 0
return
end
unless $game_player.moving? or $game_system.map_interpreter.running? or
$game_temp.message_window_showing
if @path != []
case @path[@path_count]
when 1
$game_player.through = true
$game_player.move_lower_left
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 2
$game_player.through = true
$game_player.move_down
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 3
$game_player.through = true
$game_player.move_lower_right
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 4
$game_player.through = true
$game_player.move_left
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 6
$game_player.through = true
$game_player.move_right
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 7
$game_player.through = true
$game_player.move_upper_left
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 8
$game_player.through = true
$game_player.move_up
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when 9
$game_player.through = true
$game_player.move_upper_right
@wait_count = 6 - $game_player.move_speed
@path_count += 1
$game_player.through = false
when nil
@path = []
@route = []
@array = []
@step = 1
@path_count = 0
@path_line.bitmap.clear
end
end
end
end
#--------------------------------------------------------------------------
# ● 路劲转换
#--------------------------------------------------------------------------
def exchange_path(pos,arg)
nx = pos[0]
ny = pos[1]
array = []
for i in 0..arg.size
case arg
when 1
nx -= 1
ny += 1
array.push([nx,ny])
when 2
ny += 1
array.push([nx,ny])
when 3
nx += 1
ny += 1
array.push([nx,ny])
when 4
nx -= 1
array.push([nx,ny])
when 6
nx += 1
array.push([nx,ny])
when 7
nx -= 1
ny -= 1
array.push([nx,ny])
when 8
ny -= 1
array.push([nx,ny])
when 9
nx += 1
ny -= 1
array.push([nx,ny])
when nil
return array
end
end
end
#--------------------------------------------------------------------------
# ● 刷亮主角
#--------------------------------------------------------------------------
def update
if @visible_key == false
return
end
case @step
when 1
get_mini_position
when 2
analyse_path
end
run = []
for e in $game_map.events.values
if e.starting == true
run.push(e)
end
end
if run != []
run = []
self.visible = false
@actor.visible = false
@event.visible = false
@window_pos.visible = false
return
end
mouse_x, mouse_y = Mouse.get_mouse_pos
if self.visible == true
@path_line.visible = true
$game_player.move_key = false
if mouse_x.between?(self.x,self.x+self.width) and
mouse_y.between?(self.y,self.x+self.height)
if Micro_Map::POS == true
@window_pos.visible = true
else
@window_pos.visible = false
end
else
@window_pos.visible = false
end
else
@path_line.visible = false
@window_pos.visible = false
$game_player.move_key = true
end
@window_pos.x = mouse_x
@window_pos.y = mouse_y
if mouse_x > 320
@window_pos.x = mouse_x - 176
elsif mouse_x <= 320
@window_pos.x = mouse_x + 32
elsif mouse_y <= 240
@window_pos.y = mouse_y + 32
elsif mouse_y > 240
@window_pos.y = mouse_y - 32
end
if @mouse_x != mouse_x or
@mouse_y != mouse_y
@mouse_x = mouse_x
@mouse_y = mouse_y
mx = [[0,(((mouse_x-self.x) / @stdx)-0.4).floor].max,$game_map.width-1].min
my = [[0,(((mouse_y-self.y) / @stdy)-0.4).floor].max,$game_map.height-1].min
@window_pos.refresh(mx,my)
end
draw_actor
draw_event
if self.visible == false
if (Mouse.trigger?(Mouse::LEFT) or
Input.trigger?(Input::UP) or
Input.trigger?(Input::DOWN) or
Input.trigger?(Input::LEFT) or
Input.trigger?(Input::RIGHT))
@path = []
@route = []
@array = []
@path_count = 0
@path_line.bitmap.clear
end
end
if Input.trigger?(Input::R) && run == []
self.visible = !self.visible
if self.visible == false
$game_player.move_key = true
else
$game_player.move_key = false
end
@actor.visible = !@actor.visible
@event.visible = !@event.visible
end
end
end
#==============================================================================
# ■ Window_Mini_Pos
#------------------------------------------------------------------------------
# 显示小地图坐标
#==============================================================================
class Window_Mini_Pos < Window_Base
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
super(0, 0, 160, 48)
self.contents = Bitmap.new(width - 32, height - 32)
self.visible = false
self.opacity = 155
self.z = 9998
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh(x,y)
self.contents.clear
self.contents.font.size = 14
for e in $game_map.events.values
for i in -1..1
if e.x == x+i and e.y == y+i
event = e
end
end
end
if event != nil && event.name.include?("★")
name = event.name.split(/★/)[0]
self.contents.font.color = Color.new(0,255,255,255)
self.contents.draw_text(0,-8,180,32,"NPC:#{name}")
else
self.contents.font.color = Color.new(255,255,0,255)
self.contents.draw_text(0,-8,180,32,"坐标:(#{x},#{y})")
end
end
end
Bitmap位图代码class Bitmap
def blur(strength = 2, opacity = 10)
(-strength).upto(strength) do |x|
(-strength).upto(strength) do |y|
next if x.zero? and y.zero?
src_rect = Rect.new(0, 0, width - x, height - y)
blt(x, y, self, src_rect, opacity)
end
end
end
end
|
|