This relates to DelphiX.
I've been trying to make a remake of 1942(the top-down scrolling shooter) and my code for shooting bullets looks as follows:
The Bullet Class:
Code:
TBullet = class(TImageSprite)
Public
Procedure DoMove(MoveCount: Integer); override;
Procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
End;
The Shooting Code In The Timer:
Code:
Dec(Shot_Rate);
If (Shot_Rate < 0) And (GetKeyState(32) and 128 = 128){<-- The player has pressed Spacebar(32)}
Then
Begin
Shot_Rate := 10;// So as not to shoot continuously
With TBullet.Create(Engine.Engine) Do
Begin
Image := Sprites.Items.Find('Bullet');
X := Hero.X + (Hero.Width DIV 2 - 15);
Y := Hero.Y;
Z := 14;
Width := Image.Width;
Height := Image.Height;
End;//With
End;//If
The DoMove Looks as follows:
Code:
procedure TBullet.DoMove(MoveCount: Integer);
begin
inherited;
Collision;
Y := Y - 5;
If Y < (0 - Height)
Then Free;
The Problem is:
If I shoot 1 bullet and let it leave the screen, everything works fine.
However, If I shoot a bullet and then shoot another one BEFORE the first bullet leaves the screen I get the error: "Project Plane_Project Raised Exception Class EListError with message 'List index out of bounds(10)'. Use Step Or Run To Continue"
Without the Free; the program works fine however, If I shoot continuously for a long time, the framerate decreases
Any Ideas?
Bookmarks