Types and Timers

BlitzPlus Forums/BlitzPlus Beginners Area/Types and Timers

InvincibleWall(Posted 2010) [#1]
In the game I have been making (a side scroll shooter) I have a function that prints large red numbers of how much damage a Player/Enemy just took above their head and slowly raises them into the air before they disappear.

<code>
Function Damage(Player.Player,Dmg,BlowBack)
Player\cHP = Player\cHP - Dmg
If Player\cHP < 0
Player\cHP = 0
Else If Player\cHP > Player\mHP
Player\cHP = Player\mHP
End If
Player\xv = Player\xv + BlowBack
Player\yv = Player\yv - BlowBack/2
Damage.Damage = New Damage
Damage\Damage = -Dmg
Damage\x = Player\x
Damage\y = Player\y - Player\h*3/4
Damage\Limit = CreateTimer(1)
End Function
</code>

And in the Update phase

For Damage.Damage = Each Damage
Damage\y = Damage\y - 1
If TimerTicks(Damage\Limit) >= 1
Delete Damage
End If
Next

And in the Draw phase (though I don’t think this will help any)

For Damage.Damage = Each Damage
SetFont DamageFont
Color 200,0,0
Text Damage\x - (StringWidth(Damage\Damage)) /2,Damage\y,Damage\Damage
Next

The Type Itself

Type Damage
Field x#,y#
Field Damage
Field Limit$
End Type

This is how it is called in the Collision testing function

Damage(Player,Attack\Damage,Attack\BlowBack * Attack\Dir)

Anyway there is a problem when many calls to Damage() occur. The timers implanted in Damage\Limit seem to never seem to tick if their calls were close together. So if you hit an enemy once and a big -7 goes above his head it will vanish in 1 second but if you spam the Attack key as fast as you can the obscured numbers never disappear (though if you wait a second after spamming and attack again, that attacks number will disappear.

I was also wondering if it was practical to use timers instead a variable that counts down with each interval of the loop. I know that it then voids the FPS of the game but beyond that I didn’t see anything exactly wrong with it. I’m using the same method to slow down each characters frame changing rate

Anyway if anyone can spot the problem it would be much appreciated

Thanks in advance


PS: BlitzBasic.com came up in EXTREMELY small print one day and hasn’t changed back (it is only BlitzBasic.com no other site does it) wondered if it is the new standard or if I changed some setting on the site on accident


Sauer(Posted 2010) [#2]
If I understand your problem correctly, what may be happening is that the hits are registered so close together that there may be -7's occupying the same pixel space, even though they are different items. It just appears they are not disappearing, then disappear one by one till the last one goes (when you stop hitting the attack key).

As a side note, I've never used a CreateTimer timer in this fashion, so its hard for me to say whether that is your problem. If it were me, I would have had a damage timer type variable that is just decremented every loop until 0.

Anyway, maybe one thing you could do is limit the amount of damages that can happen per second. Use the millisecs() command to see how much time has elapsed since last call to Damage, and if its above a certain number, call Damage. Otherwise ignore it.


InvincibleWall(Posted 2010) [#3]
well I have just decided to change it to a countdown variable... which is what I probably should have started with anyway

and it cannot be that since they continue to rise indefinitely. so it is easy to see it is not the same one (I should have posted this image before hand)



Last edited 2010