unit UnitBullet;
interface
uses UnitBasis, extctrls, MMSystem, Unit1;
type TBullet =
class (TBasis)
protected
Schuss1 :
array of TImage;
procedure ShotCreate;
procedure MoveShot;
function Collision(Schuss : TImage ; i : integer) : boolean;
end;
implementation
procedure TBullet.ShotCreate ;
var Schusstemp : TImage;
begin
SndPlaySound( '
.\pew.wav', SND_ASYNC );
Schusstemp := TImage.Create(FormStarship);
Schusstemp.Parent := FormStarship;
// this is important
Schusstemp.Left := Raumschiff.left + (RaumSchiff.width
div 2);
// X coordinate
Schusstemp.Top := RaumSchiff.top - 20;
// Y coordinate
Schusstemp.Picture := Schuss.Picture;
SetLength(Schuss1, High(Schuss1) + 2);
Schuss1[High(Schuss1)] := Schusstemp;
end;
function TBullet.Collision(Schuss : TImage ; i : integer) : boolean;
var xposition, yposition: integer;
begin
Collision := false;
xposition := Schuss.left;
yposition := Schuss.top;
if (xposition >= Invader[i].left)
and (xposition <= (Invader[i].left + Invader[i].width))
then
begin
if (yposition <= (Invader[i].top + Invader[i].height))
and (yposition >= Invader[i].Top)
then
Collision := true
else
Collision := false
end
else
Collision := false;
end;
procedure TBullet.MoveShot;
var j,i,x : integer;
collide : boolean;
begin
for j := High(Schuss1)
downto 0
do
begin
collide := false;
for i := 1
to 21
do
begin
if (Collision(Schuss1[j],i) = true)
and (Invader[i].Visible = true)
then
begin
collide := true;
Invader[i].visible := false;
SndPlaySound( '
.\boom1.wav', SND_ASYNC );
Schuss1[j].Free;
for x:=j
to high(Schuss1)-1
do
Schuss1[x] := Schuss1[x+1];
SetLength(Schuss1,length(Schuss1)-1);
break;
end
end;
if collide = false
then
if Schuss1[j].top > Spielfeld.top + 5
then
Schuss1[j].top := Schuss1[j].top - 10
else
begin
Schuss1[j].Free;
for x:=j
to high(Schuss1)-1
do
Schuss1[x] := Schuss1[x+1];
SetLength(Schuss1,length(Schuss1)-1);
end;
end;
end;
end.