Originally Posted by
phibermon
please post your code for how you setup the array of bullets
I'm using fixed length arrays:
Code:
bullets: array [0..100] of TBullet;
Then in a Timer event I create, move and destroy the bullets:
Code:
if (plshoot=true) and (plcanshoot=true) then
begin
abullet:=TBullet.create(Player.Left,Player.Top,bulletpic);
bullets[numofbullets]:=abullet;
inc(numofbullets);
end;
if numofbullets>=1 then
begin
for i:=0 to numofbullets-1 do
begin
if bullets[i]<>nil then
begin
bullets[i].yplace:=bullets[i].yplace-4;
if bullets[i].yplace<10 then
begin
freeandnil(bullets[i]);
if i=numofbullets-1 then
dec(numofbullets)
else
begin
for j:=i+1 to numofbullets-1 do
bullets[j-1]:=bullets[j];
dec(numofbullets);
end;
end;
end;
end;
end;
(I have already corrected the first variable of the loops from 1 to 0, as you wrote.)
When I press the fire button, the bullets are only flash at the top of the player. :-/
Bookmarks