dofile ("lua/libBattle.lua")

Sound.loadBank("lua/son/soundbank.bin")
-- Load all mods and sfx in ram
Sound.loadSFX(28)
Sound.startSFX(28)

randombackground = math.random(0, 1)


if randombackground == 1 then
back = Image.load("lua/images/forest.PNG", VRAM)
else
back = Image.load("lua/images/cavern.png", VRAM)
end

canvas2 = Canvas.new()
obj2 = Canvas.newImage(math.random(0, 0), math.random(0, 0), back)
Canvas.add(canvas2, obj2)


   monsters.a.name = "Kabuterimon"
   monsters.a.hp = 180
   monsters.a.mp = 60
   monsters.a.att = 51
   monsters.a.def = 37
   monsters.a.img = Sprite.new("lua/images/kabuterimon.PNG", 120, 130, VRAM)
   monsters.a.img:addAnimation({0,1,2,1}, 250) -- Walk up
   
   x = 70
   y = 30
   
   stat = Image.load("lua/images/windowsh.PNG", VRAM)
   stat2 = Image.load("lua/images/windowsad.PNG", VRAM)
   
   face = Image.load("lua/images/agumonface.PNG", VRAM)
   face2 = Image.load("lua/images/kabuterimonface.PNG", VRAM)
   
   
    file = io.open("lua/save/pv.txt", 'r')
    if file then
    heros.a.hp = file:read()
    file:close()
    else
    heros.a.hp = 125
    end
    
    file2 = io.open("lua/save/atc.txt", 'r')
    if file2 then
    heros.a.att = file2:read()
    file2:close()
    else
    heros.a.att = 5
    end
	
	file3 = io.open("lua/save/def.txt", 'r')
    if file3 then
    heros.a.def = file3:read()
    file3:close()
    else
    heros.a.def = 5
    end
	

    
while true do

  Controls.read ()  
 startDrawing ()

    Canvas.draw(SCREEN_UP, canvas2, 0, 0)

 initBattle ()  
 monsters.a.img:playAnimation(SCREEN_UP, x, y, direction)
 
  screen.blit(SCREEN_UP, 0, 0, stat)
  screen.blit(SCREEN_UP, 4, 0, face)
  screen.blit(SCREEN_UP, 160, 0, stat2)
  screen.blit(SCREEN_UP, 224, 0, face2)
  
  screen.print (SCREEN_UP, 53, 12, heros.a.hp)
  screen.print (SCREEN_UP, 183, 12, monsters.a.hp)
  
  screen.print(SCREEN_DOWN, 0, 20, "Agumon")
  screen.print(SCREEN_DOWN, 0, 50, "ATC")
  screen.print(SCREEN_DOWN, 0, 60, "DEF")
  screen.print(SCREEN_DOWN, 0, 70, "PV")
  screen.print(SCREEN_DOWN, 0, 80, "PM")

  screen.print (SCREEN_DOWN, 40, 50, heros.a.att)
  screen.print (SCREEN_DOWN, 40, 60, heros.a.def)
  screen.print (SCREEN_DOWN, 40, 70, heros.a.hp)
  screen.print (SCREEN_DOWN, 40, 80, heros.a.mp)
  
  screen.print(SCREEN_DOWN, 180, 20, "Kabuterimon")
  screen.print(SCREEN_DOWN, 180, 50, "ATC")
  screen.print(SCREEN_DOWN, 180, 60, "DEF")
  screen.print(SCREEN_DOWN, 180, 70, "PV")

  screen.print (SCREEN_DOWN, 220, 50, monsters.a.att)
  screen.print (SCREEN_DOWN, 220, 60, monsters.a.def)
  screen.print (SCREEN_DOWN, 220, 70, monsters.a.hp)
 
  
if monsters.a.hp < 1 then
Sound.unloadSFX(28)
Sound.unloadBank()
monsters.a.img:destroy()
monsters.a.img = nil
x = nil
y = nil
direction = nil
randombackground = nil
dofile("lua/Win.lua")
end
    
 stopDrawing ()

end
monsters.a.img:destroy()
monsters.a.img = nil
x = nil
y = nil
randombackground = nil
Sound.unloadSFX(28)
Sound.unloadBank()
clearBattle ()