unit uScene;

interface

type
  tSceneMng = class;

  tScene = class
    pX, pY : Integer;
    PSceneMng : tSceneMng;
    procedure   Draw;   virtual;
    procedure   Update; virtual;
    constructor Create(const SceneMng : tSceneMng); virtual;
    destructor Free;   virtual;
    procedure SetAsScene;
    procedure SetParam(Param : Integer); virtual;
  end;

  tSceneMng = class
    NowScene, NextScene : tScene;
    ChangeColor,
    ChangeType, ChangeP, ChangePG, CHangePD,
    ChangePD2, ChangePG2 : Integer;
    ChangeBScene, ChangeBPar, Change2Proc,
    Change : boolean;
    NextScenePar : Integer;
    procedure SetChangeType(const ChangeType_ : Integer);
    procedure ChangeScenePar(const ScenePar : Integer; const ChangeType_ : Integer);
    procedure ChangeSceneAndPar(const Scene : tScene; const ScenePar : Integer; const ChangeType_ : Integer);
    procedure ChangeScene(const Scene : tScene; const ChangeType_ : Integer);
    procedure ChangeDraw;
    procedure ChangeUpdate;
    procedure Draw;
    procedure Update;
  end;

implementation
uses
  zglHeader, uConst;
{ tScene }

constructor tScene.Create;
begin
  PSceneMng := SceneMng;
end;

procedure tScene.Draw;
begin

end;

destructor tScene.Free;
begin

end;

procedure tScene.SetAsScene;
begin
  PSceneMng.NowScene := self;
end;

procedure tScene.SetParam(Param: Integer);
begin

end;

procedure tScene.Update;
begin

end;

{ tSceneMng }

procedure tSceneMng.ChangeDraw;
begin
  case ChangeType of
    0 : begin
        if NowScene <> nil then
          NowScene.Draw;
        pr2d_Rect(0, 0, WinW, WinH, ChangeColor, ChangeP, PR2D_FILL);
      end;
  end;
end;

procedure tSceneMng.ChangeScene(const Scene: tScene; const ChangeType_: Integer);
begin
  Change := True;
  NextScene := Scene;
  ChangeBScene := true;
  ChangeBPar := false;
  SetChangeType(ChangeType_);
end;

procedure tSceneMng.ChangeSceneAndPar(const Scene: tScene; const ScenePar,
  ChangeType_: Integer);
begin
  Change := True;
  NextScene := Scene;
  NextScenePar := ScenePar;
  ChangeBScene := true;
  ChangeBPar := true;
  SetChangeType(ChangeType_);
end;

procedure tSceneMng.ChangeScenePar(const ScenePar, ChangeType_: Integer);
begin
  Change := True;
  NextScenePar := ScenePar;
  ChangeBScene := false;
  ChangeBPar := true;
  SetChangeType(ChangeType_);
end;

procedure tSceneMng.ChangeUpdate;
begin
  if ((ChangePD > 0) and (ChangeP > ChangePG))
  or ((ChangePD < 0) and (ChangeP < ChangePG)) then
  begin
    if ChangeBScene then
      NowScene := NextScene;
    if ChangeBPar then
      NowScene.SetParam(NextScenePar);
    if Change2Proc then
    begin
      ChangePG := ChangePG2;
      ChangePD := ChangePD2;
      Change2Proc := false;
    end
    else
      Change := false;
  end
  else
    ChangeP := ChangeP + ChangePD;
end;

procedure tSceneMng.Draw;
begin
  if Change then
    ChangeDraw
  else
  if NowScene <> nil then
    NowScene.Draw;
end;

procedure tSceneMng.SetChangeType(const ChangeType_: Integer);
begin
  ChangeType := ChangeType_;
  case ChangeType of
    0 : begin
      ChangeP := 0;
      ChangePG := 250;
      CHangePD := 5;
      Change2Proc := true;
      ChangePG2 := 5;
      CHangePD2 := -5;
      ChangeColor := $FFFFFF;
    end;
  end;
end;

procedure tSceneMng.Update;
begin
  if Change then
    ChangeUpdate
  else
  if NowScene <> nil then
    NowScene.Update;
end;

end.
