Public Group

# Track & Field power/speed meter

This topic is 4061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
What sort of power/speed meter do you want? And what do you find confusing about it?

##### 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 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 on other sites
Quote:
 Original post by shineabilityThe 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 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 | Bdata MeterAmount = integerdata Power = floatState = AonButtonPress(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 = AonMeterDraw(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).

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632652
• Total Posts
3007654
• ### Who's Online (See full list)

There are no registered users currently online

×