Hello everybody.
I have a little conception problem, and i would like your opinion please.
What i wish :
- A caracter can jump
- The width of jump is variale ( in pixel )
- The length of jump is variable too ( in ms )
For exemple the caracter can make a jump on 300 pixels in 1 seconde or another on 600 in 3 secondes.
it must fallow a parabole
Actualy i have succeeded to get the X position.
But it’s difficult to get the Y position.
The code :
/**
* Attributes
*/
// is the caracter jumping ?
private boolean isJumping = false;
// is the jump begun ?
private boolean isJumpingStarted = false;
// Jump length (ex : 2 seconde)
private int jumpPeriod = 2000;
// Jump length index
private long jumpIndex;
// Frame / Second
private final static int FPS = 1000/60;
// Number of cycle during a jump
private int jumpCycle = jumpPeriod / FPS;
// Jump width
private int jumpWidth = 300;
// Step width / cycle
private float pas = ((float)jumpWidth / (float)jumpCycle);
/**
* Main loop
*/
public void update()
{
// One external event put this boolean to true (mouse clic ou an another event for example)
if(isJumping)
jumping(System.currentTimeMillis());
}
/**
* Jump function
* @param gameTime
*/
public void jumping(long gameTime)
{
// The jump was not yet initialised
if(!isJumpingStarted)
{
jumpIndex = System.currentTimeMillis() + jumpPeriod;
isJumpingStarted = true;
}
// The jump is already initialised
else
{
// Jump is finished
// RAZ
if(jumpIndex - gameTime <= 0)
{
isJumpingStarted = false;
isJumping = false;
velocity = BASIC_VELOCITY;
}
// Jump not finished
// we change the velocity as a function of the length of the jump.
else
{
velocity = pas;
}
}
}
Do you think it right ?
Have you an advice for the y coordinate ?
Thank for reading
and i wish my english is readable.