Changeset 14


Ignore:
Timestamp:
Mar 22, 2011, 6:35:54 PM (13 years ago)
Author:
george
Message:
  • Fixed: If application focus is lost clear all pressed keys.
Location:
trunk
Files:
4 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;
  • trunk/UMainForm.lfm

    r13 r14  
    99  Menu = MainMenu1
    1010  OnCreate = FormCreate
     11  OnDeactivate = FormDeactivate
    1112  OnKeyDown = FormKeyDown
    1213  OnKeyUp = FormKeyUp
  • trunk/UMainForm.pas

    r13 r14  
    11unit UMainForm;
    22
    3 {$mode objfpc}{$H+}
     3{$mode Delphi}{$H+}
    44
    55interface
     
    3535    procedure AShowMapExecute(Sender: TObject);
    3636    procedure FormCreate(Sender: TObject);
     37    procedure FormDeactivate(Sender: TObject);
    3738    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    3839    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     
    9091procedure TMainForm.FormCreate(Sender: TObject);
    9192begin
     93  Application.OnDeactivate := FormDeactivate;
    9294  Randomize;
    9395  DoubleBuffered := True;
     
    126128  Engine.NewGame;
    127129  Image1Resize(Self);
     130end;
     131
     132procedure TMainForm.FormDeactivate(Sender: TObject);
     133begin
     134  Engine.KeyBoard.ClearAll;
    128135end;
    129136
     
    173180  Shift: TShiftState);
    174181begin
    175   Engine.KeyState[Key] := True;
     182  Engine.KeyBoard.KeyState[Key] := True;
    176183  StatusBar1.Panels[0].Text := IntToStr(Key);
    177184end;
     
    180187  );
    181188begin
    182   Engine.KeyState[Key] := False;
     189  Engine.KeyBoard.KeyState[Key] := False;
    183190end;
    184191
  • trunk/tunneler.lpi

    r13 r14  
    4242      </Item3>
    4343    </RequiredPackages>
    44     <Units Count="51">
     44    <Units Count="52">
    4545      <Unit0>
    4646        <Filename Value="tunneler.lpr"/>
     
    5050        <TopLine Value="1"/>
    5151        <CursorPos X="15" Y="4"/>
    52         <UsageCount Value="79"/>
     52        <UsageCount Value="82"/>
    5353      </Unit0>
    5454      <Unit1>
     
    5858        <ResourceBaseClass Value="Form"/>
    5959        <UnitName Value="UMainForm"/>
    60         <EditorIndex Value="9"/>
    61         <WindowIndex Value="0"/>
    62         <TopLine Value="62"/>
    63         <CursorPos X="25" Y="78"/>
    64         <UsageCount Value="79"/>
     60        <IsVisibleTab Value="True"/>
     61        <EditorIndex Value="11"/>
     62        <WindowIndex Value="0"/>
     63        <TopLine Value="19"/>
     64        <CursorPos X="1" Y="36"/>
     65        <UsageCount Value="82"/>
    6566        <Loaded Value="True"/>
    6667        <LoadedDesigner Value="True"/>
     
    7071        <IsPartOfProject Value="True"/>
    7172        <UnitName Value="UCore"/>
    72         <IsVisibleTab Value="True"/>
    7373        <EditorIndex Value="0"/>
    7474        <WindowIndex Value="0"/>
    75         <TopLine Value="1"/>
    76         <CursorPos X="20" Y="14"/>
    77         <UsageCount Value="79"/>
     75        <TopLine Value="350"/>
     76        <CursorPos X="22" Y="367"/>
     77        <UsageCount Value="82"/>
    7878        <Loaded Value="True"/>
    7979      </Unit2>
     
    104104      <Unit6>
    105105        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classesh.inc"/>
    106         <EditorIndex Value="3"/>
     106        <EditorIndex Value="5"/>
    107107        <WindowIndex Value="0"/>
    108108        <TopLine Value="19"/>
    109109        <CursorPos X="4" Y="36"/>
    110         <UsageCount Value="12"/>
     110        <UsageCount Value="13"/>
    111111        <Loaded Value="True"/>
    112112      </Unit6>
     
    143143      <Unit11>
    144144        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericMatrix.inc"/>
    145         <EditorIndex Value="2"/>
     145        <EditorIndex Value="4"/>
    146146        <WindowIndex Value="0"/>
    147147        <TopLine Value="152"/>
    148148        <CursorPos X="1" Y="158"/>
    149         <UsageCount Value="32"/>
     149        <UsageCount Value="33"/>
    150150        <Loaded Value="True"/>
    151151      </Unit11>
     
    175175      <Unit15>
    176176        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericList.inc"/>
    177         <WindowIndex Value="0"/>
    178         <TopLine Value="473"/>
    179         <CursorPos X="1" Y="60"/>
    180         <UsageCount Value="21"/>
     177        <EditorIndex Value="1"/>
     178        <WindowIndex Value="0"/>
     179        <TopLine Value="10"/>
     180        <CursorPos X="21" Y="13"/>
     181        <UsageCount Value="22"/>
     182        <Loaded Value="True"/>
    181183      </Unit15>
    182184      <Unit16>
     
    265267        <ResourceBaseClass Value="Form"/>
    266268        <UnitName Value="UMapForm"/>
    267         <EditorIndex Value="8"/>
    268         <WindowIndex Value="0"/>
    269         <TopLine Value="1"/>
     269        <EditorIndex Value="10"/>
     270        <WindowIndex Value="0"/>
     271        <TopLine Value="6"/>
    270272        <CursorPos X="20" Y="39"/>
    271         <UsageCount Value="58"/>
     273        <UsageCount Value="61"/>
    272274        <Loaded Value="True"/>
    273275      </Unit27>
     
    288290      <Unit30>
    289291        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/mathh.inc"/>
    290         <EditorIndex Value="1"/>
     292        <EditorIndex Value="3"/>
    291293        <WindowIndex Value="0"/>
    292294        <TopLine Value="58"/>
    293295        <CursorPos X="14" Y="75"/>
    294         <UsageCount Value="14"/>
     296        <UsageCount Value="16"/>
    295297        <Loaded Value="True"/>
    296298      </Unit30>
     
    305307        <Filename Value="../../../lazarus/lcl/intfgraphics.pas"/>
    306308        <UnitName Value="IntfGraphics"/>
    307         <EditorIndex Value="7"/>
     309        <EditorIndex Value="9"/>
    308310        <WindowIndex Value="0"/>
    309311        <TopLine Value="3131"/>
    310312        <CursorPos X="42" Y="3148"/>
    311         <UsageCount Value="15"/>
     313        <UsageCount Value="16"/>
    312314        <Loaded Value="True"/>
    313315      </Unit32>
     
    337339      <Unit36>
    338340        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericBitmap.inc"/>
    339         <EditorIndex Value="5"/>
     341        <EditorIndex Value="7"/>
    340342        <WindowIndex Value="0"/>
    341343        <TopLine Value="25"/>
    342344        <CursorPos X="14" Y="25"/>
    343         <UsageCount Value="19"/>
     345        <UsageCount Value="20"/>
    344346        <Loaded Value="True"/>
    345347      </Unit36>
     
    402404        <IsPartOfProject Value="True"/>
    403405        <UnitName Value="UPlatform"/>
    404         <UsageCount Value="38"/>
     406        <UsageCount Value="41"/>
    405407      </Unit44>
    406408      <Unit45>
     
    430432      <Unit48>
    431433        <Filename Value="../../../lazarus/lcl/include/custombitmap.inc"/>
    432         <EditorIndex Value="6"/>
     434        <EditorIndex Value="8"/>
    433435        <WindowIndex Value="0"/>
    434436        <TopLine Value="330"/>
    435437        <CursorPos X="35" Y="338"/>
    436         <UsageCount Value="15"/>
     438        <UsageCount Value="16"/>
    437439        <Loaded Value="True"/>
    438440      </Unit48>
     
    449451        <IsPartOfProject Value="True"/>
    450452        <UnitName Value="URectangle"/>
    451         <EditorIndex Value="4"/>
     453        <EditorIndex Value="6"/>
    452454        <WindowIndex Value="0"/>
    453455        <TopLine Value="120"/>
    454456        <CursorPos X="44" Y="150"/>
    455         <UsageCount Value="23"/>
     457        <UsageCount Value="26"/>
    456458        <Loaded Value="True"/>
    457459      </Unit50>
     460      <Unit51>
     461        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/sysutils/sysstrh.inc"/>
     462        <EditorIndex Value="2"/>
     463        <WindowIndex Value="0"/>
     464        <TopLine Value="147"/>
     465        <CursorPos X="10" Y="84"/>
     466        <UsageCount Value="11"/>
     467        <Loaded Value="True"/>
     468      </Unit51>
    458469    </Units>
    459     <JumpHistory Count="30" HistoryIndex="28">
     470    <JumpHistory Count="30" HistoryIndex="29">
    460471      <Position1>
    461472        <Filename Value="UCore.pas"/>
    462         <Caret Line="375" Column="1" TopLine="354"/>
     473        <Caret Line="376" Column="1" TopLine="354"/>
    463474      </Position1>
    464475      <Position2>
    465476        <Filename Value="UCore.pas"/>
    466         <Caret Line="376" Column="1" TopLine="354"/>
     477        <Caret Line="377" Column="1" TopLine="354"/>
    467478      </Position2>
    468479      <Position3>
    469480        <Filename Value="UCore.pas"/>
    470         <Caret Line="377" Column="1" TopLine="354"/>
     481        <Caret Line="379" Column="1" TopLine="354"/>
    471482      </Position3>
    472483      <Position4>
    473484        <Filename Value="UCore.pas"/>
    474         <Caret Line="379" Column="1" TopLine="354"/>
     485        <Caret Line="385" Column="1" TopLine="357"/>
    475486      </Position4>
    476487      <Position5>
    477488        <Filename Value="UCore.pas"/>
    478         <Caret Line="385" Column="1" TopLine="357"/>
     489        <Caret Line="387" Column="1" TopLine="359"/>
    479490      </Position5>
    480491      <Position6>
    481492        <Filename Value="UCore.pas"/>
    482         <Caret Line="387" Column="1" TopLine="359"/>
     493        <Caret Line="403" Column="1" TopLine="386"/>
    483494      </Position6>
    484495      <Position7>
    485496        <Filename Value="UCore.pas"/>
    486         <Caret Line="403" Column="1" TopLine="386"/>
     497        <Caret Line="404" Column="1" TopLine="386"/>
    487498      </Position7>
    488499      <Position8>
    489500        <Filename Value="UCore.pas"/>
    490         <Caret Line="404" Column="1" TopLine="386"/>
     501        <Caret Line="377" Column="10" TopLine="366"/>
    491502      </Position8>
    492503      <Position9>
    493504        <Filename Value="UCore.pas"/>
    494         <Caret Line="405" Column="1" TopLine="386"/>
     505        <Caret Line="175" Column="9" TopLine="158"/>
    495506      </Position9>
    496507      <Position10>
    497508        <Filename Value="UCore.pas"/>
    498         <Caret Line="410" Column="1" TopLine="386"/>
     509        <Caret Line="555" Column="3" TopLine="537"/>
    499510      </Position10>
    500511      <Position11>
    501         <Filename Value="UCore.pas"/>
    502         <Caret Line="411" Column="1" TopLine="386"/>
     512        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericMatrix.inc"/>
     513        <Caret Line="158" Column="1" TopLine="152"/>
    503514      </Position11>
    504515      <Position12>
    505516        <Filename Value="UCore.pas"/>
    506         <Caret Line="371" Column="1" TopLine="354"/>
     517        <Caret Line="374" Column="12" TopLine="363"/>
    507518      </Position12>
    508519      <Position13>
    509520        <Filename Value="UCore.pas"/>
    510         <Caret Line="372" Column="1" TopLine="354"/>
     521        <Caret Line="545" Column="6" TopLine="536"/>
    511522      </Position13>
    512523      <Position14>
    513524        <Filename Value="UCore.pas"/>
    514         <Caret Line="373" Column="1" TopLine="354"/>
     525        <Caret Line="565" Column="106" TopLine="561"/>
    515526      </Position14>
    516527      <Position15>
    517         <Filename Value="UCore.pas"/>
    518         <Caret Line="375" Column="1" TopLine="354"/>
     528        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericList.inc"/>
     529        <Caret Line="56" Column="58" TopLine="34"/>
    519530      </Position15>
    520531      <Position16>
    521         <Filename Value="UCore.pas"/>
    522         <Caret Line="376" Column="1" TopLine="354"/>
     532        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericList.inc"/>
     533        <Caret Line="214" Column="13" TopLine="188"/>
    523534      </Position16>
    524535      <Position17>
    525         <Filename Value="UCore.pas"/>
    526         <Caret Line="377" Column="1" TopLine="354"/>
     536        <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericList.inc"/>
     537        <Caret Line="51" Column="26" TopLine="34"/>
    527538      </Position17>
    528539      <Position18>
    529540        <Filename Value="UCore.pas"/>
    530         <Caret Line="379" Column="1" TopLine="354"/>
     541        <Caret Line="886" Column="6" TopLine="866"/>
    531542      </Position18>
    532543      <Position19>
    533         <Filename Value="UCore.pas"/>
    534         <Caret Line="385" Column="1" TopLine="357"/>
     544        <Filename Value="UMainForm.pas"/>
     545        <Caret Line="49" Column="56" TopLine="34"/>
    535546      </Position19>
    536547      <Position20>
    537         <Filename Value="UCore.pas"/>
    538         <Caret Line="387" Column="1" TopLine="359"/>
     548        <Filename Value="UMainForm.pas"/>
     549        <Caret Line="146" Column="5" TopLine="132"/>
    539550      </Position20>
    540551      <Position21>
    541         <Filename Value="UCore.pas"/>
    542         <Caret Line="403" Column="1" TopLine="386"/>
     552        <Filename Value="UMainForm.pas"/>
     553        <Caret Line="176" Column="20" TopLine="174"/>
    543554      </Position21>
    544555      <Position22>
    545         <Filename Value="UCore.pas"/>
    546         <Caret Line="404" Column="1" TopLine="386"/>
     556        <Filename Value="UMainForm.pas"/>
     557        <Caret Line="94" Column="37" TopLine="92"/>
    547558      </Position22>
    548559      <Position23>
    549         <Filename Value="UCore.pas"/>
    550         <Caret Line="377" Column="10" TopLine="366"/>
     560        <Filename Value="UMainForm.pas"/>
     561        <Caret Line="135" Column="7" TopLine="133"/>
    551562      </Position23>
    552563      <Position24>
    553564        <Filename Value="UCore.pas"/>
    554         <Caret Line="175" Column="9" TopLine="158"/>
     565        <Caret Line="156" Column="13" TopLine="139"/>
    555566      </Position24>
    556567      <Position25>
    557568        <Filename Value="UCore.pas"/>
    558         <Caret Line="555" Column="3" TopLine="537"/>
     569        <Caret Line="119" Column="24" TopLine="110"/>
    559570      </Position25>
    560571      <Position26>
    561         <Filename Value="../../PascalClassLibrary/Generics/TemplateGenerics/Generic/GenericMatrix.inc"/>
    562         <Caret Line="158" Column="1" TopLine="152"/>
     572        <Filename Value="UCore.pas"/>
     573        <Caret Line="788" Column="15" TopLine="771"/>
    563574      </Position26>
    564575      <Position27>
    565576        <Filename Value="UCore.pas"/>
    566         <Caret Line="374" Column="12" TopLine="363"/>
     577        <Caret Line="340" Column="22" TopLine="320"/>
    567578      </Position27>
    568579      <Position28>
    569         <Filename Value="UCore.pas"/>
    570         <Caret Line="545" Column="6" TopLine="536"/>
     580        <Filename Value="UMainForm.pas"/>
     581        <Caret Line="135" Column="27" TopLine="118"/>
    571582      </Position28>
    572583      <Position29>
    573         <Filename Value="UCore.pas"/>
    574         <Caret Line="565" Column="106" TopLine="561"/>
     584        <Filename Value="UMainForm.pas"/>
     585        <Caret Line="95" Column="1" TopLine="92"/>
    575586      </Position29>
    576587      <Position30>
    577         <Filename Value="UCore.pas"/>
    578         <Caret Line="521" Column="3" TopLine="519"/>
     588        <Filename Value="UMainForm.pas"/>
     589        <Caret Line="175" Column="1" TopLine="171"/>
    579590      </Position30>
    580591    </JumpHistory>
Note: See TracChangeset for help on using the changeset viewer.