class Cell

Cell is a portion of the game space, the exact size of one entity. The cell (0,0) contains subpixel coordinates (0,0) through (399,399).

The behavior I want from Cells is to consider them all unique objects. I want to be able to say “Subtract this set of cells from that set”. Treating Cells as equal if their contents are equal defeats this purpose.

It’s also handy if each Cell knows where it lives in the grid.

Previously, I was using Set as the superclass. That seemed to make sense, since this is an unordered collection. But Set stores everything as hash keys, and hashes get very confused if their keys get mutated without going through the API.

Constants

SORT_BY_REGISTRY

Attributes

x[R]
y[R]

Public Class Methods

new(cell_x, cell_y) click to toggle source
Calls superclass method
# File lib/game_2d/game_space.rb, line 46
def initialize(cell_x, cell_y)
  @a = []
  @x, @y = cell_x, cell_y
  super(@a)
end

Public Instance Methods

==(other) click to toggle source
# File lib/game_2d/game_space.rb, line 39
def ==(other)
  other.class.equal?(self.class) &&
    other.x == self.x &&
    other.y == self.y &&
    other.instance_variable_get(:@a).sort(&SORT_BY_REGISTRY) == @a.sort(&SORT_BY_REGISTRY)
end
inspect() click to toggle source
# File lib/game_2d/game_space.rb, line 53
def inspect; "Cell(#{x}, #{y}) #{@a}"; end
to_s() click to toggle source
# File lib/game_2d/game_space.rb, line 52
def to_s; "(#{x}, #{y}) [#{@a.join(', ')}]"; end