Changeset 14 for trunk/UCore.pas


Ignore:
Timestamp:
Mar 22, 2011, 6:35:54 PM (14 years ago)
Author:
george
Message:
  • Fixed: If application focus is lost clear all pressed keys.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r13 r14  
    113113  end;
    114114
     115  { TKeyboard }
     116
     117  TKeyboard = class
     118    KeyState: array[0..High(Word)] of Boolean;
     119    procedure ClearAll;
     120  end;
     121
    115122  { TEngine }
    116123
     
    127134    function IsInsideHouses(Pos: TPoint): Boolean;
    128135  public
    129     KeyState: array[0..High(Word)] of Boolean;
     136    Keyboard: TKeyboard;
    130137    World: TWorld;
    131138    Players: TObjectList; // <TPlayer>
     
    166173  TFastBitmapPixelComponents(Result).R := TFastBitmapPixelComponents(Value).B;
    167174  TFastBitmapPixelComponents(Result).B := TFastBitmapPixelComponents(Value).R;
     175end;
     176
     177{ TKeyboard }
     178
     179procedure TKeyboard.ClearAll;
     180var
     181  I: Integer;
     182begin
     183  for I := 0 to High(KeyState) do
     184    KeyState[I] := False;
    168185end;
    169186
     
    318335  Delta.X := 0;
    319336  Delta.Y := 0;
    320   if Engine.KeyState[Ord(Keys.Down)] then Delta.Y := Delta.Y + 1;
    321   if Engine.KeyState[Ord(Keys.Up)] then Delta.Y := Delta.Y - 1;
    322   if Engine.KeyState[Ord(Keys.Right)] then Delta.X := Delta.X + 1;
    323   if Engine.KeyState[Ord(Keys.Left)] then Delta.X := Delta.X - 1;
     337  if Engine.KeyBoard.KeyState[Ord(Keys.Down)] then Delta.Y := Delta.Y + 1;
     338  if Engine.KeyBoard.KeyState[Ord(Keys.Up)] then Delta.Y := Delta.Y - 1;
     339  if Engine.KeyBoard.KeyState[Ord(Keys.Right)] then Delta.X := Delta.X + 1;
     340  if Engine.KeyBoard.KeyState[Ord(Keys.Left)] then Delta.X := Delta.X - 1;
    324341
    325342  NewDirection := Direction;
     
    348365  end;
    349366
    350   if Engine.KeyState[Ord(Keys.Shoot)] then
     367  if Engine.KeyBoard.KeyState[Ord(Keys.Shoot)] then
    351368    if Bullets.Count < MaxBulletCount then begin
    352369      NewBullet := TBullet.Create;
     
    533550  Shield := 1;
    534551  PlaceHouse;
     552  ShowTank;
    535553end;
    536554
     
    756774  IntfImage := TLazIntfImage.Create(1, 1);
    757775  Players := TObjectList.Create;
     776  Keyboard := TKeyboard.Create;
    758777  World := TWorld.Create;
    759778  World.Engine := Self;
     
    766785  IntfImage.Free;
    767786  Players.Free;
     787  Keyboard.Free;
    768788  World.Free;
    769789  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.