Ok i created a mini-game which involved throwing object. There are 5 objects(TImage). If I press on 'g' then if object 1 not throwed yet then it will be throw, if object 1 is throwed then object 2 will be throw and so on. When it reach certain Top.Position it will disappear and count as not throwed. Here is my code :
shot : Array[1..5] of TImage;
procedure TForm1.FormCreate(Sender: TObject);
begin
for sh := 1 to 5 do
shot[sh] := TImage.Create(Self);
with shot[sh] do
begin
Parent := Self;
Top := 450;
Left := 250;
Width := 20;
Height := 20;
Visible := False;
Picture.loadfromFile('Item1.jpg');
end;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
if (key = 'g') then
begin
if shot[1].Visible = False then
shot[1].Visible := True
else if shot[2].Visible = False then
shot[2].Visible := True
else if shot[3].Visible = False then
shot[3].Visible := True
else if shot[4].Visible = False then
shot[4].Visible := True
else if shot[5].Visible = False then
shot[5].Visible := True;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
for sh := 1 to 5 do
if shot[sh].Visible = True then
shot[sh].Top := Shot[sh].Top - quickness - speed;
if Shot[sh].Top < 80 then
miss;
end;
procedure TForm1.miss;
begin
for sh := 1 to 5 do
if Shot[sh].Top < 80 then
begin
Shot[sh].Visible := False;
Shot[sh].Top := 450;
end;
end;
My probleem :
I cant throw more than 1 at a time .
When I throwed 1, I have to press 4 more times and object 1 have to be invisible else it wont throw
EDIT : Probleem solve. I have to start a begin and end for each loop
;