Class: Game_Map

Inherits:
Object
  • Object
show all
Defined in:
Game_Map.rb

Overview

** Game_Map


This class handles maps. It includes scrolling and passage determination

functions. The instance of this class is referenced by $game_map.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Game_Map) initialize


  • Object Initialization




26
27
28
29
30
31
32
33
34
35
# File 'Game_Map.rb', line 26

def initialize
  @screen = Game_Screen.new
  @interpreter = Game_Interpreter.new
  @map_id = 0
  @events = {}
  @display_x = 0
  @display_y = 0
  create_vehicles
  @name_display = true
end

Instance Attribute Details

- (Object) battleback1_name (readonly)

battle background (floor) filename



19
20
21
# File 'Game_Map.rb', line 19

def battleback1_name
  @battleback1_name
end

- (Object) battleback2_name (readonly)

battle background (wall) filename



20
21
22
# File 'Game_Map.rb', line 20

def battleback2_name
  @battleback2_name
end

- (Object) display_x (readonly)

display X coordinate



15
16
17
# File 'Game_Map.rb', line 15

def display_x
  @display_x
end

- (Object) display_y (readonly)

display Y coordinate



16
17
18
# File 'Game_Map.rb', line 16

def display_y
  @display_y
end

- (Object) events (readonly)

events



14
15
16
# File 'Game_Map.rb', line 14

def events
  @events
end

- (Object) interpreter (readonly)

map event interpreter



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

def interpreter
  @interpreter
end

- (Object) name_display

map name display flag



21
22
23
# File 'Game_Map.rb', line 21

def name_display
  @name_display
end

- (Object) need_refresh

refresh request flag



22
23
24
# File 'Game_Map.rb', line 22

def need_refresh
  @need_refresh
end

- (Object) parallax_name (readonly)

parallax background filename



17
18
19
# File 'Game_Map.rb', line 17

def parallax_name
  @parallax_name
end

- (Object) screen (readonly)


  • Public Instance Variables




12
13
14
# File 'Game_Map.rb', line 12

def screen
  @screen
end

- (Object) vehicles (readonly)

vehicle



18
19
20
# File 'Game_Map.rb', line 18

def vehicles
  @vehicles
end

Instance Method Details

- (Object) adjust_x(x)


  • Calculate X Coordinate, Minus Display Coordinate




267
268
269
270
271
272
273
# File 'Game_Map.rb', line 267

def adjust_x(x)
  if loop_horizontal? && x < @display_x - (width - screen_tile_x) / 2
    x - @display_x + @map.width
  else
    x - @display_x
  end
end

- (Object) adjust_y(y)


  • Calculate Y Coordinate, Minus Display Coordinate




277
278
279
280
281
282
283
# File 'Game_Map.rb', line 277

def adjust_y(y)
  if loop_vertical? && y < @display_y - (height - screen_tile_y) / 2
    y - @display_y + @map.height
  else
    y - @display_y
  end
end

- (Object) airship


  • Get Airship




91
92
93
# File 'Game_Map.rb', line 91

def airship
  @vehicles[2]
end

- (Boolean) airship_land_ok?(x, y)


  • Determine if Airship can Land


Returns:

  • (Boolean)


495
496
497
# File 'Game_Map.rb', line 495

def airship_land_ok?(x, y)
  check_passage(x, y, 0x0800) && check_passage(x, y, 0x0f)
end

- (Object) all_tiles(x, y)


  • Get Array of All Tiles (Including Events) at Specified Coordinates




462
463
464
# File 'Game_Map.rb', line 462

def all_tiles(x, y)
  tile_events_xy(x, y).collect {|ev| ev.tile_id } + layered_tiles(x, y)
end

- (Boolean) any_event_starting?


  • Determine Existence of Starting Map Event


Returns:

  • (Boolean)


682
683
684
# File 'Game_Map.rb', line 682

def any_event_starting?
  @events.values.any? {|event| event.starting }
end

- (Object) autoplay


  • Automatically Switch BGM and BGS




327
328
329
330
# File 'Game_Map.rb', line 327

def autoplay
  @map.bgm.play if @map.autoplay_bgm
  @map.bgs.play if @map.autoplay_bgs
end

- (Object) autotile_type(x, y, z)


  • Get Type of Auto Tile at Specified Coordinates




468
469
470
# File 'Game_Map.rb', line 468

def autotile_type(x, y, z)
  tile_id(x, y, z) >= 2048 ? (tile_id(x, y, z) - 2048) / 48 : -1
end

- (Object) boat


  • Get Boat




79
80
81
# File 'Game_Map.rb', line 79

def boat
  @vehicles[0]
end

- (Boolean) boat_passable?(x, y)


  • Determine if Passable by Boat


Returns:

  • (Boolean)


483
484
485
# File 'Game_Map.rb', line 483

def boat_passable?(x, y)
  check_passage(x, y, 0x0200)
end

- (Boolean) bush?(x, y)


  • Determine if Bush


Returns:

  • (Boolean)


513
514
515
# File 'Game_Map.rb', line 513

def bush?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x40)
end

- (Object) change_battleback(battleback1_name, battleback2_name)


  • Change Battle Background




633
634
635
636
# File 'Game_Map.rb', line 633

def change_battleback(battleback1_name, battleback2_name)
  @battleback1_name = battleback1_name
  @battleback2_name = battleback2_name
end

- (Object) change_parallax(name, loop_x, loop_y, sx, sy)


  • Change Parallax Background




640
641
642
643
644
645
646
647
648
# File 'Game_Map.rb', line 640

def change_parallax(name, loop_x, loop_y, sx, sy)
  @parallax_name = name
  @parallax_x = 0 if @parallax_loop_x && !loop_x
  @parallax_y = 0 if @parallax_loop_y && !loop_y
  @parallax_loop_x = loop_x
  @parallax_loop_y = loop_y
  @parallax_sx = sx
  @parallax_sy = sy
end

- (Object) change_tileset(tileset_id)


  • Change Tileset




626
627
628
629
# File 'Game_Map.rb', line 626

def change_tileset(tileset_id)
  @tileset_id = tileset_id
  refresh
end

- (Object) check_passage(x, y, bit)


  • Check Passage

    bit:  Inhibit passage check bit



438
439
440
441
442
443
444
445
446
# File 'Game_Map.rb', line 438

def check_passage(x, y, bit)
  all_tiles(x, y).each do |tile_id|
    flag = tileset.flags[tile_id]
    next if flag & 0x10 != 0            # [☆]: No effect on passage
    return true  if flag & bit == 0     # [○] : Passable
    return false if flag & bit == bit   # [×] : Impassable
  end
  return false                          # Impassable
end

- (Boolean) counter?(x, y)


  • Determine if Counter


Returns:

  • (Boolean)


519
520
521
# File 'Game_Map.rb', line 519

def counter?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x80)
end

- (Object) create_vehicles


  • Create Vehicles




55
56
57
58
59
60
# File 'Game_Map.rb', line 55

def create_vehicles
  @vehicles = []
  @vehicles[0] = Game_Vehicle.new(:boat)
  @vehicles[1] = Game_Vehicle.new(:ship)
  @vehicles[2] = Game_Vehicle.new(:airship)
end

- (Boolean) damage_floor?(x, y)


  • Determine if Damage Floor


Returns:

  • (Boolean)


525
526
527
# File 'Game_Map.rb', line 525

def damage_floor?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x100)
end

- (Object) data


  • Get Map Data




243
244
245
# File 'Game_Map.rb', line 243

def data
  @map.data
end

- (Boolean) disable_dash?


  • Get Whether Dash is Disabled


Returns:

  • (Boolean)


225
226
227
# File 'Game_Map.rb', line 225

def disable_dash?
  @map.disable_dashing
end

- (Object) display_name


  • Get Display Name




195
196
197
# File 'Game_Map.rb', line 195

def display_name
  @map.display_name
end

- (Object) do_scroll(direction, distance)


  • Execute Scroll




595
596
597
598
599
600
601
602
# File 'Game_Map.rb', line 595

def do_scroll(direction, distance)
  case direction
  when 2;  scroll_down (distance)
  when 4;  scroll_left (distance)
  when 6;  scroll_right(distance)
  when 8;  scroll_up   (distance)
  end
end

- (Object) encounter_list


  • Get Encounter List




231
232
233
# File 'Game_Map.rb', line 231

def encounter_list
  @map.encounter_list
end

- (Object) encounter_step


  • Get Encounter Steps




237
238
239
# File 'Game_Map.rb', line 237

def encounter_step
  @map.encounter_step
end

- (Object) event_id_xy(x, y)


  • Get ID of Events at Designated Coordinates (One Only)




368
369
370
371
# File 'Game_Map.rb', line 368

def event_id_xy(x, y)
  list = events_xy(x, y)
  list.empty? ? 0 : list[0].id
end

- (Object) events_xy(x, y)


  • Get Array of Events at Designated Coordinates




349
350
351
# File 'Game_Map.rb', line 349

def events_xy(x, y)
  @events.values.select {|event| event.pos?(x, y) }
end

- (Object) events_xy_nt(x, y)


  • Get Array of Events at Designated Coordinates (Except Pass-Through)




355
356
357
# File 'Game_Map.rb', line 355

def events_xy_nt(x, y)
  @events.values.select {|event| event.pos_nt?(x, y) }
end

- (Object) height


  • Get Height




207
208
209
# File 'Game_Map.rb', line 207

def height
  @map.height
end

- (Boolean) ladder?(x, y)


  • Determine if Ladder


Returns:

  • (Boolean)


507
508
509
# File 'Game_Map.rb', line 507

def ladder?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x20)
end

- (Object) layered_tiles(x, y)


  • Get Array of All Layer Tiles (Top to Bottom) at Specified Coordinates




456
457
458
# File 'Game_Map.rb', line 456

def layered_tiles(x, y)
  [2, 1, 0].collect {|z| tile_id(x, y, z) }
end

- (Boolean) layered_tiles_flag?(x, y, bit)


  • Determine Flag for All Layers at Specified Coordinates


Returns:

  • (Boolean)


501
502
503
# File 'Game_Map.rb', line 501

def layered_tiles_flag?(x, y, bit)
  layered_tiles(x, y).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }
end

- (Boolean) loop_horizontal?


  • Loop Horizontally?


Returns:

  • (Boolean)


213
214
215
# File 'Game_Map.rb', line 213

def loop_horizontal?
  @map.scroll_type == 2 || @map.scroll_type == 3
end

- (Boolean) loop_vertical?


  • Loop Vertically?


Returns:

  • (Boolean)


219
220
221
# File 'Game_Map.rb', line 219

def loop_vertical?
  @map.scroll_type == 1 || @map.scroll_type == 3
end

- (Object) map_id


  • Get Map ID




183
184
185
# File 'Game_Map.rb', line 183

def map_id
  @map_id
end

- (Boolean) overworld?


  • Determine if Field Type


Returns:

  • (Boolean)


249
250
251
# File 'Game_Map.rb', line 249

def overworld?
  tileset.mode == 0
end

- (Object) parallax_ox(bitmap)


  • Calculate X Coordinate of Parallax Display Origin




159
160
161
162
163
164
165
166
167
# File 'Game_Map.rb', line 159

def parallax_ox(bitmap)
  if @parallax_loop_x
    @parallax_x * 16
  else
    w1 = [bitmap.width - Graphics.width, 0].max
    w2 = [width * 32 - Graphics.width, 1].max
    @parallax_x * 16 * w1 / w2
  end
end

- (Object) parallax_oy(bitmap)


  • Calculate Y Coordinate of Parallax Display Origin




171
172
173
174
175
176
177
178
179
# File 'Game_Map.rb', line 171

def parallax_oy(bitmap)
  if @parallax_loop_y
    @parallax_y * 16
  else
    h1 = [bitmap.height - Graphics.height, 0].max
    h2 = [height * 32 - Graphics.height, 1].max
    @parallax_y * 16 * h1 / h2
  end
end

- (Object) parallel_common_events


  • Get Array of Parallel Common Events




110
111
112
# File 'Game_Map.rb', line 110

def parallel_common_events
  $data_common_events.select {|event| event && event.parallel? }
end

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


  • Determine Passability of Normal Character

     d:  direction (2,4,6,8)
    Determines whether the tile at the specified coordinates is passable
    in the specified direction.

Returns:

  • (Boolean)


477
478
479
# File 'Game_Map.rb', line 477

def passable?(x, y, d)
  check_passage(x, y, (1 << (d / 2 - 1)) & 0x0f)
end

- (Object) referesh_vehicles


  • Refresh Vehicles




64
65
66
# File 'Game_Map.rb', line 64

def referesh_vehicles
  @vehicles.each {|vehicle| vehicle.refresh }
end

- (Object) refresh


  • Refresh




334
335
336
337
338
339
# File 'Game_Map.rb', line 334

def refresh
  @events.each_value {|event| event.refresh }
  @common_events.each {|event| event.refresh }
  refresh_tile_events
  @need_refresh = false
end

- (Object) refresh_tile_events


  • Refresh Array of Tile-Handling Events




343
344
345
# File 'Game_Map.rb', line 343

def refresh_tile_events
  @tile_events = @events.values.select {|event| event.tile? }
end

- (Object) region_id(x, y)


  • Get Region ID




542
543
544
# File 'Game_Map.rb', line 542

def region_id(x, y)
  valid?(x, y) ? @map.data[x, y, 3] >> 8 : 0
end

- (Object) round_x(x)


  • Calculate X Coordinate After Loop Adjustment




287
288
289
# File 'Game_Map.rb', line 287

def round_x(x)
  loop_horizontal? ? (x + width) % width : x
end

- (Object) round_x_with_direction(x, d)


  • Calculate X Coordinate Shifted One Tile in Specific Direction (With Loop Adjustment)




314
315
316
# File 'Game_Map.rb', line 314

def round_x_with_direction(x, d)
  round_x(x + (d == 6 ? 1 : d == 4 ? -1 : 0))
end

- (Object) round_y(y)


  • Calculate Y Coordinate After Loop Adjustment




293
294
295
# File 'Game_Map.rb', line 293

def round_y(y)
  loop_vertical? ? (y + height) % height : y
end

- (Object) round_y_with_direction(y, d)


  • Calculate Y Coordinate Shifted One Tile in Specific Direction (With Loop Adjustment)




321
322
323
# File 'Game_Map.rb', line 321

def round_y_with_direction(y, d)
  round_y(y + (d == 2 ? 1 : d == 8 ? -1 : 0))
end

- (Object) screen_tile_x


  • Number of Horizontal Tiles on Screen




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

def screen_tile_x
  Graphics.width / 32
end

- (Object) screen_tile_y


  • Number of Vertical Tiles on Screen




261
262
263
# File 'Game_Map.rb', line 261

def screen_tile_y
  Graphics.height / 32
end

- (Object) scroll_distance


  • Calculate Scroll Distance




589
590
591
# File 'Game_Map.rb', line 589

def scroll_distance
  2 ** @scroll_speed / 256.0
end

- (Object) scroll_down(distance)


  • Scroll Down




375
376
377
378
379
380
381
382
383
384
385
# File 'Game_Map.rb', line 375

def scroll_down(distance)
  if loop_vertical?
    @display_y += distance
    @display_y %= @map.height
    @parallax_y += distance if @parallax_loop_y
  else
    last_y = @display_y
    @display_y = [@display_y + distance, height - screen_tile_y].min
    @parallax_y += @display_y - last_y
  end
end

- (Object) scroll_left(distance)


  • Scroll Left




389
390
391
392
393
394
395
396
397
398
399
# File 'Game_Map.rb', line 389

def scroll_left(distance)
  if loop_horizontal?
    @display_x += @map.width - distance
    @display_x %= @map.width 
    @parallax_x -= distance if @parallax_loop_x
  else
    last_x = @display_x
    @display_x = [@display_x - distance, 0].max
    @parallax_x += @display_x - last_x
  end
end

- (Object) scroll_right(distance)


  • Scroll Right




403
404
405
406
407
408
409
410
411
412
413
# File 'Game_Map.rb', line 403

def scroll_right(distance)
  if loop_horizontal?
    @display_x += distance
    @display_x %= @map.width
    @parallax_x += distance if @parallax_loop_x
  else
    last_x = @display_x
    @display_x = [@display_x + distance, (width - screen_tile_x)].min
    @parallax_x += @display_x - last_x
  end
end

- (Object) scroll_up(distance)


  • Scroll Up




417
418
419
420
421
422
423
424
425
426
427
# File 'Game_Map.rb', line 417

def scroll_up(distance)
  if loop_vertical?
    @display_y += @map.height - distance
    @display_y %= @map.height
    @parallax_y -= distance if @parallax_loop_y
  else
    last_y = @display_y
    @display_y = [@display_y - distance, 0].max
    @parallax_y += @display_y - last_y
  end
end

- (Boolean) scrolling?


  • Determine if Scrolling


Returns:

  • (Boolean)


556
557
558
# File 'Game_Map.rb', line 556

def scrolling?
  @scroll_rest > 0
end

- (Object) set_display_pos(x, y)


  • Set Display Position




148
149
150
151
152
153
154
155
# File 'Game_Map.rb', line 148

def set_display_pos(x, y)
  x = [0, [x, width - screen_tile_x].min].max unless loop_horizontal?
  y = [0, [y, height - screen_tile_y].min].max unless loop_vertical?
  @display_x = (x + width) % width
  @display_y = (y + height) % height
  @parallax_x = x
  @parallax_y = y
end

- (Object) setup(map_id)


  • Setup




39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'Game_Map.rb', line 39

def setup(map_id)
  @map_id = map_id
  @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
  @tileset_id = @map.tileset_id
  @display_x = 0
  @display_y = 0
  referesh_vehicles
  setup_events
  setup_scroll
  setup_parallax
  setup_battleback
  @need_refresh = false
end

- (Object) setup_autorun_common_event


  • Detect/Set Up Autorun Common Event




697
698
699
700
701
702
703
# File 'Game_Map.rb', line 697

def setup_autorun_common_event
  event = $data_common_events.find do |event|
    event && event.autorun? && $game_switches[event.switch_id]
  end
  @interpreter.setup(event.list) if event
  event
end

- (Object) setup_battleback


  • Set Up Battle Background




136
137
138
139
140
141
142
143
144
# File 'Game_Map.rb', line 136

def setup_battleback
  if @map.specify_battleback
    @battleback1_name = @map.battleback1_name
    @battleback2_name = @map.battleback2_name
  else
    @battleback1_name = nil
    @battleback2_name = nil
  end
end

- (Object) setup_events


  • Event Setup




97
98
99
100
101
102
103
104
105
106
# File 'Game_Map.rb', line 97

def setup_events
  @events = {}
  @map.events.each do |i, event|
    @events[i] = Game_Event.new(@map_id, event)
  end
  @common_events = parallel_common_events.collect do |common_event|
    Game_CommonEvent.new(common_event.id)
  end
  refresh_tile_events
end

- (Object) setup_parallax


  • Parallax Background Setup




124
125
126
127
128
129
130
131
132
# File 'Game_Map.rb', line 124

def setup_parallax
  @parallax_name = @map.parallax_name
  @parallax_loop_x = @map.parallax_loop_x
  @parallax_loop_y = @map.parallax_loop_y
  @parallax_sx = @map.parallax_sx
  @parallax_sy = @map.parallax_sy
  @parallax_x = 0
  @parallax_y = 0
end

- (Object) setup_scroll


  • Scroll Setup




116
117
118
119
120
# File 'Game_Map.rb', line 116

def setup_scroll
  @scroll_direction = 2
  @scroll_rest = 0
  @scroll_speed = 4
end

- (Object) setup_starting_event


  • Starting Event Setup




672
673
674
675
676
677
678
# File 'Game_Map.rb', line 672

def setup_starting_event
  refresh if @need_refresh
  return true if @interpreter.setup_reserved_common_event
  return true if setup_starting_map_event
  return true if setup_autorun_common_event
  return false
end

- (Object) setup_starting_map_event


  • Detect/Set Up Starting Map Event




688
689
690
691
692
693
# File 'Game_Map.rb', line 688

def setup_starting_map_event
  event = @events.values.find {|event| event.starting }
  event.clear_starting_flag if event
  @interpreter.setup(event.list, event.id) if event
  event
end

- (Object) ship


  • Get Ship




85
86
87
# File 'Game_Map.rb', line 85

def ship
  @vehicles[1]
end

- (Boolean) ship_passable?(x, y)


  • Determine if Passable by Ship


Returns:

  • (Boolean)


489
490
491
# File 'Game_Map.rb', line 489

def ship_passable?(x, y)
  check_passage(x, y, 0x0400)
end

- (Object) start_scroll(direction, distance, speed)


  • Start Scroll




548
549
550
551
552
# File 'Game_Map.rb', line 548

def start_scroll(direction, distance, speed)
  @scroll_direction = direction
  @scroll_rest = distance
  @scroll_speed = speed
end

- (Object) terrain_tag(x, y)


  • Get Terrain Tag




531
532
533
534
535
536
537
538
# File 'Game_Map.rb', line 531

def terrain_tag(x, y)
  return 0 unless valid?(x, y)
  layered_tiles(x, y).each do |tile_id|
    tag = tileset.flags[tile_id] >> 12
    return tag if tag > 0
  end
  return 0
end

- (Object) tile_events_xy(x, y)


  • Get Array of Tile-Handling Events at Designated Coordinates (Except Pass-Through)




362
363
364
# File 'Game_Map.rb', line 362

def tile_events_xy(x, y)
  @tile_events.select {|event| event.pos_nt?(x, y) }
end

- (Object) tile_id(x, y, z)


  • Get Tile ID at Specified Coordinates




450
451
452
# File 'Game_Map.rb', line 450

def tile_id(x, y, z)
  @map.data[x, y, z] || 0
end

- (Object) tileset


  • Get Tileset




189
190
191
# File 'Game_Map.rb', line 189

def tileset
  $data_tilesets[@tileset_id]
end

- (Object) unlock_event(event_id)


  • Unlock Event




666
667
668
# File 'Game_Map.rb', line 666

def unlock_event(event_id)
  @events[event_id].unlock if @events[event_id]
end

- (Object) update(main = false)


  • Frame Update

    main:  Interpreter update flag



563
564
565
566
567
568
569
570
571
# File 'Game_Map.rb', line 563

def update(main = false)
  refresh if @need_refresh
  update_interpreter if main
  update_scroll
  update_events
  update_vehicles
  update_parallax
  @screen.update
end

- (Object) update_events


  • Update Events




606
607
608
609
# File 'Game_Map.rb', line 606

def update_events
  @events.each_value {|event| event.update }
  @common_events.each {|event| event.update }
end

- (Object) update_interpreter


  • Update Interpreter




652
653
654
655
656
657
658
659
660
661
662
# File 'Game_Map.rb', line 652

def update_interpreter
  loop do
    @interpreter.update
    return if @interpreter.running?
    if @interpreter.event_id > 0
      unlock_event(@interpreter.event_id)
      @interpreter.clear
    end
    return unless setup_starting_event
  end
end

- (Object) update_parallax


  • Update Parallax




619
620
621
622
# File 'Game_Map.rb', line 619

def update_parallax
  @parallax_x += @parallax_sx / 64.0 if @parallax_loop_x
  @parallax_y += @parallax_sy / 64.0 if @parallax_loop_y
end

- (Object) update_scroll


  • Update Scroll




575
576
577
578
579
580
581
582
583
584
585
# File 'Game_Map.rb', line 575

def update_scroll
  return unless scrolling?
  last_x = @display_x
  last_y = @display_y
  do_scroll(@scroll_direction, scroll_distance)
  if @display_x == last_x && @display_y == last_y
    @scroll_rest = 0
  else
    @scroll_rest -= scroll_distance
  end
end

- (Object) update_vehicles


  • Update Vehicles




613
614
615
# File 'Game_Map.rb', line 613

def update_vehicles
  @vehicles.each {|vehicle| vehicle.update }
end

- (Boolean) valid?(x, y)


  • Determine Valid Coordinates


Returns:

  • (Boolean)


431
432
433
# File 'Game_Map.rb', line 431

def valid?(x, y)
  x >= 0 && x < width && y >= 0 && y < height
end

- (Object) vehicle(type)


  • Get Vehicle




70
71
72
73
74
75
# File 'Game_Map.rb', line 70

def vehicle(type)
  return @vehicles[0] if type == :boat
  return @vehicles[1] if type == :ship
  return @vehicles[2] if type == :airship
  return nil
end

- (Object) width


  • Get Width




201
202
203
# File 'Game_Map.rb', line 201

def width
  @map.width
end

- (Object) x_with_direction(x, d)


  • Calculate X Coordinate Shifted One Tile in Specific Direction (No Loop Adjustment)




300
301
302
# File 'Game_Map.rb', line 300

def x_with_direction(x, d)
  x + (d == 6 ? 1 : d == 4 ? -1 : 0)
end

- (Object) y_with_direction(y, d)


  • Calculate Y Coordinate Shifted One Tile in Specific Direction (No Loop Adjustment)




307
308
309
# File 'Game_Map.rb', line 307

def y_with_direction(y, d)
  y + (d == 2 ? 1 : d == 8 ? -1 : 0)
end