Class: Game_Player

Inherits:
Game_Character show all
Defined in:
Game_Player.rb

Overview

** Game_Player


This class handles the player. It includes event starting determinants and

map scrolling functions. The instance of this class is referenced by $game_player.

Constant Summary

Constant Summary

Constants inherited from Game_Character

Game_Character::ROUTE_CHANGE_BLENDING, Game_Character::ROUTE_CHANGE_FREQ, Game_Character::ROUTE_CHANGE_GRAPHIC, Game_Character::ROUTE_CHANGE_OPACITY, Game_Character::ROUTE_CHANGE_SPEED, Game_Character::ROUTE_DIR_FIX_OFF, Game_Character::ROUTE_DIR_FIX_ON, Game_Character::ROUTE_END, Game_Character::ROUTE_JUMP, Game_Character::ROUTE_MOVE_AWAY, Game_Character::ROUTE_MOVE_BACKWARD, Game_Character::ROUTE_MOVE_DOWN, Game_Character::ROUTE_MOVE_FORWARD, Game_Character::ROUTE_MOVE_LEFT, Game_Character::ROUTE_MOVE_LOWER_L, Game_Character::ROUTE_MOVE_LOWER_R, Game_Character::ROUTE_MOVE_RANDOM, Game_Character::ROUTE_MOVE_RIGHT, Game_Character::ROUTE_MOVE_TOWARD, Game_Character::ROUTE_MOVE_UP, Game_Character::ROUTE_MOVE_UPPER_L, Game_Character::ROUTE_MOVE_UPPER_R, Game_Character::ROUTE_PLAY_SE, Game_Character::ROUTE_SCRIPT, Game_Character::ROUTE_STEP_ANIME_OFF, Game_Character::ROUTE_STEP_ANIME_ON, Game_Character::ROUTE_SWITCH_OFF, Game_Character::ROUTE_SWITCH_ON, Game_Character::ROUTE_THROUGH_OFF, Game_Character::ROUTE_THROUGH_ON, Game_Character::ROUTE_TRANSPARENT_OFF, Game_Character::ROUTE_TRANSPARENT_ON, Game_Character::ROUTE_TURN_180D, Game_Character::ROUTE_TURN_90D_L, Game_Character::ROUTE_TURN_90D_R, Game_Character::ROUTE_TURN_90D_R_L, Game_Character::ROUTE_TURN_AWAY, Game_Character::ROUTE_TURN_DOWN, Game_Character::ROUTE_TURN_LEFT, Game_Character::ROUTE_TURN_RANDOM, Game_Character::ROUTE_TURN_RIGHT, Game_Character::ROUTE_TURN_TOWARD, Game_Character::ROUTE_TURN_UP, Game_Character::ROUTE_WAIT, Game_Character::ROUTE_WALK_ANIME_OFF, Game_Character::ROUTE_WALK_ANIME_ON

Instance Attribute Summary (collapse)

Attributes inherited from Game_Character

#move_route_forcing

Attributes inherited from Game_CharacterBase

#animation_id, #balloon_id, #blend_type, #bush_depth, #character_index, #character_name, #direction, #direction_fix, #id, #move_frequency, #move_speed, #opacity, #pattern, #priority_type, #real_x, #real_y, #step_anime, #through, #tile_id, #transparent, #walk_anime, #x, #y

Instance Method Summary (collapse)

Methods inherited from Game_Character

#advance_move_route_index, #distance_x_from, #distance_y_from, #force_move_route, #init_private_members, #init_public_members, #jump, #memorize_move_route, #move_away_from_character, #move_away_from_player, #move_backward, #move_forward, #move_random, #move_toward_character, #move_toward_player, #process_move_command, #process_route_end, #restore_move_route, #swap, #turn_180, #turn_away_from_character, #turn_away_from_player, #turn_left_90, #turn_random, #turn_right_90, #turn_right_or_left_90, #turn_toward_character, #turn_toward_player, #update_routine_move, #update_stop

Methods inherited from Game_CharacterBase

#bush?, #check_event_trigger_touch_front, #collide_with_characters?, #collide_with_events?, #collide_with_vehicles?, #diagonal_passable?, #distance_per_frame, #init_private_members, #init_public_members, #jump_height, #jumping?, #ladder?, #moving?, #normal_priority?, #object_character?, #passable?, #pos?, #pos_nt?, #real_move_speed, #region_id, #reverse_dir, #screen_x, #screen_y, #screen_z, #set_direction, #set_graphic, #shift_y, #straighten, #terrain_tag, #tile?, #update_animation, #update_anime_count, #update_anime_pattern, #update_bush_depth, #update_jump, #update_move, #update_stop

Constructor Details

- (Game_Player) initialize


  • Object Initialization




17
18
19
20
21
22
23
24
25
# File 'Game_Player.rb', line 17

def initialize
  super
  @vehicle_type = :walk           # Type of vehicle currently being ridden
  @vehicle_getting_on = false     # Boarding vehicle flag
  @vehicle_getting_off = false    # Getting off vehicle flag
  @followers = Game_Followers.new(self)
  @transparent = $data_system.opt_transparent
  clear_transfer_info
end

Instance Attribute Details

- (Object) followers (readonly)


  • Public Instance Variables




13
14
15
# File 'Game_Player.rb', line 13

def followers
  @followers
end

Instance Method Details

- (Object) actor


  • Get Corresponding Actor




47
48
49
# File 'Game_Player.rb', line 47

def actor
  $game_party.battle_members[0]
end

- (Object) center(x, y)


  • Set Map Display Position to Center of Screen




170
171
172
# File 'Game_Player.rb', line 170

def center(x, y)
  $game_map.set_display_pos(x - center_x, y - center_y)
end

- (Object) center_x


  • X Coordinate of Screen Center




158
159
160
# File 'Game_Player.rb', line 158

def center_x
  (Graphics.width / 32 - 1) / 2.0
end

- (Object) center_y


  • Y Coordinate of Screen Center




164
165
166
# File 'Game_Player.rb', line 164

def center_y
  (Graphics.height / 32 - 1) / 2.0
end

- (Object) check_action_event


  • Determine if Event Start Caused by [OK] Button




405
406
407
408
409
410
411
# File 'Game_Player.rb', line 405

def check_action_event
  return false if in_airship?
  check_event_trigger_here([0])
  return true if $game_map.setup_starting_event
  check_event_trigger_there([0,1,2])
  $game_map.setup_starting_event
end

- (Object) check_event_trigger_here(triggers)


  • Determine if Same Position Event is Triggered




255
256
257
# File 'Game_Player.rb', line 255

def check_event_trigger_here(triggers)
  start_map_event(@x, @y, triggers, false)
end

- (Object) check_event_trigger_there(triggers)


  • Determine if Front Event is Triggered




261
262
263
264
265
266
267
268
269
270
# File 'Game_Player.rb', line 261

def check_event_trigger_there(triggers)
  x2 = $game_map.round_x_with_direction(@x, @direction)
  y2 = $game_map.round_y_with_direction(@y, @direction)
  start_map_event(x2, y2, triggers, true)
  return if $game_map.any_event_starting?
  return unless $game_map.counter?(x2, y2)
  x3 = $game_map.round_x_with_direction(x2, @direction)
  y3 = $game_map.round_y_with_direction(y2, @direction)
  start_map_event(x3, y3, triggers, true)
end

- (Object) check_event_trigger_touch(x, y)


  • Determine if Touch Event is Triggered




274
275
276
# File 'Game_Player.rb', line 274

def check_event_trigger_touch(x, y)
  start_map_event(x, y, [1,2], true)
end

- (Object) check_touch_event


  • Determine if Event Start Caused by Touch (Overlap)




397
398
399
400
401
# File 'Game_Player.rb', line 397

def check_touch_event
  return false if in_airship?
  check_event_trigger_here([1,2])
  $game_map.setup_starting_event
end

- (Object) clear_transfer_info


  • Clear Transfer Player Information




29
30
31
32
33
34
35
# File 'Game_Player.rb', line 29

def clear_transfer_info
  @transferring = false           # Player transfer flag
  @new_map_id = 0                 # Destination map ID
  @new_x = 0                      # Destination X coordinate
  @new_y = 0                      # Destination Y coordinate
  @new_direction = 0              # Post-movement direction
end

- (Boolean) collide?(x, y)


  • Detect Collision (Including Followers)


Returns:

  • (Boolean)


152
153
154
# File 'Game_Player.rb', line 152

def collide?(x, y)
  !@through && (pos?(x, y) || followers.collide?(x, y))
end

- (Boolean) dash?


  • Determine if Dashing


Returns:

  • (Boolean)


137
138
139
140
141
142
# File 'Game_Player.rb', line 137

def dash?
  return false if @move_route_forcing
  return false if $game_map.disable_dash?
  return false if vehicle
  return Input.press?(:A)
end

- (Boolean) debug_through?


  • Determine if Debug Pass-through State


Returns:

  • (Boolean)


146
147
148
# File 'Game_Player.rb', line 146

def debug_through?
  $TEST && Input.press?(:CTRL)
end

- (Object) encounter


  • Execute Encounter Processing




228
229
230
231
232
233
234
235
236
237
238
# File 'Game_Player.rb', line 228

def encounter
  return false if $game_map.interpreter.running?
  return false if $game_system.encounter_disabled
  return false if @encounter_count > 0
  make_encounter_count
  troop_id = make_encounter_troop_id
  return false unless $data_troops[troop_id]
  BattleManager.setup(troop_id)
  BattleManager.on_encounter
  return true
end

- (Boolean) encounter_ok?(encounter)


  • Determine Usability of Encounter Item


Returns:

  • (Boolean)


220
221
222
223
224
# File 'Game_Player.rb', line 220

def encounter_ok?(encounter)
  return true if encounter.region_set.empty?
  return true if encounter.region_set.include?(region_id)
  return false
end

- (Object) encounter_progress_value


  • Get Encounter Progress Value




388
389
390
391
392
393
# File 'Game_Player.rb', line 388

def encounter_progress_value
  value = $game_map.bush?(@x, @y) ? 2 : 1
  value *= 0.5 if $game_party.encounter_half?
  value *= 0.5 if in_ship?
  value
end

- (Object) force_move_forward


  • Force One Step Forward




463
464
465
466
467
# File 'Game_Player.rb', line 463

def force_move_forward
  @through = true
  move_forward
  @through = false
end

- (Object) get_off_vehicle


  • Get Off Vehicle

    Assumes that the player is currently riding in a vehicle.



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'Game_Player.rb', line 443

def get_off_vehicle
  if vehicle.land_ok?(@x, @y, @direction)
    set_direction(2) if in_airship?
    @followers.synchronize(@x, @y, @direction)
    vehicle.get_off
    unless in_airship?
      force_move_forward
      @transparent = false
    end
    @vehicle_getting_off = true
    @move_speed = 4
    @through = false
    make_encounter_count
    @followers.gather
  end
  @vehicle_getting_off
end

- (Object) get_on_off_vehicle


  • Getting On and Off Vehicles




415
416
417
418
419
420
421
# File 'Game_Player.rb', line 415

def get_on_off_vehicle
  if vehicle
    get_off_vehicle
  else
    get_on_vehicle
  end
end

- (Object) get_on_vehicle


  • Board Vehicle

    Assumes that the player is not currently in a vehicle.



426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'Game_Player.rb', line 426

def get_on_vehicle
  front_x = $game_map.round_x_with_direction(@x, @direction)
  front_y = $game_map.round_y_with_direction(@y, @direction)
  @vehicle_type = :boat    if $game_map.boat.pos?(front_x, front_y)
  @vehicle_type = :ship    if $game_map.ship.pos?(front_x, front_y)
  @vehicle_type = :airship if $game_map.airship.pos?(@x, @y)
  if vehicle
    @vehicle_getting_on = true
    force_move_forward unless in_airship?
    @followers.gather
  end
  @vehicle_getting_on
end

- (Boolean) in_airship?


  • Determine if Riding in Airship


Returns:

  • (Boolean)


125
126
127
# File 'Game_Player.rb', line 125

def in_airship?
  @vehicle_type == :airship
end

- (Boolean) in_boat?


  • Determine if on Boat


Returns:

  • (Boolean)


113
114
115
# File 'Game_Player.rb', line 113

def in_boat?
  @vehicle_type == :boat
end

- (Boolean) in_ship?


  • Determine if on Ship


Returns:

  • (Boolean)


119
120
121
# File 'Game_Player.rb', line 119

def in_ship?
  @vehicle_type == :ship
end

- (Object) increase_steps


  • Increase Steps




186
187
188
189
# File 'Game_Player.rb', line 186

def increase_steps
  super
  $game_party.increase_steps if normal_walk?
end

- (Object) make_encounter_count


  • Create Encounter Count




193
194
195
196
# File 'Game_Player.rb', line 193

def make_encounter_count
  n = $game_map.encounter_step
  @encounter_count = rand(n) + rand(n) + 1
end

- (Object) make_encounter_troop_id


  • Create Group ID for Troop Encountered




200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'Game_Player.rb', line 200

def make_encounter_troop_id
  encounter_list = []
  weight_sum = 0
  $game_map.encounter_list.each do |encounter|
    next unless encounter_ok?(encounter)
    encounter_list.push(encounter)
    weight_sum += encounter.weight
  end
  if weight_sum > 0
    value = rand(weight_sum)
    encounter_list.each do |encounter|
      value -= encounter.weight
      return encounter.troop_id if value < 0
    end
  end
  return 0
end

- (Boolean) map_passable?(x, y, d)


  • Determine if Map is Passable

    d:  Direction (2,4,6,8)

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
102
103
# File 'Game_Player.rb', line 92

def map_passable?(x, y, d)
  case @vehicle_type
  when :boat
    $game_map.boat_passable?(x, y)
  when :ship
    $game_map.ship_passable?(x, y)
  when :airship
    true
  else
    super
  end
end

- (Boolean) movable?


  • Determine if Movement is Possible


Returns:

  • (Boolean)


287
288
289
290
291
292
293
294
# File 'Game_Player.rb', line 287

def movable?
  return false if moving?
  return false if @move_route_forcing || @followers.gathering?
  return false if @vehicle_getting_on || @vehicle_getting_off
  return false if $game_message.busy? || $game_message.visible
  return false if vehicle && !vehicle.movable?
  return true
end

- (Object) move_by_input


  • Processing of Movement via Input from Directional Buttons




280
281
282
283
# File 'Game_Player.rb', line 280

def move_by_input
  return if !movable? || $game_map.interpreter.running?
  move_straight(Input.dir4) if Input.dir4 > 0
end

- (Object) move_diagonal(horz, vert)


  • Move Diagonally




484
485
486
487
# File 'Game_Player.rb', line 484

def move_diagonal(horz, vert)
  @followers.move if diagonal_passable?(@x, @y, horz, vert)
  super
end

- (Object) move_straight(d, turn_ok = true)


  • Move Straight




477
478
479
480
# File 'Game_Player.rb', line 477

def move_straight(d, turn_ok = true)
  @followers.move if passable?(@x, @y, d)
  super
end

- (Object) moveto(x, y)


  • Move to Designated Position




176
177
178
179
180
181
182
# File 'Game_Player.rb', line 176

def moveto(x, y)
  super
  center(x, y)
  make_encounter_count
  vehicle.refresh if vehicle
  @followers.synchronize(x, y, direction)
end

- (Boolean) normal_walk?


  • Determine if Walking Normally


Returns:

  • (Boolean)


131
132
133
# File 'Game_Player.rb', line 131

def normal_walk?
  @vehicle_type == :walk && !@move_route_forcing
end

- (Boolean) on_damage_floor?


  • Determine if Damage Floor


Returns:

  • (Boolean)


471
472
473
# File 'Game_Player.rb', line 471

def on_damage_floor?
  $game_map.damage_floor?(@x, @y) && !in_airship?
end

- (Object) perform_transfer


  • Execute Player Transfer




77
78
79
80
81
82
83
84
85
86
87
# File 'Game_Player.rb', line 77

def perform_transfer
  if transfer?
    set_direction(@new_direction)
    if @new_map_id != $game_map.map_id
      $game_map.setup(@new_map_id)
      $game_map.autoplay
    end
    moveto(@new_x, @new_y)
    clear_transfer_info
  end
end

- (Object) refresh


  • Refresh




39
40
41
42
43
# File 'Game_Player.rb', line 39

def refresh
  @character_name = actor ? actor.character_name : ""
  @character_index = actor ? actor.character_index : 0
  @followers.refresh
end

- (Object) reserve_transfer(map_id, x, y, d = 2)


  • Player Transfer Reservation

    d:  Post move direction (2,4,6,8)



61
62
63
64
65
66
67
# File 'Game_Player.rb', line 61

def reserve_transfer(map_id, x, y, d = 2)
  @transferring = true
  @new_map_id = map_id
  @new_x = x
  @new_y = y
  @new_direction = d
end

- (Object) start_map_event(x, y, triggers, normal)


  • Trigger Map Event

    triggers : Trigger array
    normal   : Is priority set to [Same as Characters] ?



244
245
246
247
248
249
250
251
# File 'Game_Player.rb', line 244

def start_map_event(x, y, triggers, normal)
  return if $game_map.interpreter.running?
  $game_map.events_xy(x, y).each do |event|
    if event.trigger_in?(triggers) && event.normal_priority? == normal
      event.start
    end
  end
end

- (Boolean) stopping?


  • Determine if Stopping


Returns:

  • (Boolean)


53
54
55
56
# File 'Game_Player.rb', line 53

def stopping?
  return false if @vehicle_getting_on || @vehicle_getting_off
  return super
end

- (Boolean) transfer?


  • Determine if Player Transfer is Reserved


Returns:

  • (Boolean)


71
72
73
# File 'Game_Player.rb', line 71

def transfer?
  @transferring
end

- (Object) update


  • Frame Update




298
299
300
301
302
303
304
305
306
307
308
# File 'Game_Player.rb', line 298

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) unless moving?
  @followers.update
end

- (Object) update_encounter


  • Update Encounter




378
379
380
381
382
383
384
# File 'Game_Player.rb', line 378

def update_encounter
  return if $TEST && Input.press?(:CTRL)
  return if $game_party.encounter_none?
  return if in_airship?
  return if @move_route_forcing
  @encounter_count -= encounter_progress_value
end

- (Object) update_nonmoving(last_moving)


  • Processing When Not Moving

    last_moving : Was it moving previously?



363
364
365
366
367
368
369
370
371
372
373
374
# File 'Game_Player.rb', line 363

def update_nonmoving(last_moving)
  return if $game_map.interpreter.running?
  if last_moving
    $game_party.on_player_walk
    return if check_touch_event
  end
  if movable? && Input.trigger?(:C)
    return if get_on_off_vehicle
    return if check_action_event
  end
  update_encounter if last_moving
end

- (Object) update_scroll(last_real_x, last_real_y)


  • Scroll Processing




312
313
314
315
316
317
318
319
320
321
# File 'Game_Player.rb', line 312

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)
  $game_map.scroll_down (ay2 - ay1) if ay2 > ay1 && ay2 > center_y
  $game_map.scroll_left (ax1 - ax2) if ax2 < ax1 && ax2 < center_x
  $game_map.scroll_right(ax2 - ax1) if ax2 > ax1 && ax2 > center_x
  $game_map.scroll_up   (ay1 - ay2) if ay2 < ay1 && ay2 < center_y
end

- (Object) update_vehicle


  • Vehicle Processing




325
326
327
328
329
330
331
332
333
334
335
# File 'Game_Player.rb', line 325

def update_vehicle
  return if @followers.gathering?
  return unless vehicle
  if @vehicle_getting_on
    update_vehicle_get_on
  elsif @vehicle_getting_off
    update_vehicle_get_off
  else
    vehicle.sync_with_player
  end
end

- (Object) update_vehicle_get_off


  • Update Disembarking from Vehicle




352
353
354
355
356
357
358
# File 'Game_Player.rb', line 352

def update_vehicle_get_off
  if !@followers.gathering? && vehicle.altitude == 0
    @vehicle_getting_off = false
    @vehicle_type = :walk
    @transparent = false
  end
end

- (Object) update_vehicle_get_on


  • Update Boarding onto Vehicle




339
340
341
342
343
344
345
346
347
348
# File 'Game_Player.rb', line 339

def update_vehicle_get_on
  if !@followers.gathering? && !moving?
    @direction = vehicle.direction
    @move_speed = vehicle.speed
    @vehicle_getting_on = false
    @transparent = true
    @through = true if in_airship?
    vehicle.get_on
  end
end

- (Object) vehicle


  • Get Vehicle Currently Being Ridden




107
108
109
# File 'Game_Player.rb', line 107

def vehicle
  $game_map.vehicle(@vehicle_type)
end