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