#include "zelda.h"
#include "bitmap.h"
#include "datafile.h"
#include "timer.h"
#include "gfx.h"
#include "game.h"
#include "sound.h"
#include "dat\\menu.h"
#include "dat\\tiles.h"
int mx=0,my=0;
unsigned char map[200][130];
void GameInput();
void GameDraw();
void DrawMap();
void DrawStatusBar();

void PlayGame()
{
  PlayMod("music\\tune2.jgm");
  GameDraw();
  fade_in(pal[0].dat,fadeSpeed);
  while(!key[KEY_ESC])
  {
     GameInput();
     GameDraw();
  }
  StopMod();
  fade_out(fadeSpeed);
}

void GameInput()
{
}

void GameDraw()
{
 clear(buffer);
 DrawMap();
 DrawStatusBar();
 vsync();
 if(svga==TRUE)
  blit(buffer,screen,0,0,160,120,320,240);
 else if(svgaStretch==TRUE)
  stretch_blit(buffer,screen,0,0,320,240,0,0,640,480);
 else
  blit(buffer,screen,0,0,0,0,320,240);
}

void DrawMap()
{
   int x,y;
   for(x=0;x<20;x++)
    for(y=0;y<13;y++)
    {
       if(map[mx*20+x][my*13+y]!=255)
       switch(map[mx*20+x][my*13+y])
       {
          case TILE042_BMP:
           if(!frameTimer)
            draw_sprite(buffer,tiles[map[mx*20+x][my*13+y]].dat,x*16,32+y*16);
           else
            draw_sprite_h_flip(buffer,tiles[map[mx*20+x][my*13+y]].dat,x*16,32+y*16);
          break;
          default:
           blit(tiles[map[mx*20+x][my*13+y]].dat,buffer,0,0,x*16,32+y*16,16,16);
          break;
       }


    }
}

void DrawStatusBar()
{
   draw_sprite(buffer,menu[ZX_BMP].dat,0,0);
}

void LoadMap()
{
   PACKFILE *f;
   int x,y;
   f=pack_fopen("maps\\map1.zmf","rp");
   for(x=0;x<200;x++)
   for(y=0;y<130;y++)
    pack_fread(&map[x][y],sizeof(unsigned char),f);
   pack_fclose(f);

}

void GetZeldaPos()
{

}




