Changeset 2


Ignore:
Timestamp:
Dec 11, 2020, 11:42:27 PM (3 years ago)
Author:
chronos
Message:
  • Added: Token movement animation.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      GamePack
      GamePack.res
      GamePack.lps
      lib
  • trunk/Games/UClovece.pas

    r1 r2  
    66
    77uses
    8   Classes, SysUtils, Controls, UGame, fgl, UGraphics, UCanvas;
     8  Classes, SysUtils, Controls, Forms, UGame, fgl, UGraphics, UCanvas;
    99
    1010type
     
    7070    NextTile: TTile;
    7171    NextTileHome: TTile;
     72    AnimateToken: TToken;
    7273    function GetNext(Steps: Integer; Player: TPlayer): TTile;
     74    procedure GetNextSteps(Steps: Integer; Player: TPlayer; Tiles: TTiles);
    7375    procedure Paint(Canvas: TCanvas);
    7476    property Owner: TPlayer read FOwner write SetOwner;
     
    101103  private
    102104    MetaCanvas: TMetaCanvas;
     105    Processing: Boolean;
     106    procedure AnimateTokenMovement(Token: TToken; NewTile: TTile);
    103107  public
    104108    Board: TBoard;
     
    195199    end;
    196200  end else Result := Self;
     201end;
     202
     203procedure TTile.GetNextSteps(Steps: Integer; Player: TPlayer; Tiles: TTiles);
     204begin
     205  if Steps > 0 then begin
     206    Tiles.Add(Self);
     207    if Assigned(NextTileHome) and (NextTileHome.Owner = Player) then begin
     208      NextTileHome.GetNextSteps(Steps - 1, Player, Tiles)
     209    end else begin
     210      if Assigned(NextTile) then NextTile.GetNextSteps(Steps - 1, Player, Tiles);
     211    end;
     212  end;
    197213end;
    198214
     
    218234    );
    219235  end;
     236  if Assigned(AnimateToken) then begin
     237    Canvas.Pen.Width := 5;
     238    Canvas.Brush.Color := AnimateToken.Player.Color;
     239    Canvas.Ellipse(
     240      Position.X - TokenSize div 2,
     241      Position.Y - TokenSize div 2,
     242      Position.X + TokenSize div 2,
     243      Position.Y + TokenSize div 2
     244    );
     245  end;
    220246end;
    221247
     
    441467
    442468{ TClovece }
     469
     470procedure TClovece.AnimateTokenMovement(Token: TToken; NewTile: TTile);
     471var
     472  I: Integer;
     473  Steps: TTiles;
     474begin
     475  Steps := TTiles.Create(False);
     476  Token.Tile.GetNextSteps(DiceValue, CurrentPlayer, Steps);
     477  Token.Tile := nil;
     478  for I := 0 to Steps.Count - 1 do begin
     479    Steps[I].AnimateToken := Token;
     480    Repaint;
     481    Application.ProcessMessages;
     482    Sleep(200);
     483    Steps[I].AnimateToken := nil;
     484  end;
     485  Steps.Free;
     486  Token.Tile := NewTile;
     487end;
    443488
    444489procedure TClovece.ThrowDice;
     
    479524          // Move opponents token back to its yard
    480525          NewTile.Token.Tile := NewTile.Token.Player.YardTiles.GetTileWithoutToken;
    481           Token.Tile := NewTile;
     526          AnimateTokenMovement(Token, NewTile);
    482527          TurnDone := True;
    483528          Break;
     
    485530      end else begin
    486531        // Normal token move
    487         Token.Tile := NewTile;
     532        AnimateTokenMovement(Token, NewTile);
    488533        TurnDone := True;
    489534        Break;
     
    506551procedure TClovece.MouseUp(Button: TMouseButton; Position: TPoint);
    507552begin
    508   if State = gsRunning then
     553  if (State = gsRunning) and not Processing then begin
     554    Processing := True;
    509555    ThrowDice;
     556    Processing := False;
     557  end;
    510558end;
    511559
     
    551599begin
    552600  with Canvas do begin
     601    Pen.Color := clBlack;
    553602    Brush.Opacity := $ff;
    554603    Brush.Color := clGray;
     
    572621    Brush.Opacity := 0;
    573622    Pen.Color := clBlack;
     623    Brush.Style := bsSolid;
     624    Brush.Color := CurrentPlayer.Color;
    574625    TextOut(Point(0, 0), 'Player: ' + CurrentPlayer.Name);
     626    Brush.Style := bsClear;
    575627    TextOut(Point(0, 30), 'Dice: ' + IntToStr(DiceValue) + ' ' + IntToStr(LastDiceValue));
    576628    TextOut(Point(0, 60), 'Throw: ' + IntToStr(DiceThrow));
  • trunk/Packages/Common

    • Property svn:ignore set to
      lib
  • trunk/UFormMain.pas

    r1 r2  
    6868procedure TGameCanvas.TextOut(const Pos: TPoint; Text: string);
    6969begin
    70   if Brush.Opacity = 0 then Canvas.Brush.Style := Graphics.bsClear
     70  if Brush.Style = bsClear then Canvas.Brush.Style := Graphics.bsClear
    7171    else Canvas.Brush.Style := Graphics.bsSolid;
    7272  Canvas.Brush.Color := Brush.Color;
     
    7777procedure TGameCanvas.Rectangle(const Rect: TRect);
    7878begin
    79   //Canvas.Brush.Style := Brush.Style;
     79  if Brush.Style = bsClear then Canvas.Brush.Style := Graphics.bsClear
     80    else Canvas.Brush.Style := Graphics.bsSolid;
    8081  Canvas.Brush.Color := Brush.Color;
    81   //Canvas.Pen.Style := Pen.Style;
     82  if Brush.Style = bsClear then Canvas.Pen.Style := Graphics.psClear
     83    else Canvas.Pen.Style := Graphics.psSolid;
    8284  Canvas.Pen.Color := Pen.Color;
    8385  Canvas.FillRect(Rect);
     
    8688procedure TGameCanvas.Line(const P1, P2: TPoint);
    8789begin
     90  if Brush.Style = bsClear then Canvas.Brush.Style := Graphics.bsClear
     91    else Canvas.Brush.Style := Graphics.bsSolid;
     92  Canvas.Brush.Color := Brush.Color;
     93  if Brush.Style = bsClear then Canvas.Pen.Style := Graphics.psClear
     94    else Canvas.Pen.Style := Graphics.psSolid;
     95  Canvas.Pen.Color := Pen.Color;
    8896  Canvas.Pen.Width := Pen.Width;
    8997  Canvas.Line(P1, P2);
     
    92100procedure TGameCanvas.Ellipse(const Bounds: TRect);
    93101begin
     102  if Brush.Style = bsClear then Canvas.Brush.Style := Graphics.bsClear
     103    else Canvas.Brush.Style := Graphics.bsSolid;
     104  Canvas.Brush.Color := Brush.Color;
     105  if Brush.Style = bsClear then Canvas.Pen.Style := Graphics.psClear
     106    else Canvas.Pen.Style := Graphics.psSolid;
     107  Canvas.Pen.Color := Pen.Color;
    94108  Canvas.Pen.Width := Pen.Width;
    95   Canvas.Brush.Color := Brush.Color;
    96109  Canvas.Ellipse(Bounds);
    97110end;
Note: See TracChangeset for help on using the changeset viewer.