Changeset 65 for trunk/UGame.pas


Ignore:
Timestamp:
Jan 23, 2020, 12:21:53 AM (4 years ago)
Author:
chronos
Message:
  • Added: Separated TGame paint and state change events.
  • Modified: Animate tiles movements in background thread.
  • Modified: Initialize TCore as first application form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r63 r65  
    104104    FOnChange: TNotifyEvent;
    105105    FOnGameOver: TNotifyEvent;
     106    FOnPaint: TNotifyEvent;
    106107    FOnWin: TNotifyEvent;
    107108    FRecordHistory: Boolean;
     
    115116    procedure SetScore(AValue: Integer);
    116117    procedure DoChange;
     118    procedure DoPaint;
    117119    procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean);
    118120    procedure GameOver;
     
    129131    TopScore: Integer;
    130132    AnimationDuration: Integer;
     133    AnimationTick: Integer;
    131134    WinTileValue: Integer;
    132135    UndoEnabled: Boolean;
     
    155158    property Running: Boolean read FRunning write FRunning;
    156159    property OnChange: TNotifyEvent read FOnChange write FOnChange;
     160    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
    157161    property OnWin: TNotifyEvent read FOnWin write FOnWin;
    158162    property OnGameOver: TNotifyEvent read FOnGameOver write FOnGameOver;
     
    506510end;
    507511
     512procedure TGame.DoPaint;
     513begin
     514  if Assigned(FOnPaint) then FOnPaint(Self);
     515end;
     516
    508517procedure TGame.GameOver;
    509518begin
     
    516525  if FSkin = AValue then Exit;
    517526  FSkin := AValue;
    518   DoChange;
     527  DoPaint;
    519528end;
    520529
     
    595604  AnimateTiles;
    596605  DoChange;
     606  DoPaint;
    597607end;
    598608
     
    763773      Inc(P.Y, Area.Increment.Y);
    764774    end;
    765     DoChange;
     775    DoPaint;
    766776  end;
    767777  FMoving := False;
     
    945955              Trunc(Part * DirectionDiff[Direction].Y * 100));
    946956        end;
    947       DoChange;
    948       Application.ProcessMessages;
    949       Sleep(1);
     957      DoPaint;
     958      //Application.ProcessMessages;
     959      Sleep(AnimationTick);
    950960    until Time > EndTime;
    951961
     
    968978      Board.Tiles[Y, X].Value := Board.Tiles[Y, X].NewValue;
    969979    end;
    970   DoChange;
     980  DoPaint;
    971981  FMoving := False;
    972982end;
     
    10081018          Board.Tiles[Y, X].Shift := Point(Trunc(Part * 100), Trunc(Part * 100));
    10091019      end;
    1010     DoChange;
    1011     Application.ProcessMessages;
    1012     Sleep(1);
     1020    DoPaint;
     1021    //Application.ProcessMessages;
     1022    Sleep(AnimationTick);
    10131023  until Time > EndTime;
    10141024
     
    10191029        Board.Tiles[Y, X].Shift := Point(0, 0);
    10201030      end;
    1021   DoChange;
     1031  DoPaint;
    10221032  FMoving := False;
    10231033end;
     
    11551165  end;
    11561166  DoChange;
     1167  DoPaint;
    11571168end;
    11581169
     
    11601171begin
    11611172  AnimationDuration := 30;
     1173  AnimationTick := 10; // ms
    11621174  WinTileValue := 11; // 2^11 = 2048
    11631175  Board := TBoard.Create;
Note: See TracChangeset for help on using the changeset viewer.