Sign in to follow this  
shineability

Track & Field power/speed meter

Recommended Posts

Does anyone have an idea how to program the logic of a power/speed meter for a game in the genre of Track & Field? Or maybe a link to an article on this topic? Tnx in advance, M.

Share this post


Link to post
Share on other sites
Captain P,

In this case I mean a power meter that increases by tapping two keys in sequence very fast.
The faster you tap them, the harder it gets to reach maximum power.
I'm quite sure it can be done with some exponential function math stuff :)

Just wondering if anybody already made something like this or whether someone has insight on how something ike this can be done.

Tnx, M.


Share this post


Link to post
Share on other sites
I assume many have written such a thing before, and I also assume it's not something worthy to write a tutorial for. It sounds pretty straightforward to me at least. What I mean is, it's more important to get insight into how to convert your ideas into working code than it is to write specific things as these.

Let's break up your problem into little pieces. You want a bar to fill when two buttons are tapped repeatedly. Some questions arise: does it matter with which button the sequence is started? What should happen if the same button is tapped twice? Should the bar increase by a steady amount each press, so as soon as you stop tapping keys it starts to lower, or should there be a speed that's affected by key presses: pressing ups the speed, which slowly drops over time, so after leaving the buttons alone, the bar fills up a little, but then goes down?

In other words: how exactly do you want it to behave? Once you know that, you've probably already figured out how to do it. I hope that these questions will give you a better understanding of your problem. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by shineability

The faster you tap them, the harder it gets to reach maximum power.


Is this really what you mean... Or are you trying to say, " the higher up on the power meter you go, the faster you need to tap to increase power further" ?

symantics...

Share this post


Link to post
Share on other sites
Well, the actually visible meter and the controller behind it are separate concepts. What you want is to know how to design the controller, and then the meter is just a simple case of displaying the variable you have decided to use to represent the "power".

For an "oscillating" action, I could see something simple being done with a state machine:
data State = A | B
data MeterAmount = integer
data Power = float

State = A

onButtonPress(button):
if button == B and State == A then
// Pushed the B button, go to the B state
State = B
if button == A and State == B then
// Pushed the A button, go to the A state and increase the meter since a full cycle has been done
MeterAmount++;
State = A

onMeterDraw(MeterAmount):
drawRect(black, 100%)
drawRect(red, MeterAmount / MaxMeterAmount)

onRunning:
player.pos.x += power * time;



So something like pushing the A button in the A state will do nothing, but pushing the B button will move to the B state.

If I could find a state machine diagram generator on the web I'd draw a picture.

Now, for making the power increase taper off near the end (so it's not a linear pushes-to-power ratio) you can just use some sort of math function (I'd use something like power += 1/MeterAmount in this example, but that might be too severe for your needs).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this