Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (M_D), 1,430 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Reloading algorithm #401920
05/26/12 05:40
05/26/12 05:40
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Hey guys, so I am looking for a reloading algorithm. Something where...

X = Current Ammo (Maximum of 30)
Y = Ammo left

So when you activate the reload sequence...

if X=24 and Y=60, then X=30 and Y=54

if X=15 and Y=4, then X=19 and Y=0

if X=19 and Y=15, then X=30 and Y=4

I have been trying and trying to get this working and to no avail. All of the solutions I made work, but they require a ton of if/else statements and I know there is a much more simple way of doing this. So, anyone have any ideas?

Re: Reloading algorithm [Re: exile] #401922
05/26/12 07:28
05/26/12 07:28
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Code:
var ammo_reload = minv(
    ammo_left,          // Maximum is ammo_left, so we can't reload bullets we don't have
    30 - ammo_current); // Calculate missing ammo in weapon
ammo_left -= ammo_reload;
ammo_current += ammmo_reload;


Should do the stuff you want


Visit my site: www.masterq32.de
Re: Reloading algorithm [Re: MasterQ32] #401923
05/26/12 08:04
05/26/12 08:04
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Perfect! I never even knew about minv! After seeing how its used I could use this to reduce the amount of code I have. Thanks MasterQ32, With your permission would I be able to add this to a contribution I am making? Essentially, its a big contribution with code snippets and other useful things for beginning and advanced programmers alike. With credit going to you of course.

Re: Reloading algorithm [Re: exile] #401927
05/26/12 11:01
05/26/12 11:01
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
no problem, you don't need to credit me for this snippet, but if you want, you can grin


Visit my site: www.masterq32.de

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1