1+ #==============================================================================
2+ # ** Game_Player
3+ #------------------------------------------------------------------------------
4+ # This class handles the player. Its functions include event starting
5+ # determinants and map scrolling. Refer to "$game_player" for the one
6+ # instance of this class.
7+ #==============================================================================
8+
9+ class Game_Player < Game_Character
10+ JUMP_DISTANCE = 2
11+ JUMP_COOLDOWN_FRAMES = 30
12+ def try_jump
13+ return if @jump_cooldown && @jump_cooldown > 0
14+ dx = ( self . direction == 6 ? 1 : self . direction == 4 ? -1 : 0 ) * JUMP_DISTANCE
15+ dy = ( self . direction == 2 ? 1 : self . direction == 8 ? -1 : 0 ) * JUMP_DISTANCE
16+ if passable? ( @x + dx , @y + dy , 0 )
17+ jump ( dx , dy )
18+ Audio . se_play ( "Audio/SE/016-Jump02" , 80 , 100 )
19+ @jump_cooldown = JUMP_COOLDOWN_FRAMES
20+ end
21+ end
22+ #--------------------------------------------------------------------------
23+ # * Invariables
24+ #--------------------------------------------------------------------------
25+ CENTER_X = ( 320 - 16 ) * 4
26+ CENTER_Y = ( 240 - 16 ) * 4
27+ #--------------------------------------------------------------------------
28+ # * Passable Determinants
29+ #--------------------------------------------------------------------------
30+ def passable? ( x , y , d )
31+ new_x = x + ( d == 6 ? 1 : d == 4 ? -1 : 0 )
32+ new_y = y + ( d == 2 ? 1 : d == 8 ? -1 : 0 )
33+ unless $game_map. valid? ( new_x , new_y )
34+ return false
35+ end
36+ if $DEBUG and Input . press? ( Input ::CTRL )
37+ return true
38+ end
39+ super
40+ end
41+ #--------------------------------------------------------------------------
42+ # * Set Map Display Position to Center of Screen
43+ #--------------------------------------------------------------------------
44+ def center ( x , y )
45+ max_x = ( $game_map. width - 20 ) * 128
46+ max_y = ( $game_map. height - 15 ) * 128
47+ $game_map. display_x = [ 0 , [ x * 128 - CENTER_X , max_x ] . min ] . max
48+ $game_map. display_y = [ 0 , [ y * 128 - CENTER_Y , max_y ] . min ] . max
49+ end
50+ #--------------------------------------------------------------------------
51+ # * Move to Designated Position
52+ #--------------------------------------------------------------------------
53+ def moveto ( x , y )
54+ super
55+ center ( x , y )
56+ make_encounter_count
57+ end
58+ #--------------------------------------------------------------------------
59+ # * Increase Steps
60+ #--------------------------------------------------------------------------
61+ def increase_steps
62+ super
63+ unless @move_route_forcing
64+ $game_party. increase_steps
65+ if $game_party. steps % 2 == 0
66+ $game_party. check_map_slip_damage
67+ end
68+ end
69+ end
70+ #--------------------------------------------------------------------------
71+ # * Get Encounter Count
72+ #--------------------------------------------------------------------------
73+ def encounter_count
74+ return @encounter_count
75+ end
76+ #--------------------------------------------------------------------------
77+ # * Make Encounter Count
78+ #--------------------------------------------------------------------------
79+ def make_encounter_count
80+ if $game_map. map_id != 0
81+ n = $game_map. encounter_step
82+ @encounter_count = rand ( n ) + rand ( n ) + 1
83+ end
84+ end
85+ #--------------------------------------------------------------------------
86+ # * Refresh
87+ #--------------------------------------------------------------------------
88+ def refresh
89+ if $game_party. actors . size == 0
90+ @character_name = ""
91+ @character_hue = 0
92+ return
93+ end
94+ actor = $game_party. actors [ 0 ]
95+ @character_name = actor . character_name
96+ @character_hue = actor . character_hue
97+ @opacity = 255
98+ @blend_type = 0
99+ end
100+ #--------------------------------------------------------------------------
101+ # * Same Position Starting Determinant
102+ #--------------------------------------------------------------------------
103+ def check_event_trigger_here ( triggers )
104+ result = false
105+ if $game_system. map_interpreter . running?
106+ return result
107+ end
108+ for event in $game_map. events . values
109+ if event . x == @x and event . y == @y and triggers . include? ( event . trigger )
110+ if not event . jumping? and event . over_trigger?
111+ event . start
112+ result = true
113+ end
114+ end
115+ end
116+ return result
117+ end
118+ #--------------------------------------------------------------------------
119+ # * Front Envent Starting Determinant
120+ #--------------------------------------------------------------------------
121+ def check_event_trigger_there ( triggers )
122+ result = false
123+ if $game_system. map_interpreter . running?
124+ return result
125+ end
126+ new_x = @x + ( @direction == 6 ? 1 : @direction == 4 ? -1 : 0 )
127+ new_y = @y + ( @direction == 2 ? 1 : @direction == 8 ? -1 : 0 )
128+ for event in $game_map. events . values
129+ if event . x == new_x and event . y == new_y and
130+ triggers . include? ( event . trigger )
131+ if not event . jumping? and not event . over_trigger?
132+ event . start
133+ result = true
134+ end
135+ end
136+ end
137+ if result == false
138+ if $game_map. counter? ( new_x , new_y )
139+ new_x += ( @direction == 6 ? 1 : @direction == 4 ? -1 : 0 )
140+ new_y += ( @direction == 2 ? 1 : @direction == 8 ? -1 : 0 )
141+ for event in $game_map. events . values
142+ if event . x == new_x and event . y == new_y and
143+ triggers . include? ( event . trigger )
144+ if not event . jumping? and not event . over_trigger?
145+ event . start
146+ result = true
147+ end
148+ end
149+ end
150+ end
151+ end
152+ return result
153+ end
154+ #--------------------------------------------------------------------------
155+ # * Touch Event Starting Determinant
156+ #--------------------------------------------------------------------------
157+ def check_event_trigger_touch ( x , y )
158+ result = false
159+ if $game_system. map_interpreter . running?
160+ return result
161+ end
162+ for event in $game_map. events . values
163+ if event . x == x and event . y == y and [ 1 , 2 ] . include? ( event . trigger )
164+ if not event . jumping? and not event . over_trigger?
165+ event . start
166+ result = true
167+ end
168+ end
169+ end
170+ return result
171+ end
172+ #--------------------------------------------------------------------------
173+ # * Frame Update
174+ #--------------------------------------------------------------------------
175+ def update
176+ @jump_cooldown = [ @jump_cooldown - 1 , 0 ] . max if @jump_cooldown && @jump_cooldown > 0
177+ if Input . trigger? ( Input ::A )
178+ try_jump
179+ end
180+ last_moving = moving?
181+ unless moving? or $game_system. map_interpreter . running? or
182+ @move_route_forcing or $game_temp. message_window_showing
183+ case Input . dir4
184+ when 2
185+ move_down
186+ when 4
187+ move_left
188+ when 6
189+ move_right
190+ when 8
191+ move_up
192+ end
193+ end
194+ last_real_x = @real_x
195+ last_real_y = @real_y
196+ super
197+ if @real_y > last_real_y and @real_y - $game_map. display_y > CENTER_Y
198+ $game_map. scroll_down ( @real_y - last_real_y )
199+ end
200+ if @real_x < last_real_x and @real_x - $game_map. display_x < CENTER_X
201+ $game_map. scroll_left ( last_real_x - @real_x )
202+ end
203+ if @real_x > last_real_x and @real_x - $game_map. display_x > CENTER_X
204+ $game_map. scroll_right ( @real_x - last_real_x )
205+ end
206+ if @real_y < last_real_y and @real_y - $game_map. display_y < CENTER_Y
207+ $game_map. scroll_up ( last_real_y - @real_y )
208+ end
209+ unless moving?
210+ if last_moving
211+ result = check_event_trigger_here ( [ 1 , 2 ] )
212+ if result == false
213+ unless $DEBUG and Input . press? ( Input ::CTRL )
214+ if @encounter_count > 0
215+ @encounter_count -= 1
216+ end
217+ end
218+ end
219+ end
220+ if Input . trigger? ( Input ::C )
221+ check_event_trigger_here ( [ 0 ] )
222+ check_event_trigger_there ( [ 0 , 1 , 2 ] )
223+ end
224+ end
225+ end
226+ end
0 commit comments