I currently got help doing the following code, below!
I was wondering if I wanted to get Processer Independent Animation, what would I do? do I just do like I have done below diveided my update time by my desired Frames Per Second?
"timeSinceLastUpdate=(runTime-gotTime)/60; // 60 = desired FPS"
What do I do?
Any help would be greatly appreated!
Thanks in advance!
P.s code below:
double newAngle=angle;
if (Player_2_turn==true){
newAngle=180-angle;
glColor3d(1,1,0);
}
bananaX += bananaVelX * timeSinceLastUpdate;
bananaY += bananaVelY * timeSinceLastUpdate;
bananaVelX += (wind) * timeSinceLastUpdate;
bananaVelY -= (gravity * timeSinceLastUpdate);
double angleDouble = newAngle/360.0f*6.283185f;
if (GotThrowTime==false){
gotTime=runTime;
bananaVisible=true;
bananaVelX = (cos(angleDouble) * (strength/4));
bananaVelY = (sin(angleDouble) * (strength/4));
if (Player_1_turn==true) {
bananaX = CurrentMonkey1CoLeftX;
bananaY = CurrentMonkey1CoTopY;
} else if (Player_2_turn==true){
bananaX = CurrentMonkey2CoRightX;
bananaY = CurrentMonkey2CoTopY;
}
GotThrowTime=true;
}
if (bananaVisible==true){
glBegin(GL_POLYGON);
glColor3d(1,1,0);
glVertex2f(bananaX,bananaY);
glVertex2f(bananaX,bananaY+5);
if (Player_1_turn==true) {
glVertex2f(bananaX+5,bananaY+5);
glVertex2f(bananaX+5,bananaY);
} else {
glVertex2f(bananaX-5,bananaY+5);
glVertex2f(bananaX-5,bananaY);
}
glEnd();
}
timeSinceLastUpdate=(runTime-gotTime)/60; // 60 = desired FPS
Edit*
I already have a timer below.
I was just wondering what I had todo to make the banana move at the same rate on every computer!
Basically the code before makes a square go up at a certain angle and fail at the same rate as gravity. but I want it to do this at the same frame rate on every computer there for been Processer Independent Animation!
My timer works out the delta time(dt) which I used to get my frame rate!
My secondsSinceRun gets turned in to runTime which is used to display how long the game has been running!
The question is I could get the computers frame rate and if it is less then 50 then tought it will just have to be slow, but am not sure what I multiply or how I use this information to get it to run at this speed?
#include "timer.h"
#include <time.h>
static double current;
static double systemTime;
static double lastTime;
static double Start;
static double dt;
static double secondsSinceRun;
Timer::Timer(void){
Start = clock();
lastTime = 0;
}
Timer::~Timer(void)
{
}
double Timer::tick(){
do {
current = clock();
systemTime = (double)(current - Start)/1000;
dt = systemTime - lastTime;
lastTime = systemTime;
}while (dt <= 0);
return dt;
}
double Timer::SecondsSinceRun(){
secondsSinceRun=systemTime;
return secondsSinceRun;
}
*