Changeset 28 for trunk/UCore.pas


Ignore:
Timestamp:
Oct 3, 2011, 8:17:16 PM (13 years ago)
Author:
george
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r27 r28  
    103103    Engine: TEngine;
    104104    Position: TPoint;
     105    Score: Integer;
    105106    Direction: Integer;
    106107    ScreenFrame: TRectangle;
     
    189190    FBitmap: TBitmap;
    190191    FBitmapLock: TCriticalSection;
     192    FOnGameEnd: TNotifyEvent;
    191193    FRedrawPending: Boolean;
    192194    FBitmapLower: TBitmapTColor;
     
    209211    DigMasks: TListObject; // TListObject<TMatrixByte>
    210212    Lock: TCriticalSection;
     213    CurrentRound: Integer;
     214    MaxRound: Integer;
     215    procedure CheckGameEnd;
    211216    constructor Create;
    212217    destructor Destroy; override;
     
    215220    procedure Draw(Thread: TVirtualThread);
    216221    procedure NewGame;
     222    procedure NewRound;
    217223    property Bitmap: TBitmap read FBitmap write SetBitmap;
    218224    property Active: Boolean read FActive write SetActive;
     225    property OnGameEnd: TNotifyEvent read FOnGameEnd write FOnGameEnd;
    219226  end;
    220227
     
    938945        ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clBlack
    939946        else ItemsXY[ScreenFrame.Left + I, ScreenFrame.Bottom - 1] := clAqua;
     947
     948    for I := ScreenFrame.Left to ScreenFrame.Right - 1 do
     949      ItemsXY[I, 0] := $010101 * I;
    940950  end;
    941951end;
     
    9941004  Energy := 0;
    9951005  Shield := 0;
     1006  //Synchronize(Engine.CheckGameEnd);
    9961007end;
    9971008
     
    12261237  BytePerRow: Integer;
    12271238  RawImage: TRawImage;
    1228   Color: Integer;
     1239  Color: Int64;
    12291240  Shift: TPoint;
    12301241  XDiv, XMod, XAcc: Integer;
     
    12371248  if Assigned(FBitmap) then
    12381249  try
     1250    Lock.Acquire;
    12391251    Bitmap.BeginUpdate;
    12401252    RawImage := Bitmap.RawImage;
     
    12831295          Inc(SubPixelSizeX);
    12841296        end;
    1285 
    1286         Color := SwapBRComponent(FBitmapLower.Pixels[X, Y]);
     1297        Color := FBitmapLower.Pixels[X, Y] and $ffffff;
     1298
     1299        Color := SwapBRComponent(Color);
    12871300
    12881301        // Draw large pixel
     
    13021315  finally
    13031316    FBitmap.EndUpdate;
     1317    Lock.Release;
    13041318  end;
    13051319end;
     
    14641478    InitTanks;
    14651479    Name := SPlayer + ' ' + IntToStr(I + 1);
    1466     Enabled := True;
     1480    if I < 8 then Enabled := True;
     1481  end;
     1482end;
     1483
     1484procedure TEngine.CheckGameEnd;
     1485var
     1486  AliveCount: Integer;
     1487  I: Integer;
     1488begin
     1489  AliveCount := 0;
     1490  for I := 0 to Players.Count - 1 do
     1491  with TPlayer(Players[I]) do
     1492    if not Exploded then Inc(AliveCount);
     1493  if AliveCount <= 1 then begin
     1494    for I := 0 to Players.Count - 1 do
     1495    with TPlayer(Players[I]) do
     1496      if not Exploded then Inc(Score);
     1497    if CurrentRound < MaxRound then
     1498      NewRound else
     1499      if Assigned(FOnGameEnd) then
     1500        FOnGameEnd(Self);
    14671501  end;
    14681502end;
     
    15131547  InitDigMasks;
    15141548  Redraw;
     1549  MaxRound := 3;
    15151550end;
    15161551
     
    15741609  for I := 0 to PlayerPool.Count - 1 do
    15751610  with TPlayer(PlayerPool[I]) do
    1576   if Enabled then
     1611  if Enabled then begin
    15771612    Players.Add(PlayerPool[I]);
     1613    Score := 0;
     1614  end;
    15781615  ResizePlayerFrames;
    1579 
     1616  CurrentRound := 0;
     1617  NewRound;
     1618
     1619  Active := True;
     1620end;
     1621
     1622procedure TEngine.NewRound;
     1623var
     1624  I: Integer;
     1625begin
     1626  Active := False;
    15801627  World.Generate;
    15811628
    15821629  for I := 0 to Players.Count - 1 do
    1583   with TPlayer(Players[I]) do
     1630  with TPlayer(Players[I]) do begin
    15841631    Init;
     1632  end;
    15851633  ClearBackground := True;
    15861634  Redraw;
Note: See TracChangeset for help on using the changeset viewer.