var render = use('render')
var os = use('os')
var transform = use('transform')
var color = use('color')

render.initialize({
  width:500,
  height:500,
  resolution_x:500,
  resolution_y:500,
  mode: "letterboxed"
})

var draw = use('draw2d')

var camera = {
  size: [500,500],
  transform: new transform,
  fov:50,
  near_z: 0,
  far_z: 1000,
  surface: null,
  viewport: {x:0,y:0,width:1,height:1},
  ortho:true,
  anchor:[0.5,0.5],
}

var hudcam = {
  size: [500,500],
  transform: new transform,
  fov:50,
  near_z: 0,
  far_z: 1000,
  surface: null,
  viewport: {x:0,y:0,width:1,height:1},
  ortho:true,
  anchor:[0,0],
}

var angle = 0
var pos = [0,0,0]

var dt = 0

var sprite = use('lcdsprite')
sprite.create("ok", [50,50], [0.5,0])
sprite.create("nope", [100,100], [0.5,0])
sprite.create("sad", [150,150], [0.5,0])

function loop()
{
  var now = os.now()
  pos.x += dt*100
  camera.transform.pos = pos
  render.clear([22/255,120/255,194/255,255/255])
  render.camera(camera)

  for (var sp of sprite.sprites) 
    draw.image(sp.image, sp.rect)
    
/*  draw.line([[0,0],[100,50]])
  draw.point([100,100])
  draw.circle([200,200],40)
  draw.ellipse([300,300],[20,40], {start:0,end:1, thickness:0})
  draw.ellipse([350,350], [30,30], {start:0.1,end:-0.1, thickness:30, color: color.yellow})
  draw.ellipse([100,80],[40,25], {thickness:10, color:color.green})
  draw.ellipse([100,80], [40,25], {thickness:1,color:color.blue})
  draw.rectangle({x:150,y:150,width:50,height:50})
  draw.rectangle({x:100, y:60,  width:200, height:60}, {radius: 20, thickness:-3})
  draw.rectangle({x:350, y:60, width:200, height:120}, {radius:10,thickness:3})
*/
  render.camera(hudcam)
  draw.slice9("button_grey", {x:0,y:0,width:100,height:50}, 10)
  render.present()
  dt = os.now()-now
  var delay = (1/240) - dt
  if (delay <= 0)
    loop()
  else
    $_.delay(loop, delay)
}

var sound = use('sound')
//prosperon.myguy = sound.play('test.mp3')

loop()


