Class: GamePlay::WorldMap

Inherits:
BaseCleanUpdate::FrameBalanced show all
Defined in:
scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb

Overview

Class showing the basic World Map (TownMap) with navigation

The world map is stored inside a 2D Array ($game_data_map) that holds each columns of the world map. Each of these columns contain the ID of the zones at the y position of the cursor

Constant Summary collapse

ViewportsBaseZ =

Base Z of the viewports

Returns:

51_000
VMapX =

Coord X of the map viewport

Returns:

49
VMapY =

Coord Y of the map viewport

Returns:

37
VMapWidth =

Width of the map viewport

Returns:

257
VMapHeight =

Height of the map viewport

Returns:

168
UnknownZoneX =

Coord X of the window tell the zone is unkonwn

Returns:

76
UnknownZoneY =

Coord Y of the window tell the zone is unkonwn

Returns:

77
UnknownZoneWidth =

Width of the window tell the zone is unkonwn

Returns:

200
UnknownZoneHeight =

Height of the window tell the zone is unkonwn

Returns:

30
CursorAnimationDuration =

Duration of the whole cursor animation

Returns:

60
CursorMoveDuration =

Duration of the one case move

Returns:

4
BitmapOffset =

Offset of the World Map bitmap

Returns:

0
TileSize =

Size of a tile in the WorldMap (Used outside of the script !)

Returns:

8
UI_MAP_HEIGHT =

The height of the display zone on the map window

Returns:

168
UI_MAP_WIDTH =

The width of the display zone on the map window

Returns:

256
ZoomEnabled =

Indicate if the zoom is usable in world map

true
PROC_ZONE_COLOR =

Proc to define the zones color

proc do |counter|
  [1, 0, 0, (300 + counter).to_f / 500] # Red
end
PROC_FLY_ZONE_COLOR =

Proc to define the fly zones color

proc do |counter|
  [1, 0, 1, (300 + counter * 2).to_f / 600] # Purple
end

Constants inherited from BaseCleanUpdate

BaseCleanUpdate::AIU_KEY2METHOD

Constants inherited from Base

Base::DEFAULT_TRANSITION, Base::DEFAULT_TRANSITION_PARAMETER

Constants included from Input

Input::ALIAS_KEYS, Input::AXIS_MAPPING, Input::AXIS_SENSITIVITY, Input::DEAD_ZONE, Input::Keyboard, Input::Keys, Input::NON_TRIGGER_ZONE, Input::REPEAT_COOLDOWN, Input::REPEAT_SPACE

Constants included from DisplayMessage

DisplayMessage::MESSAGE_ERROR, DisplayMessage::MESSAGE_PROCESS_ERROR

Instance Attribute Summary

Attributes inherited from Base

#__last_scene, #__result_process, #running, #viewport

Attributes included from DisplayMessage

#message_window

Instance Method Summary collapse

Methods inherited from BaseCleanUpdate::FrameBalanced

#update

Methods included from Graphics::FPSBalancer::Marker

#frame_balanced?

Methods inherited from BaseCleanUpdate

#automatic_input_update, #update

Methods inherited from Base

#add_disposable, #call_scene, #find_parent, #main, #return_to_scene, #snap_to_bitmap, #update, #visible

Methods included from Input

dir4, dir8, get_text, joy_axis_position, press?, register_events, released?, repeat?, swap_states, trigger?

Methods included from DisplayMessage

#can_display_message_be_called?, #close_message_window, #display_message, #display_message_and_wait, #message_class, #message_processing?, #message_visible, #message_visible=

Constructor Details

#initialize(mode = :view, wm_id = $env.get_worldmap, pokemon = nil) ⇒ WorldMap

Create a new World Map view

Parameters:

  • mode (Symbol) (defaults to: :view)

    mode of the World Map (:view / :fly / :pokdex / :view_wall)

  • wm_id (Integer) (defaults to: $env.get_worldmap)

    the id of the world map to display

  • pokemon (PFM::Pokemon, Symbol) (defaults to: nil)

    <default :map> the calling situation



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 69

def initialize(mode = :view, wm_id = $env.get_worldmap, pokemon = nil)
  super(true)
  # Store parameters
  @mode = mode
  @worldmap_id = wm_id
  @pokemon = pokemon
  # Change external attributes
  $wild_battle.on_map_viewed if @mode == :view
  # Initialize attributes
  @map_display_ox = @map_display_oy = 0
  @map_display_ox_offset = @map_display_oy_offset = 0
  @worldmap_zoom = 1
  @cursor_animation_counter = 0
  @cursor_move_count = false
  @last_x = @last_y = @x = @y = 0
  @zoom = 1
  @zone_animation_backroll = false
  @zone_animation_counter = 0
end

Instance Method Details

#create_background

Create the Worldmap background



158
159
160
161
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 158

def create_background
  @bg_background = Sprite.new(@viewport_background).set_bitmap('worldmap/background_animated', :interface)
  @bg_frame = Sprite.new(@viewport_background).set_bitmap('worldmap/background_map', :interface)
end

#create_cursor

Create the cursor



169
170
171
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 169

def create_cursor
  @cursor = Sprite.new(@viewport_map_cursor).set_bitmap('worldmap/cursor', :interface).set_rect_div(0, 0, 1, 2)
end

#create_frame

Create the frame



195
196
197
198
199
200
201
202
203
204
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 195

def create_frame
  @ui_frame = Sprite.new(@viewport_ui).set_bitmap('worldmap/frame', :interface)
  @ui_infobox = UI::DexWinMap.new(@viewport_ui, @mode != :view_wall)
  @ui_infobox.data = @pokemon
  @ui_unknown_zone = UI::Window.new(@viewport_ui, UnknownZoneX, UnknownZoneY, UnknownZoneWidth, UnknownZoneHeight)
  @ui_unknown_zone.add_text(0, 0, 170, 13, ext_text(9000, 31), 1)
  @ui_unknown_zone.visible = false
  # Finish the display
  set_worldmap(@worldmap_id)
end

#create_graphics

Create all the graphics required by this Scene



147
148
149
150
151
152
153
154
155
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 147

def create_graphics
  create_viewport
  create_background
  create_map
  create_cursor
  create_player_sprite
  create_markers
  create_frame
end

#create_map

Create the map sprite



164
165
166
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 164

def create_map
  @map_worldmap = Sprite.new(@viewport_map).set_bitmap(data_world_map(@worldmap_id).image, :interface)
end

#create_markers

Create the markers (their holder)



185
186
187
188
189
190
191
192
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 185

def create_markers
  @marker_zones = []
  @marker_zones_bitmap = RPG::Cache.interface('worldmap/zones')
  # Custom icons
  @marker_custom_icons = []
  # Roaming pokemon markers
  @marker_roaming_pokemons = []
end

#create_player_sprite

Create the player marker



174
175
176
177
178
179
180
181
182
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 174

def create_player_sprite
  @marker_player = Sprite::WithColor.new(@viewport_map_markers)
  player_icon = 'worldmap/player_icons/' \
                "#{$game_player.charset_base}_#{$game_switches[Yuki::Sw::Gender] ? 'f' : 'm'}"
  player_icon = 'worldmap/player_icons/default' unless RPG::Cache.interface_exist?(player_icon)
  @marker_player.set_bitmap(player_icon, :interface)
  @marker_player.ox = @marker_player.src_rect.width / 2 - TileSize / 2
  @marker_player.oy = @marker_player.src_rect.height / 2 - TileSize / 2
end

#create_viewport

Create the viewports of the scene



137
138
139
140
141
142
143
144
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 137

def create_viewport
  @viewport_background = Viewport.create(:main, ViewportsBaseZ)
  @viewport_map = Viewport.create(VMapX, VMapY, VMapWidth, VMapHeight, ViewportsBaseZ + 1000)
  @viewport_map_zones = Viewport.create(VMapX, VMapY, VMapWidth, VMapHeight, ViewportsBaseZ + 2000)
  @viewport_map_markers = Viewport.create(VMapX, VMapY, VMapWidth, VMapHeight, ViewportsBaseZ + 3000)
  @viewport_map_cursor = Viewport.create(VMapX, VMapY, VMapWidth, VMapHeight, ViewportsBaseZ + 4000)
  @viewport_ui = Viewport.create(:main, ViewportsBaseZ + 5000)
end

#display_custom_icons

Display the customs icons



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 467

def display_custom_icons
  return unless @mode == :view
  return unless (icons_data = $env.worldmap_custom_markers[@worldmap_id])

  icons_data.each do |icon|
    file = 'worldmap/icons/' + icon[0]
    next unless RPG::Cache.interface_exist?(file)

    # Initialize the sprite
    sprite = Sprite.new(@viewport_map_markers)
    sprite.set_bitmap(file, :interface)
    # Set the sprite
    process_icon_origin_mode(sprite, icon[3], icon[4])
    sx = BitmapOffset + @map_worldmap.x + TileSize * icon[1]
    sy = BitmapOffset + @map_worldmap.y + TileSize * icon[2]
    @marker_custom_icons.push sprite.set_position(sx, sy)
  end
end

#display_fly_zones

Display the available fly zones



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 510

def display_fly_zones
  return unless @mode == :fly

  # Initialize
  grid = data_world_map(@worldmap_id).grid
  fly_zones = Table.new(grid.first.size, grid.size)
  # Test each world map case
  0.upto(fly_zones.xsize - 1) do |x|
    0.upto(fly_zones.ysize - 1) do |y|
      next if (zone_id = grid[y][x] || -1) < 0 # No zone = no flight

      zone = data_zone(zone_id)
      fly_zones[x, y] = 1 if zone.warp.x && zone.warp.y && $env.visited_zone?(zone)
    end
  end
  # Display each zone
  display_zones(fly_zones)
end

#display_pokemon_zones

Display the pokedex pokemon zones



578
579
580
581
582
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 578

def display_pokemon_zones
  return unless @mode == :pokedex

  display_zones(search_pokemon_zone)
end

#display_roaming_pokemons

Display the roaming pokemon zones and icons



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
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 530

def display_roaming_pokemons
  return unless @mode == :view

  # Initialize
  grid = data_world_map(@worldmap_id).grid
  creature_zones = Table.new(grid.first.size, grid.size)
  creatures = $wild_battle.roaming_pokemons
  coords_by_creatures = {}
  return if creatures.empty?

  # Check each tile
  0.upto(creature_zones.xsize - 1) do |x|
    0.upto(creature_zones.ysize - 1) do |y|
      next if (zone_id = grid[y][x] || -1) < 0 # No zone = no pokemon

      zone = data_zone(zone_id)
      creatures.each do |creature_info|
        next unless zone.maps.include?(creature_info.map_id)

        creature_zones[x, y] = 1
        coords_by_creatures[creature_info] ||= []
        coords_by_creatures[creature_info].push [x, y]
      end
    end
  end
  # Display zones
  display_zones(creature_zones)
  # Display creatures
  # No more than one pokemon by case
  coords_by_creatures.keys.each do |infos|
    # Look for the image, next if no icon matching
    pkm_icon = 'worldmap/pokemons_icons/' + infos.pokemon.character_name
    next unless RPG::Cache.interface_exist?(pkm_icon)

    # Initialize the sprite
    sprite = Sprite.new(@viewport_map_markers)
    sprite.set_bitmap(pkm_icon, :interface)
    sprite.ox = sprite.src_rect.width / 2 - TileSize / 2
    sprite.oy = sprite.src_rect.height / 2 - TileSize / 2
    coords = coords_by_creatures[infos].sample
    # Set the sprite
    sx = BitmapOffset + @map_worldmap.x + TileSize * coords[0]
    sy = BitmapOffset + @map_worldmap.y + TileSize * coords[1]
    @marker_roaming_pokemons.push sprite.set_position(sx, sy)
  end
end

#display_zones(tab)

Create the zones sprites

Parameters:

  • tab (Table)

    the table containing the data : 0=no zone, 1=zone



586
587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 586

def display_zones(tab)
  # Display each zone
  0.upto(tab.xsize - 1) do |x|
    0.upto(tab.ysize - 1) do |y|
      next if tab[x, y] == 0

      sx = BitmapOffset + @map_worldmap.x + TileSize * x
      sy = BitmapOffset + @map_worldmap.y + TileSize * y
      @marker_zones.push(s = Sprite::WithColor.new(@viewport_map_zones)
        .set_bitmap(@marker_zones_bitmap).set_position(sx, sy))
      set_zone_rect(tab, x, y, s)
    end
  end
end

#dispose



116
117
118
119
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 116

def dispose
  super
  @__last_scene.sprite_set_visible = true if @__last_scene.class == ::Scene_Map
end

#dispose_zone_and_marker

Delete zones and markers sprite



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 122

def dispose_zone_and_marker
  # Clear custom icons
  @marker_custom_icons.each(&:dispose)
  @marker_custom_icons.clear
  # Clear roaming pokemon
  @marker_roaming_pokemons.each(&:dispose)
  @marker_roaming_pokemons.clear
  # Clear the existing zones
  @marker_zones.each(&:dispose)
  @marker_zones.clear
  @zone_animation_counter = 0
  @zone_animation_backroll = false
end

#init_cursor_and_player

Initialize the cursor and the player positions



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 207

def init_cursor_and_player
  # Get the coords
  if @worldmap_id != $env.get_worldmap
    @x = @y = 0
    @marker_player.visible = false
  elsif (modified_coords = $env.modified_worldmap_position)
    @x = modified_coords[0]
    @y = modified_coords[1]
    @marker_player.visible = true
  else
    zone_id = $env.master_zone >= 0 ? $env.master_zone : $env.get_current_zone
    @x, @y = $env.get_zone_pos(zone_id)
    @x ||= 0
    @y ||= 0
    @marker_player.visible = true
  end
  # Set the coords
  @cursor.x = BitmapOffset + @map_worldmap.x + TileSize * @x
  @cursor.y = BitmapOffset + @map_worldmap.y + TileSize * @y
  @marker_player.x = @cursor.x
  @marker_player.y = @cursor.y
  # Update the display map
  update_display_origin
end

#on_fly_attempt

We try to fly to the selected zone



384
385
386
387
388
389
390
391
392
393
394
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 384

def on_fly_attempt
  zone = $env.get_zone(@x, @y, @worldmap_id)
  if zone&.warp&.x && zone&.warp&.y && $env.visited_zone?(zone)
    map_id = zone.maps.first
    $game_variables[::Yuki::Var::TMP1] = map_id
    $game_variables[::Yuki::Var::TMP2] = zone.warp.x
    $game_variables[::Yuki::Var::TMP3] = zone.warp.y
    $game_temp.common_event_id = 15
    return_to_scene(Scene_Map)
  end
end

#on_next_worldmap

Load the next worldmap



397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 397

def on_next_worldmap
  worldmap_count = each_data_world_map.size
  old_worldmap_id = @worldmap_id
  @worldmap_id = (@worldmap_id + 1) % worldmap_count
  @worldmap_id = (@worldmap_id + 1) % worldmap_count until $env.visited_worldmap?(@worldmap_id) || @worldmap_id == old_worldmap_id
  unless old_worldmap_id == @worldmap_id
    if @mode == :pokedex
      set_pokemon(@pokemon, @worldmap_id)
    else
      set_worldmap(@worldmap_id)
    end
  end
end

#on_toggle_zoom

Change the zoom to 0.5 or 1



369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 369

def on_toggle_zoom
  # Set the zoom value
  @viewport_map.zoom = @viewport_map_cursor.zoom = @viewport_map_zones.zoom = @viewport_map_markers.zoom = @zoom = (@zoom == 0.5 ? 1 : 0.5)
  # Correct map display
  @viewport_map.ox *= @zoom
  @viewport_map.oy *= @zoom
  @viewport_map_cursor.ox *= @zoom
  @viewport_map_cursor.oy *= @zoom
  @viewport_map_markers.ox *= @zoom
  @viewport_map_markers.oy *= @zoom
  @viewport_map_zones.ox *= @zoom
  @viewport_map_zones.oy *= @zoom
end

#process_icon_origin_mode(sprite, ox_mode, oy_mode)

Define the sprite origin with the given parameters

Parameters:

  • sprite (Sprite)

    the sprite to modify

  • ox_mode (Symbol)
  • oy_mode (Symbol)


490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 490

def process_icon_origin_mode(sprite, ox_mode, oy_mode)
  case ox_mode
  when :center
    sprite.ox = sprite.src_rect.width / 2 - TileSize / 2
  when :left
    sprite.ox = 0
  when :right
    sprite.ox = sprite.src_rect.width - TileSize
  end
  case oy_mode
  when :center
    sprite.oy = sprite.src_rect.height / 2 - TileSize / 2
  when :down
    sprite.oy = sprite.src_rect.height - TileSize
  when :up
    sprite.oy = 0
  end
end

#recenter_map

Reset the map display coords



439
440
441
442
443
444
445
446
447
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 439

def recenter_map
  @map_display_ox = @map_display_oy = @map_display_oy_offset = @map_display_ox_offset = 0
  if (map_height = @map_worldmap.src_rect.height) < UI_MAP_HEIGHT
    @map_display_oy_offset = - (UI_MAP_HEIGHT - map_height) / 2
  end
  if (map_width = @map_worldmap.src_rect.width) < UI_MAP_WIDTH
    @map_display_ox_offset = - (UI_MAP_WIDTH - map_width) / 2
  end
end

#search_pokemon_zoneTable

Search the pokemon encounter zone, return i

Returns:

  • (Table)

    the table where the pokemon spawn



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
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 641

def search_pokemon_zone
  # Initialize
  grid = data_world_map(@worldmap_id).grid
  creature_zones = Table.new(grid.first.size, grid.size)
  return creature_zones unless @pokemon

  # Test each world map case
  0.upto(creature_zones.xsize - 1) do |x|
    0.upto(creature_zones.ysize - 1) do |y|
      next if (zone_id = grid[y][x] || -1) < 0 # No zone = no pokemon

      # Check the roaming pokemon
      zone = data_zone(zone_id)
      $wild_battle.roaming_pokemons.each do |infos|
        next unless zone.maps.include?(infos.map_id)
        next unless infos.pokemon.id == @pokemon.id

        creature_zones[x, y] = 1
        infos.spotted = true
        break
      end
      next if creature_zones[x, y] > 0

      # Check the group
      db_symbol = @pokemon.db_symbol
      # @type [Array<Studio::Group>]
      groups = zone.wild_groups.map { |group_db_symbol| data_group(group_db_symbol) }
      creature_zones[x, y] = 1 if groups.any? { |group| group.encounters.any? { |encounter| encounter.specie == db_symbol } }
    end
  end
  # Return the table to display
  return creature_zones
end

#set_bounds

Method retreiving the boundaries of the worldmap



412
413
414
415
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 412

def set_bounds
  @x_max = (@map_worldmap.width - 2 * BitmapOffset) / TileSize
  @y_max = (@map_worldmap.height - 2 * BitmapOffset) / TileSize
end

#set_pokemon(pkm, forced_worldmap_id = nil)

Set the pokemon to display

Parameters:

  • pkm (PFM::Pokemon)

    the pokemon object

  • forced_worldmap_id (Integer, nil) (defaults to: nil)

    the worldmap to display, if nil, the best one will be picked



452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 452

def set_pokemon(pkm, forced_worldmap_id = nil)
  # Update the information
  @pokemon = pkm
  @ui_infobox.data = pkm
  return unless @mode == :pokedex && pkm

  # Update the worldmap display
  wm_id = forced_worldmap_id
  wm_id ||= $pokedex.best_worldmap_for_creature(pkm.db_symbol)
  set_worldmap(wm_id)
  # Display the unkown zone alert
  @ui_unknown_zone.visible = @marker_zones.empty?
end

#set_worldmap(id)

Change the display worldmap

Parameters:

  • id (Integer)

    the worldmap id to display



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 419

def set_worldmap(id)
  # Update the worldmap
  @worldmap_id = id
  @map_worldmap.set_bitmap(data_world_map(@worldmap_id).image, :interface)
  recenter_map
  @ui_infobox.set_region(data_world_map(@worldmap_id).name)
  # Update player
  set_bounds
  init_cursor_and_player
  # Display available fly zones
  dispose_zone_and_marker
  display_fly_zones
  display_roaming_pokemons
  display_pokemon_zones
  display_custom_icons
  # Update location display
  update_infobox
end

#set_zone_rect(zones_tab, x, y, sprite)

Change the zone appearence to match the neighbour

Parameters:

  • zones_tab (Table)

    the zones data

  • x (Integer)

    the x coord

  • y (Integer)

    the y coord

  • sprite (Sprite)

    the sprite to setup



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
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 606

def set_zone_rect(zones_tab, x, y, sprite)
  code = 0
  [1, 2, 3, 4].each_with_index do |dir, index|
    nx = x + (dir == 2 ? -1 : dir == 3 ? 1 : 0)
    ny = y + (dir == 4 ? -1 : dir == 1 ? 1 : 0)
    tile = zones_tab[nx, ny]
    code |= ((tile || 0) << index)
  end
  case code # :down, :left, :right, :up
  when 0b0000 then sprite.set_rect_div(0, 0, 5, 5)
  # End
  when 0b1000 then sprite.set_rect_div(0, 3, 5, 5)
  when 0b0100 then sprite.set_rect_div(0, 4, 5, 5)
  when 0b0010 then sprite.set_rect_div(2, 4, 5, 5)
  when 0b0001 then sprite.set_rect_div(0, 1, 5, 5)
  # Line
  when 0b0110 then sprite.set_rect_div(1, 4, 5, 5)
  when 0b1001 then sprite.set_rect_div(0, 2, 5, 5)
  # Angles
  when 0b1100 then sprite.set_rect_div(1, 3, 5, 5)
  when 0b1010 then sprite.set_rect_div(2, 3, 5, 5)
  when 0b0101 then sprite.set_rect_div(1, 2, 5, 5)
  when 0b0011 then sprite.set_rect_div(2, 2, 5, 5)
  # Edges
  when 0b1110 then sprite.set_rect_div(2, 0, 5, 5)
  when 0b1101 then sprite.set_rect_div(1, 1, 5, 5)
  when 0b1011 then sprite.set_rect_div(2, 1, 5, 5)
  when 0b0111 then sprite.set_rect_div(1, 0, 5, 5)
  # Cross
  else sprite.set_rect_div(4, 0, 5, 5)
  end
end

#update_background_animation

Update the background sprite animation



233
234
235
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 233

def update_background_animation
  @bg_background.set_origin((@bg_background.ox - 0.5) % 16, (@bg_background.oy - 0.5) % 16)
end

#update_button_input

Update the buttons triggered



286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 286

def update_button_input
  # Quit map if B triggered
  return @running = false if Input.trigger?(:B)

  # Toggle zoom if allowed
  on_toggle_zoom if ZoomEnabled && Input.trigger?(:X)
  # No more input if wall view
  return if @mode == :view_wall

  # Load the next worldmap
  on_next_worldmap if Input.trigger?(:Y)
  return on_fly_attempt if @mode == :fly && Input.trigger?(:A)
end

#update_cursor_animation

Update the cursor sprite animation



238
239
240
241
242
243
244
245
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 238

def update_cursor_animation
  @cursor_animation_counter += 1
  if @cursor_animation_counter == CursorAnimationDuration / 2
    @cursor.src_rect.y = @cursor.src_rect.height
  elsif @cursor_animation_counter == CursorAnimationDuration
    @cursor.src_rect.y = @cursor_animation_counter = 0
  end
end

#update_cursor_position_dir8

Update the cursor position using Input.dir8



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 339

def update_cursor_position_dir8
  case (dir8 = Input.dir8)
  when 1, 4, 7
    @x -= 1
  when 3, 6, 9
    @x += 1
  end
  case dir8
  when 7, 8, 9
    @y -= 1
  when 1, 2, 3
    @y += 1
  end
  @y = 0 if @y < 0
  @x = 0 if @x < 0
  @y = @y_max - 1 if @y >= @y_max
  @x = @x_max - 1 if @x >= @x_max
end

#update_dir_input

Get the direction 8 input and process it on the cursor



273
274
275
276
277
278
279
280
281
282
283
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 273

def update_dir_input
  return if @cursor_move_count

  @last_x = @x
  @last_y = @y
  update_cursor_position_dir8
  if @last_x != @x || @last_y != @y
    @cursor_move_count = 0
    update_infobox
  end
end

#update_display_origin

Calculate the variables @map_display_ox and @map_display_oy



317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 317

def update_display_origin
  max_x = VMapWidth / TileSize * TileSize  - TileSize
  max_y = VMapHeight / TileSize * TileSize - TileSize
  if @cursor.x < @map_display_ox
    @map_display_ox = @cursor.x
  elsif @cursor.x - @map_display_ox >= max_x
    @map_display_ox = @cursor.x - max_x
  end
  if @cursor.y < @map_display_oy
    @map_display_oy = @cursor.y
  elsif @cursor.y - @map_display_oy >= max_y
    @map_display_oy = @cursor.y - max_y
  end
end

#update_display_position

Update the map position



333
334
335
336
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 333

def update_display_position
  @viewport_map.ox = @viewport_map_cursor.ox = @viewport_map_zones.ox = @viewport_map_markers.ox = @map_display_ox + @map_display_ox_offset
  @viewport_map.oy = @viewport_map_cursor.oy = @viewport_map_zones.oy = @viewport_map_markers.oy = @map_display_oy + @map_display_oy_offset
end

#update_graphics

Update the graphics



96
97
98
99
100
101
102
103
104
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 96

def update_graphics
  # Update animations
  update_background_animation
  update_cursor_animation
  update_zones_animation
  # Update positions
  update_move
  update_display_position
end

#update_infobox

Method updating the infobox sprites



359
360
361
362
363
364
365
366
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 359

def update_infobox
  zone = $env.get_zone(@x, @y, @worldmap_id)
  if zone
    @ui_infobox.set_location(zone.name)
  else
    @ui_infobox.set_location '...'
  end
end

#update_inputs

Update the inputs



90
91
92
93
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 90

def update_inputs
  update_dir_input
  update_button_input
end

#update_move

Update the cursor movement



301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 301

def update_move
  return unless @cursor_move_count

  # Update cursor position
  @cursor.x = BitmapOffset + @map_worldmap.x + TileSize * @last_x + (@x - @last_x) *
              @cursor_move_count * TileSize / CursorMoveDuration
  @cursor.y = BitmapOffset + @map_worldmap.y + TileSize * @last_y + (@y - @last_y) *
              @cursor_move_count * TileSize / CursorMoveDuration
  # Update display coords
  update_display_origin
  # Update counter
  @cursor_move_count += 1
  @cursor_move_count = false if @cursor_move_count > CursorMoveDuration
end

#update_zones_animation

Update the animation of the zones



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 248

def update_zones_animation
  return if @marker_zones.empty? # No zones, no animation

  # Backroll indicate if the color filter become more transparency ou less
  if @zone_animation_backroll
    @zone_animation_counter -= 1
    @zone_animation_backroll = @zone_animation_counter >= 0
  else
    @zone_animation_counter += 1
    @zone_animation_backroll = @zone_animation_counter >= 100
  end
  # Update the color filter considering the mode
  case @mode
  when :pokedex, :view
    color = PROC_ZONE_COLOR.call @zone_animation_counter
  when :fly
    color = PROC_FLY_ZONE_COLOR.call @zone_animation_counter
  else
    color = [0, 0, 0, 1] # No color (white)
  end
  # Update the color of each sprite
  @marker_zones.each { |zone| zone.set_color(color) }
end

#visible=(value)



106
107
108
109
110
111
112
113
114
# File 'scripts/01450 Systems/00206 TownMap/00003 GamePlay/00400 WorldMap.rb', line 106

def visible=(value)
  super
  @viewport_background.visible = value
  @viewport_map.visible = value
  @viewport_map_zones.visible = value
  @viewport_map_markers.visible = value
  @viewport_map_cursor.visible = value
  @viewport_ui.visible = value
end