(Misc4 ^Opaque)

{define "CommonKeys"
  (#ATTACK
    "Killed by %i at (%u,%u)" From ,Class From ,Image From ,Loc (PopUp 4)
    LoseLevel
  )
  ('BACK IgnoreKey LocateMe)
  ('UP N Move)
  ('DOWN S Move)
  ('LEFT W Move)
  ('RIGHT E Move)
}

(&SetTransforms dup =@Transforms $Transform swap 0 swap SetInventory)

($Man
  Player Input
  (Image "MAN")
  (Help
    "This is the player character."
    "Push arrows to move or push enter to fly."
    "See the \iTransform:0\ icon the inventory tells you how many times you can fly."
  )
  ^Opaque
  (Height 100)
  (Density 500)
  (Strength 2)
  (Weight 1)
  (Climb 50)
  (INIT Level &SetTransforms)
  {CommonKeys}
  ('ENTER
    @Transforms if
      @Transforms 1 - &SetTransforms
      Destroy .
      $Bat Loc 0 Dir Create .
    then
  )
  (HIT From #TOUCH Dir 0 ,Send)
)

($Bat
  Player Input
  (Image "BAT")
  (Help
    "This is the player character, flying."
    "Push arrows to move or push enter to walk."
    "(Changing from flying to walking does not use up any \iTransform:0\)"
  )
  ^Opaque
  (Height 100)
  (Density 500)
  (Strength 1)
  (Weight 1)
  (Climb 100)
  {CommonKeys}
  ('ENTER
    ObjBelow ,Height 50 le if
      $Man Loc 0 Dir Create .
      Destroy .
    then
  )
)

($Floor
  (Image "FLOOR")
  (Help "There is nothing here.")
  (Density 2000)
)

($Wall
  (Image "WALL")
  (Help "Impassable.")
  ^Opaque
  (Density 1000)
  (Height 200)
  (Weight 100)
)

($Pillar
  (Image "PILLAR")
  (Help "Impassable, but pumpkins and ghosts can see through it.")
  (Density 999)
  (Height 200)
  (Weight 80)
)

($Stone
  (Image "STONE")
  (Help "Impassable.")
  ^Opaque
  (Density 999)
  (Height 160)
  (Weight 80)
)

($Door
  (Image "CDOOR" "ODOOR")
  (Help
    "The goal of the game is to go through this door."
    "You need all of the red vials in order to open the door."
  )
  ^Opaque
  (Density 1001)
  (Height 200)
  (Weight 100)
  (Arrivals InPlace)
  (:init Image if 0 else 200 then =Height)
  (INIT =:init)
  (CREATE =:init)
  (#OPEN 1 =Image =:init)
  (ARRIVED $Man Loc ObjClassAt $Bat Loc ObjClassAt lor if WinLevel then)
)

($RedVial
  (Image "VIALR")
  (Help "Collect all red vials to open the door and wake the ghosts.")
  ^Opaque
  (Density 500)
  (Height 150)
  (#TOUCH Destroy . $RedVial #NoOp 0 0 Broadcast lnot if 0 #OPEN 0 0 Broadcast . then bit21)
)

($CyanVial
  (Image "VIALC")
  (Help "Push this cyan vial into spikes to destroy them (and the vial).")
  ^Opaque
  (Density 500)
  (Height 150)
  Shovable
  (Weight 1)
  (HIT
    From $UpSpikes is if
      From ,Destroy .
      1 =Departed
      bit15
    then
  )
  (DEPARTED Destroy .)
)

($Transform
  (Image "TRNSFORM")
  (Help "Collecting this allows you to fly.")
  ^Opaque
  (Density 450)
  (Height 75)
  (#TOUCH @Transforms 1 + &SetTransforms Destroy . bit21)
)

($Block
  (Image "BLOCK")
  (Help "Can be pushed.")
  ^Opaque
  (Density 600)
  (Height 150)
  Shovable
  (Weight 1)
)

($ClayPot
  (Image "CLAYPOT")
  (Help "Can be pushed, and you can also fly over it.")
  ^Opaque
  (Density 600)
  (Height 75)
  Shovable
  (Weight 1)
)

($BlockSpecial
  (Image "SPBLOCK")
  (Help "Can be pushed; destroys spikes it touches (without destroying itself).")
  ^Opaque
  (Density 600)
  (Height 150)
  Shovable
  (Weight 1)
  (HIT
    From $UpSpikes is if
      From ,Destroy .
      bit15
    then
  )
)

($Spikes
  (Image "DSPIKE")
  (Help
    "This spikes can only be walked on once; after that the spikes are raised."
    "It is possible to fly over the spikes without triggering them."
  )
  (Density 1500)
  (PLAYERMOVING
    From Coloc From $Man is land if
      Destroy .
      $UpSpikes Loc 0 0 Create .
    then
  )
)

($UpSpikes
  (Image "UPSPIKE")
  (Help
    "You cannot walk here, but you can fly over these spikes."
    "The spikes can be removed by a Cyan Vial or Special Block."
  )
  (Density 1500)
  (Height 75)
)

($Arrow
  (Image "ARROWE" "ARROWN" "ARROWW" "ARROWS")
  (Help "Disallows passing through in the opposite direction.")
  (Density 1500)
  (:init Image 1 lsh =Dir)
  (INIT =:init)
  (CREATE =:init)
  (PLAYERMOVING Target From ,Dir Dir 4 bxor eq land)
)

($Pumpkin
  (Image "PUMPKIN")
  (Help
    "Kills you if it sees you in any of the four directions."
    "Some objects can block its view."
  )
  ^Opaque
  (Density 600)
  (Height 150)
  (:init Image 3 band 2 * =Dir)
  (INIT =:init)
  (CREATE =:init)
  (BEGIN_TURN (P Rook if F ,^Opaque again F #ATTACK next) .)
)

($Ghost
  (Image
    "SGHOSTE" "SGHOSTN" "SGHOSTW" "SGHOSTS"
    "WGHOSTE" "WGHOSTN" "WGHOSTW" "WGHOSTS"
  )
  (Help
    "Kills you if it sees you."
    "Some objects can block its view."
    "They cannot see you while sleeping; it wakes up if all red vials are collected."
  )
  ^Opaque
  (Density 600)
  (Height 150)
  (:init Image 3 band 2 * =Dir)
  (INIT =:init)
  (CREATE =:init)
  (BEGIN_TURN
    Image 4 - 2 * From Seek eq if
      (P if F ,^Opaque again F #ATTACK) .
    then
  )
  (#OPEN Image 4 bor =Image)
)

