Track & Field power bar

BlitzMax Forums/BlitzMax Beginners Area/Track & Field power bar

redmoth(Posted 2012) [#1]
I'm trying to make a running game, like from the classic Track & Field olympics game and I'm confused about the best way to make the computer competitors build up their power/sprint bar.

The player will build up their sprint bar by quickly pressing two keys as quickly as possible, and the more power, the quicker they run.
I'm a bit confused of the best way to do this, so I'm writing it here, I may solve it myself or someone else may if they are feeling helpful.

Variables for each runner object:
power (the power bar)
speed (the current speed of tapping the keys)
maxSpeed (the rate at which the computer taps the keys)

Here's my start:

Power = power - 1 //subtract 1 automatically
if power < 0 then power = 0 // make sure it can't be a negative number

//for computers
speed = speed + maxSpeed //maxSpeed will be for example 0.01
power = power + speed

x = x + power // add to the x position of the player


redmoth(Posted 2012) [#2]
That will continue to accelerate, so maybe if I add:
if power > 2 then power = 2


matibee(Posted 2012) [#3]
I came up with this....

Ignore the circular buffer stuff, that's just to graph the power value. I control power between 0 and 1.0 so if your player has a very maximum speed of 20.0/second, say, (pixels, feet, inches, whatever), you just do:

x = x + 20 * power

(assuming x is also a floating point value.)

For the computer player, simply set his newPower to 0.9 or some value depending on the difficulty you require. Don't give him max power as he'll be completely unbeatable.

(Edit played with figures and added CPU opponent value)



Last edited 2012


Derron(Posted 2012) [#4]
	If ( power < 0.0 ) 
		power = 0.0
	Else If ( power > 1.0 ) 
		power = 1.0
	End If 


Could be exchanged with

power = Max(0, Min(1, power)) 'clamping



But than you would be "set" each update, not only in case the value is out of boundaries.

Just a personal note.

bye
Ron


redmoth(Posted 2012) [#5]
Thank you that's awsome, and easily convertable for my game