Module: Transparency

Included in:
Entity
Defined in:
lib/game_2d/transparency.rb

Instance Method Summary collapse

Instance Method Details

#transparent?(one, two) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/game_2d/transparency.rb', line 10

def transparent?(one, two)
  # Walls and titanium: transparent to absolutely nothing
  return false if wall?(one) || wall?(two)

  # Teleporter destinations: transparent to everything
  return true if destination?(one) || destination?(two)

  # Teleporters: transparent to everything except other
  # teleporters, and destinations
  return teleporter_ok?(one, two) if teleporter?(one)
  return teleporter_ok?(two, 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)

  # Should only get here if both objects are players
  fail("Huh?  one=#{one}, two=#{two}") unless
    one.is_a?(Player) && two.is_a?(Player)
  false
end