Changeset 11 for trunk/UGame.pas
- Timestamp:
- Oct 4, 2019, 11:57:05 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r10 r11 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math ;8 Classes, SysUtils, Dialogs, fgl, Graphics, Types, Forms, Math, DateUtils; 9 9 10 10 type … … 30 30 TGame = class 31 31 private 32 FMoving: Boolean; 32 33 FOnChange: TNotifyEvent; 33 34 FRunning: Boolean; … … 43 44 Cells: array of array of TCell; 44 45 TopScore: Integer; 46 AnimationDuration: Integer; 45 47 procedure GameOver; 46 48 function FillRandomCell: Integer; … … 60 62 property Running: Boolean read FRunning write FRunning; 61 63 property OnChange: TNotifyEvent read FOnChange write FOnChange; 64 property Moving: Boolean read FMoving; 62 65 end; 63 66 … … 318 321 MovedCount: Integer; 319 322 X, Y: Integer; 320 Step: Integer;321 323 I: Integer; 322 const 323 StepCount = 10; 324 AnimationDuration = 30; 325 begin 324 StartTime: TDateTime; 325 EndTime: TDateTime; 326 Time: TDateTime; 327 Part: Double; 328 begin 329 FMoving := True; 326 330 //Diff := DirectionDiff[Direction]; 327 331 case Direction of … … 397 401 Inc(PI.Y); 398 402 end; 399 for Step := 0 to StepCount - 2 do begin 403 404 // Animate cell move 405 StartTime := Now; 406 EndTime := StartTime + AnimationDuration / 300 * OneSecond / Size.X; 407 if AnimationDuration > 0 then 408 repeat 409 Time := Now; 410 Part := (Time - StartTime) / (EndTime - StartTime); 400 411 for Y := 0 to Size.Y - 1 do 401 412 for X := 0 to Size.X - 1 do begin 402 413 if Cells[Y, X].Moving then 403 Cells[Y, X].Shift := Point(Trunc( Step / StepCount * MoveDirection.X * 100),404 Trunc( Step / StepCount * MoveDirection.Y * 100));414 Cells[Y, X].Shift := Point(Trunc(Part * MoveDirection.X * 100), 415 Trunc(Part * MoveDirection.Y * 100)); 405 416 end; 406 417 DoChange; 407 418 Application.ProcessMessages; 408 Sleep(AnimationDuration div StepCount); 409 end; 419 Sleep(10); 420 until Time > EndTime; 421 422 // Set final cell values 410 423 for Y := 0 to Size.Y - 1 do 411 424 for X := 0 to Size.X - 1 do begin … … 416 429 end; 417 430 Result := MovedCount; 431 FMoving := False; 418 432 end; 419 433 … … 434 448 constructor TGame.Create; 435 449 begin 450 AnimationDuration := 30; 436 451 end; 437 452
Note:
See TracChangeset
for help on using the changeset viewer.