class Goby::Map

A 2D arrangement of Tiles. The Player can move around on it.

Attributes

music[RW]
name[RW]
tiles[RW]

Public Class Methods

new(name: "Map", tiles: [[Tile.new]], music: nil) click to toggle source

@param [String] name the name. @param [[Tile]] tiles the content of the map.

# File lib/goby/map/map.rb, line 8
def initialize(name: "Map", tiles: [[Tile.new]], music: nil)
  @name = name
  @tiles = tiles
  @music = music
end

Public Instance Methods

==(rhs) click to toggle source

@param [Map] rhs the Map on the right.

# File lib/goby/map/map.rb, line 37
def ==(rhs)
  return @name == rhs.name
end
in_bounds(y, x) click to toggle source

Returns true when @tiles[x] is an existing index of @tiles. Otherwise, returns false.

@param [Integer] y the y-coordinate. @param [Integer] x the x-coordinate. @return [Boolean] the existence of the tile.

# File lib/goby/map/map.rb, line 20
def in_bounds(y, x)
  return (y.nonnegative? && y < @tiles.length && x.nonnegative? && x < @tiles[y].length)
end
to_s() click to toggle source

Prints the map in a nice format.

# File lib/goby/map/map.rb, line 25
def to_s
  output = ""
  @tiles.each do |row|
    row.each do |tile|
      output += (tile.graphic + " ")
    end
    output += "\n"
  end
  return output
end