program main;
uses
  SysUtils,
  unit2,
  windows,
  math,
  DGLEngine_header in 'DGLEngine_header.pas',
  TMenu in 'TMenu.pas',
  tenemy in 'tenemy.pas';

var
fon:cardinal;
Btn:array[1..10] of Button;
men:menu;
Cur:record
  wheel,x,y,bt:longint;
  img:Cardinal;
end;
WindowType:longint;
    procedure init;
    var
      i,w:longint;
       begin
       directsoundinit;
           WindowType:=1;
           w:=0;
           for i:=1 to 10 do
            begin
           Btn[i]:=Button.Create(w,550,100,50,i);
           inc(w,100);
           end;
           Cur.img:=LoadTextureFromFile('Data\Image\kyrsor.bmp',texdetail_best,transcolor_black);
           men:=menu.create;
           Men.LoadImg;         {graphic}
           fon:=loadtexturefromfile('data\textures\igdc.jpg')
       end;

  procedure Draw;
  var
   i:longint;
   begin
   if windowtype=1 then
    begin
      begin2d;
      men.DrwBackground;
      begin2d;
             drawtexture2d_simple(fon,0,0,1000,800);
       end2d;
      for i:=1 to 2 do
       if Cm[WindowType,i]=1 then Btn[i].DrawBtn;
      DrawTexture2D_Simple(Cur.img,Cur.x,Cur.y,32,32);
   end2d;
   end else
    begin
     draw2;
    end;
   end;

  procedure process ;
  var
    Mx,My,i:longint;
  begin
    Cur.x:=GetMousepos.x;
    Cur.y:=GetMousepos.y;
    for i:=1 to 10 do if Cm[WindowType,i]=1 then Btn[i].Run(Cur.x,Cur.y);
    if (windowtype=1)and(IsLeftMouseButtonPressed)and(cur.x>0)and(cur.x<100)and(cur.y>550)and(cur.y<600)then
    begin
    WindowType:=2;
    init2;
    end;
    if WindowType=2 then
     begin
     proces2;
     end;
  end;

   procedure Free;
       begin
       end;
begin
     if loadDGLengineDLL('DGLEngine.dll') then
      begin
            Regprocedure(PROC_DRAW,@Draw);
            Regprocedure(PROC_PROCESS,@Process);
            Regprocedure(PROC_INIT,@init);
            Regprocedure(PROC_Free,@Free);
            setgameprocessinterval(10);
            setEngineInitParametrs(1000,600,32,0,false,False,False,true);
            startEngine;
      end;



end.
