unit uGmBackground;

interface

uses
  zglHeader, uGmData;

type
  PDecor = ^TDecor;
  TDecor = record
    X, Y  : integer;
    Pat   : PDecorPat;
  end;

type
  TBackground = class
    Decor     : array of TDecor;
    DecorCnt  : integer;

    constructor Create;
    destructor Destroy; override;
    procedure Draw;
    procedure DrawGrid;
    procedure Update;
    procedure DecorCreate( pat : PDecorPat; X, Y : integer );
  end;

implementation

//==============================================================================
constructor TBackground.Create;
begin
  DecorCnt := 0;
end;

//==============================================================================
destructor TBackground.Destroy;
begin
  SetLength( Decor, 0 );
  inherited;
end;

//==============================================================================
procedure TBackground.Draw;
var
  i, j : integer;
begin
  for j := 0 to 2 do
    for i := 0 to 3 do
      ssprite2d_Draw( GrassTex, i * 256, j * 256, 256, 256, 0 );
  ssprite2d_Draw( NoiseTex, 0, 0, 800, 600, 0, 50 );

  for i := 0 to DecorCnt - 1 do
    with Decor[ i ] do
      ssprite2d_Draw( Pat.Tex, X - Pat.OffsetX, Y - Pat.OffsetY, Pat.Tex.Width, Pat.Tex.Height, 0 );
end;

//==============================================================================
procedure TBackground.DrawGrid;
var
  i, j, tx, ty : integer;
begin
  for j := 0 to 8 do
    for i := 0 to 10 do
    begin
      tx := i * 54 + 84;
      ty := j * 46 + 100;
      if j mod 2 = 0 then tx := tx + 27;
      ssprite2d_Draw( HexTex, tx, ty, 64, 64, 0 );
    end;
end;

//==============================================================================
procedure TBackground.Update;
begin

end;

//==============================================================================
procedure TBackground.DecorCreate( pat : PDecorPat; X, Y : integer );
begin
  INC( DecorCnt );
  SetLength( Decor, DecorCnt );
  Decor[ DecorCnt - 1 ].Pat := pat;
  Decor[ DecorCnt - 1 ].X   := X;
  Decor[ DecorCnt - 1 ].Y   := Y;
end;

end.
