debug = false
stats = false

-- variables
win_width  = love.graphics.getWidth()
win_height = love.graphics.getHeight()

--[[current_level = 1 -- level 1 thru 3 currently exist
staircases = {
  {['tl-x'] = 300, ['tr-x'] = 380, ['t-y'] = 700,
   ['bl-x'] = 590, ['br-x'] = 670, ['b-y'] = 1050},
  {['tl-x'] = 420, ['tr-x'] = 500, ['t-y'] = 360,
   ['bl-x'] = 80, ['br-x'] = 150, ['b-y'] = 700}
}]]

state = 'splash'  -- what state the game is in
playagain = true
quitgame = false

stairsactive = false
stairbase = false
stairmiddle = false
stairtop = false

--level1_base = 440
--level2_base = 100
pnum = 1
darkness = true

require('libs/AnAL')
require('game')
require('player')
require('callout')

function reset_game()
  darkness = true

  house.x = 0
  house.y = -600
  player[pnum].x = 10
  player[pnum].y = 488

  stairsactive = false
  stairbase = false
  stairmiddle = false
  stairtop = false

  callout.count = 0

  -- hiding spots
  hider_found = false
  detect_area = 100

  -- create hider player
  hider = Player.create(0,0, 80,112, 4)

  -- select random hiding spot
  rhide = love.math.random(3)

  -- init hider type
  if rhide == 1 then
    hider.x = 1826
    hider.y = 1072
    hider.x_out = hider.x - 160
  elseif rhide == 2 then
    hider.x = 2888
    hider.y = 1072
    hider.x_out = hider.x - 160
  elseif rhide == 3 then
    hider.x = 1450
    hider.y = 472
    hider.x_out = hider.x - 160
  end

  -- select player who's hiding
  if pnum == 1 then
    hidden_player = 'tommy'
  else
    hidden_player = "claire"
  end

  -- create "Claire" player object
  hider.anim[1] =
  newAnimation(love.graphics.newImage('assets/'..hidden_player..'-walk-rt.png'),
  80,112, 0.1,5)
  hider.anim[2] =
  newAnimation(love.graphics.newImage('assets/'..hidden_player..'-walk-lt.png'),
  80,112, 0.1,5)

  --[[hider.anim[3] =
  newAnimation(love.graphics.newImage('assets/claire-call-rt.png'),
  80,112, 0.1,1)
  hider.anim[4] =
  newAnimation(love.graphics.newImage('assets/claire-call-lt.png'),
  80,112, 0.1,1)]]



  --[[hiding_spot = {}
  hiding_spot[1] = {x = 1826, y = 1072}
  hiding_spot[2] = {x = 2888, y = 1072}
  hiding_spot[3] = {x = 1450, y = 472}

  rhide = 1 --love.math.random(3)
  hider = {x = hiding_spot[rhide].x, y = hiding_spot[rhide].y, anim = nil}
  if pnum == 1 then
    hidden_player = 'tommy-walk-rt.png'
  else
    hidden_player = "claire-walk-rt.png"
  end
  hider.anim = newAnimation(love.graphics.newImage('assets/'..hidden_player),
  80,112, 0.1,1)]]
end

function love.load(arg)
  -- load image assets

  -- start-screen
  startscreen = {x = 0, y = 0, img = nil}
  startscreen.img = love.graphics.newImage('assets/start-screen.png')

  -- game over
  --gameover = {x = 223, y = 190, w = 554, h = 220, img = nil}
  gameover = {x = 0, y = 0, w = 554, h = 220, img = nil}
  gameover.img = love.graphics.newImage('assets/gameover.png')

  -- house backdrop
  house = {x = 0, y = -600, w = 3000, h = 1200, speed = 3, img = nil}
  house.img = love.graphics.newImage('assets/house-map.png')
  -- house objects
  steps1 = {x = 330, y = 794, w = 662, h = 392, speed = house.speed, img = nil}
  steps1.img = love.graphics.newImage('assets/steps1.png')
  steps2 = {x = 338, y = 370, w = 476, h = 636, speed = house.speed, img = nil}
  steps2.img = love.graphics.newImage('assets/steps2.png')
  door = {x = 36, y = 705, w = 306, h = 552, speed = house.speed, img = nil}
  door.img = love.graphics.newImage('assets/door.png')
  large_plant = {x = 1730, y = 767, w = 334, h = 420, speed = house.speed, img = nil}
  large_plant.img = love.graphics.newImage('assets/large-plant.png')
  laundry_basket = {x = 1374, y = 448, w = 146, h = 140, speed = house.speed, img = nil}
  laundry_basket.img = love.graphics.newImage('assets/laundry-basket.png')
  towels = {x = 2822, y = 975, w = 160, h = 168, speed = house.speed, img = nil}
  towels.img = love.graphics.newImage('assets/towels.png')

  -- player object
  player = {}
  -- create "Claire" player object
  player[1] = Player.create(10,488, 80,112, 4)
  player[1].anim[1] =
    newAnimation(love.graphics.newImage('assets/claire-walk-rt.png'),
    80,112, 0.1,5)
  player[1].anim[2] =
    newAnimation(love.graphics.newImage('assets/claire-walk-lt.png'),
    80,112, 0.1,5)
  player[1].anim[3] =
    newAnimation(love.graphics.newImage('assets/claire-call-rt.png'),
    80,112, 0.1,1)
  player[1].anim[4] =
    newAnimation(love.graphics.newImage('assets/claire-call-lt.png'),
    80,112, 0.1,1)

  -- create "tommy" player object
  player[2] = Player.create(10,488, 80,112, 4)
  player[2].anim[1] =
    newAnimation(love.graphics.newImage('assets/tommy-walk-rt.png'),
    80,112, 0.1,5)
  player[2].anim[2] =
    newAnimation(love.graphics.newImage('assets/tommy-walk-lt.png'),
    80,112, 0.1,5)
  player[2].anim[3] =
    newAnimation(love.graphics.newImage('assets/tommy-call-rt.png'),
    80,112, 0.1,1)
  player[2].anim[4] =
    newAnimation(love.graphics.newImage('assets/tommy-call-lt.png'),
    80,112, 0.1,1)

  -- callout object
  callout = Callout.create(
    love.graphics.newImage('assets/callout.png'),
    60,40, 200, 120) --150)

    reset_game()

  -- load audio assets
  rain_low = love.audio.newSource('assets/rain_low.ogg')
  rain_low:setVolume(0.2)

  claire_footsteps = love.audio.newSource('assets/claire_footsteps.ogg')
  claire_footsteps:setVolume(0.3)
  claire_callout1 = love.audio.newSource('assets/claire_callout1.ogg')
  claire_callout1:setVolume(0.3)
  claire_callout2 = love.audio.newSource('assets/claire_callout2.ogg')
  claire_callout2:setVolume(0.3)
  claire_callout3 = love.audio.newSource('assets/claire_callout3.ogg')
  claire_callout3:setVolume(0.3)
  claire_callout4 = love.audio.newSource('assets/claire_callout4.ogg')
  claire_callout4:setVolume(0.3)
  rclaire_callout = love.math.random(4)

  tommy_footsteps  = love.audio.newSource('assets/tommy_footsteps.ogg')
  tommy_footsteps:setVolume(0.3)
  tommy_callout1 = love.audio.newSource('assets/tommy_callout1.ogg')
  tommy_callout1:setVolume(0.3)
  tommy_callout2 = love.audio.newSource('assets/tommy_callout2.ogg')
  tommy_callout2:setVolume(0.3)
  tommy_callout3 = love.audio.newSource('assets/tommy_callout3.ogg')
  tommy_callout3:setVolume(0.3)
  tommy_callout4 = love.audio.newSource('assets/tommy_callout4.ogg')
  tommy_callout4:setVolume(0.3)
  rtommy_callout = love.math.random(4)

  thunder1 = love.audio.newSource('assets/thunder1.ogg')
  thunder1:setVolume(0.4)
  thunder2 = love.audio.newSource('assets/thunder2.ogg')
  thunder2:setVolume(0.6)
  thunder3 = love.audio.newSource('assets/thunder3.ogg')
  thunder3:setVolume(0.3)

  rthunder = (love.math.random(2000) * -1)
  rthunder_num = love.math.random(3)

  -- load music assets
end

function love.update(dt)
  if state == 'splash' then
    -- ???
  end
  if state == 'game' then

    rain_low:play()

    if house.x <= rthunder+20 and house.x >= rthunder-20 then
      if rthunder_num == 1 then
        thunder1:play()
      end
      if rthunder_num == 2 then
        thunder2:play()
      end
      if rthunder_num == 3 then
        thunder3:play()
      end
      rthunder = (love.math.random(2000) * -1)
      rthunder_num = love.math.random(3)
    end

    if not stairsactive then

      -- 'left' direction
      if love.keyboard.isDown('left') then
        if pnum == 1 then
          claire_footsteps:play()
        else
          tommy_footsteps:play()
        end
        player[pnum].animate = true

        if player[pnum].anim[2]:getCurrentFrame() == 4 then
          player[pnum].anim[2]:reset()
        end
        player[pnum].anim[2]:update(dt)
        -- player moving to 'left' scroll point
        if house.x < 0 and player[pnum].x > (win_width/2 - 34) then --466 then
          player[pnum].x = player[pnum].x - player[pnum].speed
          if player[pnum].x < (win_width/2 - 34) then --466 then
            player[pnum].x = 466
          end
        end
        -- player at 'left' scroll point. background scrolls
        if house.x < 0 and player[pnum].x == (win_width/2 - 34) then --466 then
          -- player hit right edge of middle stairs
          if stairmiddle and house.x > -270 then
            -- don't move house.x
          else
            house.x = house.x + house.speed
          end
          --house.x = house.x + house.speed
        end
        -- background scrolling ends. move player to 'left' edge
        if house.x == 0 then
          if player[pnum].x > 0 then
            player[pnum].x = player[pnum].x - player[pnum].speed
          end
        end

      -- 'right' direction
      elseif love.keyboard.isDown('right') then
        if pnum == 1 then
          claire_footsteps:play()
        else
          tommy_footsteps:play()
        end
        player[pnum].animate = true

        if player[pnum].anim[1]:getCurrentFrame() == 4 then
          player[pnum].anim[1]:reset()
        end
        player[pnum].anim[1]:update(dt)
        -- player moving to 'right' scroll point
        if player[pnum].x < (win_width/2 + 4) then
          player[pnum].x = player[pnum].x + player[pnum].speed
        end
        -- player at 'right' scroll point. background scrolls
        if (win_width - house.w) < house.x and player[pnum].x >= (win_width/2 + 4) then
          -- player hit right edge of middle stairs
          if stairmiddle and house.x < -404 then
            -- don't move house.x
          else
            house.x = house.x - house.speed
          end
        end

        -- background scrolling ends. move player to 'right' edge
        if house.x <= (win_width - house.w) then
          if player[pnum].x < (win_width - player[pnum].width) then
            player[pnum].x = player[pnum].x + player[pnum].speed
          end
        end
      end

    end

    -- 'up' direction
    if love.keyboard.isDown('up') then
      -- stairs base. is player on same level?
      if player[pnum].y == 488 then
        -- is player in the entry bounds
        if player[pnum].x >= 260 and player[pnum].x <= 330 then
          -- enable stairs action
          stairbase = true
          stairsactive = true
          player[pnum].x = 260
        end
      end

      -- run base to middle stairs sequence
      if stairbase then
        -- move player to middle of stairs
        if player[pnum].y > 246 then
          if pnum == 1 then
            claire_footsteps:play()
          else
            tommy_footsteps:play()
          end
          -- bx = 330, mx = 810, by = 1200, my = 955
          player[pnum].animate = true

          if player[pnum].anim[1]:getCurrentFrame() == 4 then
            player[pnum].anim[1]:reset()
          end
          player[pnum].anim[1]:update(dt)
          -- player at 'right' scroll point. background scrolls
          if (win_width - house.w) < house.x and player[pnum].x >= (win_width/2 + 4) then
            house.x = house.x - 4--house.speed
            player[pnum].y = player[pnum].y - 2
          else
            player[pnum].y = player[pnum].y - 2
            player[pnum].x = player[pnum].x + 4
          end
        else
          stairsactive = false
          stairbase = false
          stairmiddle = true
        end
      end


      -- stairs middle
      if stairmiddle then
        if player[pnum].y == 246 then
          -- is player in the entry bounds?
          if house.x <= -300 and house.x >= -320 then
            -- enable stairs action
            stairmiddle = true
            stairsactive = true
            house.x = -280
            player[pnum].x = 466
          end
        end

        if stairsactive then
          -- move player to top of stairs
          if player[pnum].y > 45 then
            if pnum == 1 then
              claire_footsteps:play()
            else
              tommy_footsteps:play()
            end
            -- player at 'left' scroll point. background scrolls
            if house.x < 0 and player[pnum].x == (win_width/2 - 34) then
              house.x = house.x + 3.5--house.speed
              player[pnum].y = player[pnum].y - 3
            else
              -- move map down
              if player[pnum].y <= 100 then
                house.y = house.y + house.speed
                player[pnum].y = player[pnum].y - 1
                player[pnum].x = player[pnum].x - 3.5
              else
                player[pnum].y = player[pnum].y - 3
                player[pnum].x = player[pnum].x - 3.5
              end
            end

          else
            stairsactive = false
            stairbase = false
            stairmiddle = false
            stairtop = true
            house.x = 0
            house.y = 0
            player[pnum].x = 260
            player[pnum].y = 484
          end
        end
      end

      -- stairs top


    -- 'down' direction
    elseif love.keyboard.isDown('down') then
      -- run middle to base stairs sequence
      if stairmiddle then

        -- stairs base. is player on stame level?
        if player[pnum].y == 246 then
          -- is player in the entry bounds
          if house.x <= -240 and house.x >= -290 then
            -- enable stairs action

            stairmiddle = true
            stairsactive = true
            house.x = -270
            player[pnum].x = 466
          end
        end

        -- move player to base of stairs
        if stairsactive then
        if player[pnum].y < 488 then
          if pnum == 1 then
            claire_footsteps:play()
          else
            tommy_footsteps:play()
          end
          -- bx = 330, mx = 810, by = 1200, my = 955
          player[pnum].animate = true

          if player[pnum].anim[2]:getCurrentFrame() == 4 then
            player[pnum].anim[2]:reset()
          end
          player[pnum].anim[2]:update(dt)
          -- player at 'left' scroll point. background scrolls
          if house.x < 0 and player[pnum].x == (win_width/2 - 34) then
            house.x = house.x + 4--house.speed
            player[pnum].y = player[pnum].y + 2
          else
            player[pnum].y = player[pnum].y + 2
            player[pnum].x = player[pnum].x - 4
          end
        else
          stairsactive = false
          stairmiddle = false
          house.x = 0
          player[pnum].x = 260
          player[pnum].y = 488
        end
        end
      end

      -- stairs top
      if stairtop then
        -- is player on same level?
        if player[pnum].y == 484 then
          if pnum == 1 then
            claire_footsteps:play()
          else
            tommy_footsteps:play()
          end
          -- is player in the entry bounds
          if player[pnum].x >= 270 and player[pnum].x <= 350 then
            -- enable stairs action
            stairtop = true
            stairsactive = true
            player[pnum].x = 330
            player[pnum].y = 485
          end

        -- move player to middle of stairs
        elseif stairsactive and house.y < 480 and player[pnum].y < 600 then
          -- bx = 330, mx = 810, by = 1200, my = 955

          house.x = -370
          house.y = -600
          player[pnum].x = 505
          player[pnum].y = 246
          stairsactive = false
          stairmiddle = true
          stairtop = false
          --[[ player at 'right' scroll point. background scrolls
          if (win_width - house.w) < house.x and player[pnum].x >= (win_width/2 + 4) then
            house.x = house.x - 4--house.speed
            house.y = house.y - house.speed - 1
            player[pnum].y = player[pnum].y + 2
          else
            house.y = house.y - house.speed - 2
            player[pnum].y = player[pnum].y + 2
            player[pnum].x = player[pnum].x + 4
          end]]
        else
          stairsactive = false
          stairmiddle = true
          stairtop = false
          --house.x = 0
          house.y = -600
          player[pnum].y = 264
        end
      end

    end

    -- hider found. come on out
    if hider_found then
      -- hider moves out
      if hider.x > hider.x_out then
        hider.x = hider.x - hider.speed
        hider.animate = true

        if hider.anim[2]:getCurrentFrame() == 4 then
          hider.anim[2]:reset()
        end
        hider.anim[2]:update(dt)
        if hider.x < hider.x_out then
          hider.x = hider.x_out
          hider.animate = false
          hider.anim[2]:seek(5)
          hider.anim[2]:update(dt)
        end
      end
    end

    -- 'callout' keyboard event
    if love.keyboard.isDown('c') then
      -- claire callout sound
      if pnum == 1 then
        if rclaire_callout == 1 then
          claire_callout1:play()
        elseif rclaire_callout == 2 then
          claire_callout3:play()
        elseif rclaire_callout == 3 then
          claire_callout4:play()
        else
          claire_callout3:play()
        end
        rclaire_callout = love.math.random(4)
      else
        -- tommy callout sound
        if rtommy_callout == 1 then
          tommy_callout1:play()
        elseif rtommy_callout == 2 then
          tommy_callout2:play()
        elseif rtommy_callout == 3 then
          tommy_callout1:play()
        else
          tommy_callout4:play()
        end
        rtommy_callout = love.math.random(4)
      end

      --callout:show(player[pnum].x,player[pnum].y)
      callout:show(
        (math.abs(house.x) + player[pnum].x), player[pnum].y)
        --(math.abs(house.y) + player[pnum].y))
    end

    callout:countdown()

  -- end of 'game' state
  end

-- end of love.update()
end

function love.keyreleased(key)
  if state == 'splash' then
    -- ???
  end
  if state == 'game' then
    if key == 'left' then
      player[pnum].animate = false
      player[pnum].anim[1]:seek(5)
      if pnum == 1 then
        claire_footsteps:stop()
      else
        tommy_footsteps:stop()
      end
    elseif key == 'right' then
      player[pnum].animate = false
      player[pnum].anim[1]:seek(5)
      if pnum == 1 then
        claire_footsteps:stop()
      else
        tommy_footsteps:stop()
      end
    elseif key == 'up' then
      player[pnum].animate = false
      player[pnum].anim[1]:seek(5)
      if pnum == 1 then
        claire_footsteps:stop()
      else
        tommy_footsteps:stop()
      end
    elseif key == 'down' then
      player[pnum].animate = false
      player[pnum].anim[1]:seek(5)
      if pnum == 1 then
        claire_footsteps:stop()
      else
        tommy_footsteps:stop()
      end
    end
  end
end

function love.draw(dt)
  if state == 'splash' then
    love.graphics.draw(startscreen.img, 0,0)

    love.graphics.setColor(0,255,0)
    -- claire selected
    if pnum == 1 then
      love.graphics.polygon('fill', 450,272, 490,272, 470,315)
    end
    -- tommy selected
    if pnum == 2 then
      love.graphics.polygon('fill', 525,272, 565,272, 545,315)
    end
    love.graphics.setColor(255,255,255)
  end
  if state == 'game' then
    -- house backdrop
    love.graphics.draw(house.img, house.x,house.y)

    -- hidden child
    hider.anim[pnum]:draw((hider.x + house.x), (hider.y + house.y))

    -- draw house objects
    love.graphics.draw(door.img, (door.x + house.x), door.y + house.y)
    love.graphics.draw(steps1.img, (steps1.x + house.x), (steps1.y + house.y))
    love.graphics.draw(steps2.img, (steps2.x + house.x), (steps2.y + house.y))
    love.graphics.draw(large_plant.img, (large_plant.x + house.x),
      (large_plant.y + house.y))
    love.graphics.draw(towels.img, (towels.x + house.x), (towels.y + house.y))
    love.graphics.draw(laundry_basket.img,
      (laundry_basket.x + house.x), (laundry_basket.y + house.y))

    -- draw a hole
    myStencilFunction = function()
      --love.graphics.draw(callout.img, callout.x, callout.y)

      love.graphics.circle('fill', (callout.x + house.x), (callout.y) ,callout.size)

      --[[love.graphics.setColor(12,76,224)
      love.graphics.setBlendMode('alpha')
      love.graphics.circle('fill', (callout.x + house.x), (callout.y) ,callout.size-20)
      love.graphics.setColor(255,255,255)]]
      --[[ stick 'call out' image effect to house
      love.graphics.circle('fill',
        (callout.x + player[pnum].x), (callout.y),
         callout.size)]]
    end

    -- draw callout mask
    if callout.visible then
      love.graphics.setInvertedStencil(myStencilFunction)
      --love.graphics.draw(callout.img, callout.x, callout.y)
      --love.graphics.setStencil(myCalloutStencil)
    end

    -- map darkness
    if darkness then
      love.graphics.setColor(0,0,0)
      love.graphics.rectangle('fill', 0,0,1000,600)
      love.graphics.setColor(255,255,255) -- reset to default
    end
    love.graphics.setInvertedStencil()
    if callout.visible then
      love.graphics.draw(callout.img,
        ((callout.x-callout.size) + house.x), (callout.y-callout.size))
    end


    -- draw player
    if love.keyboard.isDown('right') then
      player[pnum].anim[1]:draw(player[pnum].x,player[pnum].y)
      if love.keyboard.isDown('c') then
        player[pnum].anim[3]:draw(player[pnum].x,player[pnum].y)
      end
    elseif love.keyboard.isDown('left') then
      player[pnum].anim[2]:draw(player[pnum].x,player[pnum].y)
      if love.keyboard.isDown('c') then
        player[pnum].anim[4]:draw(player[pnum].x,player[pnum].y)
      end
    else
      player[pnum].anim[1]:draw(player[pnum].x,player[pnum].y)
    end

    -- draw stair steps
    -- steps2
    if (stairmiddle and player[pnum].y < 246) or stairtop then
      love.graphics.draw(steps2.img, (steps2.x + house.x), (steps2.y + house.y))
    end
    -- steps1
    if love.keyboard.isDown('up') or stairmiddle then
      love.graphics.draw(steps1.img, (steps1.x + house.x), (steps1.y + house.y))
    end

    -- game over
    if hider_found then
      love.graphics.draw(gameover.img, gameover.x, gameover.y)

      love.graphics.setColor(0,255,0)
      -- 'play again' selected
      if playagain then
        --love.graphics.polygon('fill', 610,330, 650,310, 650,350)
        love.graphics.polygon('fill', 488,400, 528,420, 488,440)
      end
      -- 'quit game' selected
      if quitgame then
        --love.graphics.polygon('fill', 610,380, 650,360, 650,400)
        love.graphics.polygon('fill', 196,400, 236,420, 196,440)
      end
      love.graphics.setColor(255,255,255)
    end

    -- debug text
    if debug then
      if stats then
        love.graphics.print('player.x = '..player[pnum].x, 10,0)
        love.graphics.print('player.y = '..player[pnum].y, 10,15)
        love.graphics.print('house.x = '..house.x, 10,30)
        love.graphics.print('house.y = '..house.y, 10,45)

        if player[pnum].animate then
          love.graphics.print('player.animate = true', 10,55)
        else
          love.graphics.print('player.animate = false', 10,55)
        end

        love.graphics.print('callout.x = '..callout.x, 10,70)
        love.graphics.print('callout.y = '..callout.y, 10,85)

        if stairsactive then
          love.graphics.print('stairsactive = true', 10,100)
        else
          love.graphics.print('stairsactive = false', 10,100)
        end

        if stairbase then
          love.graphics.print('stairs = base', 10,115)
        elseif stairmiddle then
          love.graphics.print('stairs = middle', 10,115)
        elseif stairtop then
          love.graphics.print('stairs = top', 10,115)
        end

        love.graphics.print('random_hide = '..rhide, 10,130)
      end
    end

  end
end

-- keyboard events
function love.keypressed(key)
  if state == 'splash' then
    --splash.keypressed(key)
    if key == 'right' and pnum == 1 then
      -- select tommy
      pnum = 2
    end
    if key == 'left' and pnum == 2 then
      -- select claire
      pnum = 1
    end
    -- enter 'game' state
    if key == 'return' then
      reset_game()
      state = 'game'
    end
    -- quit to dekstop
    if key == 'escape' then
      love.event.quit()
    end

  -- new game is running
  elseif state == 'game' then
    --game.keypressed(key)
    -- quit to start-screen
    if key == 'escape' then
      rain_low:stop()
      state = 'splash'
    end
    -- find hidden child if close by
    if key == 'f' then
      if
      (math.abs((hider.x + house.x) - player[pnum].x) < detect_area) and
      callout.count > 0 then
        hider_found = true
        darkness = false
      end
    end

    -- game over
    if hider_found then
      -- play again
      if key == 'down' and playagain then
        playagain = false
        quitgame = true
      end
      -- quit game
      if key == 'up' and quitgame then
        playagain = true
        quitgame = false
      end
      -- quitgame choice
      if key == 'return' then
        if playagain then
          reset_game()
          state = 'game'
        end
        if quitgame then
          state = 'splash'
        end
      end
    end

    -- game testing controls
    --[[if key == 'lshift' then
      -- turn darkness on/off
      if darkness then
        darkness = false
      else
        darkness = true
      end
    end]]
    -- turn stats on/off
    if key == 'lctrl' then
      if stats then
        stats = false
      else
        stats = true
      end
    end

  end
end

local mask = love.graphics.newImage('assets/callout-mask.png')

local mask_effect = love.graphics.newShader [[
vec4 effect ( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ) {
  // a discarded fragment will fail the stencil test.
  if (Texel(texture, texture_coords).rgb == vec3(0.0))
  discard;
  return vec4(1.0);
}
]]

myCalloutStencil = function()
  love.graphics.setShader(mask_effect)
  --love.graphics.draw(callout.img, callout.x, callout.y)
  love.graphics.draw(mask, 50,50)
  love.graphics.setShader()
end
