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