title: Collision detection in delphi (pascal)
body: <p>I'm making my own version of Space Invaders for my A Level project and I am stuck with the collision detection. I need to detect collision when the bullet hits one of the invaders and I'm really stuck.</p>
  
  <p>The invaders currently are stored in a 2d array and move on a timer, the code for this is as follows:</p>
  
  <pre><code>for Row:=1 to 5 do
  begin
  frmGame.Canvas.FillRect(WaveArea)
  for Column:=1 to 11 do
    begin
      frmGame.Canvas.Draw(30+Column*50+x, 180 Images[1].Picture.Graphic);
      frmGame.Canvas.Draw(30+Column*50+x, 230 Images[2].Picture.Graphic);
    end;
   x:=x+xShift;
  end;
  if x&gt;500 then
   tmrMoveInvaders.Enabled:=False;
  </code></pre>
  
  <p>The collision code which I have written does not work but I am not sure why. It could be the way in which the images are loaded onto the form by using a 2D array but I'm not sure.</p>
  
  <p>The code for the collision procedure is:</p>
  
  <pre><code>Procedure Collision(img:TImage);
  Var
   TargetLeft,BulletLeft:integer;
   TargetRight,BulletRight:integer;
   TargetTop,BulletTop:integer;
   TargetBottom,BulletBottom:integer;
   Hit:boolean;
  
  begin
   with frmGame do
    hit:=true;
    TagetLeft:=img.Left;
    BulletLeft:=shpBullet.Left;
    TargetRight:=img.Left+46; //left + width of the image
    BulletRight:=shpBullet.Left+8;
    TargetTop:=img.Top;
    BulletTop:=shpBullet.Top;
    TargetBottom:=img.Top+42; //top + height of image
    BulletBottom:=shpBullet.Top+15;
  
    if (TargetBottom &lt; BulletTop) then hit:=false;
    if (TargetTop &gt; BulletBottom) then hit:=false;
    if (TargetRight &lt; BulletLeft) then hit:=false;
    if (TargetLeft &gt; BulletRight) then hit:=false;
    if not img.Visible then hit:=false;
  
    if hit=true then
     img.Visible:=false;
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>