Project1
标题:
存放腳本
[打印本页]
作者:
熊喵酱
时间:
2013-8-29 09:01
标题:
存放腳本
純屬給LBQ腳本:
=begin #=======================================================================
* K( Y+ u# ]3 r& m
9 E2 }( r# e0 W3 v% S+ {( @
Sion Mouse System v1.3e
1 u9 Z; s5 c" ? o. u$ _
2 Z( f7 d; R: f# t
Changlog
" _9 B- d. I" `) E2 B4 v5 X
* e( C' {7 c( W5 ^3 h7 p& L. g
2013.4.21 v1.3f
9 [% j" X* J( p$ B! L
% A8 H" L# P" C3 L) M% E% ^
1.3f 卷动地图 bug 修正
6 U- g R. g& l% F
1 P$ S5 }7 V, r0 S$ u: s
1.3e 逻辑优化;提供解除鼠标固定的接口
: |: G2 Y0 I3 N$ x" F
在事件中执行脚本 Mouse.lock_mouse_in_screen 将鼠标锁定在屏幕内
. j" a3 ~ I4 I/ @" Z! `
Mouse.unlock_mouse_in_screen 解除锁定
% b* ?0 _1 T2 {4 x3 ]7 n3 L
4 A3 D( A& f) v W) o( A5 \
1.3f bug修正
' Y% }' u" @3 g6 e% @6 g
3 p5 m) y7 }. y3 [! b' O
1.3d 常数设置增加:Menu_Set_Pos,用来设置打开菜单时鼠标是否移动到光标处以及
* \; X1 d3 w$ R" _1 w
关闭菜单时,鼠标是否移动到原来的位置。
; }7 u6 K; ?# W4 \
4 b- z8 ?2 D/ R+ s! [# ~
1.3c 打开菜单、光标移动时鼠标会移动到光标位置处
* r* H! ` ?5 h; w. ^
% x, D5 n/ y+ b( c9 |6 V" S' k+ c' _
1.3b 修正一些罕见的bug;
7 e) ` T+ w# K: F6 `$ e
( G+ b7 ^/ U' C$ G1 q
1.3a 代码小修改;
/ t' J1 N7 x/ ?1 N
加入了鼠标点击启动事件的功能,
/ W: m: N/ g. x2 A& c; [4 u
在事件中加入“注释”: 鼠标启动 ,
1 q! g( c5 C+ {4 U* R' ~; L
该事件将无法用其它方式启动,只能用鼠标左键点击启动。
% `! u. {5 N P; k
3 }, m+ _( B* r4 u! D& x
2013.2.12 v1.2
5 W7 h7 }' ] `$ y7 h
6 n+ f) l# m5 G
寻路逻辑优化;
2 x4 h [( E6 J' E1 S' h3 C/ r
优化了事件判断,现在点击事件附近的格子,移动到指定点后不会触发该事件了;
9 X3 Y- p% w! \9 `5 _* u
现在支持用鼠标来操作载具了。
( }; z d# \5 }) G2 e
4 m; W) z( U: e! @
2013.2.8 v1.1
8 Y' I/ m! v5 ]4 w* W9 b+ ]
( @" N* {$ E' _# Z! C
优化了事件判断,现在可以方便地启动柜台后面的事件;
1 \" Z3 ]. I$ Z! _
修复了某些菜单(例如更换装备的菜单)掉帧的问题;
$ G+ q" k! r3 D; A& Q# ]
移动时,路径指示点的绘制更加稳定;
: Q! \) M7 e3 s7 s8 r- X; b
现在支持默认存档画面的鼠标操作了。
" N* N3 f' K% a7 _0 l, O8 f9 F
, }" N5 j6 K! T3 ~& {+ J
3 I% m, ^& P$ Y7 @
OrigenVersion
, C2 _& s V3 h1 f" ?6 R' ^2 L. z
" g$ {% y# ?4 b8 z! Z
2013.2.7 v1.0
K5 o% R5 w( e; |- W
- [ f% j3 M0 Q2 W+ K! H; F& s; a
主要功能
) t3 Q) F( u" s/ [1 L4 S
+ n n4 ?! ]( a1 P" W
使用鼠标进行各种操作...
9 z8 k( l! X2 M) D, f
将鼠标锁定在游戏窗口内
$ Z8 R1 G3 ]1 d9 z6 b' \0 ?* f
自动寻路,按住 D 键可以扩大寻路的范围
: Q1 ? `$ [0 ]4 o9 W/ |; t
双击鼠标进行冲刺
$ x9 I- h+ E6 ]5 ~/ D3 a
更改地图卷动方式以适应鼠标移动
" G8 h0 ~; M( |8 X
变量输入框改良
, L- J4 j, F# w0 M
2 {. G; z3 E, V7 h+ n
★ 鼠标指针图片 Cursor.png 放入 GraphicsSystem 文件夹
0 r1 \6 Y$ v3 r: I, U
: U4 b' y8 |3 m! e! k; q
★ 路径点指示图片 $Arrow.png 放入 GraphicsCharacters 文件夹
9 n7 o0 \+ P o1 [
! o' F6 t }) N/ H/ q3 L8 ~/ V. P
★ 如果未放入会弹出提示,并使用RM自带图片代替缺失文件;该提示可以在下面关闭
9 A$ D' R6 ]+ ]
( l8 s( t* C: _, j& E) o5 _5 J8 A
# v2 Z: v0 ?% m- L; a& u
=end #★★★★★★★★ 可能需要设置的参数都在下面用“★”标出了 ★★★★★★★★★★
5 c+ j) m' S1 X
6 L& w: h& ~4 }2 M6 Q) ~
, g# b, b: r# v' @
$no_arrowpic_warn = true # ★ 设置为false不弹出图片缺失提示
( i S9 q j5 G0 [) k
4 J# Q: p. D& b6 e3 J% Q" v
#==============================================================================
6 }% R# i8 ?: K
# ■ 常数设置
* J$ D3 V0 I2 ]( R& J
#==============================================================================
/ V1 M; O; {% B. L* Z4 ~8 D
module KsOfSion
' M2 z7 C1 z% I, H2 X# q
Clip_Cursor = false # ★ 鼠标锁定在游戏窗口内,需要关闭设置为false
8 T, i) p. L4 e' i, d( X8 W2 w% p
Dbclick_Frame = 20 # ★ 双击的最大间隔帧数。在地图画面双击进行奔跑
5 ]- E, K( a" R! _/ r7 h* m
New_Scroll = false # ★ 更改地图卷动方式,需要关闭设置为false
( o7 D7 P# |- s% l* I- V
Map_Scroll_Spd = 1.0 # ★ 更改地图卷动速率,请确保此值为大于0的float变量
3 y) X8 f, K% r2 N5 p3 u2 v
Menu_Set_Pos = true # ★ 打开菜单时将鼠标移动到光标处
" j6 ^: V2 T- g, C. J) |
Break_Steps = 30 # ★ 鼠标寻路最大步数,防止路径太长导致卡帧
2 P; J n" Z& P. r6 ^
# “30” 是默认显示格子数 长(17) + 宽(13)
) F/ ?" I+ Q; a% w4 F, T
Find_Path_Key = Z # ★ 扩大寻路范围至全地图按键 Z 对应 D键
, C' ? u/ k7 q3 [* Y
# RM几个内置的空键位 (X = A)(Y = S)(Z = D)
2 f- M) h _2 y2 e, O) y9 A
end
* @& X" G5 {; d$ D2 ]
! h: }2 E! q" a
#==============================================================================
* T3 O+ x2 [3 c. `5 O# q7 r/ u% a
# ■ 用来显示路径点的类
/ a: S5 p K0 H& }4 y
#==============================================================================
; W) p2 z& x: }9 i* t- w/ I! x |
class Move_Sign Game_Character
. g5 n6 _5 ?! o( C' L
#--------------------------------------------------------------------------
8 K3 e3 H+ w/ a [4 L9 e
# ● 设置目标点指示图的各种参数,请注意要使用的图片是行走图
+ k% G* B0 f5 ?; t% @
#--------------------------------------------------------------------------
/ _0 ~% V' w) |: s$ ]
def init_public_members
5 Z7 k- {) u4 ?- r! b( ]1 j
@character_name = '!$Arrow'# ★ 路径点箭头,置于.GraphicsCharacters文件夹
/ X( U( J& s* S d
@character_index = 0 # ★ 图片索引。$开头的行走图设为0
: U% |2 _5 E8 p, g
@move_speed = 5 # ★ 踏步速度
" s" P& _; T( d( M1 _, p
@step_anime = true # ★ 踏步动画(如果想使用静态图标就关闭这个)
' y# t8 W, I3 S
[url=home.php?mod=space&uid=316553]@opacity[/url] = 255 # ★ 不透明度
6 M! R3 u$ p2 G) @
@blend_type = 0 # ★ 图片合成方式,默认为0(正常)
" l, T7 e, B2 m8 m
@direction = 2 # ★ 朝向,2 4 6 8 分别对应行走图第1 2 3 4 列
& I" H: R2 f4 A' h, ?8 G, o
@priority_type = 1 # ★ 优先级(默认与人物同级:1)
( x( x; S- b3 j: F5 H
8 J O( m8 e# H+ X" a3 ~
+ o# S- r, @& H9 S _
# ★★★★★★★★★★★★★★★ 参数设置完毕 ★★★★★★★★★★★★★★★★★★★
$ { S X0 q( o' n8 U9 a
i7 r0 Y4 g3 H, B6 ?7 Z, c3 m
4 F4 c: i: H# e7 _8 |
# 如果 $Arrow.png 不在对应的文件夹内,弹出提示,并使用游戏一张内置的行走图
- [/ i. H. y) J9 x1 r# o+ K
unless File.exist('GraphicsCharacters' + @character_name + '.png')
; Q3 g7 X( a+ T
( e- |- U3 g) y/ U" C3 A
if $no_arrowpic_warn
* V: g% {# A0 L5 v
MouseShow_Cursor.call(1)
1 i" Z/ g W/ q3 s
msgbox('未找到文件:GraphicsCharacters' + @character_name + '.png
* m7 T4 M- |$ F; X# Q
6 i% _! h+ ^" A- n/ J6 Z% F: n4 _
“路径指示点”将使用游戏自带图片
; \/ j: R; i* P: D# g& y& u' R% i4 B9 K
T% z8 w1 X2 d
该提示可以在脚本内关闭')
+ b+ y, e( N# J* v
MouseShow_Cursor.call(0)
. a3 D3 F8 r. g$ G
$no_arrowpic_warn = false
2 w- \$ L+ w% T4 t( @
end
4 o4 h9 J4 \# _0 S! i$ b, w
@character_name = '!Flame'
2 W; \; m$ [3 e; V! X2 R
@character_index = 6
" O0 K& x$ j5 P$ A' p
& `$ t( n6 u1 R, w% k- T! ? J
end
5 E* K' Y( g- S- x8 g
@direction_fix = false # 固定朝向
* @* [& @; u3 }% k( s$ Y# I9 B
@move_frequency = 6 # 移动频率
9 D+ \0 w5 K( m F/ E9 d; k
@walk_anime = true # 步行动画
$ j- K$ O# y0 [/ y* x7 g
@pattern = 1 # 图案
7 G( o( q9 ~3 f: k% |& G
@through = true # 穿透
' T1 R$ r3 \" w
@bush_depth = 0 # 草木深度
# [) i' \4 S5 G' _5 v/ i: F+ z
@animation_id = 0 # 动画 ID
$ s8 J/ ] a. [' f: I+ t
@balloon_id = 0 # 心情 ID
: {4 d; R9 h1 k& O! ~+ ^
@transparent = true # 透明
( ]# O+ L; n6 `% p
@id = 0
( x5 O i7 P9 P. @) {
@x = 0
5 L# j: B# z8 n6 b0 i
@y = 0
( F% Q8 ?# P% j- f( q
@real_x = 0
: B0 k1 d0 `1 A- b, L- W7 P+ c$ y
@real_y = 0
0 c0 i! Q* c" Z7 u$ w7 |6 S6 j: h
@tile_id = 0
+ c( J4 S# M) [6 h4 X
end
4 ]6 M' _! ^# d$ E# {, p6 X
#--------------------------------------------------------------------------
: L( w I, t" c+ k! _5 x+ i
# ● 定义实例变量
+ S7 b! w( c% S# L c- a
#--------------------------------------------------------------------------
$ i, H* Y$ V# R
attr_accessor direction
. Z+ `5 ^4 z& F, k; q
end
( b' A; M5 V" h
( e$ {; E) }7 p( Q4 q
#==============================================================================
& w) h( g$ s3 S) g! F1 V9 s0 K
# ■ Module Mouse
" u+ K+ a* \5 r$ s M
#==============================================================================
X8 w1 o/ G" F$ ?: Y) C! T# D: Y ]
module Mouse
+ ?8 N- }; L B; Q+ c9 W$ @
#--------------------------------------------------------------------------
0 C3 {4 y: q! Q0 e+ Y- T
# ● API
4 _) v( L$ Y5 K" k, p; K
#--------------------------------------------------------------------------
; L" t2 i# q& M9 r6 x5 U
Show_Cursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
, {8 x/ K) t. \2 r6 E% u
Get_Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
! g1 T& _* Q0 S
Set_Cursor_Pos = Win32API.new('user32', 'SetCursorPos', 'ii', 'l')
0 {' |* v: X( A. l% S
Screen_To_Client = Win32API.new('user32', 'ScreenToClient', 'ip', 'i')
- u- L! v# g% d6 o1 A
Get_Active_Window = Win32API.new('user32', 'GetActiveWindow', nil, 'l')
0 e4 C7 V/ N0 F
Clip_Cursor = Win32API.new('user32', 'ClipCursor', 'p', 'l')
% z8 y* W" I6 |4 f8 c
Get_Key_State = Win32API.new('user32', 'GetKeyState', 'i', 'i')
+ h* s( Y2 P) ~, D1 t
Window_Hwnd = Get_Active_Window.call
% c9 V# ?1 M' S5 c
; z6 t4 C1 P# H) s% \
class self
. J% V* ^) V# N0 Y4 l
#--------------------------------------------------------------------------
2 e: ^+ S8 k k. o* _
# ● 初始化
' X' l& H3 d: l: o& M6 J5 d6 j
#--------------------------------------------------------------------------
* `' K: n* D$ p3 s; r6 ?& Y. b8 G
def init
& N. P4 @7 J: R/ e6 W6 `' u+ h
lock_mouse_in_screen if KsOfSionClip_Cursor
& h7 P P; `# k
@left_state = 0
' z8 `8 @/ }: _' ?
@right_state = 0
; u; A9 p- n g. l7 G( K
@ck_count = 0 # 帧数计,单击以后从0开始
- G Y' L8 A$ l4 t
@dk_count = 0 # 用于双击的判定
8 `6 c' L, O" w4 c* M6 |( F
@clicked = false
! i5 [) [1 h5 t& s* M3 S
creat_mouse_sprite
4 Y% j& x$ P) B/ `, J# o2 u
update
& W- T9 X0 H4 ^5 H
end
% Q5 h( c& ?; H' f1 S
#--------------------------------------------------------------------------
. I" d- \/ d* Q8 g* t# K% q
# ● 鼠标指针精灵
8 `0 ?* J9 d6 ^+ b5 a1 ?1 I8 I; k
#--------------------------------------------------------------------------
7 k) _0 c. ^6 H! x0 {0 r
#~ def creat_mouse_sprite
* h1 l0 a# o6 r" h
#~
# e- k7 R, t, J' x; I
#~ @mouse_sprite = Sprite.new
; H5 Q9 [5 l6 N% f
#~ panda = 2#rand(2)+1
0 Z' j$ [& ^ z9 Q; G/ b0 b. g
# t. X# d" a- j4 K0 z
#~ if panda = 1
+ \0 i8 v& l3 y
#~ if File.exist('GraphicsSystemCursor2.png')
8 N, |8 @9 ^# a" B
#~ @mouse_sprite.bitmap = Bitmap.new('GraphicsSystemCursor2')
% b5 M" L+ p+ j' E" t. B7 t
#~ end#with if File.exist
' n. ?. g9 \5 u7 u4 J8 f
#~
/ \+ R, A$ z# i& |" @
#~ else if panda = 2 #with if panda=1
' h' j1 s; W/ l; |% }, b
#~
0 m/ ~" t" H: _
#~ if File.exist('GraphicsSystemCursor2.png')
/ E% o& p$ U* H/ R
#~ @mouse_sprite.bitmap = Bitmap.new('GraphicsSystemCursor2')
' s3 {4 F! h& q# L/ u
#~ end#with if File.exist
2 C4 d. H7 i9 e) L
#~
% L7 J4 d) R9 \2 _
#~ else #with if panda=1
6 L9 P) c3 [" V" b2 w6 [) A% b
#~ @mouse_sprite.bitmap = Bitmap.new(24, 24)
1 R) |( ^* o- {3 o2 p- @3 A
#~ @mouse_sprite.bitmap.blt(0, 0, Cache.system('Iconset'),
! }) M" Y3 B+ u2 }7 ^! C- T) q
#~ Rect.new(5 24, 24 24, 24, 24))
$ C; n5 O# u- q) F6 a1 j
#~ end#with if panda=1
4 ^! Q( T$ V* z1 T' C1 e3 j' R
#~
2 S+ w4 H- p( U$ Z5 c8 M9 C) [
#~ #with def
8 d6 g2 V# ^* e7 t
#~ end
5 ]5 y" b' w9 ?( K
def creat_mouse_sprite
6 [8 m* \; ?8 Y5 A
@mouse_sprite = Sprite.new
, O- p* d7 T% z- t W( `
@mouse_sprite.bitmap = Bitmap.new(GraphicsSystemCursor#{rand(2)+1})
& l' J) j- G2 h5 [0 D
@mouse_sprite.z = 9999
Y- X6 |' d" |8 g
Show_Cursor.call(0)
3 I# O0 h* p7 K" M
end
* J4 q) Y8 l3 l ?1 z: X; Y
& A, }7 ^8 U; x' U* _
#--------------------------------------------------------------------------
3 ]& K- d3 _' I: H2 }# j' b$ t
# ● 更新
# I% z; L+ a; ~! p7 L# g
#--------------------------------------------------------------------------
; U5 }4 ?0 u: Q+ C! M0 K
def update
9 _# J L1 M# @ i' f9 O7 j
@mouse_sprite.x, @mouse_sprite.y = get_mouse_pos
' m3 ] K( @( j3 `; n3 Z5 R
left_state = Get_Key_State.call(0x01)
% H5 [; N3 x# p n( ?
left_state[7] == 1 @left_state +=1 @left_state = 0
* O2 [) o' d5 ?0 u; C
right_state = Get_Key_State.call(0x02)
- y2 G9 [' }4 t$ T. _
right_state[7] == 1 @right_state +=1 @right_state = 0
8 N* p6 L: j5 z3 E" T# B
update_double_click
3 g% l( j! d; O( \9 g/ ]! I* v
@left_state == 1 @ck_count = 0 @ck_count += 1
/ {' }- k1 {* J7 b; F/ z# A [
end
/ p( @* @8 r- |( m
#--------------------------------------------------------------------------
- s& ]1 F- h% h( A; O
# ● 获取鼠标坐标
( Y$ Y0 L& j+ A" A$ h
#--------------------------------------------------------------------------
" K2 ?8 ?" O7 d- e; h: c* ?
def get_mouse_pos
! p8 }& D. v1 B5 A
arg = [0, 0].pack('ll')
! V6 I6 p2 T# w7 n1 a, f% G
Get_Cursor_Pos.call(arg)
6 b/ \) T: z, m- `, ]
Screen_To_Client.call(Window_Hwnd, arg)
9 R: T0 P) K! ^; W( B
x, y = arg.unpack('ll')
$ V1 E1 @* o( g6 w+ ]) }
return x, y
; K* V) X1 k) D0 b4 w
end
8 k8 o9 A6 L4 v/ J
#--------------------------------------------------------------------------
: ]9 M+ N* @) \+ {5 W" w
# ● 将鼠标固定在屏幕内
# A! [ A$ U2 }; D2 O2 C
#--------------------------------------------------------------------------
g' x" N$ Q9 F2 O2 R
def lock_mouse_in_screen
; @+ V2 x1 D4 h* Z* D% N
arg = [0, 0].pack('ll')
- R. U- b* R q4 U, X8 }; g, t: B- {
Screen_To_Client.call(Window_Hwnd, arg)
# K' i, O D$ P/ d' l5 h: E
x, y = arg.unpack('ll')
8 @% ~5 M2 U6 \- S* H" h: I
Clip_Cursor.call([-x, -y, Graphics.width-x, Graphics.height-y].pack('llll'))
* R8 [' X( p2 o2 ` N7 k1 X" u0 T
end
! h, B$ O; X2 ~$ W L# M2 b- h
#--------------------------------------------------------------------------
% @' R# c9 n4 J- C$ ?3 p
# ● 解除鼠标固定
9 s8 Z# F+ {. C' H( ~
#--------------------------------------------------------------------------
1 `8 e, \. @) v! w' L; S
def unlock_mouse_in_screen
+ D8 v" y+ ^# f; A- ]/ {0 f+ `) `
Clip_Cursor.call(0)
# \( {' X9 \& d6 Q
end
: A0 M4 O; w2 Z* l+ n
#--------------------------------------------------------------------------
7 T* w9 j# M4 v9 h) Q
# ● 鼠标双击判定
# k4 u; N' I, d$ s* X8 _
#--------------------------------------------------------------------------
! T% n9 z& M) A2 t) S9 E- X) l
def update_double_click
$ c* b/ O1 }) B2 s
@clicked = true if @left_state == 1
- P) m/ o+ t3 t
if @dk_count 0 && @left_state == 1
! X( [& f. R) f! n# U
@dk_count = 0; @clicked = false
9 h, O$ K0 D- l% C
return @double_click = true
0 _# k4 h* z/ h# o' n, @# ^
elsif @clicked
; n/ X, l7 Q" C8 L
if @dk_count KsOfSionDbclick_Frame
5 L3 [2 Q4 |4 ?
@dk_count += 1
. W5 ~" j2 M/ u! H
else
# c: h4 j2 F* c- c% s
@dk_count = 0; @clicked = false
7 O( w0 e; j1 X- l: @" z
end
/ e! \% g' ]- k, {+ E- R, E; J
end
0 Y) _0 j( K; G b
@double_click = false
/ Y- u) R, V0 p' E6 ]: I! g$ Y
end
; Y- s+ |- y8 Z; C' s5 a
#--------------------------------------------------------------------------
% L; A" @% z6 w
# ● 按键被按下就返回true
4 P. g9 B! e, r
#--------------------------------------------------------------------------
; G" u! ?3 u4 L$ u/ o3 c' J! c4 W9 U
def press(button)
8 @, M. p: T& y# I- g0 P5 _1 Z
case button
7 F0 e" v* }' u
when 0x01; return !@left_state.zero
% R" n% h- C) W9 A% k( c$ l' i% @" Q
when 0x02; return !@right_state.zero
* R4 ?6 c/ D3 H! b! C( q3 p; h
end
; Q* V% U! B+ G4 W" m
return false
6 @% E c# I/ q: j7 [
end
6 }1 r+ O- i4 q0 v5 B: q4 k. e
#--------------------------------------------------------------------------
5 g, _& J: |* Q; d' c
# ● 按键刚被按下则返回true
6 g7 a# n: Z5 f
#--------------------------------------------------------------------------
- p! f" E0 G q' L. K7 n; h8 a
def trigger(button)
: G, T: O# J* E% a% o3 J9 X, ]5 O
case button
0 U" L' i# M% ^. [" \
when 0x01; return @left_state == 1
! v: e8 B$ X( {9 f8 j% M& T
when 0x02; return @right_state == 1
/ B+ C4 y! m5 [1 f: T
end
- s1 S% T% ~$ ?) I! e+ R- F, m/ e
return false
& g- O4 d; z2 e( S& @" ^
end
6 B$ z% p) [* B; ~
#--------------------------------------------------------------------------
5 c; ~; `+ @# o- B: R+ R
# ● 持续按住键一段时间的话,每隔5帧返回一次true
8 {( x- h" [$ [5 [9 ^
#--------------------------------------------------------------------------
6 [+ c$ a, a1 T. l8 F- f
def repeat(button)
4 {7 r: a* O" B9 g2 I. J
case button
! Z' u' d' S9 C d3 c
when 0x01; return @left_state == 1
% R* w, j6 T! K( I) c7 g
(@left_state 22 && (@left_state % 6).zero)
9 J: V* v# S1 f6 P
when 0x02; return @right_state == 1
& w1 Y2 i" v. b7 v) }+ S
(@right_state 22 && (@right_state % 6).zero)
6 P1 ^- E: [ o1 A
end
$ I8 P# r& b3 l
return false
8 y* `- p' f; f+ a d( P: t
end
! o' ^ s- R! J% H+ x8 l
#--------------------------------------------------------------------------
6 }: j. n3 j. W. ]& @
# ● 判断是否双击鼠标
* r W* ^/ c" H- U* f) f" Y
#--------------------------------------------------------------------------
; G, F1 M* i5 P- b: E( X
def double_click
" T9 P* \" z/ M9 L# ^! w7 @, z9 Q
@double_click
, {' [! Y+ z8 Y$ ?& {& r5 e3 }
end
2 ?+ d8 `1 h% ~7 J. P" Q+ w, y2 E
#--------------------------------------------------------------------------
2 [. |* y' D2 c0 n9 n! [$ B4 [5 f, I
# ● 获取@ck_count(每一帧+=1,单击后重置为0)
5 \& B% l, ^9 A* ~, m7 P
#--------------------------------------------------------------------------
# U3 A9 I$ T p: J: h
def click_count
& Q4 J( ?4 s" ^# G7 ?: J9 J' B6 q% @5 f
@ck_count
- t0 ~" \ q* k+ t3 |& z; K
end
( C8 ^2 s$ l( z& @. l4 \# [
#--------------------------------------------------------------------------
& o% A+ \- i1 f$ R4 ~! V
# ● 获取@left_state(按住左键每一帧+=1)
: j+ B1 Q' Z' U6 M! ~
#--------------------------------------------------------------------------
" ^& [! l% u2 L
def left_state
! Z. E1 c8 c# H; H
@left_state
0 B) P. J! E* \3 d* ^! t
end
" e7 S9 M1 E- G
#--------------------------------------------------------------------------
7 f! @. K2 N4 q
# ● 获取鼠标的x坐标
4 ]4 O. @/ L$ m. I6 t! Q _4 g8 Q3 R
#--------------------------------------------------------------------------
0 l, v7 _- @) M! n( I. B4 w
def mouse_x
. Y6 m( \% X# N
@mouse_sprite.x
9 T4 e: [: ?7 e+ ~
end
: T, A+ Y0 S) f# ] O; ^
#--------------------------------------------------------------------------
% u& @ Z6 T) i, i8 l# I$ x
# ● 获取鼠标的y坐标
( a. B; j; ]* ]1 Y1 s+ y* X
#--------------------------------------------------------------------------
. U0 v8 T' ~4 t
def mouse_y
6 F$ W* B4 n% L3 y% `
@mouse_sprite.y
' E6 m- [5 h; I8 O7 J7 k
end
4 K3 y0 T) h- K
#--------------------------------------------------------------------------
" r& i: ]" s: }0 K6 P7 ?
# ● 设置鼠标坐标
5 O& c0 k2 i" P, M7 K; h
#--------------------------------------------------------------------------
- _" g- ?2 E+ Q2 j! @. I) O/ x
def set_mouse_pos(new_x, new_y)
; m( N* Z) u l
arg = [0, 0].pack('ll')
/ L1 a3 C7 v! i6 w* z# _2 k4 a; f9 r
Screen_To_Client.call(Window_Hwnd, arg)
8 e* k/ j- r6 \0 L' h: O. m
x, y = arg.unpack('ll')
5 f8 S4 X- H2 h+ p: i
Set_Cursor_Pos.call(new_x - x, new_y - y)
% X4 {( C/ T2 F9 [4 ?
end
7 D3 c/ w; c3 a
end #end of class self
f! c# z' E' j ~4 j6 P
8 C& u9 f- W: M7 M7 q) X
end
/ Q; e# I9 f9 ` ~
5 \$ j' I$ i, ] Y# Y9 r
#==============================================================================
2 I# ?% c( k6 S+ X
# ■ SceneManager
. c K T# p7 e3 @! V) [
#==============================================================================
# o% _& @) l4 { t6 \ `6 H
class SceneManager
0 d/ i0 S9 C) h( X+ D. s+ g" n9 n
#--------------------------------------------------------------------------
: g, {1 U9 e+ R6 K3 l1 u) c' N6 W
# ● alias
) ^# n8 Z1 x0 D9 P# R' u G
#--------------------------------------------------------------------------
$ @; E/ G: K; d; c" F# ^
unless self.method_defined(sion_mouse_run)
& P9 H c4 ^) V. Y
alias_method sion_mouse_run, run
# Q) v) d# O/ o# t1 a6 i# Z% |
alias_method sion_mouse_call, call
: N" F [. a/ Q
alias_method sion_mouse_return, return
7 U1 V% A( Z# t/ j1 i) U% i
end
. ]1 T9 G/ F3 j' x) S* E+ d+ }
#--------------------------------------------------------------------------
2 C! s* X& O4 v
# ● 运行
+ H8 Y: U; O) E( P: ?0 \
#--------------------------------------------------------------------------
+ M, [7 E4 x8 W3 X+ u& B6 F5 o% Y
def run
. ]8 |& o, K1 {
Mouse.init
0 v* L2 e: k* h) s N
sion_mouse_run
+ `" B B( x' V0 e8 a
end
; n; [- m* J# s$ G7 Q5 o& O) N
#--------------------------------------------------------------------------
: H) r1 V7 ~1 K
# ● 切换
5 J" ?8 |4 L& M# R: i' ~/ K
#--------------------------------------------------------------------------
" m/ B) d: }, |+ ^: j
def call(scene_class)
9 @0 i3 e, O: _# J
$game_map.prepare_reset_mouse_pos if @scene.instance_of(Scene_Map)
) @$ A) T% a) K* W; s
sion_mouse_call(scene_class)
( {3 k# ~0 S& W8 ^: o, H
end
1 L* Y1 o! ~4 s' O8 N
#--------------------------------------------------------------------------
3 l; Y$ H1 v- ~4 \
# ● 返回到上一个场景
! b% V3 N! Y. R. P
#--------------------------------------------------------------------------
5 F) n" ~& H1 W5 m# L; S" \
def return
/ V" m. ~9 G, W# U" y
sion_mouse_return
7 }, Y+ v- m! H3 ?, l# r" N3 \: f
$game_map.reset_mouse_pos if KsOfSionMenu_Set_Pos &&
) x$ J; u2 V. l/ j( m+ h+ i
@scene.instance_of(Scene_Map)
v# k7 C ~( o
end
4 @+ U# t9 H% M# d- ^
end
( q* L: @5 S& O4 ^ b B* {
3 w# _1 V4 w8 v* Q! l4 n
#==============================================================================
4 L3 g7 X3 Y7 W
# ■ Module Input
3 |# d% I5 N8 ]5 }. r( U
#==============================================================================
: r; x" A- M. E+ W, \' l
class Input
! K$ ~: W7 x# |$ ]" D
#--------------------------------------------------------------------------
' [; S$ @5 e( [& n2 |" q6 Q2 l ~: A
# ● alias
* ]+ a" L+ b9 }- w/ u0 y/ c
#--------------------------------------------------------------------------
* k+ k% x4 i) Q3 r% c8 `8 Q4 Q! R
unless self.method_defined(sion_mouse_update)
/ D a$ |. [9 y3 f7 g2 L
alias_method sion_mouse_update, update
4 V+ R4 F& D: u" a
alias_method sion_mouse_press, press
1 p5 ]/ ^* U4 e" d9 j" \$ Q
alias_method sion_mouse_trigger, trigger
! `7 c0 j! l9 o5 L, I
alias_method sion_mouse_repeat, repeat
! |. C# L/ ?! n+ k
end
4 R. T. |, d+ b+ _. Y8 S
#--------------------------------------------------------------------------
+ b7 E2 Y4 M5 ?- Z: I# T
# ● 更新鼠标
" U1 T& j% j( R2 V1 t- W
#--------------------------------------------------------------------------
3 G5 o1 h% B9 q \( I' W
def update
1 v* `7 y5 v2 R8 u0 b
Mouse.update
0 @9 m+ |9 \4 \' V, c& C
sion_mouse_update
1 h! V; P, g6 E% T% F6 X6 l/ N
end
1 i# B. s) @% L) n
#--------------------------------------------------------------------------
1 i: f/ |8 F& X2 W# V* |# R$ ?
# ● 按键被按下就返回true
0 p& x; N' c' R6 I# ]( C! ?/ T7 d8 n
#--------------------------------------------------------------------------
A6 \+ H3 ]7 u/ o* ~$ C& f: j
def press(key)
$ b5 [: o6 M$ [3 C: q
return true if sion_mouse_press(key)
- o J; d$ m# ?* s
return Mouse.press(0x01) if key == C
; u/ \* b% K& R' [0 r7 t8 ^
return Mouse.press(0x02) if key == B
l3 i) v' ]3 W
return false
" X0 J8 d. c9 b! G, y
end
% s. I$ ?, j S, F4 [
#--------------------------------------------------------------------------
- Z ~( V* p$ i5 l5 Z. N% h1 f
# ● 按键刚被按下则返回true
. r$ \$ ]& O1 S7 m1 U' I/ P& R. T
#--------------------------------------------------------------------------
( i3 Q7 r2 h* D% I$ B) D5 z
def trigger(key)
W, u2 f& f$ t5 k1 Z v$ X
return true if sion_mouse_trigger(key)
7 R1 ]- ^7 P' y; Y& u t$ k! f
return Mouse.trigger(0x01) if key == C
) E0 {4 x% O. S" {( U
return Mouse.trigger(0x02) if key == B
3 r& X4 V. y1 L! l) F, x6 w
return false
& n3 j3 W3 K# ~! N l
end
7 h! b2 K: b" K' d
#--------------------------------------------------------------------------
: ]+ v: ^0 x, U( R1 b7 n
# ● 持续按住键一段时间的话,每隔5帧返回一次true
& v! u' J! O4 P( @) f
#--------------------------------------------------------------------------
1 Y- a7 d3 w6 `8 D; S' h
def repeat(key)
% f+ _, P8 D5 i7 U, A: b
return true if sion_mouse_repeat(key)
7 ^( A' `7 \& u" n9 `
return Mouse.repeat(0x01) if key == C
- y( Z4 ~, V- U4 q9 C/ X
return Mouse.repeat(0x02) if key == B
/ S* b4 i# |$ N5 C+ W8 g! G
return false
6 q% A$ w4 o6 Y' z' w7 s: [0 |
end
% R) T u+ c X) w4 Y0 d
end
* `' R: ^' E% H- R% P3 ~
/ f" {8 m' L/ N8 l2 ]
" }: Y9 W9 S m* }/ f( t
#==============================================================================
6 v+ K, G& J' G$ f$ g1 f: T g
# ■ Window_Selectable
4 H% E: e. [$ a# T7 q% |0 g
#------------------------------------------------------------------------------
/ z8 a8 L, ]% M) x' m3 T+ Q
# 拥有光标移动、滚动功能的窗口
+ L0 F9 ~; r! r) v
#==============================================================================
) k8 P1 |' R; Q) r! K3 O3 l
class Window_Selectable
# G9 U5 M: K4 s* \% U3 J$ x
#--------------------------------------------------------------------------
( x3 \$ H+ e- R
# ● 初始化
* C! ?7 g2 }% b ~, O; j
#--------------------------------------------------------------------------
/ {3 O$ U g! m# s& X, C: _
alias sion_mouse_initialize initialize
. {, [# a) l2 v' S* I5 J
def initialize(x, y, width, height)
0 p) S/ @# M2 I
sion_mouse_initialize(x, y, width, height)
7 n6 c$ x, r! L
@move_state = 0
0 |- ]) _9 J# ?( H! x* S. b2 \" O
end
$ X' b5 S3 ]% f1 w
#--------------------------------------------------------------------------
+ \6 n4 R0 U/ |! z! C6 b4 M
# ● 更新
" K; N/ k( A2 W
#--------------------------------------------------------------------------
2 o% z# L0 l6 h
alias sion_mouse_update update
! m4 ^* n" ~6 g l
def update
9 q6 A; Z) `- Y9 z5 s$ [( Z
sion_mouse_update
# ]1 ^# X0 o' {: W# x
update_mouse_cursor
" w( L9 Y- k' z9 }: n2 \+ l
end
; p F( r; I( I+ p
#--------------------------------------------------------------------------
* z) O5 i: E& [
# ● 启动后设置鼠标到index位置
+ g z s% Z3 o. X
#--------------------------------------------------------------------------
1 \4 W, }- ^0 d5 w: D, m4 |: y
def activate
+ h5 f: ~5 b7 x4 L, U& r# B+ q% @
@need_set_pos = true if KsOfSionMenu_Set_Pos
# d: b$ m- ^6 b; H+ ?5 _
super
; e. d+ a& @/ G' @' y8 e5 n, T- S J
end
8 S f: m9 x# y5 U D4 M6 T
#--------------------------------------------------------------------------
" c2 z4 W- y) Y4 V
# ● 更新鼠标和光标的位置
- i J$ h7 s; E
#--------------------------------------------------------------------------
1 X: d4 R. A w- O- M- r5 w% [
def update_mouse_cursor
f7 s4 T' _4 M3 _
if active
0 p3 G' X( E/ A1 k0 L
if @need_set_pos
$ @0 ~2 S+ z8 @
@need_set_pos = nil
) T. E3 _& r; J) t
set_mouse_pos
# f* r2 a$ `& q
elsif cursor_movable
$ y/ J5 y& [0 j1 D
Input.dir4.zero set_cursor set_mouse_pos
% v* m* Z B" F8 y6 _
end
) J9 {$ K! Z0 i3 \0 F$ v
end
. @' P2 O2 J7 b. L1 |( H( x" }
end
" c* J9 W! A- U4 J" V9 }
#--------------------------------------------------------------------------
5 A' y7 E, s+ o2 \# t5 B: m. m/ i
# ● 将光标设置到鼠标所在的位置,附带卷动菜单的功能
" b: H5 Q& ^7 V% W
#--------------------------------------------------------------------------
, _/ `# [4 W/ V5 B
def set_cursor
. n$ j9 }$ X" ~5 D m
mouse_row, mouse_col = mouse_window_area
" v% F# }0 ^" c0 H s m8 x
if mouse_row == -1
/ o0 M2 O# t" ~. v$ R2 q' d
@move_state += 1 if need_scroll
, @! D# D% ~5 u+ w7 X$ K6 u
cursor_up if (@move_state - 1) % 4 == 0 && !is_horzcommand
; D& K6 _- {7 h- W5 ~
elsif mouse_row == -2
: M T9 t% `& u0 ?" Q0 s2 D+ O
@move_state += 1 if need_scroll
, _: z* j3 a7 w4 u; f) Y
cursor_down if (@move_state - 1) % 4 == 0 && !is_horzcommand
6 M1 ^3 a- ]% l# A( i: E% n1 Q
elsif mouse_col == -1
0 z k% J* G# _9 I
@move_state += 1 if need_scroll
; N8 P: K; A+ N) |/ U* U
cursor_left if (@move_state - 1) % 16 == 0 && is_horzcommand
! S! A7 ]0 X& p3 C4 u
elsif mouse_col == -2
3 p( M, u" R, N+ H
@move_state += 1 if need_scroll
! r% A5 p: Z" U9 t2 E! n5 g( {& U8 J
cursor_right if (@move_state - 1) % 16 == 0 && is_horzcommand
) E0 D" Y) ?' U: z' f# g% I
else
" I3 O* F& T- j; u7 x) m/ @+ K
@move_state = 0
4 Z0 A4 A& N6 Q8 O( m
new_index = (top_row + mouse_row) col_max + mouse_col
+ K! N/ @! i) \& L# n) x8 X
select(new_index) if new_index item_max && new_index != @index
9 N# l' ^0 W7 E) J3 q6 W% J% f( k
end
9 E$ U0 i+ a$ M3 h
end
7 a6 D7 s" D- X& Y5 n8 h3 w
#--------------------------------------------------------------------------
, e& p- Q5 b% q) n$ ?; F, z4 J
# ● 判断鼠标位于菜单的第几行、第几列
5 N8 G l" `0 x1 Z' J8 O
#--------------------------------------------------------------------------
- D5 B; D; ]$ Q. D- x
def mouse_window_area
- q5 b8 R; J% Z& C$ _% i
if viewport.nil # necessary!
1 ], A6 i: O5 d. a* r
vp_x, vp_y = 0, 0
" z0 ~# | D- q& }* p
else
3 x9 [ n- w3 G4 J3 A8 m5 h) b
vp_x = viewport.rect.x - viewport.ox
1 v9 |4 J$ I- [0 H8 }
vp_y = viewport.rect.y - viewport.oy
/ W5 g7 a9 Y6 _9 ]: a1 q/ v
end
" Y9 S; M4 Y" l G A
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
1 _* B: v* K7 f7 H
item_x1 = vp_x + x + standard_padding
: U) _2 n: _6 v! r. V6 q$ |
item_y1 = vp_y + y + standard_padding
# i, x' W% X. S
item_x2 = vp_x + x - standard_padding + width
' p7 Y7 _8 x; L5 a0 h& C4 N$ W! c
item_y2 = vp_y + y - standard_padding + height
# a' K3 @! L4 ]1 F# m& Y& b+ a& p$ ?
if mouse_x item_x1
( ?8 a8 {. s9 k8 C
mouse_col = -1
+ p+ X3 `8 Y. N6 `. o# j$ i, m
elsif mouse_x item_x2
/ W+ d u, Z0 [# n6 g* l
mouse_col = -2
1 H- Q. Y1 P, i7 [
else
' W% R0 L- ?5 G1 a9 V! \! r% p
mouse_col = col_max (mouse_x - item_x1) (item_x2 - item_x1)
5 u, f8 a; a1 x) j) O
end
# M, a n2 p/ h: H$ \
if mouse_y item_y1
1 [& ~! _& O: Z8 U
mouse_row = -1
0 D$ Z, c# V0 e5 [- A( R: o
elsif mouse_y item_y2
( h+ ?! q) s; L: {# e$ s! `4 M
mouse_row = -2
5 s! P/ L8 d. ?2 y9 D9 A; D
else
& e+ H& D% I* V# R
mouse_row = page_row_max (mouse_y - item_y1 - 1) (item_y2 - item_y1)
- ^3 f( a8 |' Y- D; t
end
% }; J" x' ], r) F% H
return mouse_row, mouse_col
, V% t9 z/ x5 E" t5 @, y9 W+ k9 v
end
: U- g0 u. ^) k- z! O) I
#--------------------------------------------------------------------------
+ V5 `! K& b; B. G4 q: c- R7 v
# ● 方向键移动光标时将鼠标移动到对应的光标位置
5 K& N6 D& d _/ o
#--------------------------------------------------------------------------
! m* S- h$ i5 ^2 y& @
def set_mouse_pos
' t! l' M7 u/ \% v) o7 [
if viewport.nil # necessary!
) K& S/ W0 g1 g* }2 ~+ M
vp_x, vp_y = 0, 0
1 M! R0 K: B8 b. q( j% b( V
else
$ ^% j& r( n' I$ H" e# [' G
vp_x = viewport.rect.x - viewport.ox
& ~7 _6 D# ^; _3 \) p
vp_y = viewport.rect.y - viewport.oy
! o; ~4 U4 U7 w: \& c- T
end
! j! q: _$ S' P { h
item_x1 = vp_x + x + standard_padding
7 a4 |% r7 Z% H2 v' n# b& z
item_y1 = vp_y + y + standard_padding
% q; g# {0 N) j& ?
get_index = [url=home.php?mod=space&uid=370741]@Index[/url] 0 0 @index
4 {. V1 T: a. s% m1 L) F3 x
row = get_index col_max - top_row
' o! |, P' Y$ Y W$ V% I
col = get_index % col_max
. i7 N2 C3 R- g( F- T
new_x = item_x1 + item_width (col + 0.5)
% s5 P. h9 R0 V: c
new_y = item_y1 + item_height (row + 0.5)
8 H( \8 G# X/ h: I G8 u0 {# Z [
Mouse.set_mouse_pos(new_x, new_y)
3 g; x6 v6 F1 X" S" g$ a$ h
end
% V, L9 t% [6 W$ d! m4 ?; R
#--------------------------------------------------------------------------
r; u* ]( m4 K) C6 H% q/ W
# ● 判断菜单是否需要卷动
2 d# L+ a j) j. d6 n
#--------------------------------------------------------------------------
- Y$ _) L% ]& @4 S7 j6 H" F
def need_scroll
2 l' F8 L8 ^8 Z9 E8 K: B% ?
item_max col_max page_row_max
; j' k k: K1 c/ ^. M% D
end
4 a' N6 k) B. S+ M3 x O" w5 ~$ r
#--------------------------------------------------------------------------
: W$ F& t& c9 [6 ~/ a9 W
# ● 判断是否为水平卷动菜单
7 w$ V, r/ X/ {1 b( b/ K% Y5 q
#--------------------------------------------------------------------------
2 o, F6 B& y, U/ D0 c }/ H' l
def is_horzcommand
0 J3 o" y/ C; f( H4 N
return false
2 ]5 k0 b3 \( H+ w4 I8 n
end
0 f# ^/ _ N+ t7 W
end
, ?# p7 O" s( n2 N; d! o
! @, B `# p* C5 b
class Window_HorzCommand
( q6 h* h+ P x# f5 G4 f
#--------------------------------------------------------------------------
9 a) ?7 ?, X5 @
# ● 判断是否为水平卷动菜单
6 H' x ?- j$ f# D6 y
#--------------------------------------------------------------------------
4 o' i! X4 y1 q* T
def is_horzcommand
7 I: {# j3 E" @7 S& H" K$ H# J
return true
& C1 @2 o, ~! L, K+ m3 |# [' G8 `
end
$ D( f; D1 {+ z* K
end
6 P8 W7 N: n& C$ d( u5 t* l
) |* N- u# F5 I( `3 b* c( J
#==============================================================================
! X0 e; Y2 T- o( G2 W; [0 ~( L
# ■ Window_NameInput
4 M9 M! A T2 a4 a$ V; b
#------------------------------------------------------------------------------
. c s/ f, D- L( e6 k
# 名字输入画面中,选择文字的窗口。
& T. G$ K* S2 Q* b
#==============================================================================
_: |; z1 i- D# d2 }9 s6 G" J# \
class Window_NameInput
# Y+ u, C# x3 ]3 B6 I/ [
#--------------------------------------------------------------------------
7 v9 c9 q. L. \: v+ C% |
# ● 设置列数
5 h8 t9 [* \2 }
#--------------------------------------------------------------------------
: v7 T( E- J3 X, ?# d* k E* U
def col_max
' _# ?. @5 C3 m9 L) x
return 10
4 E) J+ m5 J* U2 W
end
/ h9 d& m- m! y) D# q# v, V0 _
#--------------------------------------------------------------------------
# w: |& [# q' c! Q! \, r) k* n
# ● 设置填充的Item个数
- F% J- M& E* m. ]$ B$ V2 y# V
#--------------------------------------------------------------------------
6 m7 a3 k) u. H, h
def item_max
, U+ a+ m9 p7 l1 N* `, K% x% m2 U' S
return 90
W. p, D9 C" c- Q
end
. Q/ F8 v# P7 j6 i5 ^1 I e
#--------------------------------------------------------------------------
7 X8 H' K) n# |7 t
# ● 设置填充的Item个数
, F! h q% B4 I& N5 S6 R
#--------------------------------------------------------------------------
8 N- r+ s" W" T. k; \
def item_width
, J$ k s- r/ V, y+ j, H
return 32
- T) T( `: |8 M( i. U
end
d1 w9 E2 s4 O5 r; O& h- I
#--------------------------------------------------------------------------
3 \: p! Q) C0 W
# ● 判断鼠标位于菜单的第几行、第几列
" j5 u, L0 y F7 u- q+ b& }
#--------------------------------------------------------------------------
3 _ b7 }/ ^' m4 Z
def mouse_window_area
% e, N7 _. g1 V9 r1 t( i P: t
if viewport.nil
b9 G J$ n P) z4 r' M7 V
vp_x, vp_y = 0, 0
& W6 ~) P* h! q! X5 m2 _7 k
else
: j, V* H, N. x, ?) Y2 ~7 N
vp_x = viewport.rect.x - viewport.ox
0 x! ^; S- b+ ]! Y/ s, a
vp_y = viewport.rect.y - viewport.oy
$ l7 z0 l3 o' a# x! v
end
; k0 G2 [: ^% b$ j& _; C' N3 ~
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
0 n* X! M& N& e% V; ]8 e0 b$ g
item_x1 = vp_x + x + standard_padding
% j. Z5 n) u5 L4 l
item_y1 = vp_y + y + standard_padding
9 ~6 G* P Q) S7 w O
item_x2 = vp_x + x - standard_padding + width
' _. d \# q# O2 e D
item_y2 = vp_y + y - standard_padding + height
1 g9 A8 }# @3 R u( n
if mouse_x item_x1
9 x s8 t( ]4 f7 T! R' \! X
mouse_col = -1
& P+ i( I6 R/ A/ X2 @0 {
elsif mouse_x item_x2
0 M9 i$ F' v/ s- _/ m
mouse_col = -2
# @6 e; _$ m& P, n% a
elsif mouse_x item_x1 + 160
- j$ Q1 c' U$ F7 J& v* ?
mouse_col = (mouse_x - item_x1)32
& R* g( O& K" `
elsif mouse_x item_x2 - 160
8 {/ b3 r5 I3 l' _% i4 X# d9 p( b
mouse_col = 9 - (item_x2 - mouse_x)32
8 E2 G3 e1 b- ?/ x
else
, K. \& J# `% z6 e: |0 N
mouse_col = mouse_x x + width2 5 4
4 k3 q. O" S; s6 r% i
end
4 r0 ^$ b1 _ a$ Q
if mouse_y item_y1
% C7 V5 a9 H* s; z, o
mouse_row = -1
# S/ I; R% j2 p: N% w* C, L! X& n" X
elsif mouse_y item_y2
: n! G( E$ h! g) E
mouse_row = -2
' { S( x6 b: J! O0 T5 I
else
* j0 {. g+ A7 u! t" l/ G
mouse_row = page_row_max (mouse_y - item_y1 - 1)(item_y2 - item_y1)
3 h& c4 F! u# s# F
end
9 K( D3 V6 b7 c3 q/ R! g
return mouse_row, mouse_col
6 |3 T$ }+ ]0 C4 W1 T, r
end
4 f- X, |4 H5 W5 S5 d7 d& o( b8 ^& i
#--------------------------------------------------------------------------
/ v4 v- s. {4 s) n
# ● 方向键移动光标时将鼠标移动到对应的光标位置
# D V+ Q4 O& @6 J* Z& |( `8 J
#--------------------------------------------------------------------------
: g, J1 t, K/ v: q( j2 `, p' i
def set_mouse_pos
. a' s, P$ A+ F9 G8 e2 I! A
if viewport.nil # necessary!
: L; d y8 Y. n
vp_x, vp_y = 0, 0
' j0 W# X0 X, G k' J! W A* Y( S
else
! ]3 {' _5 k" ~3 [1 a( V, \; q) S
vp_x = viewport.rect.x - viewport.ox
' s4 P0 e" T/ Y: O: G+ H
vp_y = viewport.rect.y - viewport.oy
7 W ] r* ^2 y% x3 s
end
8 R' `! b8 e; j6 _1 i5 \: b
item_x1 = vp_x + x + standard_padding
e! w3 w8 j/ p' @7 H$ c" n
item_y1 = vp_y + y + standard_padding
; k: M" y) ?1 m/ q+ ~6 q {
get_index = @index 0 0 @index
2 J& a( d- U- A3 K: M$ P7 o
row = get_index col_max - top_row
8 p' ^$ t+ ?& ` b
col = get_index % col_max
; ]0 Q- G4 |2 V' g0 ~, P
new_x = item_x1 + item_width (col + 0.5)
9 e5 L: M# u7 s& j# ]) R6 }
new_y = item_y1 + item_height (row + 0.5)
0 o e3 S# d' q. o# ?
new_x += 14 if col 4
# P% {1 z3 P8 T
Mouse.set_mouse_pos(new_x, new_y)
{" ?# ~) `7 A1 Z) f* |- W* [ _
end
! S% ~; H9 J, Z+ s" w
end
9 {: m5 S* a8 v: i* M' }' c* D
9 Z; X; p( ?$ j$ k7 L
#==============================================================================
/ X: H( ?2 f$ B% e3 a
# ■ Window_NumberInput
' s, {3 q# x- o! [7 c: Y! k/ v& P
#------------------------------------------------------------------------------
# i/ l S; G$ g6 J$ w& T; Q" K2 d: ?3 m/ C
# 重写了数值输入的方法以适应鼠标
7 P: T: A6 ~( Z# I1 _% x
#==============================================================================
1 T, s% ]+ F% \. H x
class Window_NumberInput Window_Base
8 K& F0 A; Q7 a& ]- I5 O2 |$ o
#--------------------------------------------------------------------------
9 l. ?+ L2 N! J; [
# ● 定义实例变量
4 }8 s1 h$ f6 t- w9 b% E, @$ D
#--------------------------------------------------------------------------
/ }4 \/ n( W: a/ X5 j6 \
attr_reader extra_window
/ Y% W( f' w3 h% C5 X, Q
#--------------------------------------------------------------------------
! u- R6 { X/ {5 `( Y
# ● 初始化
2 j8 m8 r: g' M! r4 `
#--------------------------------------------------------------------------
5 y& G3 ^$ {) f- L5 o9 L
alias sion_mouse_initialize initialize
4 d8 ?4 j" k/ q( h
def initialize(arg)
0 m2 y9 U* o! z; a! j9 Q. j
sion_mouse_initialize(arg)
% _) `" g/ @5 D, a& K
create_extra_window
: P; Z s( d3 J: C) D
end
: A" q* b2 B6 [% w9 S/ k* p
#--------------------------------------------------------------------------
+ ?: y+ a% i7 A u
# ● 启动
' |5 V6 e% p s' u1 V* j& K0 T5 r; l
#--------------------------------------------------------------------------
" m4 g- ^1 {2 }: |3 r
alias sion_mouse_start start
5 k4 S- ^. a* o8 S
def start
) ~+ i5 X( R- }: J8 q( w8 o) z8 o
sion_mouse_start
; A3 Z( V! a: p5 ] m, O: \
deactivate
* ?" A/ U( ]! k; U; A! A
extra_start
# P. B: N7 n# Y3 t/ }
end
6 t- Q) ]# c) \8 e8 K; c
#--------------------------------------------------------------------------
3 |' c2 m: [+ z8 J4 M1 ~
# ● 创建新的数值输入窗口
; |' V" Y) l2 f
#--------------------------------------------------------------------------
( B. D% C( `9 P/ F" D3 D; w9 z
def create_extra_window
7 D3 p/ |; `5 Z$ G1 x0 ~" j; j
@extra_window = Window_NumberInput_Ex.new
: a- {8 `4 v5 \ ^
@extra_window.x = (Graphics.width - @extra_window.width) 2
0 @( n0 m8 h) {1 c C6 A
@extra_window.number_proc = Proc.new {n [url=home.php?mod=space&uid=27178]@Number[/url] = n }
@7 o: {) W+ ^4 ^9 x5 E
@extra_window.index_proc = Proc.new {n @index = n }
) }9 o% w# d" O0 K$ O
@extra_window.close_proc = Proc.new { close }
. O% w4 ^5 \( O; @. J* z
@extra_window.refresh_proc = Proc.new { refresh }
, X- d* I' r# N4 E# H1 _
end
3 g- q0 b4 K5 }+ @6 O
#--------------------------------------------------------------------------
) D9 w6 ?, m: n# I/ n
# ● 激活新窗口
+ P% V% E/ S- L; f& D; R X% x
#--------------------------------------------------------------------------
. c q9 C' ~ K% g( v6 ^
def extra_start
# j B* k' t6 v# w# W- h
case $game_message.position
3 o) Z& D' k- m% _3 f
when 0; @extra_window.y = y + height + 4
4 W' J' ?! K( [
when 1; @extra_window.y = @message_window.y - @extra_window.height - 8
3 T( `% m2 ]1 ^) Z
when 2; @extra_window.y = y - @extra_window.height - 4
3 s" X' X5 g' a) A
else ; @extra_window.y = 8
$ S' M% X2 F* w0 {" r
end
+ H/ \2 s& B1 K* [7 Q% Y
@extra_window.variable_id = $game_message.num_input_variable_id
1 B! Z4 p4 G7 {& y$ k5 J" t; Y
@extra_window.digits_max = @digits_max
! d' ~/ p( T, _# u9 G; K1 X5 S+ h
@extra_window.number = @number
, w5 `# k7 |* d2 O: m
@extra_window.open
c+ F7 q# H a7 o4 M7 ?( K
@extra_window.activate
+ ?6 l& A! A; s. U) H, m
end
Y n! X$ V0 b, v
#--------------------------------------------------------------------------
$ r5 E6 b# i8 n- R
# ● 更新
$ s2 T6 M' A: R5 G/ F/ m
#--------------------------------------------------------------------------
8 N5 j* k% c+ I& q$ B# d1 j6 O
def update
# T5 x T. ?, T( W3 g6 O" z& h+ I
super
- H- t3 w4 g& P1 S# H9 {& t1 I
@extra_window.update
( d1 y% D$ H6 w6 U. |4 L B
update_cursor
/ O+ s2 Y' R1 G
end
' x) i% e E2 S4 J5 A
#--------------------------------------------------------------------------
, J* u+ b7 F. g" u4 A z# j4 W
# ● 关闭窗口
6 b: a) Q% ~: [9 h, {8 ]0 `* ^" b
#--------------------------------------------------------------------------
2 m1 e& |. h. ?/ ^ \) B9 P+ o: |
def close
, V: U& f0 v9 L% s7 ^. U5 r
super
" e# s0 |. R( M
@extra_window.close
9 q n: K: G `2 ?6 M
@extra_window.deactivate
$ R+ g$ C4 V4 F- X" [
end
; J7 d# V1 k# S
end
; _4 `/ F# H; W# |4 i H5 G. V
5 ^8 R; E& g) \" H; w2 V$ r
#==============================================================================
; n( }: {& c3 E1 D( ^
# ■ Window_NumberInput_Ex
: X+ c9 P6 I6 J6 r+ s% u9 u5 [
#------------------------------------------------------------------------------
! N) z1 y5 Z' g7 c
# 新的数值输入窗口(NewClass)
$ m' P/ k! Q) ~6 I. [
#==============================================================================
+ j1 y* ~4 ]" I$ j3 N
class Window_NumberInput_Ex Window_Selectable
# W Q2 ]5 N& _
#--------------------------------------------------------------------------
2 {" L/ F/ l- b
# ● 定义实例变量
9 ?* r: Y; w3 G0 n% g1 x
#--------------------------------------------------------------------------
) Z6 |4 x$ V$ {* d
attr_accessor number_proc
% o4 v8 w8 o% O7 U' l4 V1 q0 ^. V
attr_accessor index_proc
! P; N4 r8 l1 m2 p
attr_accessor close_proc
0 z# O8 ^* o4 H* \4 q; I
attr_accessor refresh_proc
* r+ I% c2 J, Z" u- I
attr_accessor number
3 g3 P5 _( O3 A& S
attr_accessor digits_max
% K& b! L. P' R4 F8 a5 z
attr_accessor variable_id
2 `) }5 {+ e( H3 ^2 C
#--------------------------------------------------------------------------
; Y0 J* I* \" T2 j0 j8 X5 f; A/ l
# ● 数字表
- m* h+ k4 n! }4 i# i2 b \1 W
#--------------------------------------------------------------------------
' |- I: Q L+ j$ w5 b. a
TABLE = [ 7, 8, 9,
" T$ ?. V$ }) D+ C
4, 5, 6,
: y- y9 {; X" K, f6 a& [
1, 2, 3,
& c" B8 B i. k+ s. e& }
'←',0,'确定',]
' ~1 T& R( [0 s! ~, ^
#--------------------------------------------------------------------------
7 M! v* t+ U- a% H/ D: Q5 k4 T
# ● 初始化对象
; W$ N( b0 K) x* d
#--------------------------------------------------------------------------
7 c$ p3 i+ Y4 a
def initialize
6 m* O+ {% x, j
super(0, 0, 120, fitting_height(4))
o9 L. t8 x8 r; L* `# I: q1 s) W
self.openness = 0
" B, v/ C |3 x1 h9 ~' Z
@index = 0
) E7 n8 ]6 s8 y
@number = 0
8 c+ N$ ~/ p' b2 R
@old_window_index = 0
7 j+ b0 z- T( T# L# k2 |
@digits_max = 0
& T) Z+ X* L$ {+ I
12.times {i draw_text(item_rect(i), TABLE[i], 1) }
# u! S2 a' p6 t; I' N
end
9 K6 _6 [# ^% d4 M0 P$ s: v
#--------------------------------------------------------------------------
+ | l2 B- S" V8 X5 S2 G$ g2 U
# ● 获取项目的绘制矩形
, B' F" ?3 B' q7 B; `
#--------------------------------------------------------------------------
, G. p" s+ H. W$ s; H' y) ]; T" x
def item_rect(index)
+ V! F0 v7 ]3 q* z7 @
rect = Rect.new
, N! F- s1 Q1 q* H7 k
rect.x = index % 3 32
; O. Z+ t" H, l$ }
rect.y = index 3 line_height
! m2 @" U6 i0 c: H* t
rect.width = 32
* o' z j Q# u. U9 A& Y a
rect.height = line_height
) e" ?2 A% r' K0 Y' h
return rect
; t" s8 g! ?6 T% {& @
end
1 G" o% R0 ^# U1 \6 E
#--------------------------------------------------------------------------
8 G B; q& t% p; y. T
# ● 将光标设置到鼠标所在的位置
; @/ h3 u0 N5 i
#--------------------------------------------------------------------------
" Z5 c1 L+ N! K! X* K
def set_cursor
: A1 N& k- S/ P) K! z
mouse_row, mouse_col = mouse_window_area
6 a1 J3 ~9 e4 r4 h( }9 w* M( a
if mouse_row = 0 && mouse_col = 0
/ O: i7 P! ?+ g6 W3 Z
new_index = mouse_row 3 + mouse_col
) R: L& H7 E: }
select(new_index) if new_index = 11
3 Q, f$ t- O8 E
end
) a/ z/ U# a: D" e
end
; O* Q- N; G' V7 m
#--------------------------------------------------------------------------
% V: t. }( \" r
# ● 判断鼠标位于新数值输入窗口的第几行、第几列
* I# _- e8 o' M
#--------------------------------------------------------------------------
( X. c5 \7 r0 f, x' M) ?
def mouse_window_area
; ^" |% m9 b" e6 }/ V6 u" Y
if viewport.nil
5 Z4 P4 |9 c; L0 u" J
vp_x, vp_y = 0, 0
7 l8 V( M8 B. _ M
else
! {# z0 c6 p X4 K
vp_x = viewport.rect.x - viewport.ox
% t- X$ s3 ?+ o4 i5 A
vp_y = viewport.rect.y - viewport.oy
. w) F; i/ [! j5 J
end
/ e1 w3 c- F4 }/ `, _ J0 f
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
+ V8 {) C! F) D# p& w
item_x1 = vp_x + x + standard_padding
9 @' \" R4 l6 k7 z2 H e
item_y1 = vp_y + y + standard_padding
& w, z; B1 U- _/ P/ x$ T e
item_x2 = vp_x + x - standard_padding + width
1 C$ V L( Q" R* C1 _
item_y2 = vp_y + y - standard_padding + height
' P' l% J" y' v. {5 Y8 G
if mouse_x item_x1
5 N: N7 K1 K# w2 Z6 v" ?6 Z% y
mouse_col = -1
6 E. r; A( l; p% ]# }1 R2 p
elsif mouse_x item_x2
. ~/ t1 O$ e- B: A" E5 a* U
mouse_col = -2
' G& q' i. B5 e+ N I
else
* U7 l& S# ?4 A2 W5 l) U
mouse_col = (mouse_x - item_x1) 32
/ l a+ j N1 g
end
6 P3 d% \; C9 [, B8 m5 g
if mouse_y item_y1
/ u, C, u$ m3 J0 x4 R
mouse_row = -1
6 o N' o: H: h
elsif mouse_y item_y2
/ W; ?& ~2 H8 ?+ ]2 U+ B
mouse_row = -2
2 h" V' {( r# q# E9 G: n
else
, [8 _0 R* G; o0 _% j
mouse_row = 4 (mouse_y - item_y1 - 1) (item_y2 - item_y1)
; s- x. O v3 \+ V- Q! e, l
end
0 g {% ?* ?. B% S" A2 B3 J. \- C
return mouse_row, mouse_col
+ g% G3 I8 }; F
end
7 y3 Y# ]: `, I6 h) \+ E' n
#--------------------------------------------------------------------------
# F U) c4 ^$ F1 X
# ● 获取文字
& _" h T: P/ W5 H2 |& ]
#--------------------------------------------------------------------------
7 Q% |' Z8 G( r
def get_number
* P1 V- p; {- z# s2 t' ?8 {% b
return false if @index == 9 @index == 11
1 v8 j2 \0 s" H, |- o+ w5 `" [8 T
return TABLE[@index]
: Q1 B d. [0 _' t
end
0 s5 G( ~) D6 | p% o$ W0 V5 ~
#--------------------------------------------------------------------------
+ G G3 \9 \# e `) C' A. l
# ● 判定光标位置是否在“退格”上
* U; d& ~: c$ ~! k7 Q' R& L: P' J
#--------------------------------------------------------------------------
5 g6 h4 k9 a, X; C0 d
def is_delete
7 x- }: t3 f+ _( ?# `
@index == 9
! f. v' x7 t" I3 K0 @9 [: N
end
& J* ?1 V) z' {, r& Q4 }
#--------------------------------------------------------------------------
: h8 _- q& i2 n; J5 u4 @
# ● 判定光标位置是否在“确定”上
6 K2 E: b1 t2 x: I2 H
#--------------------------------------------------------------------------
5 u4 V! U& p# x( S4 @
def is_ok
" T/ h- e" m7 o' r- H% K- ?/ b' X
@index == 11
+ ]6 v a. c8 d3 Z2 B
end
, ]/ D& o: P7 z- i
#--------------------------------------------------------------------------
( ], ] _) ^5 X/ t
# ● 更新光标
k1 \5 G6 v+ D9 H( ]4 C6 v6 |
#--------------------------------------------------------------------------
+ f2 d, u+ ~& z- ~1 ^. ]
def update_cursor
$ E w4 A$ R+ d
cursor_rect.set(item_rect(@index))
1 F4 J$ N6 J/ \+ l7 q* Z
end
& R2 }. v4 F% N/ _7 e2 |4 t
#--------------------------------------------------------------------------
$ W6 L: p. Q. t: R( I$ u1 q
# ● 判定光标是否可以移动
9 c% \: w0 m+ S% Q+ L
#--------------------------------------------------------------------------
, V. i( M* _) B$ d
def cursor_movable
# M3 v- U& ^% \: t
active
# x+ ?( W/ N- Y6 w' P, u1 e
end
$ d2 K$ v8 O2 X
#--------------------------------------------------------------------------
7 [0 U6 V7 I! j( m# ^" k v
# ● 光标向下移动
! f5 y! _1 j7 m1 s
# wrap 允许循环
" @" d; i- Q( y4 U7 J
#--------------------------------------------------------------------------
5 z5 m( N& O& i5 ^
def cursor_down(wrap)
6 H, H- h( L% }& Q6 r$ E. v4 _
if @index 9 or wrap
9 V+ o0 T1 s- X0 E: v: G5 r( C. }6 Y' S
@index = (index + 3) % 12
! z2 E6 G1 x) f: E9 F, S+ _
end
. b4 y' X2 C9 t
end
& ^2 d" Z5 {( Q% h
#--------------------------------------------------------------------------
! c( n* B* A P3 H; u4 C; N- X
# ● 光标向上移动
! g* n- p2 y; l/ b0 w. O2 G; [9 X f
# wrap 允许循环
9 d( Y5 n9 ~+ T6 Z, d# |, L1 X5 ^
#--------------------------------------------------------------------------
5 @; C' t8 f9 A# @0 @
def cursor_up(wrap)
* g9 @0 }- X( Z
if @index = 3 or wrap
. L' X- b7 k; z# f! z, X! E9 }- V
@index = (index + 9) % 12
0 R! T$ B- R; C& r% k3 c
end
' u) N( {, J, l( P" M i
end
4 T8 h( G( [# H# w9 [ i. s9 s
#--------------------------------------------------------------------------
: B' _ p! D, o7 M6 x/ \
# ● 光标向右移动
& y; m! i: u( @) ]9 D
# wrap 允许循环
+ q7 K F& l. R
#--------------------------------------------------------------------------
0 {* Y; r9 n- i8 K1 X4 [) p0 N
def cursor_right(wrap)
6 q8 S" i, m: n9 M
if @index % 3 2
, H8 V! ?$ q, c$ r5 g1 h+ c
@index += 1
; o0 r8 u, d$ M& q) K, t
elsif wrap
/ a) W3 i$ E9 _. p! M& U, T7 m
@index -= 2
1 s, W# }+ Y1 E" U# T
end
& O% l4 T$ ~6 C* _- M
end
5 e9 P. H+ U6 }
#--------------------------------------------------------------------------
, h+ ?" ?$ |! E7 p, d" E
# ● 光标向左移动
7 u! f, ] V H
# wrap 允许循环
) G# s- d2 ^& E
#--------------------------------------------------------------------------
9 H! A. R2 @9 Z; T
def cursor_left(wrap)
k7 e6 i" G4 f0 w$ z8 i. U
if @index % 3 0
- H& t9 c9 n+ [! @, p& @. _
@index -= 1
& O/ G0 j- U- b: X' m; r* d& x
elsif wrap
! \% i7 P9 T& ?; h. u
@index += 2
* B5 C" _+ c0 J) l: D
end
0 r. k5 W$ u8 ?
end
" p- c3 C! ^ \! M/ ]. O6 Q6 X
#--------------------------------------------------------------------------
5 b) o7 D, h% p$ n
# ● 处理光标的移动
( w( ^- L2 ?- r( C- i
#--------------------------------------------------------------------------
/ y6 P) d, W; P0 @$ _' v
def process_cursor_move
" a1 h+ E/ e% B. N% }; C# m
super
) h, B( `7 f$ F) z
update_cursor
3 A# ^ ~2 o. u a
end
2 y7 n. o T& f3 b* {# S# ~
#--------------------------------------------------------------------------
0 [+ A% w4 G9 ~* P7 T& b$ m
# ● “确定”、“删除字符”和“取消输入”的处理
' x3 v. ?. U7 w% u2 F
#--------------------------------------------------------------------------
- C. ?! h# L' F$ H7 l
def process_handling
5 n$ s/ y7 _0 l" g
return unless open && active
6 u% ?3 Q5 j7 a' S8 s& L
process_jump if Input.trigger(A)
. e9 |1 a. d5 g) Q; S
process_back if Input.repeat(B)
- _. B6 Y( e% i# y' y
process_ok if Input.trigger(C)
, b. U! j* J9 m: i& F: n3 e
end
5 A1 z1 F% t) w0 A7 t) i( E+ [
#--------------------------------------------------------------------------
/ K' \% U$ n. g
# ● 跳转“确定”
1 u9 T3 Z x. ^9 K, j9 k
#--------------------------------------------------------------------------
- w0 p! l! ? Y& \. w* n6 m/ R
def process_jump
9 b/ P5 r9 L: Y7 y3 D! z7 [: H! S2 `
if @index != 11
2 |; [$ K: H8 f3 P2 X
@index = 11
# S% |9 U9 F! J
Sound.play_cursor
0 j+ V( H$ }. I. g
end
t9 W* k b& {
end
# J: ]& g: @4 @% V K4 v
#--------------------------------------------------------------------------
4 ~8 `) p/ m' {$ z- M- \# M
# ● 后退一个字符
% O; Q" L' q9 {
#--------------------------------------------------------------------------
+ z4 `. [; j' X/ A1 l- n
def process_back
7 T2 P% o+ k. D% c: M. d
Sound.play_cancel
* `$ W/ F; a$ |+ n6 h) r
place = 10 (@digits_max - 1 - @old_window_index)
9 ]3 U- F8 T' D: h7 X
n = (@number place) % 10
5 [7 g' h% J ?6 w
@number -= n place
8 `& x4 Y* ?( c1 F% B- N& f
@number_proc.call(@number)
6 d+ z% i" W0 B
@old_window_index -= 1 if @old_window_index 0
5 P# t4 N. |6 P2 g3 s
@index_proc.call(@old_window_index)
( |; h9 G" i5 ?' D1 H8 ~
@refresh_proc.call
8 ^! F$ l. H3 t2 N# v( |
end
2 i. I; k0 \( X0 Y* V
#--------------------------------------------------------------------------
. p5 R" a+ ]1 y2 q
# ● 按下确定键时的处理
7 e# p# N0 [8 {" K3 W2 ~! q4 }9 H) G
#--------------------------------------------------------------------------
8 q' Q! o7 ?% a7 L. V" j# K4 H
def process_ok
3 i! |% e( I" M7 S- |6 v
if get_number
* k b7 e3 Y6 a3 ?2 I3 u& C8 u- o
Sound.play_cursor
6 J4 L: w1 ^1 T6 A+ L+ {" X u
place = 10 (@digits_max - 1 - @old_window_index)
1 O9 L# Y( ~( i% n, a7 l- U
n = get_number - (@number place) % 10
4 S5 I! P% e+ B# ~( ^) C9 e' ?& R; R
@number += n place
+ H6 F! O8 B! [( K' F* B
@number_proc.call(@number)
}0 E/ C8 {2 k: r/ s# b$ J! o7 Z
@old_window_index += 1 if @old_window_index @digits_max - 1
+ e& X5 M7 L& v* [
@index_proc.call(@old_window_index)
' T8 M8 f6 D% H* G% G7 u
@refresh_proc.call
$ r: `( o0 W* U! k
elsif is_delete
: O' a$ i6 [) g- _7 R) x% f
process_back
2 R0 Z }) B( G& {# W. ~. O
elsif is_ok
9 _6 u! |6 O% q5 \
on_input_ok
2 W! e7 s8 T" l+ ^
end
. i6 q2 S$ j7 W! F
end
! d2 }: R }0 p: O2 p# ?% J, p: v# k: K
#--------------------------------------------------------------------------
1 G U/ |) U1 i
# ● 确定
# h: C7 s. y5 p+ `# b
#--------------------------------------------------------------------------
; T! | ?7 a0 e: v% R
def on_input_ok
2 J9 {" r5 m! s% l0 ~: I
@index = 0
( l7 q, Z2 M: [+ W7 K# v" J- M, h
@old_window_index = 0
4 q5 M9 [1 @ D l% `
$game_variables[@variable_id] = @number
9 ^! @ t* f' [$ J9 E
Sound.play_ok
" g9 p( u7 ~% M) C( u% M2 I5 F8 }
@close_proc.call
6 @6 { b3 `$ X$ B3 i
end
; J6 P7 `% L. H- o+ A/ K) r
#--------------------------------------------------------------------------
& j0 m$ J4 Z; q8 J# G
# ● 方向键移动光标时将鼠标移动到对应的光标位置
0 j/ q+ h+ S7 H$ t
#--------------------------------------------------------------------------
+ E4 ?" A$ ^7 X# H- V) [
def set_mouse_pos
, C/ j5 o N) ]' N& K1 C1 O
if viewport.nil # necessary!
9 S4 \, }4 L7 r! q( U; ?
vp_x, vp_y = 0, 0
6 \( U2 Z7 I& u0 }/ a3 ]
else
+ _6 @7 @0 d- n7 c4 `& j7 i& A
vp_x = viewport.rect.x - viewport.ox
3 a2 @% _2 C% V8 B9 j1 w$ Y: ~
vp_y = viewport.rect.y - viewport.oy
' T0 _# s2 p0 \4 x
end
: J0 i: i3 T4 h
item_x1 = vp_x + x + standard_padding
: m4 @8 ~/ l& z* S
item_y1 = vp_y + y + standard_padding
& Z( q, D) F1 X F' ^( I3 j
get_index = @index 0 0 @index
. ^( v2 c+ B4 } |1 Z
new_x = item_x1 + 32 (get_index % 3 + 0.5)
' s. n" _! G1 L- m9 c% Q
new_y = item_y1 + 24 (get_index 3 + 0.5)
, }2 D! P' W v A2 p! ^$ F9 m
Mouse.set_mouse_pos(new_x, new_y)
$ u- Y! _: e) r- Y' {" I+ u
end
/ z( C9 O3 j3 T, d/ j# n
end
8 `5 \$ ^3 L# d2 U3 ~; ?7 }
2 W% a8 }4 E; V7 l) g
#==============================================================================
. g$ g. s! _0 A+ O) H. A
# ■ Window_Message
8 n1 s$ ]9 a. m0 r W# K+ y2 V
#------------------------------------------------------------------------------
: B0 I T4 c5 Q6 j
# 显示文字信息的窗口。
( A" j1 ~4 `! k" ]3 R
#==============================================================================
1 w# }5 D" F L& U4 T4 u
class Window_Message Window_Base
4 p/ Z( T) S# W4 v7 H* e( k
#--------------------------------------------------------------------------
# r7 \ c5 ~- \3 x) X3 c+ l) s
# ● 处理数值的输入(覆盖原方法)
# `0 ^( |4 A! `, m
#--------------------------------------------------------------------------
$ P9 h7 e) l% {2 x4 \2 O: l9 g
def input_number
8 e. T, @' I" ]
@number_window.start
3 k- M' d; A, V2 c) a
Fiber.yield while @number_window.extra_window.active
! \1 R/ n4 n" D5 @
end
) W9 X0 x/ | e+ T$ o
end
# t1 u, s; C! v% g4 P$ f
( _1 z3 ]6 I. M* e4 Q7 b
#==============================================================================
K" ]: Y* T' B% w: L9 c
# ■ Window_PartyCommand
9 c6 g3 g0 X) }; A& q
#------------------------------------------------------------------------------
; }0 p5 z2 ~& j- @- t, s' Q ]
# 战斗画面中,选择“战斗/撤退”的窗口。
2 Y7 v, o) H6 B0 d, a
#==============================================================================
0 D; A, C& h7 d! z' @5 C3 f, \
class Window_PartyCommand Window_Command
1 ]. x" [' U7 ]( h& N5 {0 b: D
#--------------------------------------------------------------------------
- p. B2 {3 l( t/ |
# ● 方向键移动光标时将鼠标移动到对应的光标位置
- L, V8 b9 M# V$ o% E5 {( P% y# Y+ C
#--------------------------------------------------------------------------
i0 N" d/ U) g! Z7 r2 E' E
def set_mouse_pos
+ A% f) i0 H+ p
if viewport.nil
# ?( ?: B B, O+ ]4 F
vp_x, vp_y = 0, 0
) u/ a. f% A v% |5 ^
else
' L' H8 X( w$ b* o1 O7 t
#vp_x = viewport.rect.x - viewport.ox
& h6 F+ Q6 b6 b$ g* v+ B
vp_y = viewport.rect.y - viewport.oy
" e: c6 u) H1 e6 o4 o4 t e
end
5 E: G2 M. f* C* {/ O# P
item_x1 = x + standard_padding
% Z* c0 |+ T$ p4 T0 a
item_y1 = vp_y + y + standard_padding
% ^8 { [6 h! S; R3 `
get_index = @index 0 0 @index
2 f) h- x% @7 I7 D1 l
row = get_index col_max - top_row
! z9 P# x4 }' M. A+ s4 l
col = get_index % col_max
' j& o. \3 r# n e
new_x = item_x1 + item_width (col + 0.5)
! I3 g- R. y S4 t' B8 c7 m) z
new_y = item_y1 + item_height (row + 0.5)
0 c! p u* V" A8 ]. \
Mouse.set_mouse_pos(new_x, new_y)
2 h. C. t1 T- r5 D8 L) A
end
, Z3 e( J2 }! m
end
U. S& R% I. \
- |) `, b; E6 b/ ~, v/ F
#==============================================================================
9 |$ R* J: B/ B3 h k& J
# ■ Window_ActorCommand
2 c1 b+ c! _" l/ N( `
#------------------------------------------------------------------------------
! D3 e$ [8 I" Q# z" P; [
# 战斗画面中,选择角色行动的窗口。
3 d$ U+ @6 Z1 d5 u' P/ I4 }! ^- C3 n
#==============================================================================
4 Y& X& _% D7 {1 j- n) w# {5 {/ `
class Window_ActorCommand Window_Command
! T5 V: C1 ]" d8 u S9 e
#--------------------------------------------------------------------------
3 g$ S2 P$ O4 O8 E' `7 \" t
# ● 方向键移动光标时将鼠标移动到对应的光标位置
' B( b& |& k& {7 b
#--------------------------------------------------------------------------
9 Y( @% C* D- n) w2 K# |
def set_mouse_pos
C9 K% m2 ^' G; |; @9 t
if viewport.nil
9 j" y* Q1 Z' p5 `
vp_x, vp_y = 0, 0
- k" F1 A$ X( R" ?1 X
else
7 ~& O; k& b' R" n0 z4 N
#vp_x = viewport.rect.x - viewport.ox
! F% @, m' b, W6 I4 W e
vp_y = viewport.rect.y - viewport.oy
. |* B+ Q- B3 V, I- I
end
! Q) X8 V# _0 _( f2 ]
item_x1 = Graphics.width - width + standard_padding
% \% y; F" W$ W6 `8 {; U
item_y1 = vp_y + y + standard_padding
! w- A4 U' n0 Y% r0 L
get_index = @index 0 0 @index
; x& h; R8 M) R7 t, d! n/ Y+ V
row = get_index col_max - top_row
+ F" y/ K0 ?& Y. C. T
col = get_index % col_max
# @- J4 M$ t( J: V7 E; V5 X
new_x = item_x1 + item_width (col + 0.5)
& E& f8 K+ q% @3 B7 r
new_y = item_y1 + item_height (row + 0.5)
1 J. ?. c2 j% L( P
Mouse.set_mouse_pos(new_x, new_y)
4 B6 a& V& N; \9 t9 J- }
end
# n$ f6 T$ t/ v0 d8 X
end
5 O6 y# s! y# g. s) H
0 U; B5 ~9 F: x
#==============================================================================
) t( U" y5 I7 d3 |' m
# ■ Game_Player
+ C& D( I' q+ ?# R7 m4 y. @ n
#------------------------------------------------------------------------------
8 J ~# H' \- J& ]0 v
# 处理玩家人物的类。拥有事件启动的判定、地图的卷动等功能。
! y8 _! B2 H/ E7 i+ d! l* H& `7 A
# 本类的实例请参考 $game_player 。
$ [6 P9 A7 @4 F
#==============================================================================
: q C/ B5 T9 c' l9 Z
class Game_Player Game_Character
5 O" y7 v+ L' S& I+ G2 M
#--------------------------------------------------------------------------
/ a9 b; [/ [4 c' \
# ● 由方向移动(覆盖原方法)
2 V. ^. ^, k3 J" Q$ ~! q v" K
#--------------------------------------------------------------------------
# x6 v; R3 r( ]4 h; A1 \
def move_by_input
/ I) x; b' `7 V
return if !movable $game_map.interpreter.running
1 Z' x/ b. F7 W* ]& r
if Input.dir4 0
% _+ F. `+ Q- B" o4 g$ d2 f+ ?# k- Z
move_straight(Input.dir4)
- o# Z, R( ~) Q+ D+ ~$ F7 {: l
reset_move_path
; L# ^ B4 ~# O' }
else
* N/ g3 f2 }8 h# D5 X. |- q6 Y2 h
move_by_mouse
3 Y, N( l |( v; a) _ i3 M4 l' w5 x
end
: o; s7 }6 P4 w0 y* H) [8 c( x9 I
end
# `) H5 e2 U! F Y, i0 }% J
#--------------------------------------------------------------------------
3 `0 C% I- g* d% p
# ● 非移动中的处理(覆盖原方法)
2 W1 p( q4 K" V: B* ?
# last_moving 此前是否正在移动
+ \! s9 E& |/ g9 {; K4 J' o$ |
#--------------------------------------------------------------------------
: F' c0 n! A, G2 R) f- h! {
def update_nonmoving(last_moving)
: E5 k, \8 p1 @2 x3 w* d
return if $game_map.interpreter.running
# T* @3 E8 C& b4 n2 [9 J
if last_moving
8 x" i% G, q/ O: O/ F( C' {
$game_party.on_player_walk
% l3 M6 H8 K. h0 e/ n
return if check_touch_event
% u1 J. F8 R8 A
end
* w4 P, c" ]1 l7 k
if movable && Input.trigger(C)
+ L% ]6 C! q2 W7 X( f
return if Mouse.press(0x01) # 防止按下鼠标左键绘制路径时触发事件或载具切换
$ e0 l8 G- R' d8 I, |, S8 {
return if get_on_off_vehicle
; q, g* U* e6 H/ P3 W
return if check_action_event
) m5 w- H8 u) }
end
( U8 V& `9 l* U2 i; r# a
update_encounter if last_moving
# H/ ?; u( A( d3 I* ?1 v1 ~
end
- u' u7 S0 q0 q0 g; S
#--------------------------------------------------------------------------
/ c; f8 O a$ C" y/ U
# ● 判定是否跑步状态(覆盖原方法)
8 ^, Z8 p* [& d0 C
#--------------------------------------------------------------------------
+ X+ b/ o! ~. t/ O& h( S( d9 b
def dash
, N5 i7 q( ~6 G2 Z S
return false if @move_route_forcing
) c. A, {" o1 Q
return false if $game_map.disable_dash
/ H$ e1 ?' \/ Q$ ^% `
return false if vehicle
8 o X& p& M! O0 [5 E) e
return Input.press(A) @mouse_dash
2 Y. \8 J1 A/ S( E. n% h
end
% v' d2 K8 i5 X( J& n* S
#--------------------------------------------------------------------------
4 |$ [0 i8 C+ V
# ● 初始化
4 `# S( {1 a/ D' \! k- u* [
#--------------------------------------------------------------------------
. ^9 l ~7 l( l& B7 c
alias sion_mouse_initialize initialize
" j; e; K: W7 W8 e
def initialize
# Q8 Q4 ?5 ]- m; m0 P+ W
sion_mouse_initialize
, r5 q/ Z8 ^' P# P4 C+ r" F3 D' C
reset_move_path
' M$ b: u2 N \
@moveto_x = 0
2 N+ x5 r) o9 U
@moveto_y = 0
: a w: t) \6 a2 h) x/ u9 N
end
5 `) Z& g* Q) t4 W7 [7 q
#--------------------------------------------------------------------------
# s# H2 o& o+ _4 S$ ?
# ● 更新
% r3 {7 B1 g! R: k1 q
#--------------------------------------------------------------------------
: p w# F+ N6 T3 l+ I% [* G2 ?
alias sion_mouse_update update
( }9 T+ `5 E& |
def update
; p* S* {5 x- t* x2 i
sion_mouse_update
. ~( R$ m6 m6 F9 P8 ^/ x
clear_unreachable_sign
4 u3 Z, g( C) ]. G, ]+ L$ ~% b9 J- f
end
* |/ k5 v7 I& G9 Q
#--------------------------------------------------------------------------
" H& K, s; q0 v5 `+ R
# ● 处理卷动
! q2 u6 p" M) D# v$ N' [
#--------------------------------------------------------------------------
8 D/ f2 _- s/ ]- {5 d1 l
alias sion_mouse_update_scroll update_scroll
( Y) G% O5 ~. Z% E$ A
def update_scroll(last_real_x, last_real_y)
* |0 {, ?5 c5 E7 ?: t
return if $game_map.scrolling
2 T: k6 Y- m& O8 z) }
KsOfSionNew_Scroll new_update_scroll
1 X( r* G0 R* F9 I+ \ o3 x' I
sion_mouse_update_scroll(last_real_x, last_real_y)
: P* F, Z1 J( M8 L2 C4 ^
end
4 J9 D- y" R; D, h9 I4 W! |
#--------------------------------------------------------------------------
5 \- \; ]; ^- H: @; c
# ● 重置移动路径相关信息
) w+ i; e$ E2 t; p8 c+ H
#--------------------------------------------------------------------------
, @: F) h! O4 }# n) o
def reset_move_path
+ |! `! n- {9 q8 b) V
@mouse_dash = false
8 ^8 m9 ?- {( o4 L, K" E5 d% |
@mouse_move_path = []
: x" U$ i+ m+ E4 V2 ~! E
$mouse_move_sign.transparent = true
# A+ Y# N6 n+ V4 l
end
9 P" X# k$ N9 L i. A
#--------------------------------------------------------------------------
. p4 r* H* m6 k) G: b& J
# ● 新的卷动地图方法
2 n; Z5 z4 C% i. G7 n9 b
#--------------------------------------------------------------------------
4 {8 j7 d d2 S) Q2 w7 T. i
def new_update_scroll
2 C( ^' O. Y$ y4 u% P: y- \7 Y
horz_speed = 2 @move_speed KsOfSionMap_Scroll_Spd Graphics.width
1 d8 x' C+ {1 ^3 d5 E
vert_speed = 2 @move_speed KsOfSionMap_Scroll_Spd Graphics.height
! w/ M% b( j8 B5 w; M1 H
ax = $game_map.adjust_x(@real_x)
" \. [: O) f9 W7 L9 h
ay = $game_map.adjust_y(@real_y)
7 S2 a6 q' M( i. d+ c
$game_map.scroll_down (vert_speed (ay - center_y)) if ay center_y
6 C1 {0 `2 A* O; h, O
$game_map.scroll_left (horz_speed (center_x - ax)) if ax center_x
3 ?1 o2 M. V. m# q
$game_map.scroll_right(horz_speed (ax - center_x)) if ax center_x
7 c. @0 h/ E% D+ D$ f0 M
$game_map.scroll_up (vert_speed (center_y - ay)) if ay center_y
, o3 D3 P9 a8 j: U* J6 K/ R
end
( a9 }" L1 {! u: p: ^7 }& r3 \8 C
#--------------------------------------------------------------------------
s# W# L H4 E; k
# ● 消除不能抵达图标
# G+ r; J: C. K& a x
#--------------------------------------------------------------------------
" S9 b* B1 W7 e; e) y5 c6 \
def clear_unreachable_sign
t8 \ V _4 F9 U6 K2 T) k9 ?
return if Mouse.press(0x01)
K6 V- B8 [( W6 B
if $mouse_move_sign.direction == 4 && Mouse.click_count % 20 == 0
e5 b. A* I3 M2 l5 e% t/ E: G/ Z
$mouse_move_sign.transparent = true
) b' U, ^2 x4 N) i4 L; E
$mouse_move_sign.direction = 2
D/ D% Z3 ^/ U: a, c
end
& u P6 k% T! Y' a! H4 n5 j
end
8 r7 q+ w1 V" I7 D
#--------------------------------------------------------------------------
* Q- w" O5 `/ r
# ● 由鼠标移动
* d+ H* k/ W& |
#--------------------------------------------------------------------------
: p0 k: g/ o8 @/ N" h
def move_by_mouse
2 r. q/ a' p& l4 e. l3 y2 y
unless @mouse_move_path.empty # 移动路线数组不为空则执行移动
/ ^6 J0 K5 x4 n$ G4 }" ]
dir = @mouse_move_path.shift
0 Y- l+ I8 z/ }% i7 H. Q
if passable(x, y, dir) && !@mouse_move_path.empty
9 q; K; E. D3 H$ a/ y8 [
move_straight(dir)
. Z6 o* v& F5 v2 j
elsif @mouse_move_path.empty # 判断是否是最后一步
# G" v, P0 a3 {. `. f/ P
x2 = $game_map.round_x_with_direction(x, dir)
- O0 U, M: E* y8 B7 X
y2 = $game_map.round_y_with_direction(y, dir)
3 f6 p7 R4 Q' o6 [3 }" k
move_straight(dir) unless dir.zero
1 n+ b' m+ G* F0 k. Z Y
unless x == x2 && y == y2 # 如果移动失败,检查是否启动前方事件、上下载具
: P& D$ B8 S+ g
check_event_trigger_there([0,1,2])
6 @) @) }/ w O% s9 @: U
get_on_off_vehicle unless $game_map.setup_starting_event
# c- }' M3 P! F" M( W- P& e J* t
end
7 ]' R) U9 w- L/ D3 @+ E( f
$mouse_move_sign.transparent = true if $mouse_move_sign.direction == 2
9 m3 i3 u. E6 N* v8 q/ W# r: u+ I
@mouse_dash = false
2 d- B5 ~1 G, o
elsif @mouse_move_path[0].zero # 目标点无法抵达,调整朝向→目标点
! q ~, H4 s2 g. w
@mouse_move_path.shift
8 Y" V7 d1 ^$ S5 z" R1 `
@direction = dir
( G& o* q5 \$ o" A
@mouse_dash = false
$ d& e+ A0 L5 V4 T9 J' b2 B0 V$ Y
else
' @; [9 Z3 R* }: o9 p1 O
draw_move_path
4 ~; U, F6 E, ^& r; P# s' D
end
* t6 t5 t. a$ N( b, c+ F# c9 R
end
4 a$ n3 X% H/ v0 A7 @
end
1 d* Q/ s! x+ F
#--------------------------------------------------------------------------
! J8 c) P1 } b4 \8 H; X
# ● 地图界面按下鼠标左键的处理
4 _) i: I5 {3 T4 u; C& Q/ W
#--------------------------------------------------------------------------
( h% z, E- y/ m+ y5 A
def left_button_action
' z' x# d& p& U! Z9 I6 i
return if !drawable $game_map.interpreter.running
3 D; M* j5 l8 x- k8 T3 m0 J& q% @
get_mouse_pos
( w% F9 f7 K# ?1 R/ Q. O
$mouse_move_sign.moveto(@moveto_x, @moveto_y) # 移动路径点指示图
( _0 F0 b+ C# ~3 A; E
if @shift_event
) w( E: n) N) w4 H+ r
if Mouse.trigger(0x01)
}% m {+ H z2 g
@shift_event.jump(@moveto_x - @shift_event.x,
; z) {- B( I! Y' `6 O$ x+ ~% L |
@moveto_y - @shift_event.y)
" I+ Y- w1 _5 o% V- `9 H
@shift_event = nil
; C( Q5 D" z5 f* n' x {5 j
end
( k; z! U6 _) n& g U
return
. H6 P3 [9 ?4 W$ V2 s# Y& A2 W
end
8 C+ N. ]1 \2 e" ]" p) r# @
if @moveto_x == x && @moveto_y == y # 判断目标点是否与角色重合
0 {, R0 n1 T. k3 C, `
return if moving (vehicle && !vehicle.movable)
- ^! ~ d/ w9 p
check_event_trigger_here([0]) # 判断是否触发重合点事件
l$ J0 J. z( x! R: U9 R& Z- ]0 G
get_on_off_vehicle if !$game_map.setup_starting_event &&
" I. ~1 f* z8 s9 m) }. j2 o- ]
$game_map.airship.pos(x, y) # 判断是否要上、下飞艇
: ~: _7 H- U# j& m. s. U& @8 S
return
8 v- K7 s4 Q6 M& N' W. f# e
end
$ K1 x) `* |3 I( V5 `- m
# 判断是否用鼠标启动事件
4 l) Q, ?4 e6 @7 P% [0 _
$game_map.events_xy(@moveto_x, @moveto_y).each do event
; R( N6 n6 j5 D y
if event.mouse_start
# V5 X8 M$ a* q" L
reset_move_path
9 r% z# y) P9 b" o
event.start if Mouse.trigger(0x01)
5 c* s8 ]2 |3 T. @7 S$ C( E
return
" S0 S3 \7 Z6 n
end
3 l% C: L8 }7 H
end
$ E, u+ x* X8 a
@mouse_dash = true if Mouse.double_click # 双击冲刺
0 k/ _& O0 W/ j; z
return if Mouse.left_state % 10 != 1 # 按住鼠标左键10帧绘制1次路径
5 ?) k2 r5 K3 Y7 E- ?1 d
for i in 1..4 # 判断目标点是否为角色周围四点
$ x6 N' r& ]6 C
if x == $game_map.round_x_with_direction(@moveto_x, i 2) &&
6 l" g3 r9 E+ l3 m8 }
y == $game_map.round_y_with_direction(@moveto_y, i 2)
) I$ Q+ `' P) l% Q6 b4 S' N
$mouse_move_sign.transparent = true
v% ]" S/ u3 S3 x ^- Y+ P; `" j
@mouse_move_path = [10 - i 2] if Mouse.trigger(0x01)
0 s/ M( W! p) g. ~3 Z+ v
return; end
5 E2 e8 S3 l) r
end
- I* G8 k7 \, x5 x. v
draw_move_path
- f u; Z, v% d6 c
end
: k- c5 P+ I$ i
#--------------------------------------------------------------------------
: W0 P1 h* O& D) C- h6 }# x
# ● 取得鼠标处对应地图坐标点
1 v& q2 r( {2 {2 g9 f
#--------------------------------------------------------------------------
' d" j o( _# m3 t8 i" ^# A5 L* X* t) n
def get_mouse_pos
0 A& P- o! P2 l2 a
$game_map.get_mouse_map_xy
( g# O# u3 M& f) P$ @
@moveto_x = $game_map.mouse_map_x
3 k8 `1 T& M$ A# @" Q/ e$ ^
@moveto_y = $game_map.mouse_map_y
$ V0 Y9 M6 k6 s2 m
#mouse_x, mouse_y = Mouse.get_mouse_pos
0 T' i# L( \' M ]& ^
#@moveto_x = $game_map.round_x(x + (mouse_x -
& @0 k+ T/ a$ e1 c
# ($game_map.adjust_x(x) 32 + 16).to_i + 16) 32)
1 r1 {" P5 u& l+ N; R9 d9 x
#@moveto_y = $game_map.round_y(y + 1 + (mouse_y -
/ f! u% V" ]( s: i' O5 J: Q
# ($game_map.adjust_y(y) 32 + 16).to_i - 16) 32)
. }. ?( t) j# J! w( _$ T
end
% L1 ]( p7 U: n3 K! k
#--------------------------------------------------------------------------
6 m0 d7 t, E) {* N# s5 O0 c
# ● 绘制移动路径 @array[move_directions...]
6 U0 C% _& u& b" ?, E- T
#--------------------------------------------------------------------------
( N4 @1 E, a7 j8 z3 F! f
def draw_move_path
9 Q2 c- z* |) }' X' t, h% O0 H
#temp = Time.now
+ i% ^" Y2 |6 g
case @vehicle_type
" L! k E. x' s" |' \: j
when walk
. U) ~. a: }1 q- ?* ~) n
draw_walk_path
' [) F; ?* Q% u
when boat
4 q- t) `" P( [, [2 N9 t1 g
draw_boat_path
' n0 {2 t Z+ n6 m
when ship
, A6 k, h8 d" X! G- Y) S
draw_ship_path
; j% ?1 L3 ^8 X$ t
when airship
& f, _/ X1 A* G- I1 d
draw_air_path
! j/ s# w* w; `6 }
end
* |: Z3 W; D& P( \4 ?5 x
#p (Time.now.to_f - temp.to_f) # 测试效率
0 y9 ~- o( R( q; P
end
+ Y: p5 A, L% ?; Y7 k$ k; _
#--------------------------------------------------------------------------
5 S; F* J, u) {5 q5 @/ V
# ● 判定是否可以绘制移动路径
: U0 l7 N" g+ U3 y
#--------------------------------------------------------------------------
5 G3 a6 g G% J1 Y+ d; R
def drawable
: ~7 |' Y+ X! T1 H5 H
return false if @move_route_forcing @followers.gathering
2 Z3 S9 H8 J W4 Y* d3 s0 k
return false if @vehicle_getting_on @vehicle_getting_off
2 N4 z, ~5 F) h2 _2 @3 ]
return false if $game_message.busy $game_message.visible
( M9 v2 ~& H& ~, {6 z0 P
return true
; ^7 M5 P& x6 l- A* p0 d$ X
end
3 u8 n( F; v9 m7 ^
#--------------------------------------------------------------------------
2 p- J! |" f, P$ r8 }9 \0 B; P1 X
# ● 绘制walk移动路径 @array[move_directions...]
2 x( \- a" T; [7 S( p
#--------------------------------------------------------------------------
: s1 p. A. z1 i/ m/ W9 Z+ }
def draw_walk_path
+ b& {$ k1 W( E$ Y3 E: h
# 准备绘制路径表格
2 V& p7 ~# N, G" j7 C
sheet = Table.new($game_map.width, $game_map.height)
/ B" r6 f+ e* x1 x) j1 b5 ]
reversed_chase_path = []; chase_path = []
0 q4 @/ x; y/ K7 n
reversed_chase_point = []; chase_point = []
& v: d# \2 y, n
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
$ H# `5 z( N7 P) G0 u0 i A
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
7 ]+ S4 Z0 b$ U4 L$ E7 m/ v' P
reach_point = false
( U( i! ?; u+ F' B6 [
step = 3
) u& w7 D# @0 y1 \& K- H- |- F
loop do #loop1 开始填充表格
% C8 ~4 P# f( L& R5 B- {) b5 F
draw_path = false
/ t; D) z. P$ [* s: E% _& n% ^( q
check_points = new_start_points
- M) Y, A! F/ \' y6 |! }
new_start_points = []
# ?" t# l1 M J5 R0 x. Q
loop do #loop2 从起点开始正向填充
1 j v( G( U( J1 {- D: H& l
point_x = check_points.shift
9 W) A* J, K. T+ A4 d3 Z
break if point_x == nil
6 D. k5 U- h3 Z0 Y7 ~
point_y = check_points.shift
% L2 H5 M; s& X: ?' B: b4 j6 e$ [
left_x = $game_map.round_x(point_x - 1)
9 \) |! q6 {# V% d9 C
right_x = $game_map.round_x(point_x + 1)
. m3 |" U, {4 b' Y
up_y = $game_map.round_y(point_y - 1)
: h; A) u4 Y& X7 E
down_y = $game_map.round_y(point_y + 1)
5 J8 W2 C! f' o
# 判断路径是否连通
) _% f9 ?8 u3 V" N
path_step = step - 1
3 B: |! T7 P0 b/ D* w
if sheet[left_x, point_y] == path_step &&
. G$ r0 a3 J. d7 J0 M4 g3 Q
$game_map.passable(left_x, point_y, 6) &&
8 R g- e8 H* { f
$game_map.passable(point_x, point_y, 4)
4 s, y9 t w7 K7 w
chase_path.push(4)
5 _" B$ |* M8 ]0 O! P
chase_point = [left_x, point_y]
4 J; x; l4 V: Y i* |
reversed_chase_point = [point_x, point_y]
( A9 J5 F- A+ D; D1 S8 n
reach_point = true; break
# {2 e6 B( E+ ~8 {% i) `
elsif sheet[right_x, point_y] == path_step &&
9 [- Q0 m) r1 A3 ?/ E
$game_map.passable(right_x, point_y, 4) &&
4 \* f. N2 [+ L5 p: j+ @* |% q9 z0 o7 @
$game_map.passable(point_x, point_y, 6)
; p& n2 E# h2 V( R z$ C
chase_path.push(6)
w) B; K+ L$ I) x" e R
chase_point = [right_x, point_y]
& S/ b3 D* \- t C
reversed_chase_point = [point_x, point_y]
2 G: G7 l4 S9 E( m7 N, m$ ?
reach_point = true; break
% F& P+ K& H! [8 X, T
elsif sheet[point_x, up_y] == path_step &&
4 @# {# p( }1 @- D& q6 Q8 p! M, S
$game_map.passable(point_x, up_y, 2) &&
# [( E7 w) y" q% A5 g G
$game_map.passable(point_x, point_y, 8)
$ T0 [" @8 l3 ?0 @
chase_path.push(8)
1 A5 p# ?$ ]! G/ t6 `/ W
chase_point = [point_x, up_y]
, S% {4 e4 ]& d4 v, H% X3 K4 N3 x
reversed_chase_point = [point_x, point_y]
0 w! k: T% l9 b
reach_point = true; break
a8 o* c( {/ \( J# @
elsif sheet[point_x, down_y] == path_step &&
& q2 [, w! T* X4 p) t, l
$game_map.passable(point_x, down_y, 8) &&
1 ~0 `+ E0 K8 L: D$ D5 ~4 i
$game_map.passable(point_x, point_y, 2)
1 I' P( ~0 d, Q: j, n
chase_path.push(2)
0 n. h' K; O7 ?. f* H4 i; d
chase_point = [point_x, down_y]
$ l. B8 a2 v0 y/ L) g1 G0 ?5 W
reversed_chase_point = [point_x, point_y]
+ v% d/ v& O8 n
reach_point = true; break
+ _% a2 z+ @& S. n$ ~+ `2 \
end
. `8 X& o' u' Z7 o- t) f
# 以需要抵达该点的步数填充路径表格 #
$ |" d: o e& g5 a# \ M: Y
if sheet[left_x, point_y] == 0 &&
2 F* e: O T: n" I1 p0 a; q4 U
$game_map.passable(left_x, point_y, 6) &&
6 L- k" E9 w5 D
!collide_with_events(left_x, point_y) &&
) _% Y- L; e @5 a( O+ i
$game_map.passable(point_x, point_y, 4) &&
2 r4 `8 M4 p$ w, S. m
!collide_with_vehicles(left_x, point_y) #judge_end
& c4 L- N) `5 m( N2 r4 |
sheet[left_x, point_y] = step
. R* R1 j7 Y7 n4 W+ C3 q
draw_path = true
2 Z+ u: f6 C' T! T7 V8 L5 n+ r
new_start_points.push(left_x, point_y)
2 H, J5 B( A6 i' ^$ c6 v7 c, l
end
, |' [- v2 q7 o
if sheet[right_x, point_y] == 0 &&
- R3 y* _$ r9 W) I1 H6 ^5 p+ ^6 c
$game_map.passable(right_x, point_y, 4) &&
; w+ w- x- o$ M: |! p
!collide_with_events(right_x, point_y) &&
: [9 z E: H, b& W- c
$game_map.passable(point_x, point_y, 6) &&
% |/ C% x8 P2 p) t: c
!collide_with_vehicles(right_x, point_y)#judge_end
/ m) q, u! C4 \
sheet[right_x, point_y] = step
3 w7 U5 @. ?9 R; \- _; t3 W
draw_path = true
! ~$ \6 b) B* x( x2 J7 Q; S' W
new_start_points.push(right_x, point_y)
4 T, b7 `( C2 T" }5 L
end
) h7 F! A) I; Y
if sheet[point_x, up_y] == 0 &&
9 U$ |! N4 p* E ] ^' j/ p
$game_map.passable(point_x, up_y, 2) &&
2 n& u# q* {, z7 ]) `
!collide_with_events(point_x, up_y) &&
2 p/ m* d, p% x8 @3 j4 L% v
$game_map.passable(point_x, point_y, 8) &&
. S; b3 a. B3 D s
!collide_with_vehicles(point_x, up_y) #judge_end
3 l# `6 g/ Y3 |6 d! v
sheet[point_x, up_y] = step
" \% Y# V( I4 L7 b3 w2 N
draw_path = true
! F+ D# W- L/ Q0 _( g$ G' f; S
new_start_points.push(point_x, up_y)
: T. w; m" z- x: f Y6 `5 `; `
end
8 A" G% i) J4 M
if sheet[point_x, down_y] == 0 &&
& O; i6 t U. ~: W* v
$game_map.passable(point_x, down_y, 8) &&
$ [1 L2 r* c4 x
!collide_with_events(point_x, down_y) &&
& x" ~1 H$ e) i p* ~4 w
$game_map.passable(point_x, point_y, 2) &&
7 {! k+ j4 p. I) t. G1 X
!collide_with_vehicles(point_x, down_y) #judge_end
- q) s3 ~6 Q% T. R* v( M
sheet[point_x, down_y] = step
. r" Y5 s' m. q) L' t* D* P* p
draw_path = true
& Y* r# c" w5 X9 X" ?# [
new_start_points.push(point_x, down_y)
' f( ?* Y A2 W, w
end
, g, v; Y) P* ?# [4 \( C, ~- V
end#endOfLoop2
/ w2 e5 q9 ?/ V: e
break if !draw_path reach_point
1 s0 m+ n& ?/ Z; x$ U
draw_path = false
0 H9 ]" C& x+ }3 P( \
check_points = new_end_points
- z3 K5 Q) e9 s9 R2 l
new_end_points = []
2 }; {4 K+ b% V! p2 Y
step += 1
, t% h& @# j0 j: b
break if step KsOfSionBreak_Steps &&
5 c. L2 T* P( W; W" T+ j5 d
!Input.press(KsOfSionFind_Path_Key)
. v# ]* j& B8 S& W% `1 z. h
loop do #loop3 从终点开始反向填充
9 z, u) c; ^; i8 T0 E
point_x = check_points.shift
' H, l1 r* t2 o4 v+ t4 i2 W; M
break if point_x == nil
( i W/ C, { [. y+ [1 N8 b" f9 d
point_y = check_points.shift
: e5 s. f9 H* {; s3 a
left_x = $game_map.round_x(point_x - 1)
" u# N/ C) M9 K: u% W8 p' h
right_x = $game_map.round_x(point_x + 1)
: A2 I1 ?' p/ O9 P4 j2 j5 c
up_y = $game_map.round_y(point_y - 1)
6 J: [3 x3 {$ X# h, O7 c- U
down_y = $game_map.round_y(point_y + 1)
3 z; J( g% A) ~( z( `
# 判断路径是否连通
: v: T# }( Y+ w% _# P/ R
path_step = step - 1
T3 c6 v3 u0 S% h) U
if sheet[left_x, point_y] == path_step &&
0 {1 T5 J4 J) y! a: ]
$game_map.passable(left_x, point_y, 6) &&
) ?4 J4 @" E# M# M
$game_map.passable(point_x, point_y, 4)
3 ~: ~8 T; p! {
chase_path.push(6)
# L! H0 p' d) i4 X1 V2 E) }7 }
chase_point = [point_x, point_y]
. D5 ]7 Z7 l7 y. w2 k
reversed_chase_point = [left_x, point_y]
2 Q. N2 J& {) v) @8 J# b
reach_point = true; break
1 ~" r; M; C3 ?5 o% _
elsif sheet[right_x, point_y] == path_step &&
7 E7 H6 \6 c$ w
$game_map.passable(right_x, point_y, 4) &&
, Q# J% x0 ~5 _( }
$game_map.passable(point_x, point_y, 6)
3 t% F" ~* \# l {
chase_path.push(4)
" @1 Q8 V: z( Q* l) M
chase_point = [point_x, point_y]
# ?( a& c0 `! E- f) h
reversed_chase_point = [right_x, point_y]
5 |0 ]; c8 V: S5 X
reach_point = true; break
4 f( M8 a. M" R$ M4 ~. r
elsif sheet[point_x, up_y] == path_step &&
I9 X% {8 Y7 z# c
$game_map.passable(point_x, up_y, 2) &&
0 b9 \! M+ e" q% q
$game_map.passable(point_x, point_y, 8)
9 E3 [: ~/ m. i, e2 Z( Z3 }
chase_path.push(2)
" S: \/ m/ n. N
chase_point = [point_x, point_y]
: h' Y {6 `. O; b/ C @2 x! J0 w
reversed_chase_point = [point_x, up_y]
# B2 h# H0 {8 ]) o9 L5 [
reach_point = true; break
: r* m. X8 G9 e6 J9 d# U# P
elsif sheet[point_x, down_y] == path_step &&
. A$ Y4 Z( H; r2 r1 |( q8 b! c% k
$game_map.passable(point_x, down_y, 8) &&
. I$ t: t A+ I) [: |% m6 f
$game_map.passable(point_x, point_y, 2)
# H, o' e% J* P" L, L' l9 K, u
chase_path.push(8)
$ ]* c+ U3 V5 r0 L- _: I) U
chase_point = [point_x, point_y]
9 [8 @1 C% R! N5 A3 {, G
reversed_chase_point = [point_x, down_y]
% h+ x8 R$ K) L8 f1 W
reach_point = true; break
1 H% B' |" R! O5 F4 ?8 T3 j% b% P+ ~
end
6 Z5 G) @( f; c0 ]; F
# 以需要抵达该点的步数填充路径表格 #
: ~3 g4 V5 z5 j m- l6 H+ j% m
if sheet[left_x, point_y] == 0 &&
+ g# S' l$ F3 C+ F5 G
$game_map.passable(left_x, point_y, 6) &&
6 K- `) |8 K% {; o
!collide_with_events(left_x, point_y) &&
5 h: ~3 l% X2 i
$game_map.passable(point_x, point_y, 4) &&
# v1 k! A8 \! B6 o% `& D
!collide_with_vehicles(left_x, point_y) #judge_end
/ _7 A9 y7 b$ U% I0 J) n: J: n
sheet[left_x, point_y] = step
6 l! L& O4 a/ A) s0 p& l7 L
draw_path = true
4 b# a9 X5 I$ t+ V
new_end_points.push(left_x, point_y)
1 }3 O N: I# O. C, { b3 h
end
+ P# S1 @( j1 v* a. }
if sheet[right_x, point_y] == 0 &&
1 p9 G/ F2 @; b2 C* H, @% ]
$game_map.passable(right_x, point_y, 4) &&
- x5 l7 A: a5 M5 [3 C
!collide_with_events(right_x, point_y) &&
1 m. _) ?9 v/ j- [- |0 Q
$game_map.passable(point_x, point_y, 6) &&
6 ~) r4 `: ]% N4 V
!collide_with_vehicles(right_x, point_y)#judge_end
# Y; y9 o, |8 i# J8 L
sheet[right_x, point_y] = step
# t# L" |; [5 g9 b5 h) V
draw_path = true
( w) D. P4 |, g# _* Q2 }4 O
new_end_points.push(right_x, point_y)
5 w0 `$ p% a! O9 D. s+ g
end
+ D& k9 J5 m' {" o" Q- Y' e9 a& i& {
if sheet[point_x, up_y] == 0 &&
- V0 G/ G& U( j0 _ C
$game_map.passable(point_x, up_y, 2) &&
# k$ c! m1 e; m. V' u. [" y
!collide_with_events(point_x, up_y) &&
r* ?( r7 C7 A* r' ~! C5 j6 Q5 [
$game_map.passable(point_x, point_y, 8) &&
8 H: ]$ Q# @$ k" V* ?
!collide_with_vehicles(point_x, up_y) #judge_end
% C4 \. F0 ], h# }) q# ]5 B7 l: L% e5 h
sheet[point_x, up_y] = step
6 `9 D" r$ K. }
draw_path = true
% ]6 z: X. a* O% Z% c8 g, p; K
new_end_points.push(point_x, up_y)
" `+ ~. t/ X- b3 J; v# ^& I3 ]6 K
end
2 _7 f7 b" B; S6 O# V4 C' y
if sheet[point_x, down_y] == 0 &&
- _3 e5 F" E/ g) D( G; p$ _1 E
$game_map.passable(point_x, down_y, 8) &&
- I7 W" s1 u: J% t. g" B# _
!collide_with_events(point_x, down_y) &&
5 m/ I; ?& D$ I' l1 q6 g; H# q
$game_map.passable(point_x, point_y, 2) &&
6 t# I, x+ v, V
!collide_with_vehicles(point_x, down_y) #judge_end
" M& i9 \ G- U: p
sheet[point_x, down_y] = step
2 s F4 t1 I+ q4 v0 b
draw_path = true
$ @7 q5 z( o8 C
new_end_points.push(point_x, down_y)
0 R' a# D! ?- v1 }2 q
end
+ O) O- B" U# z/ b+ O
end#endOfLoop3
2 ^/ ^5 C6 O4 @ X
break if !draw_path reach_point
9 X# X5 }' [/ {
step += 1
) `/ X) R* W6 u# _
end #endOfLoop1 路径表格填充完毕
9 k3 z2 P, [) |9 \" S
$mouse_move_sign.transparent = false
, f! O/ ]4 i: ^- c" E& {
# 判断指定地点能否抵达
m# j5 J6 v8 P. y/ [; T6 l# F
if reach_point
" Y. p. I/ f5 P+ W
$mouse_move_sign.direction = 2
- Z2 [# \1 ~2 Q# ]2 ]" S
else
5 a' q* H7 H( Y
not_reach_point
; _# @8 I! {3 P; ?3 h* {5 ?
return
& Q/ y q) A8 j2 Z6 w/ L
end
$ g+ }5 I/ |0 w' M
# 根据路径表格绘制最短移动路径(反向)
) y* v, c9 b2 T6 g
steps = step 2 2 + 1
/ G! ?0 K3 U1 E
loop_times = step 2
# C8 |5 V5 S6 g$ l
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
2 t4 S, ]# b H0 i
for i in 1..loop_times # forLoop
5 P$ n7 a6 G; c8 D/ `1 N8 l
steps -= 2
9 l0 |, e) i* O- `# E$ C
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs #反过来?蛋疼了……
* y- ]( ^ u! O1 k8 o; B
if sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
; N, j8 v. v; D8 t I
$game_map.passable($game_map.round_x(point_x - 1), point_y, 6) &&
2 @" J p3 ^3 E8 `; G4 W
$game_map.passable(point_x, point_y, 4) #judge_end
2 _" M/ G0 Q0 N! E E( i! q8 K
reversed_chase_path.push(6)
% F% n) |: U' t1 v5 O/ w8 V l
point_x = $game_map.round_x(point_x - 1)
7 v7 S4 }9 N) p* K! @4 a
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
9 H$ W( r6 s9 Q/ G
$game_map.passable($game_map.round_x(point_x + 1), point_y, 4) &&
3 r7 h, ]' T- k# Y3 l
$game_map.passable(point_x, point_y, 6) #judge_end
5 ^/ V% x) P" D
reversed_chase_path.push(4)
( E" }! F5 X' t+ f
point_x = $game_map.round_x(point_x + 1)
" N( v) j, N; y
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
0 d+ Z4 }2 E7 A& O7 X
$game_map.passable(point_x, $game_map.round_y(point_y + 1), 8) &&
. [ F) ~( p( L) z9 j
$game_map.passable(point_x, point_y, 2) #judge_end
9 C: L# _2 h; r! Z' V4 {1 T
reversed_chase_path.push(8)
' W4 M- P( x& f3 X
point_y = $game_map.round_y(point_y + 1)
[2 I* I$ V. ~2 u9 x# t
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
J! Q( O; I- O
$game_map.passable(point_x, $game_map.round_y(point_y - 1), 2) &&
w0 F' R+ t. S7 P6 P) q
$game_map.passable(point_x, point_y, 8) #judge_end
+ w. z9 Q# S' k% c
reversed_chase_path.push(2)
2 m3 t7 V6 m' y9 T
point_y = $game_map.round_y(point_y - 1)
% |2 ]6 s% n; u& y' a4 q
end
9 B! V' `; D" H" C
else
# W! }, `" }/ N1 F
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
1 [6 V+ r4 ?7 o# ]2 b5 k8 B
$game_map.passable(point_x, $game_map.round_y(point_y + 1), 8) &&
5 k) f* p4 b5 h/ a& ~ D! y6 |
$game_map.passable(point_x, point_y, 2) #judge_end
9 }9 P. b8 \. K5 \; D
reversed_chase_path.push(8)
2 a% N( M* g; m
point_y = $game_map.round_y(point_y + 1)
7 e u0 t2 E! E, K
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
6 B& t+ U+ W* {; F" M9 Q& k. `
$game_map.passable(point_x, $game_map.round_y(point_y - 1), 2) &&
H+ O( ^! V! N! k0 Q
$game_map.passable(point_x, point_y, 8) #judge_end
^! Q1 m* ?; K1 `& J; r
reversed_chase_path.push(2)
* ^9 X8 c. f8 T) ~
point_y = $game_map.round_y(point_y - 1)
; I1 z. x, e$ \' v' y- p! N
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
, S. P) X, c k# a# M9 y
$game_map.passable($game_map.round_x(point_x - 1), point_y, 6) &&
+ U+ `8 \9 S3 o$ J( I* u+ y
$game_map.passable(point_x, point_y, 4) #judge_end
9 P, V- l+ N3 M- h1 b3 |- {
reversed_chase_path.push(6)
- ^! H( ^' w& R+ O( m" J
point_x = $game_map.round_x(point_x - 1)
. `( ?) O2 e1 A# L0 d: t
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
: t% }, J; d$ q- X& l( }* t* A
$game_map.passable($game_map.round_x(point_x + 1), point_y, 4) &&
: u0 h6 g0 {2 ~1 S( c0 j& b) G4 j
$game_map.passable(point_x, point_y, 6) #judge_end
S4 v" @) [3 K0 b" v
reversed_chase_path.push(4)
& [5 H, C" U# e/ c
point_x = $game_map.round_x(point_x + 1)
6 y) }; d- y5 Q+ q! ? A
end
! x) _/ Z" |/ l1 }
end
, k) Y& A' ~/ d# S$ S
end #endOfForLoop
- w) @. V, p3 N( E
# 根据路径表格绘制最短移动路径(正向)
; K: r2 q. Y* N. ?* c
steps = step 2 2
# @6 V6 m' Z4 b5 W% {5 {7 S
loop_times = step 2
r n" a( ~6 D1 k
point_x, point_y = chase_point[0], chase_point[1]
; K& i. r" c ?" k
for i in 2..loop_times # forLoop
# N9 r8 L8 d$ R
steps -= 2
, ?. Z. I3 {2 E4 U* Q
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
7 `2 b+ U# x' u- c
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
) S& n& a# c: S3 z& c: H
$game_map.passable(point_x, $game_map.round_y(point_y + 1), 8) &&
7 I" }9 s1 Y9 V6 I' @! T' N' A
$game_map.passable(point_x, point_y, 2) #judge_end
6 N% k! l4 Q n' O! L
chase_path.push(2)
. E: @5 }/ K( a$ m" l; A
point_y = $game_map.round_y(point_y + 1)
8 G1 r, Z$ {3 D4 e( p( G6 [
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
- U2 N& u3 \" P% m/ O/ N
$game_map.passable(point_x, $game_map.round_y(point_y - 1), 2) &&
/ p0 D; S& A- q
$game_map.passable(point_x, point_y, 8) #judge_end
" i/ n" C6 }( Q$ M$ v8 u
chase_path.push(8)
& S) t% m1 n4 ]8 T( _5 X
point_y = $game_map.round_y(point_y - 1)
5 L5 a) c, Y* g K
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
' x) z% A, h* m* o! C2 o. F
$game_map.passable($game_map.round_x(point_x - 1), point_y, 6) &&
( i7 K' @! v8 [1 ^; |% n
$game_map.passable(point_x, point_y, 4) #judge_end
3 v6 m1 h3 Z( h" Y0 C6 j( {7 M
chase_path.push(4)
" i5 e3 b4 q) u$ O( Z( o6 _0 \
point_x = $game_map.round_x(point_x - 1)
8 N- i% a0 A) v+ u7 ?" y+ ]
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
8 [( @. H/ s; k- R/ Q/ r: {, y
$game_map.passable($game_map.round_x(point_x + 1), point_y, 4) &&
+ g+ D0 S/ C" Q* h
$game_map.passable(point_x, point_y, 6) #judge_end
/ f5 P) e8 D9 D0 l2 A5 q/ x# V7 _
chase_path.push(6)
$ `3 v B: n( d5 Q0 q% ]
point_x = $game_map.round_x(point_x + 1)
: C( d0 n3 `9 y
end
5 `9 y+ a( ^; J* Q- [3 ]3 D6 f
else
( ^8 u7 }$ {3 L& ]" l& @+ Q2 d
if sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
* z1 u$ ^% `; B; Z
$game_map.passable($game_map.round_x(point_x - 1), point_y, 6) &&
% z; R# f- r V3 E0 |5 S& @; u
$game_map.passable(point_x, point_y, 4) #judge_end
2 E7 c; y8 H) N; {. Z
chase_path.push(4)
* ?2 `7 U* F5 D8 Y
point_x = $game_map.round_x(point_x - 1)
& c6 J/ k4 b% q+ @5 t4 G! l
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
* X8 w$ {3 z' f- O8 j9 E
$game_map.passable($game_map.round_x(point_x + 1), point_y, 4) &&
, I- ^* N$ ?3 } b4 N# Y
$game_map.passable(point_x, point_y, 6) #judge_end
0 y1 O' Y$ p" ~! Q* c9 ?
chase_path.push(6)
/ d; @ i4 n0 z5 D) q
point_x = $game_map.round_x(point_x + 1)
* G5 r" r1 ~' y2 G3 ~" }1 q& A
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
c( w1 ]& O/ t
$game_map.passable(point_x, $game_map.round_y(point_y + 1), 8) &&
$ X, e% ~& W5 v# p
$game_map.passable(point_x, point_y, 2) #judge_end
) E+ \- H6 \4 K8 ^; _( s! ?7 g
chase_path.push(2)
$ r1 p" t$ I4 g; t1 i6 U9 T
point_y = $game_map.round_y(point_y + 1)
* P% X6 p2 |6 Q- U% Z$ V9 Y
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
- u1 p; Q8 c+ W" ?
$game_map.passable(point_x, $game_map.round_y(point_y - 1), 2) &&
: M: R% k! ~2 ]; w) [; I2 @* Y7 x
$game_map.passable(point_x, point_y, 8) #judge_end
[- t3 w3 W2 N9 c* \5 e
chase_path.push(8)
5 r& ^1 D5 V; ], J* ^6 N' l
point_y = $game_map.round_y(point_y - 1)
1 _. p- R% g" N% }& F
end
2 K/ a; C. ?0 G1 |% S6 V+ N* H
end
5 O1 [. j2 G( _2 p
end #endOfForLoop
: E% Q0 O8 U6 W7 a: w2 t
@mouse_move_path = reversed_chase_path.reverse + chase_path
9 k; ]( |' \3 h% D. a$ y8 F
end#walk
* [) A$ @; `! `# D, p# I
#--------------------------------------------------------------------------
$ K# c `6 S# O
# ● 绘制boat的移动路径 @array[move_directions...]
- G5 [$ E- x; U& J) y$ }/ w
#--------------------------------------------------------------------------
: ^# a" s ?' ^: E! r' A/ R
def draw_boat_path
1 f% X2 g- s- ^, t
# 准备绘制路径表格
6 `# {; J2 W. s
sheet = Table.new($game_map.width, $game_map.height)
* v$ L, n6 z9 y* J( V2 c
reversed_chase_path = []; chase_path = []
- y. t4 w& w8 T' s' k
reversed_chase_point = []; chase_point = []
( t0 r) `& H. N% B
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
% y9 A0 @, K6 J2 h! M d" q- t; I/ I
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
% a9 y6 V# u7 k/ x* M8 H& w
reach_point = false
) P! s; h5 G+ \& ?7 ?
step = 3
! r: U1 Y b- u6 O2 ]6 z; W
loop do #loop1 开始填充表格
/ a1 M, ~( P0 x) j) f0 n
draw_path = false
2 z. I2 G) R3 e7 u1 H3 ]; w
check_points = new_start_points
5 w# ?: v0 t6 w* q3 V2 t
new_start_points = []
- h. ~) t; C K; G/ b
loop do #loop2 从起点开始正向填充
: P0 ~2 Q- B, U& s
point_x = check_points.shift
z, Y5 }5 h( z! s! u6 [6 m9 d% L
break if point_x == nil
. [( n: Z% F; @% o" N% E; n
point_y = check_points.shift
8 x" _/ K5 A# x- G p* C0 G% T
left_x = $game_map.round_x(point_x - 1)
: ~9 ] \7 d5 N6 `' b
right_x = $game_map.round_x(point_x + 1)
3 y' v: l( p4 g, c" i1 O0 Y. W
up_y = $game_map.round_y(point_y - 1)
. L5 q# r: d6 C, m3 w
down_y = $game_map.round_y(point_y + 1)
' B) T3 k, V4 p
# 判断路径是否连通
! z$ w5 i0 ]2 c) I4 y) T8 d
path_step = step - 1
' Q0 b% l# w" B% K
if sheet[left_x, point_y] == path_step
" w' }4 @/ D$ ?3 \& [2 m
chase_path.push(4)
4 o7 V/ e# Y9 y; r( ^
chase_point = [left_x, point_y]
) p7 C- q' l$ @
reversed_chase_point = [point_x, point_y]
- I; d; m# k1 B& v) H# \% P( `
reach_point = true; break
0 x5 k6 P7 G" y, B: L q
elsif sheet[right_x, point_y] == path_step
$ s( U3 y( M i f* L6 v2 N
chase_path.push(6)
0 l) v+ b' k- b
chase_point = [right_x, point_y]
, L: _) x x, H/ M, Q8 T
reversed_chase_point = [point_x, point_y]
2 ?6 q8 A. A( B9 }" d
reach_point = true; break
7 _" T _1 ~& H( L$ W9 |1 y
elsif sheet[point_x, up_y] == path_step
/ c3 Q# O* |8 e0 @5 G, o! T
chase_path.push(8)
7 L" F5 ^5 A2 ?* m$ b5 v8 m9 a: [. \
chase_point = [point_x, up_y]
) t" M' s; E8 b2 l/ ~7 ?
reversed_chase_point = [point_x, point_y]
- r& B! H$ U4 n
reach_point = true; break
, D! v! F d5 K8 F t. A
elsif sheet[point_x, down_y] == path_step
' B5 o1 b3 }& o% O/ {
chase_path.push(2)
$ D/ s4 S+ G. L8 V3 j" s8 y: }
chase_point = [point_x, down_y]
, o/ w! D6 ~8 d
reversed_chase_point = [point_x, point_y]
; Z, u; W) h- m2 u x8 z& q
reach_point = true; break
4 |5 b3 N8 m+ m: Z; }
end
- \# @4 L8 v1 t4 d$ h' I% ^1 M
# 以需要抵达该点的步数填充路径表格 #
/ U* n" p( W( ^4 n T: |( J) ~% ^
if sheet[left_x, point_y] == 0 &&
; @" Z3 i2 C% C: h
$game_map.boat_passable(left_x, point_y) &&
6 l+ N: v7 B8 c
!collide_with_events(left_x, point_y) &&
! t; u! S: d) V; [; O. x. @; X4 y( w
!collide_with_vehicles(left_x, point_y) #judge_end
" e( U9 N& x; o. O" u% N) `
sheet[left_x, point_y] = step
[0 F$ `- w H5 _: z
draw_path = true
% P, \$ A( i% ]0 w- p
new_start_points.push(left_x, point_y)
! e1 @0 r# ?* K8 ], C
end
, b V7 p. K2 R) X% N [6 u
if sheet[right_x, point_y] == 0 &&
& n5 J' a2 B' W# H
$game_map.boat_passable(right_x, point_y) &&
* `4 @$ O9 |. H' G
!collide_with_events(right_x, point_y) &&
: E! t2 v( ]8 ^7 q t9 ^
!collide_with_vehicles(right_x, point_y) #judge_end
( F: [ U o% B+ [- a. z' ]
sheet[right_x, point_y] = step
, z# |1 H3 z* I O8 G" o
draw_path = true
& A! ^) r( D/ C7 c2 J. Y/ S Y4 D- I
new_start_points.push(right_x, point_y)
$ C) F1 i8 `4 m3 K
end
1 [5 f5 S& H2 J; W; m
if sheet[point_x, up_y] == 0 &&
+ T8 q& a; I) R( V
$game_map.boat_passable(point_x, up_y) &&
! l9 E, m& i( t- L" t% B& m
!collide_with_events(point_x, up_y) &&
. R) ~! U6 C/ X, q8 x- z
!collide_with_vehicles(point_x, up_y) #judge_end
. V) s, L3 T- q$ T, b
sheet[point_x, up_y] = step
' X, r' U5 @$ n/ l
draw_path = true
/ { j; r. _1 h" i/ N
new_start_points.push(point_x, up_y)
6 Q' }6 }, Z& P' T
end
+ g- L% ]% p; f# x
if sheet[point_x, down_y] == 0 &&
, Z$ }% _: `! s! S* {2 D% [
$game_map.boat_passable(point_x, down_y) &&
) z" R. X5 p: T, @# g
!collide_with_events(point_x, down_y) &&
* S0 ~4 l$ ]: X% C& ?
!collide_with_vehicles(point_x, down_y) #judge_end
, p, Q7 J6 {! {$ P6 D
sheet[point_x, down_y] = step
) g! B+ T9 k4 a* {
draw_path = true
H& f/ b$ }2 I% }
new_start_points.push(point_x, down_y)
$ P, g L& k- @# h! x% M! J Z1 ~
end
( |" P8 Q3 n4 R3 v" l* j- a
end#endOfLoop2
: i6 V$ P3 F& K3 S* I f: _
break if !draw_path reach_point
2 d) X2 H1 n0 W$ e |0 K! u
draw_path = false
. k9 |+ J5 R/ n7 a0 f7 x6 p7 y, l0 l
check_points = new_end_points
' C7 c6 z. v; b
new_end_points = []
; z4 J2 z" m& l
step += 1
. y* E$ [- N, V
break if step KsOfSionBreak_Steps &&
7 g0 \/ M* H. I, u1 e5 f
!Input.press(KsOfSionFind_Path_Key)
3 \2 {$ C( y0 ^
loop do #loop3 从终点开始反向填充
$ A! c$ v5 w7 R8 Y
point_x = check_points.shift
* T9 d4 _$ T( b& p* L* Z2 |) `
break if point_x == nil
) R+ x2 w6 P3 ~; V
point_y = check_points.shift
" N1 X3 V" T7 C8 g8 Q9 ?+ s
left_x = $game_map.round_x(point_x - 1)
" i6 W/ S* j) }0 R
right_x = $game_map.round_x(point_x + 1)
% L/ w7 H+ T7 w. O
up_y = $game_map.round_y(point_y - 1)
2 z, W( a( O+ R3 a
down_y = $game_map.round_y(point_y + 1)
$ A# O! o' K5 Z" [4 N5 c
# 判断路径是否连通
/ _7 r) D8 I# f- C8 s: E$ E
path_step = step - 1
' q) P2 {0 d" C6 P# w, {; z# ?( k- z% A
if sheet[left_x, point_y] == path_step
4 e& r. J$ |; m$ Y [7 I
chase_path.push(6)
! {. f! a1 q4 }& j# H
chase_point = [point_x, point_y]
( f4 ~0 W# }5 i& U! p7 p8 T
reversed_chase_point = [left_x, point_y]
; u; {% b+ [" \2 J/ P" d7 A& P
reach_point = true; break
: N/ {" e, V( V- R* a, O$ j
elsif sheet[right_x, point_y] == path_step
5 t+ M/ S" R+ U0 @8 y4 O
chase_path.push(4)
6 Z# S0 v/ P; {$ C& i
chase_point = [point_x, point_y]
! _& J1 k; j( ~* y, ], U
reversed_chase_point = [right_x, point_y]
, O* S5 ?9 ~! O v8 P, p8 v
reach_point = true; break
! ~( l+ l* n% [8 M% d
elsif sheet[point_x, up_y] == path_step
/ o, ?; ~) ^) O {6 l
chase_path.push(2)
2 Z: S* F4 R1 p; O4 p* ~5 d
chase_point = [point_x, point_y]
3 B; @* x2 a1 L {; u$ ]
reversed_chase_point = [point_x, up_y]
% |7 b/ Q% C1 F8 n
reach_point = true; break
' E; T+ `$ S) h9 h+ v
elsif sheet[point_x, down_y] == path_step
5 f9 ^& N/ H9 G% ?# _* E
chase_path.push(8)
, c' `; o! u+ [
chase_point = [point_x, point_y]
0 T V3 b# i7 `: w' a
reversed_chase_point = [point_x, down_y]
; @% \6 H# H0 N+ |* G
reach_point = true; break
/ r! J( I- D. f" G5 i
end
, d+ t6 C" f2 J4 Q* A
# 以需要抵达该点的步数填充路径表格 #
) z& p9 L) h) j; f+ y
if sheet[left_x, point_y] == 0 &&
' b% m( P3 v0 z& [( O& I
$game_map.boat_passable(left_x, point_y) &&
4 I: R; q! ?8 V! }( s3 T6 S
!collide_with_events(left_x, point_y) &&
7 L1 `5 q8 c/ b7 r$ q& g* L2 b; g
!collide_with_vehicles(left_x, point_y) #judge_end
1 P9 V/ _6 V6 F8 \) O0 W9 ?
sheet[left_x, point_y] = step
3 k e; s. t* Q# h5 m4 |: q- ]1 w
draw_path = true
+ R* ~1 D6 |+ j$ Y8 `: J, w
new_end_points.push(left_x, point_y)
: ?7 k8 Q" @ \ g3 z3 k" i4 Z
end
( P/ P4 r; T4 s
if sheet[right_x, point_y] == 0 &&
; z7 P; T* Y& m7 w, c$ ]
$game_map.boat_passable(right_x, point_y) &&
0 x- @& \* B. C" F Y, Q
!collide_with_events(right_x, point_y) &&
' Q0 [$ b x* B. ~- H
!collide_with_vehicles(right_x, point_y) #judge_end
$ N# j. G1 ]) S; [7 e
sheet[right_x, point_y] = step
+ c, f' Y3 S5 D8 T- Q' w9 K9 @3 F
draw_path = true
, B+ A" s G3 S2 m( l
new_end_points.push(right_x, point_y)
6 B1 |- \; ?8 U# m) T: W7 R
end
" H/ {, t$ {9 n, T& D+ O& w
if sheet[point_x, up_y] == 0 &&
3 e8 }2 s k/ `
$game_map.boat_passable(point_x, up_y) &&
- F2 X! N. y* O+ E
!collide_with_events(point_x, up_y) &&
2 T/ S6 {6 K, } J8 }
!collide_with_vehicles(point_x, up_y) #judge_end
) u& a9 U4 j( V" y& W5 h4 `4 i
sheet[point_x, up_y] = step
5 Q _# A. o) `: [4 ?, {2 k" x
draw_path = true
, ?9 O0 J% N1 v4 Q9 f+ b
new_end_points.push(point_x, up_y)
, m; V$ V! r7 d
end
+ S- `5 {0 d. y/ K2 I/ o- O& V
if sheet[point_x, down_y] == 0 &&
6 w2 G' }" s. G7 n) d
$game_map.boat_passable(point_x, down_y) &&
$ v6 B% q" n9 H5 K1 v1 s
!collide_with_events(point_x, down_y) &&
! ]! s- W( W7 s
!collide_with_vehicles(point_x, down_y) #judge_end
* n% P4 q$ m, h- w2 A+ e
sheet[point_x, down_y] = step
3 |2 c& q! u2 t* v4 V
draw_path = true
+ H& n1 G% X( {1 I% u3 F9 {$ A5 _: P9 O
new_end_points.push(point_x, down_y)
$ m0 ~# Y. o1 ]8 \1 H! F3 C
end
\3 v1 m' K* f. Z1 X
end#endOfLoop3
1 M7 k% i7 G: z
break if !draw_path reach_point
' h. P9 K. ?* ^4 B; z
step += 1
* B0 i8 y! Q a, [% I$ s
end #endOfLoop1 路径表格填充完毕
0 f% a: ]- C# S6 z4 J; c+ I
$mouse_move_sign.transparent = false
! D2 Y" \, J2 ?* }0 @( r8 t; b
# 判断指定地点能否抵达
2 B5 U# ~7 T* ]" g
if reach_point
; {. H- S* R* ]4 Q
$mouse_move_sign.direction = 2
i: H9 o! E% S$ i, g- i7 D7 B) [
else
! E( S; ^7 w! i; e& g' V
not_reach_point
) s {/ Q2 r6 G" I& B. k" j
return
/ _, A' Q! Q& |- r7 v! x& ^
end
4 A; A# F# ^$ x! R2 ?6 _
# 根据路径表格绘制最短移动路径(正向)
9 ~- Z2 Y. d' J. E- A* C& G. P L& C" S
steps = step 2 2
- z5 u0 M1 r% o
loop_times = step 2
) ] ?& H" I0 u; ]( E+ K, }* D0 H
point_x, point_y = chase_point[0], chase_point[1]
2 U. N) m5 I% ]8 A$ a
for i in 2..loop_times # forLoop
9 {# v( R% W1 f( r
steps -= 2
/ m) _ l( ]& q2 E, ?
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
; Q: \; F& E3 w: c5 Z, O% n" Z
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
' b( L, S, K. o& M9 {' N9 i( g
chase_path.push(2)
3 o8 ^( o. N5 v e
point_y = $game_map.round_y(point_y + 1)
! |+ [' E; y$ `3 g
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
6 Z/ }) `5 }4 J6 B; T% H F
chase_path.push(8)
" |6 A7 K+ g! \, W$ J
point_y = $game_map.round_y(point_y - 1)
0 n" ]4 s7 i9 p; b& ]5 h( i* u
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
3 K9 E+ G0 M" R) W& F
chase_path.push(4)
; ^4 m$ ?8 d* G! E& I) Z. i
point_x = $game_map.round_x(point_x - 1)
5 ^; z% Z+ o& \* [% q4 [
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
1 p1 T q9 x# s9 Z& h
chase_path.push(6)
/ K& k) M+ s% i k& Y- P
point_x = $game_map.round_x(point_x + 1)
1 ]& y$ i+ F- X
end
; j0 O1 W1 |6 w, f, T! T; t) P
else
; S, n2 T% P- x/ C
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
" n7 `; x0 j. ?& p ]6 D0 x7 e
chase_path.push(4)
8 \) T4 C$ J) U- C" b) ?& r
point_x = $game_map.round_x(point_x - 1)
& n/ t* j9 [- p+ ]% K
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
- U: B$ X9 a5 ^0 U
chase_path.push(6)
0 }5 M V% p- y
point_x = $game_map.round_x(point_x + 1)
) _4 Z5 A6 P0 W" F3 _
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
7 u+ p6 C3 _3 n! h4 E$ N
chase_path.push(2)
; G# c' T5 A; h; V& u8 c
point_y = $game_map.round_y(point_y + 1)
( E' J1 k$ ?8 O( W
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
& L2 p+ S# X5 v7 G+ a
chase_path.push(8)
; N0 a8 Q: h/ ~7 m5 M s6 D$ T: o$ p
point_y = $game_map.round_y(point_y - 1)
1 g7 ?6 P+ z- m
end
/ {- Y3 i4 v2 i6 [
end
; B6 \& v- w7 m$ g( _
end #endOfForLoop
4 F$ }8 K7 E( ?0 }
# 如果指定点无法抵达或者登陆
- I$ j0 v4 Z) g3 D0 w
return not_reach_point unless landable(@moveto_x, @moveto_y, chase_path)
+ w& X- {3 Q% ?/ j0 y! H" I4 U
# 根据路径表格绘制最短移动路径(反向)
+ |( z/ K7 H" O6 t3 Q& z6 D
steps = step 2 2 + 1
" P9 C- F7 x; A! ? y$ d
loop_times = step 2
7 v2 D5 R r9 m" [4 Q5 `: ~
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
2 W6 C, y% \+ F/ M
for i in 1..loop_times # forLoop
) I0 `: _9 o1 M# H0 g
steps -= 2
) d% M% B5 b; V4 b0 x- d& [ O& F
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
; g2 o9 S5 S4 E* c
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
. G( [, ?* W+ w- e7 D; h* {6 X0 C4 D
reversed_chase_path.push(6)
4 E- j7 d2 x2 G! s0 _
point_x = $game_map.round_x(point_x - 1)
+ ~& B! }4 B- Q" m# z
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
; `" y( s# _4 Q" K& f5 s' ^! j
reversed_chase_path.push(4)
8 e2 G$ }* F0 m: ~. ]7 \2 y
point_x = $game_map.round_x(point_x + 1)
) _9 b% W' j, E$ S& K; O) c( x# H6 h
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
$ T v! D9 R% w% O5 @
reversed_chase_path.push(8)
6 |9 I8 x4 u4 z: u2 T* `9 B
point_y = $game_map.round_y(point_y + 1)
7 m, ?1 B8 W- Y4 j- s, O6 k6 o
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
1 r% f5 A! v A0 h
reversed_chase_path.push(2)
6 G; b6 w( Q+ c/ Q0 z2 k
point_y = $game_map.round_y(point_y - 1)
Y. m' k' X8 }1 i8 S) j% k' E5 n
end
% t- f5 r8 ]# l; q
else
5 j4 s9 x9 h( N$ F. r
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
& I$ W: m& ^% G" ?. g$ \
reversed_chase_path.push(8)
) d( D* H B& E# o
point_y = $game_map.round_y(point_y + 1)
" s* a6 H; B4 p$ x$ W2 H
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
/ b) C& j" f3 A4 ?4 A
reversed_chase_path.push(2)
( g/ x0 l0 n% X4 J$ V7 U+ W/ d
point_y = $game_map.round_y(point_y - 1)
7 r7 i3 | l" C, ?
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
, I4 M$ Z2 R+ L& m- ?; w
reversed_chase_path.push(6)
5 y: U* D) L* {
point_x = $game_map.round_x(point_x - 1)
+ }; S. r/ g8 R+ A/ r4 |% `2 |
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
2 h- S1 c. Z) s n& r
reversed_chase_path.push(4)
% ?' m" z1 x+ K' X
point_x = $game_map.round_x(point_x + 1)
" X" g, B% Q2 v' m7 M
end
! W. G) ` q" f2 q' w5 z& F* q
end
3 x2 c; @! c) D& g
end #endOfForLoop
' R; q6 n0 C8 c7 p5 O
@mouse_move_path = reversed_chase_path.reverse + chase_path
2 ^0 Y& C Q; ]( K5 N
end#boat
- s- |: _* x7 f$ A( v
#--------------------------------------------------------------------------
: @8 p# H, `2 p9 b/ l; B
# ● 绘制ship的移动路径 @array[move_directions...]
$ ?2 t* n" J% g2 I$ x
#--------------------------------------------------------------------------
: m, T0 D* ~$ k0 d- N+ `5 Y
def draw_ship_path
7 G' W6 C. s/ P6 z% p5 m% T, S
# 准备绘制路径表格
' F. n- J# j3 Y9 o/ \- p! J) F Q
sheet = Table.new($game_map.width, $game_map.height)
6 m( a2 y& [- j" N9 U
reversed_chase_path = []; chase_path = []
3 }$ o6 L! O* k8 W2 A# G
reversed_chase_point = []; chase_point = []
# `7 U9 Y& a9 m: Y
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
/ C' e5 I! m% a7 u. k$ i* T8 Q
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
3 {4 c9 T% z r r8 R1 \5 E6 d
reach_point = false
Q0 j" N+ O4 I0 a- I( I$ `
step = 3
( M' I8 G7 B. ~) f* \
loop do #loop1 开始填充表格
t+ C. _1 b2 V/ P- C: j
draw_path = false
6 i$ @. [4 _- D7 m0 P+ D
check_points = new_start_points
# }; ]- N% m8 Y* f6 n; G
new_start_points = []
9 F" E1 T, \2 b0 K, n# F
loop do #loop2 从起点开始正向填充
8 e# ^" o, k! w: r2 R4 R* v4 M
point_x = check_points.shift
6 w4 o7 ~1 L! h$ A Y
break if point_x == nil
4 J0 V! L+ E9 E6 J' v) |
point_y = check_points.shift
' @4 c$ o6 Z8 M" a7 \8 u7 F8 d
left_x = $game_map.round_x(point_x - 1)
* {5 R( S7 ~; M* F2 `6 c* p U
right_x = $game_map.round_x(point_x + 1)
8 R) }/ y" B7 g* U1 z+ e
up_y = $game_map.round_y(point_y - 1)
; G1 }1 t, J+ P) x: }
down_y = $game_map.round_y(point_y + 1)
, a( M+ B ~8 l/ z% m2 }( [
# 判断路径是否连通
6 f, i8 e' ? H' h! Y. z2 |$ i
path_step = step - 1
0 s* `* E! x3 i& k
if sheet[left_x, point_y] == path_step
0 E2 ?& u2 }6 w8 o7 ]
chase_path.push(4)
! Y- \1 ~; J2 i6 S. M/ g
chase_point = [left_x, point_y]
' ]1 V- L% |: {( b0 i0 Y' _
reversed_chase_point = [point_x, point_y]
# e% f# Y, V; R& P, h# C2 s) M n
reach_point = true; break
9 Z: T6 P( ^; U! x
elsif sheet[right_x, point_y] == path_step
& V' ~" {4 ]! w0 f
chase_path.push(6)
: \- S6 ^- H# `3 s0 ]8 C% Y" j
chase_point = [right_x, point_y]
, A/ q# [1 V4 P c# N
reversed_chase_point = [point_x, point_y]
8 X* B* z! E! P; k
reach_point = true; break
) y/ p# d# K3 m) f
elsif sheet[point_x, up_y] == path_step
) L$ v4 x% M$ ~9 m9 X5 C8 v$ T
chase_path.push(8)
! W% Q7 J! X* F0 ^
chase_point = [point_x, up_y]
" Y( b8 V/ J2 B
reversed_chase_point = [point_x, point_y]
9 O: c6 ?6 b4 Q' Z: ^
reach_point = true; break
! L" C% Z5 |1 ~, @
elsif sheet[point_x, down_y] == path_step
3 _ k5 t0 }3 z
chase_path.push(2)
: A L( P" \3 D+ e
chase_point = [point_x, down_y]
# M: b5 F/ K& M! G
reversed_chase_point = [point_x, point_y]
( c. b! D9 V0 I" _
reach_point = true; break
+ C2 n8 S8 {: [) J0 b C
end
8 @ t$ A& i2 [$ @" l) Y
# 以需要抵达该点的步数填充路径表格 #
* P$ n5 v# I! C' a9 q' s! V
if sheet[left_x, point_y] == 0 &&
, c ?. k/ G/ @* U1 \$ E
$game_map.ship_passable(left_x, point_y) &&
$ G* ~4 k3 w- t5 g; u/ A
!collide_with_events(left_x, point_y) &&
& ^: Q( d# J( e6 J
!collide_with_vehicles(left_x, point_y) #judge_end
' r( W8 p6 V4 l, d* a7 p
sheet[left_x, point_y] = step
B0 l9 q* B% ?' X
draw_path = true
' n. j* W1 o4 P: {
new_start_points.push(left_x, point_y)
6 w+ o3 Y1 K) O# T$ i; p5 S* }6 S
end
! w0 c( k7 x& ?, _7 N9 a( |: {4 M
if sheet[right_x, point_y] == 0 &&
) \4 p8 T( X1 q/ g8 |
$game_map.ship_passable(right_x, point_y) &&
+ r5 {3 Q- J0 B f, ]- y7 D" U; X
!collide_with_events(right_x, point_y) &&
4 u6 A- _$ \- u% ^2 p3 a
!collide_with_vehicles(right_x, point_y) #judge_end
5 z- P7 b+ D$ i, X l
sheet[right_x, point_y] = step
, i3 s% m- W$ C9 o7 i: B& \
draw_path = true
' u- f# r2 I) I0 O+ K6 B1 N
new_start_points.push(right_x, point_y)
& U7 f2 w( N5 S' j& K
end
8 m! X* b3 z3 F% k. X3 @/ D7 |
if sheet[point_x, up_y] == 0 &&
$ D% a: I( s# e
$game_map.ship_passable(point_x, up_y) &&
# V& a0 g0 X5 O% A9 t5 B" e
!collide_with_events(point_x, up_y) &&
9 Z7 a/ J2 f+ Q# E* U( `( R
!collide_with_vehicles(point_x, up_y) #judge_end
2 h9 p: T5 }( d% I/ ^+ V
sheet[point_x, up_y] = step
) @% l; S" I8 s' l
draw_path = true
+ _ z" K. |! V5 ~7 u; K. u" h
new_start_points.push(point_x, up_y)
9 j7 @, `1 S( p: l4 m
end
/ R5 \. N. Z" U7 h# R: C# A
if sheet[point_x, down_y] == 0 &&
$ u/ k- {! b& U+ Q2 q# R9 ], A
$game_map.ship_passable(point_x, down_y) &&
# ]- y$ n9 D2 |7 _' @
!collide_with_events(point_x, down_y) &&
' j, S, o3 v0 I7 w" C' v7 P
!collide_with_vehicles(point_x, down_y) #judge_end
: g' W7 y" y% v
sheet[point_x, down_y] = step
- z7 Y1 |' ?. n6 c" U9 T/ K# g' w
draw_path = true
9 P: ?: V; z0 k. x0 `
new_start_points.push(point_x, down_y)
( H- y( H, t: S' c3 z6 ^
end
' [' w9 }% T" I8 M) H5 T* {, T: z
end#endOfLoop2
; Y4 ?( \3 _7 N" z Z
break if !draw_path reach_point
3 z6 A/ @) x, R+ \! {" ?
draw_path = false
1 y, {2 ~/ h, d. G, K
check_points = new_end_points
" v4 a+ T# \/ ]8 {1 L- g
new_end_points = []
; t! l/ {: u" U3 T8 A- F+ R
step += 1
4 T8 w0 a5 T, ?$ u( M: y, o* f) I
break if step KsOfSionBreak_Steps &&
/ H) l% X5 C9 \' Q# B, Y) Z9 ^
!Input.press(KsOfSionFind_Path_Key)
& U% B8 Y( y5 S5 I6 ^. e( p( ]
loop do #loop3 从终点开始反向填充
$ u. d; N9 ?; V% ]3 O
point_x = check_points.shift
0 f' |/ ?3 U7 u8 W
break if point_x == nil
% S: \. I/ ~! I# J% q' ^
point_y = check_points.shift
7 V3 y( U$ @! ]1 I6 S
left_x = $game_map.round_x(point_x - 1)
9 ~: `7 E8 C( |: G* N
right_x = $game_map.round_x(point_x + 1)
9 `0 A) ]2 e1 H b8 v$ J/ {
up_y = $game_map.round_y(point_y - 1)
B- Y3 B: u+ V& c5 F5 I
down_y = $game_map.round_y(point_y + 1)
, A4 I* W. D9 i8 L4 a
# 判断路径是否连通
) F. |( w; a! h' h" g$ }4 F
path_step = step - 1
0 T. C) u& m; B& _" G+ \
if sheet[left_x, point_y] == path_step
: J1 S$ b7 v/ l; l/ D' v' [
chase_path.push(6)
2 x9 R% b$ _5 S( b9 f% x0 N# O& Q% Y
chase_point = [point_x, point_y]
: U% A5 I. G" J9 @( [- B% i
reversed_chase_point = [left_x, point_y]
/ C( d& R/ U# b0 h; G3 o" W
reach_point = true; break
9 |3 o$ L1 @$ Y- n$ y( N2 q
elsif sheet[right_x, point_y] == path_step
: [! \" l+ X- z: E5 ?8 l& C4 [
chase_path.push(4)
) t* ?5 _ r/ l. I
chase_point = [point_x, point_y]
% N6 K, \& D, E, O0 L
reversed_chase_point = [right_x, point_y]
2 ~, p0 }6 o7 {1 Z& F7 x
reach_point = true; break
( o1 b6 _& r1 L# z' y6 \* `
elsif sheet[point_x, up_y] == path_step
2 O! Z2 {3 G0 x4 v% E
chase_path.push(2)
+ y* Y. C+ ]4 R' a+ X* U+ L$ L+ y
chase_point = [point_x, point_y]
7 \. C5 G0 G" K+ j
reversed_chase_point = [point_x, up_y]
5 h* P' H T3 \+ W* \3 w9 F/ j' c
reach_point = true; break
) I) |) u6 i' e1 Q" W4 T) K
elsif sheet[point_x, down_y] == path_step
$ q7 S" a, D4 x# C
chase_path.push(8)
/ ?) \: I9 H; Y
chase_point = [point_x, point_y]
0 b; g( Z+ P2 Z
reversed_chase_point = [point_x, down_y]
- A e0 w8 n6 {% S
reach_point = true; break
: Y) r9 R' D+ b8 Q" e- Z( i
end
! `. f; E; u/ u0 z( F! O
# 以需要抵达该点的步数填充路径表格 #
8 w6 q) J& r+ d7 y$ I) n6 n
if sheet[left_x, point_y] == 0 &&
1 w) ]# J' U% M9 T# K: |# o4 Y
$game_map.ship_passable(left_x, point_y) &&
8 F1 Y) ^% H/ X+ L! _: x* s, `* ?8 ]
!collide_with_events(left_x, point_y) &&
+ X; O2 u! X( ]! I5 ?9 ]. M
!collide_with_vehicles(left_x, point_y) #judge_end
8 W, i1 L y$ ]/ g2 k# c4 X1 F. L& F
sheet[left_x, point_y] = step
7 t" z. n( i. V5 m. ^+ O
draw_path = true
h( E" a' h/ {. E! w. t
new_end_points.push(left_x, point_y)
# B/ f3 y! I9 s; z
end
3 U/ q% {6 Y! I1 X; A5 U" ^
if sheet[right_x, point_y] == 0 &&
2 s, ^; M9 ?: p" V8 i6 Y! m
$game_map.ship_passable(right_x, point_y) &&
) [" w/ \8 C4 g% r- t
!collide_with_events(right_x, point_y) &&
& y0 y4 ~3 n' {7 D4 T
!collide_with_vehicles(right_x, point_y) #judge_end
$ ]; I4 C4 v, E
sheet[right_x, point_y] = step
4 I; J- D7 D# ?. @% d
draw_path = true
: g3 C0 H- G, u% `% Z$ I R
new_end_points.push(right_x, point_y)
0 t n) I3 j6 X8 F# _' S
end
4 G: j0 d0 h8 u- B
if sheet[point_x, up_y] == 0 &&
, ^% z3 \5 L6 c: w8 F, z! U
$game_map.ship_passable(point_x, up_y) &&
4 ~ L' E9 e1 C- l" m" Z/ }- o; A
!collide_with_events(point_x, up_y) &&
! f: y1 K6 E4 K2 V3 I5 S7 D% h1 W
!collide_with_vehicles(point_x, up_y) #judge_end
1 j& o8 L9 @* [6 ~7 g
sheet[point_x, up_y] = step
+ N* e+ g9 i" L0 A8 W% _, c' r* S+ n
draw_path = true
' ?' O6 A \, B+ b/ f D
new_end_points.push(point_x, up_y)
3 K+ A& o1 R, T% c& R
end
) Q y2 j1 Z; H7 l4 T2 w
if sheet[point_x, down_y] == 0 &&
8 ]* w; R9 S( }8 z4 k
$game_map.ship_passable(point_x, down_y) &&
$ C M& m% T3 q8 \! t3 s$ z
!collide_with_events(point_x, down_y) &&
& Q2 r+ |5 w) s" b& [8 Z8 s* i. F
!collide_with_vehicles(point_x, down_y) #judge_end
% ?- a' }1 s8 U8 Y0 C4 @
sheet[point_x, down_y] = step
7 Z4 {5 j* u& O8 y. _; E
draw_path = true
) t6 w, W/ F. g( L8 W0 [
new_end_points.push(point_x, down_y)
+ {: g2 N- N3 A7 O+ k! c
end
' z+ B5 o5 U5 K# Q* e3 Y9 n
end#endOfLoop3
4 \( m( S' X4 s# ^0 q
break if !draw_path reach_point
. r4 V+ Z4 ?8 |: q7 O. F7 I. A% K
step += 1
, a3 ]0 q6 i2 j5 n) u
end #endOfLoop1 路径表格填充完毕
B! G+ G+ D3 [/ x. E/ t" _
$mouse_move_sign.transparent = false
8 r: f7 ?. X& ^$ f( U9 [
# 判断指定地点能否抵达
" @' L' U! S" g' f4 G Y
if reach_point
( _3 e/ C0 T' R
$mouse_move_sign.direction = 2
9 \- Q" t" {7 o. O/ T/ Q
else
' u/ w: t% Z4 n
not_reach_point
8 s$ U" i5 }. {
return
: |1 K* m. O9 W# n8 {2 U
end
4 k, y" z A1 v* d
# 根据路径表格绘制最短移动路径(正向)
4 K! M; O$ X0 J6 G
steps = step 2 2
' O1 u0 ?% e$ \' m, a+ O c$ B* z( t
loop_times = step 2
; i, S% H: l' A* e! ?+ \9 Q
point_x, point_y = chase_point[0], chase_point[1]
* R, ~, A5 O& w
for i in 2..loop_times # forLoop
" }- H, }: S5 L) Q
steps -= 2
! f7 N# @7 S7 U3 C
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
3 [. V# J# k! k2 {& U) Z
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
( _6 b5 w$ W: [' G
chase_path.push(2)
5 B0 D2 L: l/ q; P, ?
point_y = $game_map.round_y(point_y + 1)
& o" i2 C$ t: Z" }, g1 G, w9 `
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
/ N# j. y5 ]4 U: p8 R8 j5 k$ Y
chase_path.push(8)
9 x' |3 p9 F% `: ]& U' x
point_y = $game_map.round_y(point_y - 1)
5 x, Z7 f! q5 E7 B3 `" f8 }" j2 s
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
- ~/ X u4 n1 D1 t& H4 t, e# ~8 Y, J
chase_path.push(4)
% M9 I0 T3 x1 d, |- h% }
point_x = $game_map.round_x(point_x - 1)
8 ^9 ^: n8 O4 i( A0 M, I. e
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
6 D" v/ v1 e; w. q* e( ^5 ~3 H/ i
chase_path.push(6)
7 H6 |$ ^ Y7 o' _. o, A5 L7 X+ w
point_x = $game_map.round_x(point_x + 1)
" W9 S. j1 p F: A# u
end
" @& h6 A" I" N! L' q, B* {
else
1 c5 `, }& q) V" ~/ z( s7 l6 J5 @
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
7 k9 ]7 F. J; {7 o( q1 D
chase_path.push(4)
% Q$ b; l, Y4 ]: A
point_x = $game_map.round_x(point_x - 1)
8 t( e' E# |. V! {
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
2 H3 s6 N% [5 U, u
chase_path.push(6)
, Z7 `1 O t% I" I+ Q# `+ G U% n
point_x = $game_map.round_x(point_x + 1)
! I& ]9 D& O1 a+ e$ B; p, u
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
" x( @+ g# G, L2 Y# C+ x: C& q
chase_path.push(2)
@7 [4 x; v6 X [, }
point_y = $game_map.round_y(point_y + 1)
0 F, b5 }! }* d: a5 `
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
! D4 `) [" I6 [7 v. _& M
chase_path.push(8)
3 U' O$ w) y, ^9 \
point_y = $game_map.round_y(point_y - 1)
; A2 Z, E# ^' N5 J4 I2 H
end
' `$ g) k6 l2 G! X/ d! j% s
end
% A7 o6 W4 d0 n# {
end #endOfForLoop
# N' d/ C6 P* [9 B* M8 D
# 如果指定点无法抵达或者登陆
+ a% F( }$ q* o% ]/ w9 h
return not_reach_point unless landable(@moveto_x, @moveto_y, chase_path)
: J+ }9 A; J8 g, V: R. F/ |( c
# 根据路径表格绘制最短移动路径(反向)
2 T0 Q( w. J: L% r
steps = step 2 2 + 1
8 _8 r( G \7 V6 X2 m: V
loop_times = step 2
# d$ G) q2 |" K$ ?' `4 t8 d; |
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
: e% ? C1 u& o9 j2 r; W2 z
for i in 1..loop_times # forLoop
9 i; B ?: X( T. J. Q, c
steps -= 2
/ j: k$ T1 X* j8 r# _
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
" r; \1 t/ D/ x5 V% m
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
% \0 N& q9 D* j/ n
reversed_chase_path.push(6)
, G! w. e7 _$ `7 _' `
point_x = $game_map.round_x(point_x - 1)
1 C. ]0 ? T! J( r- L# p
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
1 J+ w" r7 O( T ]
reversed_chase_path.push(4)
# M- p$ E' h( F
point_x = $game_map.round_x(point_x + 1)
- N0 l" A" s& u9 } ~
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
$ C/ U- v3 U3 d) X& h
reversed_chase_path.push(8)
/ f' G6 M! d: a+ s: F T8 j
point_y = $game_map.round_y(point_y + 1)
) r) x3 F7 t4 z( n4 c6 K+ q! ]1 A+ G
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
9 w1 h4 @+ W' c9 v/ b
reversed_chase_path.push(2)
- Q; y8 I7 N, Z6 v- b6 x
point_y = $game_map.round_y(point_y - 1)
8 W* T8 L& O& |, Y' Z
end
1 ~) h) P5 C- u: m. Q! _0 N. S
else
2 c# L& {1 M' N0 V A3 M" d
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
5 K8 I" S6 y: u; Z4 U+ V7 a4 O0 _
reversed_chase_path.push(8)
2 n$ j/ K( U/ `! K! M9 _
point_y = $game_map.round_y(point_y + 1)
8 g* w1 \; o( x0 {
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
0 q; B2 C1 y+ R
reversed_chase_path.push(2)
4 R4 G3 }% v& X5 e4 L
point_y = $game_map.round_y(point_y - 1)
6 A! k- v* P& b; i
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
4 g; v1 }0 R& M0 F7 H
reversed_chase_path.push(6)
5 d7 J7 g/ t: |7 q
point_x = $game_map.round_x(point_x - 1)
+ P ?# E: X- N1 l; u# N( j% m9 q y
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
: c% n) S" P( |0 H) ^
reversed_chase_path.push(4)
8 t8 ?, n# h8 r V, [9 G- ^
point_x = $game_map.round_x(point_x + 1)
: ?0 i" g' U) K4 [
end
9 c5 C) e1 U0 o6 j/ S R4 j
end
5 O8 s$ j2 w8 d( A3 n N" X
end #endOfForLoop
) p% D: I9 w% o) @( U, r# E
@mouse_move_path = reversed_chase_path.reverse + chase_path
" X8 [! i$ v1 f8 Q) G
end#ship
6 k- F% o3 g4 {
#--------------------------------------------------------------------------
5 }2 \; b" _; l, |) M
# ● 绘制airship的移动路径 @array[move_directions...]
9 b" D! X' o, [9 n$ E
#--------------------------------------------------------------------------
0 t& s# V/ x' f, [% } }- Z
def draw_air_path
; U: [3 q a9 @1 Q
$mouse_move_sign.transparent = false
- w R. G# i7 ?2 {' ~1 k! I
# 准备绘制路径表格
" k( U% T$ k7 q) e6 O" Z6 L0 m
sheet = Table.new($game_map.width, $game_map.height)
& P. k& Z q/ T6 A! I% ?7 ^/ \
new_check_point = [x, y]; sheet[x, y] = 1
$ N$ T: F6 a- w: e
reach_point = false; step = 2
7 J, z" h7 [% v4 r6 h) K$ S, k
loop do #loop1
& Q0 X( d' q3 s% O# L
check_point = new_check_point
8 @7 V% Y) \) x1 z! N3 q
new_check_point = []
7 T' j" i! E5 v: H& ^5 |' l- s
loop do #loop2
5 u" N+ c# t/ c9 s9 S7 F
point_x = check_point.shift
% e: t; p/ T/ r2 X* Y, b; K5 v, u
break if point_x == nil
! w, b4 G% t8 |4 r6 c d' k
point_y = check_point.shift
7 i: P T( e# _7 U8 x
if point_x == @moveto_x && point_y == @moveto_y
8 L) W* c/ ^, a( @# h+ o' K, K) \8 }
reach_point = true; break
' i5 u% F# O; l. q, _( E! d4 e4 Y! [
end
! T# D0 `5 r8 [% x; O" q, @" M8 a
left_x = $game_map.round_x(point_x - 1)
2 |/ b( O5 ~0 S- }4 q9 ~9 U0 f/ p
right_x = $game_map.round_x(point_x + 1)
7 r" f; V( U% L3 \) K; d
up_y = $game_map.round_y(point_y - 1)
3 u, @/ d% M; N* S
down_y = $game_map.round_y(point_y + 1)
; j/ D' Y+ T+ B* l3 f1 O
# 以需要抵达该点的步数填充路径表格 #
; v! l; K3 v& d2 V3 G" k. X" u
if sheet[left_x, point_y] == 0
' `! g- s/ F# j* B/ m( k
sheet[left_x, point_y] = step
- d% E8 M2 m9 G7 L8 I
new_check_point.push(left_x, point_y)
' E; ?4 g) \! [; q3 s% O3 f
end
( S. u- K& F0 Q
if sheet[right_x, point_y] == 0
- H. w: A4 w+ E i. V
sheet[right_x, point_y] = step
1 I9 M1 ]3 m$ L& u+ e/ i+ H, ?& g- ^ z
new_check_point.push(right_x, point_y)
" \/ c$ @4 N0 }) V% U
end
" T" |) W4 R! }; h
if sheet[point_x, up_y] == 0
4 o, @+ Q9 a# R2 C$ ~
sheet[point_x, up_y] = step
, ? ]" {( N) O) J3 }/ l
new_check_point.push(point_x, up_y)
0 D3 N2 d6 z: C
end
+ c4 {% s, N( I+ e+ P* j
if sheet[point_x, down_y] == 0
7 T: e" } o. f6 X% p
sheet[point_x, down_y] = step
K2 E U1 u) Q- i" C8 E
new_check_point.push(point_x, down_y)
$ [5 ]6 o4 x. ^% ~; ]/ v( q b
end
% n, H) `* S2 }6 O t* c1 A: B
end#endOfLoop2
& o9 D1 M, H( _4 V3 G
break if reach_point
; m& T; A1 e0 F# T L( q
step += 1
6 C" f$ y0 q4 R! g! b& R
end #endOfLoop1
: s- c" D. [5 r" b) Y) l6 g
# 根据路径表格绘制最短移动路径 #
) B# k4 q$ w0 p2 e# J+ ]
reversed_chase_path = []; step -= 1
! [6 h3 K) ?% j+ V: W
point_x, point_y = @moveto_x, @moveto_y
9 F" G1 l3 P! M, ?
for i in 2..step
( J# o, j* Q+ I. p' Q
step -= 1
9 N# M5 \* m9 u* z% `
if (@moveto_x - point_x).abs (@moveto_y - point_y).abs
! f) @6 X. B- t& T
if sheet[$game_map.round_x(point_x - 1), point_y] == step
/ `3 F% K8 e1 k H1 T5 l* |
reversed_chase_path.push(6)
9 U7 \4 i8 U1 D7 h2 E
point_x = $game_map.round_x(point_x - 1)
" b( [" I) R4 s8 z
elsif sheet[$game_map.round_x(point_x + 1), point_y] == step
! B5 q% o, \! l+ e' T* T- A
reversed_chase_path.push(4)
" G- `6 X p/ E# w3 d4 L' X
point_x = $game_map.round_x(point_x + 1)
# X) l- \* ^/ P6 o% C2 x8 ^
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == step
& @, w6 b( t$ n: R" B
reversed_chase_path.push(8)
" t: d7 O: z( c7 s- ?+ N
point_y = $game_map.round_y(point_y + 1)
! V; p5 B' P' q( C8 Y% ` M
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step
8 Q$ ?) F: i# l' B9 ]1 B/ t; E
reversed_chase_path.push(2)
+ ~8 i* z* H# K g
point_y = $game_map.round_y(point_y - 1)
# c. f. S/ Q' B: q8 ]! {
end
% s0 v) |" B0 d2 U6 I/ n. x
else
0 ?$ p+ T9 z+ @- a% ?% x5 p
if sheet[point_x, $game_map.round_y(point_y + 1)] == step
" x1 l/ C& i9 Q4 q0 F9 B
reversed_chase_path.push(8)
! w" f* _" ?8 w' n; m7 n" h+ p
point_y = $game_map.round_y(point_y + 1)
5 f5 v. j# w7 C" |/ w: b
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step
- a$ ^1 Y9 E" u
reversed_chase_path.push(2)
, O1 r, j9 H. u( J, W
point_y = $game_map.round_y(point_y - 1)
* Q Q0 K0 w1 G9 c7 p$ {# T
elsif sheet[$game_map.round_x(point_x - 1), point_y] == step
, b5 |9 @9 e" E( E+ A, v
reversed_chase_path.push(6)
! W8 l9 w- P: b6 c& K+ T
point_x = $game_map.round_x(point_x - 1)
: ~9 Y @6 T6 \, \. v5 z
elsif sheet[$game_map.round_x(point_x + 1), point_y] == step
6 ~ N6 f" K5 D% V
reversed_chase_path.push(4)
: S! B& Z# H2 a5 v, f
point_x = $game_map.round_x(point_x + 1)
1 q4 a7 j- Y) e# Y
end
$ T8 {5 t# ?3 r* m
end
1 p% d. q$ A0 \$ n" Z% ?/ W" @
end #endOfForLoop
' F5 @* v5 e% n0 N9 {" Q" C
@mouse_move_path = reversed_chase_path.reverse
8 M: Y9 ~3 l5 s, w
end#airship
7 P: k$ f8 ^* g$ c1 t% Y3 b" N
#--------------------------------------------------------------------------
! Q* k. _' k. S: e3 [3 g6 @
# ● 目标点无法抵达时的处理,用于各路径绘制方法内部
9 V8 A. A' W% j1 j$ d8 y* r- K
#--------------------------------------------------------------------------
) o1 x u' B5 y8 R9 A( _
def not_reach_point
- f" u, o! R1 n% _: X
$mouse_move_sign.direction = 4
k% c( l8 ?- a- U3 f. |
dx = 0; dy = 0; dir = 0
7 J2 Y4 j0 {! _7 `/ j1 \( x
if @moveto_x - x 0
: P* S; {( u/ B
if @moveto_x - x $game_map.width - @moveto_x + x &&
1 @0 Y9 b% F0 j+ ?, p8 a' n
$game_map.loop_vertical
4 T3 Z% k- l, o$ W" P$ i
dx = $game_map.width - @moveto_x + x; dir = 4
! X& x* W5 m6 U0 l8 i- H/ @. }
else
: W: U8 y' ?" ~! G4 \
dx = @moveto_x - x; dir = 6
$ ~3 ?0 u& h# W" x5 O8 _# t% J2 M! _
end
) r+ x/ W8 c- `6 b5 O) Q
else
" X- t# o) Q u3 L0 S
if x - @moveto_x $game_map.width - x + @moveto_x &&
, Z- z9 N7 B/ u
$game_map.loop_vertical
9 L) b% {. `, `6 H$ `2 ~1 s% d
dx = $game_map.width - x + @moveto_x; dir = 6
6 [8 m# h1 v6 i# |* `9 E
else
$ d' ]* f! m) Y& {
dx = x - @moveto_x; dir = 4
% `( I4 [) x8 d% Z
end
1 ]( F7 V$ @+ g* z0 z: ] v9 P
end
0 W6 v3 B1 {8 v. f
if @moveto_y - y 0
1 k: R% ^9 r9 n& S/ r: l/ z, S
if @moveto_y - y $game_map.height - @moveto_y + y &&
. ^9 l1 ?& f% J" G8 [' k! j
$game_map.loop_horizontal
; ?$ E- A+ H! W# ]
dy = $game_map.height - @moveto_y + y
2 X/ s4 |- B8 I8 W/ ~5 t9 y. g# j
dir = 8 if dy dx
% s" f% H' P# \. q
else
" s+ A& M' b2 V4 W
dy = @moveto_y - y
* g9 K0 }* `8 q0 n4 y0 C
dir = 2 if dy dx
8 M- O/ ?: `9 k
end
6 T" ~( L) a$ g9 P( g \
else
: A+ s! f* ], F/ O- ]. D
if y - @moveto_y $game_map.height - y + @moveto_y &&
& S r8 M! v6 A2 n% c8 `+ A
$game_map.loop_horizontal
6 X$ G8 _( d% J# I) C- V, C
dy = $game_map.height - y + @moveto_y
7 Q& |* A1 I( g2 u( s4 s
dir = 2 if dy dx
; Z: E( ^% Q9 Z/ M2 j: C
else
" m6 u5 {4 |4 v; k2 K. G
dy = y - @moveto_y
$ j! J$ E" r7 Y! B) m" M
dir = 8 if dy dx
- b" ^' U" J) A* s
end
8 m# ^. N* h' D. D# k, S7 g
end
* ^, S/ s* P# p% U, A% l
@mouse_move_path = [dir, 0] # 0方向用于防止移动过程中触发事件
: x/ I) U$ N9 W! f8 ~8 e$ ?1 B
end
c, C( K; b* ]: `1 U% h$ e
#--------------------------------------------------------------------------
$ O' w$ h; H3 D8 O0 j% C5 d
# ● 判断目标点是否能抵达、登陆,用于船只路径绘制
# g' B. J' a$ g2 f2 z' U
#--------------------------------------------------------------------------
8 L" V) a" D! o3 U! i) b
def landable(x, y, path)
3 W3 |/ { E3 D+ c4 m+ V
case @vehicle_type
+ S3 Q6 ^; m6 D+ T" ~( R
when ship; return $game_map.ship_passable(x, y)
( x) C7 o0 O# l) p0 _1 U0 F4 T8 E
$game_map.passable(x, y, 10 - path[-1])
: E+ t6 K6 j* i1 a
when boat; return $game_map.boat_passable(x, y)
* `* z, @' W: u5 ?7 `9 |8 G7 }* Q
$game_map.passable(x, y, 10 - path[-1])
/ ]' a8 s* [4 m) O' h* l' @+ c8 _
end
4 B# ~9 i2 X' E7 d# Y
end
8 E0 I- {' L* m7 u: k
end
) Y ~: Y4 O9 z9 ]6 f
+ b; i. L+ o! A b+ d
#==============================================================================
0 s9 [0 h9 J$ R; b4 C6 `# C
# ■ Game_Map
" V5 L" E1 ?- e" n. U
#------------------------------------------------------------------------------
8 `8 V6 r9 [- c. l9 S, R$ e. N
# 管理地图的类。拥有卷动地图以及判断通行度的功能。
6 N$ g# P8 p* n; N0 U2 \
# 本类的实例请参考 $game_map 。
8 y) H( N. L; T. b j
#==============================================================================
Q0 }; i/ ?% W3 l8 `! w; P3 n
class Game_Map
9 w# v K; D, s4 T% ]7 K: a" P2 O
#--------------------------------------------------------------------------
# @* U: m0 p7 P; Y8 V
# ● 定义实例变量
8 E1 \. S% @( P9 k
#--------------------------------------------------------------------------
4 G8 a3 U' C) o8 E
attr_reader mouse_map_x # 使用前需先使用 get_mouse_map_xy 方法来更新数据
( g/ _! z, v2 v& f* o2 O
attr_reader mouse_map_y # 同上
# k* n0 U: A* U+ G7 B
#--------------------------------------------------------------------------
* J9 c6 \( ?: ]" b+ P
# ● 初始化对象
" {. _/ P# Z1 o; T. t7 t
#--------------------------------------------------------------------------
" X8 W$ M) j( \# I
alias sion_mouse_initialize initialize
( v/ F8 I- k5 `' j
def initialize
* k" e B9 D" ` D
sion_mouse_initialize
. z+ i% b7 S7 V. O1 u0 p0 i0 |" S9 N
creat_move_sign ###
1 B' j$ y5 L$ h) D" L- a
set_constants
9 ^0 G% h( M8 h. m
end
$ e, o- ~0 n# \$ m3 W' ]$ {
#--------------------------------------------------------------------------
' z6 G$ X, Q: n/ X3 q4 q8 S) O! F
# ● 更新画面
2 G2 H5 s q0 }5 d
# main 事件解释器更新的标志
! k' Z) E1 S8 y% S z3 W
#--------------------------------------------------------------------------
4 M; x9 s: w1 M: {
alias sion_mouse_update update
: ~+ z- k; t! d
def update(main = false)
O* a9 U) s" r$ C& \* g
sion_mouse_update(main)
7 v( p2 G. z: K0 `3 Y. |+ W& o' `
update_move_sign
# f+ A8 z$ F# t, _0 v( @7 x
end
# z9 h+ g) n8 m# S. e( i0 \: G
#--------------------------------------------------------------------------
V! H+ Y8 V# h) l% M; [. G
# ● 创建显示路径点的事件
& }# v) K% B- d: ]+ B# h" J- C5 `
#--------------------------------------------------------------------------
, Q! a4 b C5 E/ k& W
def creat_move_sign
6 h2 F$ |- ^: B% G% P, Z
$mouse_move_sign = Move_Sign.new
/ F M/ W- W: ~5 G+ Z' O. q
end
7 g P P/ r7 P6 L2 `* I
#--------------------------------------------------------------------------
) D. e3 W5 t% P& Q8 b& m
# ● 更新显示路径点的事件
" Z7 }8 W6 f( o5 F
#--------------------------------------------------------------------------
$ O' D4 I/ g# T; w& ^3 M
def set_constants
4 N! K9 B% ?6 Q1 R
@mouse_pos_setted = true
8 X! h+ _) M y2 ?6 Z# j" G- S5 L' h
@set_pos_prepared = false
! a" A$ B x4 v
@mouse_old_x = 0
) H0 C- y( I/ ^* ~! M) Q
@mouse_old_y = 0
* u6 l9 u# U: M* ], U: Z
end
, B" b3 @) M3 n: \5 I* N
#--------------------------------------------------------------------------
: m, {0 `& g: [- k+ k
# ● 更新显示路径点的事件
; T, }3 q) m( V
#--------------------------------------------------------------------------
& N4 r4 A3 l4 F
def update_move_sign
/ x* b' e/ g9 N8 \% d5 c1 ?+ Z
$mouse_move_sign.update
( U! u! t4 z2 Q9 z4 L
end
% a# r4 m, M: d2 \7 G' w) K/ `3 ~
#--------------------------------------------------------------------------
% a) w3 Y, `7 r! ?8 S! v
# ● 获取鼠标位于的地图块的x、y坐标
|& R" ]! ]: s+ G4 S4 H
#--------------------------------------------------------------------------
- s; b* d/ H$ U4 r7 g
def get_mouse_map_xy
3 V0 _" Y1 B- r( ]: x) b; H4 N
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
1 o' `4 c- J$ A
@mouse_map_x = round_x((@display_x + mouse_x 32.0).to_i)
l1 B8 d! }; z9 o+ z& g
@mouse_map_y = round_y((@display_y + mouse_y 32.0).to_i)
* `$ c/ ]& H( T: H
end
2 \0 X( {1 a; l- v- O7 n+ `( w3 Y P
#--------------------------------------------------------------------------
6 ~1 `. c% c- f& [* U6 Z i# o
# ● 返回地图画面时重设鼠标坐标
) o. v% A! R# j& G0 w
#--------------------------------------------------------------------------
; M1 b9 D( `+ i
def reset_mouse_pos
# y0 x. E: Q+ W! V, F" R4 R/ K1 n
return if @mouse_pos_setted
' W0 u' Q: i& Z7 L7 A2 @8 A
Mouse.set_mouse_pos(@mouse_old_x, @mouse_old_y)
9 l- `( b6 J" g& Y, t
@mouse_pos_setted = true
S7 T9 j$ o. c/ w
@set_pos_prepared = false
+ s. Z- o! S+ B. A% C- M% X
end
+ }1 A' w4 s; G& Z
#--------------------------------------------------------------------------
?$ Q$ M% a, }
# ● 重设鼠标的坐标
i% O: ?! U, ?. \7 o( K
#--------------------------------------------------------------------------
' a& [$ h( X- g+ z0 @, l# P
def prepare_reset_mouse_pos
( ^5 U8 {% R6 C3 Z& U
return if @set_pos_prepared
2 c" T, K9 [' V# J0 ^
@mouse_pos_setted = false
2 f) ^! h- ]# m5 d5 v4 e
@mouse_old_x = Mouse.mouse_x
( N7 j+ K: t8 J3 C
@mouse_old_y = Mouse.mouse_y
: Y1 ^1 p. W0 y. [! T( ^. X
@set_pos_prepared = true
# F* I- g/ I& A& c# S( ~ i7 E
end
5 g4 t4 V6 @ W- L6 y% x9 Q1 f, A
end
9 N, b! u; h" [+ K1 B+ _
, q. ^- Z" t: n
#==============================================================================
2 g0 I C5 b; t3 s- A8 e z" k
# ■ Spriteset_Map
$ B) i+ i- W$ }; Q2 f
#------------------------------------------------------------------------------
. N3 G, ~' W7 D2 l+ z1 n$ e: ?
# 处理地图画面精灵和图块的类。本类在 Scene_Map 类的内部使用。
+ E6 _1 d, H' C- y
#==============================================================================
, w2 a% w) W0 |! [8 a5 V2 p
class Spriteset_Map
$ T- P7 }5 @# v5 _+ A/ q
#--------------------------------------------------------------------------
. \7 a' c' e( d V
# ● 生成路径点精灵
8 k! e& i" V: h3 u; c
#--------------------------------------------------------------------------
& ]9 L% [, Q/ {* u4 _) k0 e: R
alias sion_mouse_create_characters create_characters
: Q) y3 `4 [) }! U4 }
def create_characters
$ X$ P+ J9 m: }- C' A7 m
sion_mouse_create_characters
4 p/ M" |( b' c/ K
@character_sprites.push(Sprite_Character.new(@viewport1, $mouse_move_sign))
) p. f' T8 ?4 @1 A5 A X
end
" j6 Q2 y6 U! H% H C% {/ K
end
& F- D5 D; [; {: |1 m
4 x; q1 R7 Y7 l. Z, ~) F6 }* L
#==============================================================================
: K( M" L/ r. |# h- R0 U
# ■ Scene_Map
# D/ Z3 K0 l- J6 ~& \' ~
#------------------------------------------------------------------------------
! U0 ~( F+ R' w3 H& q, g
# 地图画面
: J! i Z; b$ I* u8 g
#==============================================================================
2 O0 Z p1 S' L, T) s+ o+ U
class Scene_Map Scene_Base
! H3 Y8 L% e% Y
#--------------------------------------------------------------------------
. H% B, E# Z$ e O! \( c
# ● 画面更新
9 d# i' ^ D: @
#--------------------------------------------------------------------------
x1 s4 D Q9 U6 M, i. o7 E
alias sion_mouse_update_scene update_scene
! g$ X$ J' P2 t) O
def update_scene
2 z( _7 b7 L6 P h0 Y. e! A
sion_mouse_update_scene
9 c8 V3 a4 A) g- E6 {( h4 l f
update_mouse_action unless scene_changing
0 s1 U$ V. k; W: E& M
end
6 g; q# [0 X7 a5 ^) U$ G# v) d
#--------------------------------------------------------------------------
, O. d, N( M5 x4 p
# ● 场所移动前的处理
* s5 S' I4 d* _( P( J& x" o4 y" C
#--------------------------------------------------------------------------
; @& [4 [. z+ ?3 U
alias sion_mouse_pre_transfer pre_transfer
9 T! x* ~) ] c% R2 N2 g; H# f
def pre_transfer
- d1 X6 c g' N5 \
$game_player.reset_move_path
; K5 z1 G# Z, F0 t1 O7 c0 S( C! T
sion_mouse_pre_transfer
3 `4 y" G9 g9 C0 o; a3 s7 X
end
- q1 n8 Y- y; w6 a; K3 r
#--------------------------------------------------------------------------
) h* _0 i) m1 R& q$ Z9 O
# ● 监听鼠标左键的按下
3 b/ B( s+ S* V m' I, Z' r( f' \- v
#--------------------------------------------------------------------------
9 z- U. |3 Q0 Z5 y0 M! W0 ]
def update_mouse_action
% V; V( D# m2 n7 s6 l/ [1 J5 F: l
$game_player.left_button_action if Mouse.press(0x01)
6 f4 f% y2 a3 b4 C7 B3 E$ x
end
( G W( f+ m- Q6 ^. o x& H
end
J1 b- S' I% _$ Y/ I3 j+ k, H
' q9 x$ N) ~ D1 f2 \, R
#==============================================================================
5 I/ R9 W; a' E7 b
# ■ Scene_File
" d" C( A! p. f" n7 z7 Q6 E
#------------------------------------------------------------------------------
4 B5 L! d: K( @- | g
# 存档画面和读档画面共同的父类
4 p- U/ {* c2 b$ q
#==============================================================================
$ b; ~% d% p8 R# d
class Scene_File Scene_MenuBase
/ Y* |* j7 a6 C
#--------------------------------------------------------------------------
1 d9 V& e& k$ o& ~& K
# ● 开始处理
, Z; T! H+ N2 d/ n+ y% Z
#--------------------------------------------------------------------------
/ Z' v/ {( c3 r* |
alias sion_mouse_start start
! u6 g* H$ r, ?; s. d$ W
def start
4 x @1 P+ b- q+ h1 H" N
sion_mouse_start
: K1 Z+ S1 ~/ Z
@move_state = 0
, O4 n+ C5 @5 A% `6 ?2 n/ I
set_mouse_pos
1 t$ L' p7 _* e& k$ Q
end
3 ~! u2 F+ }, P8 ?$ C
#--------------------------------------------------------------------------
; ~+ ?/ |$ w3 a' }- F* ]5 j
# ● 更新画面
5 F) C% m; {. x6 f" D* J- s5 z
#--------------------------------------------------------------------------
5 y1 A# C. d, X
alias sion_mouse_update update
* |$ M2 v2 z8 y. B: \
def update
) x. y$ K( H. k( z4 r6 s2 q
sion_mouse_update
0 t/ {# X6 j6 a/ S
Input.dir4.zero set_cursor set_mouse_pos
! O& J$ C' N4 ]; Q: ~# F
end
" [9 b3 F0 r: S7 E; c- O
#--------------------------------------------------------------------------
) |" J3 A! U. v; |7 ^- v2 J1 r% O
# ● 更新光标
0 n" p- B4 g1 i- B4 Q
#--------------------------------------------------------------------------
& i d" O$ Y( k# J' l
def set_cursor
, I+ w: g. z+ D8 F& m3 \* d5 p$ P
@move_state += 1
* k" [) y; A* y5 G
last_index = @index
# a) p2 P9 H# T' \4 S
if mouse_which_window == -2
. x# c& I. S/ Q4 v
if (@move_state - 1) % 6 == 0
$ y/ }; H8 W( S7 c# I: I
@index = (@index + 1) % item_max if @index item_max - 1
0 o) x& K3 \+ z, ^8 ?
end
, _' [) I+ O) @4 n
elsif mouse_which_window == -1
, J( N- ]: M: e$ c0 i, C
if (@move_state - 1) % 6 == 0
) `1 m0 k! p/ k* A8 X
@index = (@index - 1 + item_max) % item_max if @index 0
$ i. Z/ j, {: p7 h. W
end
8 R7 {, Y! a) ]8 b8 `0 ]; [
else
4 W. Q( f& o) a
@move_state = 0
( q9 ]' A M9 \8 `. ~
@index = top_index + mouse_which_window
; G& C7 u0 M4 ^! l1 H8 }! ]
end
- e. x4 b6 I( c
ensure_cursor_visible
6 `8 a3 `% q" {. ]
if @index != last_index
/ M6 m8 R& I1 z0 v9 R4 b: A+ n" }& I Z
@savefile_windows[last_index].selected = false
. N3 S4 q8 Y7 e r+ x
@savefile_windows[@index].selected = true
( x8 U L; a& [3 {- f' j
end
) n/ v9 G0 B9 b7 L" i
end
) G1 {$ a5 Z# g
#--------------------------------------------------------------------------
# B# T5 }8 A8 ^* Z$ ]
# ● 判断鼠标位于哪个窗口
k8 h w8 P; O1 B
#--------------------------------------------------------------------------
/ w% W) h7 L. v; Y
def mouse_which_window
7 S8 ]/ |) H7 T
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
+ k9 \) l, a1 a, F/ v: y$ x
if mouse_y @help_window.height + 14
1 ~5 K! v( [4 ^: V
mouse_row = -1
# Q4 t; K( k- R+ _9 S0 u
elsif mouse_y Graphics.height - 14
' p Y9 q+ t# k: Y. F
mouse_row = -2
) f' o' b& m+ l8 {: B# e
else
' t; d' v* e! b, C
mouse_row = 4 (mouse_y - @help_window.height)
2 |- G+ X3 C0 e# u2 \( s9 L
(Graphics.height - @help_window.height)
0 Y I% x8 t5 `1 }, q4 U4 y
end
6 a/ f8 @# t0 i- z" q
return mouse_row
4 n V% e; i/ M7 |( ]
end
6 ?& q* N' @/ H8 @1 | r
#--------------------------------------------------------------------------
* @& e/ O8 l* v% ~$ m8 S6 `4 ]
# ● 方向键移动光标时将鼠标移动到对应的光标位置
1 p+ b% R4 [3 n3 b6 Z5 _
#--------------------------------------------------------------------------
+ `! f' Q6 Q# Y
def set_mouse_pos
4 g) H) ^8 r0 A& ~) g e
new_x = 40
: `& a* |" H3 _
new_y = @help_window.height + savefile_height (@index - top_index) + 24
* r) ~9 a% S: q7 D0 v6 a4 X
Mouse.set_mouse_pos(new_x, new_y)
; h6 l3 ?% I% W; E0 K0 s d* L' I
end
9 q; p( S9 `4 H% y5 h+ i: p( @( \
end
- N) f2 w+ N W7 J" d7 @6 |
% l* K9 q) w9 Q# q% n2 h) V
#==============================================================================
& d& S3 R" G( o8 M
# ■ Game_Event
3 j2 b7 N/ _4 u& f4 x. L
#------------------------------------------------------------------------------
4 n, W) d _; a1 e2 d- @; L
# 处理事件的类。拥有条件判断、事件页的切换、并行处理、执行事件等功能。
7 P6 A% A- p# u2 c* Q" N) L
# 在 Game_Map 类的内部使用。
* G. y3 g8 L! N; T+ N2 j
#==============================================================================
4 v3 @7 W* R, }1 q$ Q3 ^
class Game_Event Game_Character
( m# b- T; @0 ? A
#--------------------------------------------------------------------------
* u% j3 F" Q* v/ d- U/ ~, ?8 D# [8 f
# ● 事件启动
$ v; Y# k" N' V' X, z
#--------------------------------------------------------------------------
2 G- x w0 n. y! q& M+ q* a7 Y
alias sion_mouse_start start
: X/ o) {; G$ m, r
def start
8 G6 X/ C4 M, O' ^! g
return if mouse_start && !Mouse.press(0x01)
) ^6 f2 J! ^3 G! J
sion_mouse_start
) c6 t2 E, h4 J" F- \0 [0 }) W
end
/ {3 [" a& y: Y2 t5 V+ O8 }
#--------------------------------------------------------------------------
9 u9 N- x+ T+ ]- n
# ● 判断事件是否由鼠标启动
% x$ P! e6 _. Y8 r& n; l, J
#--------------------------------------------------------------------------
t0 `* h V% s* b' ?
def mouse_start
( B& [; f7 q; e: B6 m; B# F- n% H
return false if empty
* I) g% l% c# l2 x: t& A6 o D5 s
@list.each do index
- |& q2 a/ v8 @3 w, k$ s
return true if (index.code == 108 index.code == 408) &&
8 l7 `( \" b7 f& a
index.parameters[0].include('鼠标启动')
0 K1 ^& [! Y# } Q6 w
end
& \5 k3 U8 z5 S: M
return false
) m) V: e2 F! C0 B' `5 K3 B% k
end
" l+ t+ W. [- r8 z2 S
end
) y; `% ~; s# V
4 \7 I" ~5 S: l9 ~% j+ H
####泥煤的height
( H8 A* f+ f: r
# @height = height
' ]* i0 X2 z" k5 o8 H4 M& ~" G# v
; l9 e5 h L. r V, a& p( a6 ]6 e7 x
class Area_Response
" ~3 K" K0 [# f1 s. c
attr_accessor type
7 K8 ?' g, ?' i9 e) z6 K, D0 ?
attr_reader ox
- i+ v7 X( v) i ?2 O) o2 A
attr_reader oy
5 n- k1 W! y1 U: e2 U* R
attr_reader width
/ J& ]/ C6 C. {$ H1 V0 H
attr_reader height
% z0 K9 g" I8 J
attr_reader switch_id
0 o7 r ~0 x0 \6 @4 o4 o
def initialize(type, ox, oy, width = 32, height = 32, switch_id = nil)
6 Q$ K+ E9 @* h1 M5 c1 r; a
@type = type
0 f$ |. e7 N! [+ Q8 v4 N
@ox = ox
' U# F( f* X. J
@oy = oy
. P7 O2 l ?4 ~6 H* X, r6 [2 s/ _
@width = width
5 j3 P$ B3 b& C X# n- h- I+ l! k
@height = height
9 t4 u8 _7 j% w Y" m
@switch_id = switch_id
- i1 E* u5 U" B w6 p6 M3 ]- U
end
( F6 s* p% @) K, `" w! l3 W
end
" C, t9 F u# w- A5 ~
3 n) p) k9 a, a
$area_responses = []
6 H5 B, t$ t/ w
$ z2 T0 g4 y8 n" f+ c8 G9 A
class Scene_Map
: H: c: D* V! h$ E |
alias update_mouse_2013421 update_mouse_action
& O; q0 d2 f8 L: N* v
def update_mouse_action
% y5 I: B. T4 b8 }! ]
update_area_response
4 L: w$ n3 Q% `7 n* [. v
update_mouse_2013421
7 q) n6 r+ I* f: Z1 l
end
# u2 G' h$ B2 l: Y
def update_area_response
" h# J2 e6 N* o) o. m6 v
responses = $area_responses
8 S! _+ X9 | I- }" h- S
responses.each {response
# E5 o* @8 `- l( p+ J
ox = response.ox
' c) b4 e! b4 Y# D' m: ~5 Q0 Q3 u
oy = response.oy
C: c) M+ [; ~
width = response.width
) z5 l( S( b# i' s1 |, L
height = response.height
" f9 M- |$ C2 N# H
switch_id = response.switch_id
* r. X9 t) X# {# L: u' p# A
case response.type
) W/ n. F. {( ^$ ^5 t( l7 P
when 0
9 t# O# e l/ u3 u
if mouse_in_area(ox, oy, width, height)
. {% V& X$ f0 v3 o0 M4 s
$game_switches[switch_id] = true
% T4 o7 |5 K3 z
$area_responses.delete(response)
" [# m7 l3 y% Z
end
c; q- Y* @9 p/ i' l( s G' c! S' e
when 1
7 K3 f2 U/ ]0 E, I8 b
if mouse_in_area(ox, oy, width, height) && Mouse.trigger(0x01)
# A' i5 C0 s+ ]; R( L+ @ j! H
$game_switches[switch_id] = true
; [/ z& e, M( \5 f/ b2 O
$area_responses.delete(response)
6 d9 A H+ P) Q3 D$ R/ K
end
6 g9 W* a4 @2 A* b% D0 P
when 2
; j4 @, |- e0 M2 W% N% v1 U: E, x
if mouse_in_area(ox, oy, width, height)
1 v9 y } \* y8 N7 V- R
$game_switches[switch_id] = true
0 M* y9 k8 a2 P
else
8 \9 Z/ r- Y( D6 ?2 v- @! _
$game_switches[switch_id] = false
`3 g& C5 f0 f8 {
end
3 C6 f Q) e. ~
when 3
/ N& s' ]1 \0 K, Z7 h) K7 @
if mouse_in_area((ox - $game_map.display_x) 32 ,
. K) m1 c \7 s* ?1 F' p
(oy - $game_map.display_y) 32, width, height)
9 w; p0 a+ l1 |! p @: D
$game_map.events_xy(ox, oy).each {event
, r+ f5 C* O1 } O! Q
event.start
+ D& H; v# N# J y" c2 ?, h
$area_responses.delete(response)
/ R& J: _* x! A- m
return
" C( P2 Q* r% j; ^" {! F
}
% t/ g0 T) O8 Q; b8 V3 `
end
/ N1 d1 v% [) O3 |+ w
when 4
3 t/ M5 c; }( t+ J
if mouse_in_area((ox - $game_map.display_x) 32,
/ R5 ]0 C, d5 i9 K9 T
(oy - $game_map.display_y) 32, width, height)
4 e: P. [; H# K; `- w4 }
$game_map.events_xy(ox, oy).each {event
3 t- H9 m V5 t
event.start
" l% }1 p: v0 C- d6 P! l$ \5 v
return
) q0 L; l$ T1 O$ H8 y
}
3 W, R6 D( F$ Y& f
end
, s9 S: h8 k* v( Y! y
end
& n& r, ?! ]5 M; c2 _
}
7 T0 n. ?& A/ }* H; L7 g7 D
end
4 J2 _9 h( t+ x* I/ K( n
def mouse_in_area(ox, oy, width, height)
. \% [; W i* }8 l
Mouse.mouse_x = ox && Mouse.mouse_x = ox + width &&
( n& A6 f5 R" ~5 q9 H
Mouse.mouse_y = oy && Mouse.mouse_y = oy + height
' i' J! _1 i ?, Y! \2 Z/ z
end
( d1 d0 y l: f
end
, x4 q5 |1 B( h0 b
class Game_Interpreter
0 C9 ^9 B+ [/ `9 A$ x3 a: y
def area_response(arg)
. i: Z2 h) s9 }
$area_responses.push(Area_Response.new(arg))
; D: ?# H4 _5 o$ l4 r8 L( H
end
, s2 k! S$ N( I3 e" j: W7 W! I
end
- a+ g* U5 N) ~- |- j
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1