I am making a topdown shooter and have some logic problems with gun reload.
I did some vars to allow me to reload.
Pistol have vars to: max ammo, current ammo and reload need to max ammo.
Player have var ammo amount.
THE LOGIC IS:
I. Player ammo amount > reload ammo need = player have more, so max ammo of pistol and subtract the ammo reload need from player.
II. Player ammo amount = reload ammo need = player have exacly ammo, so just make pistol max ammo amount (15) and makes player ammo = 0
III. Player ammo amount < reload ammo need = player have less ammo than need, so do pistol current ammo + player ammo amount, and after that makes player ammo = 0
Works fine in almost all cases, but have some problems:
- when I have 5 bullets in Pistol and 15 on player, the game reload all making the pistol have 20 and player 0.
- when I have 10 bullets in Pistol and 10 on player, the game math do pistol have 15 and player 0 (losting 5 in the process)
Seems the gdev is using the wrong logic:
Because in the case 1, the engine should use the logic I, but seems the engine is choosing the logic III.
In the case 2, the engine should use the logic I, but seems the engine is choosing the logic II.
Idk where I am wrong