Hey folks,
Has someone got the code to make the players speed start of slow and gradually get faster?
And also, a code to limit his speed to a certain level?
Thanks
//not sure how to declare variables but they might help in this bit of code...
//Also not sure if it redeclares them...
//Varibles can simply be replaced with set numbers.
int speed;
int topspeed=10;
int delay;
delay++;
if (delay=5)
{
if (speed!=topspeed)
{
speed++;
xvelocity+speed;
}
delay=0;
}
xvelocity ++; //increase xvelocity
xvelocity --; //decrease xvelocity
if (xvelocity > 10) //10 is the limit value, you can change it to what you want
{
xvelocity = 10;
}
if (xvelocity < - 10) //- 10 is the limit value, you can change it to what you want
{
xvelocity = - 10;
}
xvelocity *= .95; //make it slow down if not pressing any key
run = 1;
run = 0;
float accel = 0.1; // change to set the acceleration
float decel = 0.2; // change to set the deceleration
int maxspeed = 20; // change to set the max
if (run == 1)
{
if (xvelocity < maxspeed)
{
xvelocity = xvelocity + accel;
}
}
if (run == 0)
{
if (xvelocity > 0)
{
xvelocity = xvelocity - decel;
}
}
if (run == 2)
{
if (xvelocity > -maxspeed)
{
xvelocity = xvelocity - accel;
}
}
Users browsing this forum: No registered users and 1 guest