Thread: Fps help
View Single Post
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 05-21-2010, 03:54 PM

Just use a number variable called "ammo" and set it to the amount you want for that gun. Then, in the method where you shoot, say "if(ammo > 0), do the shoot method and decrement "ammo" by 1. You can then have a reloading method where you do the animation of reloading the gun, and at the end of the animation you do "ammo = (amount of ammo you want in the gun)". Once you do that you will have a system where you only shoot if you have a set amount of ammo in the gun, and once you run out you have to reload.

You can even go a step more realistic (only if you want) and have a limited amount of ammo overall, which could be another number variable called "totalAmmo", and in the reloading method you do "if((amount of ammo you want in gun) > totalAmmo), ammo = (amount of ammo you want in gun) - totalAmmo, else ammo = (ammount of ammo you want in gun)". Tell me if this does not make sense to you and maybe I will make an example.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote