Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Recharge System  (Read 365 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771
« Posted 2014-05-15 17:49:05 »

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?


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();

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Nausica
« Reply #1 - Posted 2014-05-15 18:21:16 »

If my math serves me right, you would use a logarithmic function for that no?

something like this graph here where the x is the Capacitor value, and the y is the time it takes to charge. As the Capacitor value increases, it takes more time to charge up to a certain threshold...

In JAVA, you would implement that by doing something like

Time it takes to charge = Math.log(Capacitor value);
and you could use
to limit the values.

This may not be what you're looking for, but it's what immediately came to mind
Offline Gibbo3771
« Reply #2 - Posted 2014-05-15 18:29:26 »

Thanks for your reply, that graph make sense however the pseudo you wrote is a bit eh, well no idea what that really does? lol

I just implemented a cheat way of doing it but it really sucks, that is to basically run a while loop in the constructor of the capacitor, since I only ever regen capacitor every 1 second, I basically done:

while current value < max value
  do the thing
  increase an integer

integer is how many loop iterations that it took to generate cap from 0 to max, however this is


I think I might have misunderstood your post, that will increase my cap over time the way I want it.

What I really want is the time it takes from 0 to max. If that is what you are trying to show me, sorry but yeah, I don't get it lol.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nausica
« Reply #3 - Posted 2014-05-15 18:35:22 »

They are static values. I.e you would do something like

- Get the current recharge%
- Apply the Math.log() using the recharge% (so Math.log(recharge%))
- That will return the current pace at which the recharge would increase, relative to the other recharge%
- Use Math.floor() and Math.ceil() to limit the pace value, so it doesn't increase too slowly, or too quickly.

I have no idea what your game code looks like so I can't really implement it to your actual values for you, just saying it could be done using Math.log()

Since you have different Capacitors you could use different Multipliers for the pace values. Sorry if I'm not understanding your problem correctly.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (36 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (44 views)
2015-07-27 16:38:00

Riven (24 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (39 views)
2015-07-25 00:14:37

BurntPizza (48 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53

NoxInc (40 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!