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)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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