Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 285 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?

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.

1  
2  
3  
4  
      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

1  
Time it takes to charge = Math.log(Capacitor value);
and you could use
1  
Math.floor()
and
1  
Math.ceil()
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:

1  
2  
3  
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 crap....lol

EDIT:

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!