So I am a big fan of EVE Online, I am working on my own little 2D top down space shooter that takes quite a few elements from that, at the moment it is simple and nothing like it. So far all I have is a way to create basic ships, then mount weapons on them, of which I have 2 that yet again, don’t do anything. It is not an MMO or multiplayer, just imagine a fun little top down action game with some depth and thought put into what you are using to blast the bad guys.
I am going to be building the Ship class up to have at least the basics down.
So I want to implement a “Ship Capacitor” that can be used to activate weapons and such, however I am not quite sure how to implement it.
For anyone who has never played EVE Online…
- Every ship has a capacitor, it is needed to use the majority of modules available to you.
- Capacitors have a recharge time in seconds that it takes to get from 0 to max
- They charge faster the lower they get
So my problem is, how on earth would I go about getting the time it would take to get a ships capacitor from 0 to max?
I was thinking at creation of the object, I simply simulate this in the constructor and then save the time in seconds to a field? Terrible idea
Is there a better way to do this?
EDIT:
Here is my code snippet, it recharges every 1 second and it takes the current - the max / 15 to simulate the lower it gets the faster it increases, later I will probably change the 15 variable so that it can be altered.
if(TimeUtils.nanoTime() - lastRecharge > TimeCoversion.secondToNanos(1)){
current = current + (max - current) / 15;
lastRecharge = TimeUtils.nanoTime();
}