unit uObj;

interface
uses
  Classes, zglHeader, Math, uConst, uMaterials;

type
TRect = record
  X, Y, X2, Y2, W, H, Wd2, Hd2 : Integer;
  Color : Integer;
end;

{ TObj }

TObj = class
  DrawRect : TRect;
  zRect   : zglTRect;
  oldCircle,
  zCircle : zglTCircle;

  public
  constructor Create(const X, Y, W, H : Single; const Color : Integer); virtual;
  procedure Init(const X, Y, W, H : Single; const Color : Integer); virtual;
  procedure Update; virtual;
  procedure DrawBottom; virtual;
  procedure Draw; virtual;
  procedure RectUpdate;
  procedure DrawRectUpdate;
end;

var
  Objs : TList;

implementation
uses
  uWorld;

constructor TObj.Create(const X, Y, W, H: Single; const Color: Integer);
begin
  Init(X, Y, W, H, Color);
end;

{ TObj }
procedure TObj.Init(const X, Y, W, H : Single; const Color: Integer);
begin
  zCircle.cX := X;
  zCircle.cY := Y;
  zCircle.Radius := trunc(max(W, H)) div 2;

  DrawRect.W := trunc(W);
  DrawRect.H := trunc(H);
  DrawRect.Wd2 := trunc(W/2);
  DrawRect.Hd2 := trunc(H/2);

  zRect.W := DrawRect.W;
  zRect.H := DrawRect.H;
  DrawRect.Color := Color;
  
  RectUpdate;
  DrawRectUpdate;
end;

procedure TObj.Draw;
begin
  with DrawRect do
  begin
 //   pr2d_Rect(X, Y+15, W, H, Color, $FF, PR2D_FILL);
 //   pr2d_Rect(X, Y+15, W, H, $101010, $A7, PR2D_FILL);
    pr2d_Rect(X, Y, W, H, Color, $FF, PR2D_FILL);
  end;
end;

procedure TObj.RectUpdate;
begin
  zRect.X := zCircle.cX - DrawRect.Wd2;
  zRect.Y := zCircle.cY - DrawRect.Hd2;
end;

procedure TObj.DrawRectUpdate;
begin
  with DrawRect do
  begin
    X := round(zRect.X);
    Y := round(zRect.Y);
    X2 := X + W;
    Y2 := Y + H;
  end;
end;

procedure TObj.Update;
var
  mX, mY : Integer;
  aX, aY : Single;
  aSpeed : SIngle;
begin
 { mX := 0;
  mY := 0;
  if key_Down(K_T) then mY := mY - 1;
  if key_Down(K_G) then mY := mY + 1;
  if key_Down(K_F) then mX := mX - 1;
  if key_Down(K_H) then mX := mX + 1;

  if (mX <> 0) and (mY <> 0) then
    aSpeed := 2 * 0.7
  else
    aSpeed := 2;

  aX := mX * aSpeed;
  aY := mY * aSpeed;

  zCircle.cX := zCircle.cX + aX;
  zCircle.cY := zCircle.cY + aY;
  Collision(Self);
  RectUpdate;}
end;

procedure TObj.DrawBottom;
begin

end;

end.
