PDA

View Full Version : Attacker running out of bombs DelphiX Starfighter Game



Wizard
23-10-2007, 12:24 PM
Hi everyone. I did some tests and the code below generates bombs at the correct intervals. I played my game and realized that my attacker runs out of bombs for some reason after playing my game for a long period of time. Am I doing something wrong? I have the same code for the other attackers but they can get destroyed and this one not yet -- they seem to be fine.

if((FTamaCount<300) and (FCounter-FOldTamaTime>=150)) then
begin
Bomb := TBomb.create(FormGame.DXSpriteEngine.Engine);
Bomb.OnCollision := formGame.BombCollision;
FTamaCount := fTamaCount+1*updatespeed;
FOldTamaTime := FCounter;
end;
FCounter := FCounter + UpdateSpeed;
Any suggestions?

Traveler
23-10-2007, 12:59 PM
Hmm, if the problem is inside this piece of code, I'd say this

if&#40;FTamaCount 300>=150&#41; then
part shouldn't be something like

if&#40;&#40;FTamaCount<300&#41; and &#40;FTamaCount>=150&#41;&#41; then

If it's not that, then I think we need to see a bit more of the code

(Edit: I see the pascal tags mess up the code a bit, so it could be that your code is already in the mentioned format)

Wizard
23-10-2007, 01:09 PM
This is what I've got:

if FTamaCount smaller than 300 and FCounter-FOldTamaTime greater or equal to 150 then

Thanks Traveller. Yes the tags messed it up. Some code:


procedure TAttacker.DoMove&#40;MoveCount&#58; integer&#41;;
begin
inherited DoMove&#40;MoveCount&#41;;
if &#40;fMode = 0&#41; then
begin
if &#40;Movement = 0&#41; Then
Movement &#58;= Random&#40;2&#41;;
if X > 1250 Then Movement &#58;= 1;
if X < -500 Then Movement &#58;= 2;

Case Movement of
1&#58;
X &#58;= X - &#40;1.5*UpdateSpeed&#41;;
2&#58;
X &#58;= X + &#40;1.5*UpdateSpeed&#41;;
end;
if&#40;&#40;FTamaCount<300&#41; and &#40;FCounter-FOldTamaTime>=150&#41;&#41; then
begin
Bomb &#58;= TBomb.create&#40;FormGame.DXSpriteEngine.Engine&#41;;
Bomb.OnCollision &#58;= formGame.BombCollision;
FTamaCount &#58;= fTamaCount+1*updatespeed;
FOldTamaTime &#58;= FCounter;
end;
FCounter &#58;= FCounter + UpdateSpeed;
end;
end;

constructor TBomb.create&#40;parent&#58; TSpriteEngine&#41;;
begin
inherited Create&#40;parent&#41;;
self.Image &#58;= FormGame.DXImageList.Items&#91;formGame.FireBallImageI ndex&#93;;
self.X &#58;= attacker.X + 80;
self.Y &#58;= attacker.Y + 100;
self.Width &#58;= self.Image.Width;
self.Height &#58;= self.Image.Height;
self.PixelCheck &#58;= false;
end;

procedure TBomb.DoMove&#40;MoveCount&#58; integer&#41;;
begin
inherited DoMove&#40;MoveCount&#41;;
Y &#58;= Y + &#40;4 * UpdateSpeed&#41;;
if &#40;Player.hit&#41; then
Dead;
if &#40;Y >= FormGame.DXDrawGame.Height +20&#41; Then
Dead;
collision;
end;

Traveler
23-10-2007, 08:15 PM
Hmm, it's still not easy to spot the error. What's FCounter used for? I see you are updating it every pass and then use it's value for FOldTamaTime. It's never being reset or initialized to a certain value though.
I'm not sure, but that could be the problem.

Wizard
24-10-2007, 09:56 AM
I think FCounter is used to calculate the intervals at which bombs are created...not too sure. It's used in the Delphix samples.

Anyway, I set FCounter to 0 in the attacker.create and the bomb.create and now it generates bombs for about double the time it used to do and then it stops for some reason.

I now changed the values to 600 and 300 and it seems to be working fine :-)

User137
24-10-2007, 03:44 PM
if (FTamaCount<300 and (FTamaCount>=150) then

Edit #12+: Where's option to delete posts? :twisted:

jdarling
24-10-2007, 04:02 PM
Any time you have <> in your posts you need to check the "Disable HTML in this post" check box below the post editor. Then your stuff will come through just fine. The problem is that phpBB is trying to escape your >= and <'s and thus your getting garbage out. This is explained in many threads on this site, unfortunately searching for > and < return too many results (HINT HINT on a sticky about it guys).

Wizard
25-10-2007, 05:35 AM
if((FTamaCount<600) and (FCounter-FOldTamaTime>=300)) then
begin
Bomb := TBomb.create(FormGame.DXSpriteEngine.Engine);
Bomb.OnCollision := formGame.BombCollision;
FTamaCount := fTamaCount+1*updatespeed;
FOldTamaTime := FCounter;
end;
FCounter := FCounter + UpdateSpeed;

This is what I got, it seems to be working fine now.