thetawavegame / thetawave

A physics based, space shooter game made with Rust and the Bevy engine.
https://thetawave.metalmancy.tech
MIT License
164 stars 9 forks source link

Compute the fire rate using a method rather than updating the PlayerComponents each frame #133

Closed varoonp123 closed 9 months ago

varoonp123 commented 11 months ago

This reduces the number of times the fire rate is recalculated and avoids taking mutable/exclusive access to the players every frame.

This PlayerComponent.fire_period or what I renamed to base_attack_cooldown_seconds isnt really being used for anything. Should we delete it? Do you want this to not depend at all on the character type (captain vs juggernaut)?

Right now, the fire rate is entirely determined by

1.0 / (1.5 * ((0.8 * player.money as f32) + 4.0).ln())

Technically we could also memoize this, but it shouldnt need to be recomputed every frame. I kinda prefer this to incrementally updating a struct field because here we know exactly why the value is what it is.