module Transparency

Public Instance Methods

transparent?(one, two) click to toggle source
# File lib/game_2d/transparency.rb, line 14
def transparent?(one, two)
  # Walls: transparent to absolutely nothing
  return false if wall?(one) || wall?(two)

  # Ghosts: transparent to everything except a wall
  return true if ghost?(one) || ghost?(two)

  # Titanium: transparent to nothing except ghosts
  return false if titanium?(one) || titanium?(two)

  # Holes and teleporter destinations: transparent to
  # everything except walls and titanium
  return true if transparent_to_most?(one) || transparent_to_most?(two)

  # Teleporters: transparent to everything except other
  # teleporters
  return teleporter_ok?(two) if teleporter?(one)
  return teleporter_ok?(one) if teleporter?(two)

  # Owned entities are transparent to the owner, and other
  # objects with the same owner
  return related_by_owner?(one, two) if owned?(one)
  return related_by_owner?(two, one) if owned?(two)

  # Bases are transparent to players, only
  return player?(two) if base?(one)
  return player?(one) if base?(two)

  # Default case: opaque
  # Should only get here if both objects are non-ghost players,
  # or slime
  fail("Huh?  one=#{one}, two=#{two}") unless
    normal?(one) && normal?(two)
  false
end

Private Instance Methods

base?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 81
def base?(entity)
  entity.is_a? Entity::Base
end
ghost?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 85
def ghost?(entity)
  entity.is_a? Entity::Ghost
end
normal?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 93
def normal?(entity)
  player?(entity) || entity.is_a?(Entity::Slime)
end
owned?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 77
def owned?(entity)
  entity.is_a? Entity::OwnedEntity
end
player?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 89
def player?(entity)
  entity.is_a?(Player)
end
teleporter?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 63
def teleporter?(entity)
  entity.is_a?(Entity::Teleporter)
end
teleporter_ok?(other) click to toggle source
# File lib/game_2d/transparency.rb, line 59
def teleporter_ok?(other)
  !teleporter?(other)
end
titanium?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 55
def titanium?(entity)
  entity.is_a?(Entity::Titanium)
end
transparent_to_most?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 67
def transparent_to_most?(entity)
  entity.is_a?(Entity::Destination) || entity.is_a?(Entity::Hole)
end
wall?(entity) click to toggle source
# File lib/game_2d/transparency.rb, line 51
def wall?(entity)
  entity.is_a?(Wall)
end