Changeset 46 for trunk/Forms


Ignore:
Timestamp:
Nov 2, 2019, 12:22:07 AM (5 years ago)
Author:
chronos
Message:
  • Added: Key buffer to capture consecutive key presses even with slow animation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r40 r46  
    3636  private
    3737    RedrawPending: Boolean;
     38    KeyBuffer: array of Word;
    3839  public
    3940    procedure Redraw;
     
    5556procedure TFormMain.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    5657begin
    57   if Core.Game.Running and not Core.Game.Moving then begin
    58     case Key of
    59       37: Core.Game.MoveAllAndUpdate(drLeft, True);
    60       38: Core.Game.MoveAllAndUpdate(drUp, True);
    61       39: Core.Game.MoveAllAndUpdate(drRight, True);
    62       40: Core.Game.MoveAllAndUpdate(drDown, True);
     58  if Core.Game.Running then begin
     59    SetLength(KeyBuffer, Length(KeyBuffer) + 1);
     60    KeyBuffer[Length(KeyBuffer) - 1] := Key;
     61    if not Core.Game.Moving then begin
     62      while Length(KeyBuffer) > 0 do begin
     63        case KeyBuffer[0] of
     64          37: Core.Game.MoveAllAndUpdate(drLeft, True);
     65          38: Core.Game.MoveAllAndUpdate(drUp, True);
     66          39: Core.Game.MoveAllAndUpdate(drRight, True);
     67          40: Core.Game.MoveAllAndUpdate(drDown, True);
     68        end;
     69        if Length(KeyBuffer) > 1 then
     70          Move(KeyBuffer[1], KeyBuffer[0], (Length(KeyBuffer) - 1) * SizeOf(Word));
     71        SetLength(KeyBuffer, Length(KeyBuffer) - 1);
     72      end;
     73    end else begin
    6374    end;
    6475  end;
Note: See TracChangeset for help on using the changeset viewer.