The Daily Click ::. Forums ::. Klik Coding Help ::. reloading handgun logic
 

Post Reply  Post Oekaki 
 

Posted By Message

tetsuya_shino



Registered
  12/08/2004
Points
  491
23rd December, 2008 at 10:20:51 -

Greetings. I have a little math problem for anyone that is interested. I have an idea of how I have to do it, but maybe someone can think of a less painful way. I want to have a reloading animation for my game. The animation is already done, but the problem is the logic.

I want to have 3 values;

current ammo in clip
max ammo clip can hold
number of extra bullets (doesn't enclude the first value)

an example would be 'handgun 9/9 30'

I want the player to be able to reload when the clip runs dry (0/9), but also reload at any given time. If there are already bullets in the clip (but isn't totally filled) then the corrent number of bullets should be taken from the numuber of extra bullets value and added do the current ammo vaule.. but not to excend the max ammo clip value.

any ideas?

 
n/a

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
23rd December, 2008 at 10:45:35 -

I think you should do something like this:

+Player presses 'r'

-Subtract ("max ammo clip can hold" - "current ammo") from "Number of extra bullets"
-Set "current ammo" to "max ammo clip can hold" // Sets the current ammo to 9 in this case

If the player presses 'r' while there are 5 bullets left ('handgun 5/9 30') then it will set the current ammo to 9 and subtract 4 (max ammo - current ammo = 9 - 5) from the extra bullets, making it 'handgun 9/9 26'

This will also work if the current ammo is 0 (9-0 = 9) so it would be 'handgun 9/9 21'. But when the current ammo reaches 0 you should display a "reload warning' or something and prevent the player from shooting. Or if you want it to automatically reload when it reaches 0, just use the same code as above but replace "player presses 'r'" with "current ammo = 0"

Sorry, I've just re-ordered the events above. You need to subtract from the extra bullets before you set the current ammo, or else the extra bullets value won't change as it should.

Here's one I prepared earlier:

http://download340.mediafire.com/ndzmndjbzwzg/qydoz3ldqzn/Reload.mfa

Hope this helps!

Edited by -J-

 
n/a ...
   

Post Reply



 



Advertisement

Worth A Click