Changeset 56


Ignore:
Timestamp:
Nov 5, 2019, 1:27:20 AM (4 years ago)
Author:
chronos
Message:
  • Added: Animation of tiles merge.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r55 r56  
    633633    Frame.Top + Frame.Height div 2 + (Board.Size.Y * TileSize.Y) div 2);
    634634
    635   TileMargin := Round(Frame.Width / Board.Size.X * 0.025);
     635  TileMargin := Round(Frame.Width / Board.Size.X * 0.03);
    636636
    637637  Canvas.Brush.Style := bsSolid;
     
    673673    end;
    674674
    675   // Draw moving tiles
     675  // Draw appearing tiles
    676676  for Y := 0 to Board.Size.Y - 1 do
    677677    for X := 0 to Board.Size.X - 1 do
     
    691691      TileRect := Rect(TileCenter.X - S.X div 2, TileCenter.Y - S.Y div 2,
    692692        TileCenter.X + S.X div 2, TileCenter.Y + S.Y div 2);
     693      RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
     694    end;
     695
     696  // Draw merging tiles
     697  for Y := 0 to Board.Size.Y - 1 do
     698    for X := 0 to Board.Size.X - 1 do
     699    if Board.Tiles[Y, X].Action = taMerge then begin
     700      Canvas.Brush.Color := GetTileColor(Board.Tiles[Y, X].Value);
     701      Canvas.Brush.Style := bsSolid;
     702      TileRect := Bounds(
     703        Frame.Left + X * TileSize.X + TileMargin,
     704        Frame.Top + Y * TileSize.Y + TileMargin,
     705        TileSize.X - 2 * TileMargin,
     706        TileSize.Y - 2 * TileMargin);
     707      S := Point(
     708        Trunc((50 - Abs(Board.Tiles[Y, X].Shift.X - 50)) / 50 * TileMargin),
     709        Trunc((50 - Abs(Board.Tiles[Y, X].Shift.Y - 50)) / 50 * TileMargin)
     710      );
     711      TileRect := Rect(TileRect.Left - S.X, TileRect.Top - S.Y,
     712        TileRect.Right + S.X, TileRect.Bottom + S.Y);
    693713      RenderTile(Canvas, Board.Tiles[Y, X], TileRect, True);
    694714    end;
     
    777797    FCanUndo := False;
    778798    FRunning := CanMove;
    779     History.Moves.Delete(History.Moves.Count - 1);
     799    if RecordHistory then History.Moves.Delete(History.Moves.Count - 1);
    780800    DoChange;
    781801  end;
     
    938958  for Y := 0 to Board.Size.Y - 1 do
    939959    for X := 0 to Board.Size.X - 1 do begin
     960      if Board.Tiles[Y, X].Merged then
     961        Board.Tiles[Y, X].Action := taMerge;
    940962      Board.Tiles[Y, X].Shift := Point(0, 0);
    941       Board.Tiles[Y, X].Action := taNone;
     963      if Board.Tiles[Y, X].Action = taMove then begin
     964        Board.Tiles[Y, X].Action := taNone;
     965      end;
    942966      Board.Tiles[Y, X].Value := Board.Tiles[Y, X].NewValue;
    943967    end;
     
    959983procedure TGame.AnimateTiles;
    960984var
    961   I: Integer;
    962985  StartTime: TDateTime;
    963986  EndTime: TDateTime;
     
    9801003        if Board.Tiles[Y, X].Action = taAppear then
    9811004          Board.Tiles[Y, X].Shift := Point(Trunc(Part * 100), Trunc(Part * 100));
     1005        if Board.Tiles[Y, X].Action = taMerge then
     1006          Board.Tiles[Y, X].Shift := Point(Trunc(Part * 100), Trunc(Part * 100));
    9821007      end;
    9831008    DoChange;
     
    9881013  for Y := 0 to Board.Size.Y - 1 do
    9891014    for X := 0 to Board.Size.X - 1 do
    990       if Board.Tiles[Y, X].Action = taAppear then begin
     1015      if Board.Tiles[Y, X].Action <> taNone then begin
    9911016        Board.Tiles[Y, X].Action := taNone;
    9921017        Board.Tiles[Y, X].Shift := Point(0, 0);
Note: See TracChangeset for help on using the changeset viewer.