-1

私は自分の A レベル プロジェクト用に独自のバージョンのスペース インベーダーを作成していますが、衝突検出に行き詰まっています。弾丸が侵入者の 1 つに当たったときに衝突を検出する必要があり、本当に立ち往生しています。

現在、侵入者は 2 次元配列に格納され、タイマーで移動します。このコードは次のとおりです。

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>500 then
 tmrMoveInvaders.Enabled:=False;

私が書いた衝突コードは機能しませんが、その理由がわかりません。2D 配列を使用して画像をフォームにロードする方法かもしれませんが、よくわかりません。

衝突手順のコードは次のとおりです。

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 < BulletTop) then hit:=false;
  if (TargetTop > BulletBottom) then hit:=false;
  if (TargetRight < BulletLeft) then hit:=false;
  if (TargetLeft > BulletRight) then hit:=false;
  if not img.Visible then hit:=false;

  if hit=true then
   img.Visible:=false;

どんな助けでも大歓迎です。

4

1 に答える 1