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