1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
| #==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# プレイヤーを扱うクラスです。イベントの起動判定や、マップのスクロールなどの
# 機能を持っています。このクラスのインスタンスは $game_player で参照されます。
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 定数
#--------------------------------------------------------------------------
CENTER_X = (544 / 2 - 16) * 8 # 画面中央の X 座標 * 8
CENTER_Y = (416 / 2 - 16) * 8 # 画面中央の Y 座標 * 8
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :vehicle_type # 現在乗っている乗り物の種類 (-1:なし)
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
super
@vehicle_type = -1
@vehicle_getting_on = false # 乗る動作の途中フラグ
@vehicle_getting_off = false # 降りる動作の途中フラグ
@transferring = false # 場所移動フラグ
@new_map_id = 0 # 移動先 マップ ID
@new_x = 0 # 移動先 X 座標
@new_y = 0 # 移動先 Y 座標
@new_direction = 0 # 移動後の向き
@walking_bgm = nil # 歩行時の BGM 記憶用
end
#--------------------------------------------------------------------------
# ● 停止中判定
#--------------------------------------------------------------------------
def stopping?
return false if @vehicle_getting_on
return false if @vehicle_getting_off
return super
end
#--------------------------------------------------------------------------
# ● 場所移動の予約
# map_id : マップ ID
# x : X 座標
# y : Y 座標
# direction : 移動後の向き
#--------------------------------------------------------------------------
def reserve_transfer(map_id, x, y, direction)
@transferring = true
@new_map_id = map_id
@new_x = x
@new_y = y
@new_direction = direction
end
#--------------------------------------------------------------------------
# ● 場所移動の予約中判定
#--------------------------------------------------------------------------
def transfer?
return @transferring
end
#--------------------------------------------------------------------------
# ● 場所移動の実行
#--------------------------------------------------------------------------
def perform_transfer
return unless @transferring
@transferring = false
set_direction(@new_direction)
if $game_map.map_id != @new_map_id
$game_map.setup(@new_map_id) # 別マップへ移動
end
moveto(@new_x, @new_y)
end
#--------------------------------------------------------------------------
# ● マップ通行可能判定
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def map_passable?(x, y)
case @vehicle_type
when 0 # 小型船
return $game_map.boat_passable?(x, y)
when 1 # 大型船
return $game_map.ship_passable?(x, y)
when 2 # 飛行船
return true
else # 徒歩
return $game_map.passable?(x, y)
end
end
#--------------------------------------------------------------------------
# ● 歩行可能判定
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def can_walk?(x, y)
last_vehicle_type = @vehicle_type # 乗り物タイプを退避
@vehicle_type = -1 # 一時的に徒歩に設定
result = passable?(x, y) # 通行可能判定
@vehicle_type = last_vehicle_type # 乗り物タイプを復元
return result
end
#--------------------------------------------------------------------------
# ● 飛行船の着陸可能判定
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def airship_land_ok?(x, y)
unless $game_map.airship_land_ok?(x, y)
return false # タイルの通行属性が着陸不能
end
unless $game_map.events_xy(x, y).empty?
return false # 何らかのイベントがある地点には着陸しない
end
return true # 着陸可
end
#--------------------------------------------------------------------------
# ● 何らかの乗り物に乗っている状態判定
#--------------------------------------------------------------------------
def in_vehicle?
return @vehicle_type >= 0
end
#--------------------------------------------------------------------------
# ● 飛行船に乗っている状態判定
#--------------------------------------------------------------------------
def in_airship?
return @vehicle_type == 2
end
#--------------------------------------------------------------------------
# ● ダッシュ状態判定
#--------------------------------------------------------------------------
def dash?
return false if @move_route_forcing
return false if $game_map.disable_dash?
return false if in_vehicle?
return Input.press?(Input::A)
end
#--------------------------------------------------------------------------
# ● デバッグすり抜け状態判定
#--------------------------------------------------------------------------
def debug_through?
return false unless $TEST
return Input.press?(Input::CTRL)
end
#--------------------------------------------------------------------------
# ● 画面中央に来るようにマップの表示位置を設定
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def center(x, y)
display_x = x * 256 - CENTER_X # 座標を計算
unless $game_map.loop_horizontal? # 横にループしない?
max_x = ($game_map.width - 17) * 256 # 最大値を計算
display_x = [0, [display_x, max_x].min].max # 座標を修正
end
display_y = y * 256 - CENTER_Y # 座標を計算
unless $game_map.loop_vertical? # 縦にループしない?
max_y = ($game_map.height - 13) * 256 # 最大値を計算
display_y = [0, [display_y, max_y].min].max # 座標を修正
end
$game_map.set_display_pos(display_x, display_y) # 表示位置変更
end
#--------------------------------------------------------------------------
# ● 指定位置に移動
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def moveto(x, y)
super
center(x, y) # センタリング
make_encounter_count # エンカウント初期化
if in_vehicle? # 乗り物に乗っている
vehicle = $game_map.vehicles[@vehicle_type] # 乗り物を取得
vehicle.refresh # リフレッシュ
end
end
#--------------------------------------------------------------------------
# ● 歩数増加
#--------------------------------------------------------------------------
def increase_steps
super
return if @move_route_forcing
return if in_vehicle?
$game_party.increase_steps
$game_party.on_player_walk
end
#--------------------------------------------------------------------------
# ● エンカウント カウント取得
#--------------------------------------------------------------------------
def encounter_count
return @encounter_count
end
#--------------------------------------------------------------------------
# ● エンカウント カウント作成
#--------------------------------------------------------------------------
def make_encounter_count
if $game_map.map_id != 0
n = $game_map.encounter_step
@encounter_count = rand(n) + rand(n) + 1 # サイコロを 2 個振るイメージ
end
end
#--------------------------------------------------------------------------
# ● エリア内判定
# area : エリアデータ (RPG::Area)
#--------------------------------------------------------------------------
def in_area?(area)
return false if area == nil
return false if $game_map.map_id != area.map_id
return false if @x < area.rect.x
return false if @y < area.rect.y
return false if @x >= area.rect.x + area.rect.width
return false if @y >= area.rect.y + area.rect.height
return true
end
#--------------------------------------------------------------------------
# ● エンカウントする敵グループの ID を作成
#--------------------------------------------------------------------------
def make_encounter_troop_id
encounter_list = $game_map.encounter_list.clone
for area in $data_areas.values
encounter_list += area.encounter_list if in_area?(area)
end
if encounter_list.empty?
make_encounter_count
return 0
end
return encounter_list[rand(encounter_list.size)]
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
if $game_party.members.size == 0
@character_name = ""
@character_index = 0
else
actor = $game_party.members[0] # 先頭のアクターを取得
@character_name = actor.character_name
@character_index = actor.character_index
end
end
#--------------------------------------------------------------------------
# ● 同位置のイベント起動判定
# triggers : トリガーの配列
#--------------------------------------------------------------------------
def check_event_trigger_here(triggers)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(@x, @y)
if triggers.include?(event.trigger) and event.priority_type != 1
event.start
result = true if event.starting
end
end
return result
end
#--------------------------------------------------------------------------
# ● 正面のイベント起動判定
# triggers : トリガーの配列
#--------------------------------------------------------------------------
def check_event_trigger_there(triggers)
return false if $game_map.interpreter.running?
result = false
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
if result == false and $game_map.counter?(front_x, front_y)
front_x = $game_map.x_with_direction(front_x, @direction)
front_y = $game_map.y_with_direction(front_y, @direction)
for event in $game_map.events_xy(front_x, front_y)
if triggers.include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
end
return result
end
#--------------------------------------------------------------------------
# ● 接触イベントの起動判定
# x : X 座標
# y : Y 座標
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
return false if $game_map.interpreter.running?
result = false
for event in $game_map.events_xy(x, y)
if [1,2].include?(event.trigger) and event.priority_type == 1
event.start
result = true
end
end
return result
end
#--------------------------------------------------------------------------
# ● 方向ボタン入力による移動処理
#--------------------------------------------------------------------------
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
case Input.dir8
when 1
move_lower_left
when 3
move_lower_right
when 7
move_upper_left
when 9
move_upper_right
end
end
#--------------------------------------------------------------------------
# ● 移動可能判定
#--------------------------------------------------------------------------
def movable?
return false if moving? # 移動中
return false if @move_route_forcing # 移動ルート強制中
return false if @vehicle_getting_on # 乗る動作の途中
return false if @vehicle_getting_off # 降りる動作の途中
return false if $game_message.visible # メッセージ表示中
return false if in_airship? and not $game_map.airship.movable?
return true
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
last_real_x = @real_x
last_real_y = @real_y
last_moving = moving?
move_by_input
super
update_scroll(last_real_x, last_real_y)
update_vehicle
update_nonmoving(last_moving)
end
#--------------------------------------------------------------------------
# ● スクロール処理
#--------------------------------------------------------------------------
def update_scroll(last_real_x, last_real_y)
ax1 = $game_map.adjust_x(last_real_x)
ay1 = $game_map.adjust_y(last_real_y)
ax2 = $game_map.adjust_x(@real_x)
ay2 = $game_map.adjust_y(@real_y)
if ay2 > ay1 and ay2 > CENTER_Y
$game_map.scroll_down(ay2 - ay1)
end
if ax2 < ax1 and ax2 < CENTER_X
$game_map.scroll_left(ax1 - ax2)
end
if ax2 > ax1 and ax2 > CENTER_X
$game_map.scroll_right(ax2 - ax1)
end
if ay2 < ay1 and ay2 < CENTER_Y
$game_map.scroll_up(ay1 - ay2)
end
end
#--------------------------------------------------------------------------
# ● 乗り物の処理
#--------------------------------------------------------------------------
def update_vehicle
return unless in_vehicle?
vehicle = $game_map.vehicles[@vehicle_type]
if @vehicle_getting_on # 乗る途中?
if not moving?
@direction = vehicle.direction # 向きを変更
@move_speed = vehicle.speed # 移動速度を変更
@vehicle_getting_on = false # 乗る動作終了
@transparent = true # 透明化
end
elsif @vehicle_getting_off # 降りる途中?
if not moving? and vehicle.altitude == 0
@vehicle_getting_off = false # 降りる動作終了
@vehicle_type = -1 # 乗り物タイプ消去
@transparent = false # 透明を解除
end
else # 乗り物に乗っている
vehicle.sync_with_player # プレイヤーと同時に動かす
end
end
#--------------------------------------------------------------------------
# ● 移動中でない場合の処理
# last_moving : 直前に移動中だったか
#--------------------------------------------------------------------------
def update_nonmoving(last_moving)
return if $game_map.interpreter.running?
return if moving?
return if check_touch_event if last_moving
if not $game_message.visible and Input.trigger?(Input::C)
return if get_on_off_vehicle
return if check_action_event
end
update_encounter if last_moving
end
#--------------------------------------------------------------------------
# ● エンカウントの更新
#--------------------------------------------------------------------------
def update_encounter
return if $TEST and Input.press?(Input::CTRL) # テストプレイ中?
return if in_vehicle? # 乗り物に乗っている?
if $game_map.bush?(@x, @y) # 茂みなら
@encounter_count -= 2 # カウントを 2 減らす
else # 茂み以外なら
@encounter_count -= 1 # カウントを 1 減らす
end
end
#--------------------------------------------------------------------------
# ● 接触(重なり)によるイベント起動判定
#--------------------------------------------------------------------------
def check_touch_event
return false if in_airship?
return check_event_trigger_here([1,2])
end
#--------------------------------------------------------------------------
# ● 決定ボタンによるイベント起動判定
#--------------------------------------------------------------------------
def check_action_event
return false if in_airship?
return true if check_event_trigger_here([0])
return check_event_trigger_there([0,1,2])
end
#--------------------------------------------------------------------------
# ● 乗り物の乗降
#--------------------------------------------------------------------------
def get_on_off_vehicle
return false unless movable?
if in_vehicle?
return get_off_vehicle
else
return get_on_vehicle
end
end
#--------------------------------------------------------------------------
# ● 乗り物に乗る
# 現在乗り物に乗っていないことが前提。
#--------------------------------------------------------------------------
def get_on_vehicle
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
if $game_map.airship.pos?(@x, @y) # 飛行船と重なっている?
get_on_airship
return true
elsif $game_map.ship.pos?(front_x, front_y) # 正面に大型船がある?
get_on_ship
return true
elsif $game_map.boat.pos?(front_x, front_y) # 正面に小型船がある?
get_on_boat
return true
end
return false
end
#--------------------------------------------------------------------------
# ● 小型船に乗る
#--------------------------------------------------------------------------
def get_on_boat
@vehicle_getting_on = true # 乗り込み中フラグ
@vehicle_type = 0 # 乗り物タイプ設定
force_move_forward # 一歩前進
@walking_bgm = RPG::BGM::last # 歩行時の BGM 記憶
$game_map.boat.get_on # 乗り込み処理
end
#--------------------------------------------------------------------------
# ● 大型船に乗る
#--------------------------------------------------------------------------
def get_on_ship
@vehicle_getting_on = true # 乗る
@vehicle_type = 1 # 乗り物タイプ設定
force_move_forward # 一歩前進
@walking_bgm = RPG::BGM::last # 歩行時の BGM 記憶
$game_map.ship.get_on # 乗り込み処理
end
#--------------------------------------------------------------------------
# ● 飛行船に乗る
#--------------------------------------------------------------------------
def get_on_airship
@vehicle_getting_on = true # 乗る動作の開始
@vehicle_type = 2 # 乗り物タイプ設定
@through = true # すり抜け ON
@walking_bgm = RPG::BGM::last # 歩行時の BGM 記憶
$game_map.airship.get_on # 乗り込み処理
end
#--------------------------------------------------------------------------
# ● 乗り物から降りる
# 現在乗り物に乗っていることが前提。
#--------------------------------------------------------------------------
def get_off_vehicle
if in_airship? # 飛行船
return unless airship_land_ok?(@x, @y) # 着陸できない?
else # 小型船・大型船
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
return unless can_walk?(front_x, front_y) # 接岸できない?
end
$game_map.vehicles[@vehicle_type].get_off # 降りる処理
if in_airship? # 飛行船
@direction = 2 # 下を向く
else # 小型船・大型船
force_move_forward # 一歩前進
@transparent = false # 透明を解除
end
@vehicle_getting_off = true # 降りる動作の開始
@move_speed = 4 # 移動速度を戻す
@through = false # すり抜け OFF
@walking_bgm.play # 歩行時の BGM 復帰
make_encounter_count # エンカウント初期化
end
#--------------------------------------------------------------------------
# ● 強制的に一歩前進
#--------------------------------------------------------------------------
def force_move_forward
@through = true # すり抜け ON
move_forward # 一歩前進
@through = false # すり抜け OFF
end
end |