package.path = package.path .. ";./assets/scripts/?.lua"
require "luascape.objects"
require "luascape.graphics"
require "luascape.render"
require "luascape.scene"
require "luascape.math"
require "luascape.logic"


-- create renderer
renderer = scape.tinyandbig.Act.currentAct().renderer
inputManager = scape.input.InputManager.instance()

display = Display.instance()
width = display.width
height = width * (display.height/width)
halfWidth = width / 2.0
halfHeight = height / 2.0

assetManager = scape.io.AssetManager.instance()
camera = Camera()
scene = Scene()

standardPass = scape.tinyandbig.renderer.LevelRenderPass()
standardPass.scene = scene
standardPass.camera = camera
renderer.passes:add(standardPass)

function initLevel(_renderingSystem, _rootNode, _physicsSpace)
--  local level = scape.tinyandbig.Act.currentAct()
--  level.nextAct = "demolevel.lua"
  
  assetManager:registerDirectory("assets/textures/menu")

  camera.parallel = true
  camera.translation = Vector(0, 0, 100)
  camera:lookAt(Vector.ZERO, Vector.AXIS_Y)
  camera.width = display.width
  camera.height = display.height

  local ratio = width / height;
  local gridHeight = height;
  if (ratio < 1.6) then
    gridHeight = height / ratio
  end
  scene.visual = Grid(width, gridHeight, 2, 2)
  graphics.applyTexture(scene.visual, "introtext.png", 0)
  graphics.applyColor(scene.visual, Color.WHITE, Color.WHITE, Color.WHITE, 0)

  local light = Light()
  light.translation = Vector(100, 100, 100)
  scene.children:add(light)
end

function updateLevel()
  local act = scape.tinyandbig.Act.currentAct()
  inputManager:showMouseCursor(false)
  
  local currentIterationTime = Pacemaker.instance().frameTime
 
 -- End game
  if (currentIterationTime > 5.0) then
    act:exit()
  end
end
