Hi!
I’m learning C++ and oF (just had 4 classes) and I’m developing a very simple game, in which a ball has to reach the top of the screen (the ball moves with sound, using OfxOsc through Max/MSP and Osculator) and when it reaches the top, the game is over.
I have a timer that counts miliseconds ( I don’t know how to put it counting seconds ) that is resetted everytime the user clicks the key ‘s’.
When the ball reaches the top, appears an image saying “Game over”, but the timer should stop when the game is over and I really don’t know how to do it. (because it will win the user that takes less time to reach the top, so the timer has to stop).
Can anyone help me? I tried so many things… I erased almost all, but put in comments the last ones I tried. I don’t know how to program something to stop the time.
I’m using oF 007 with Xcode.
timebola.cpp
#include “ofMain.h”
#include “timebola.h”
Time::Time()
{
lastTime=500;
}
//faz reset de todos os valores de tempo
void Time:: setStartTime(int val)
{
startTime=ofGetElapsedTimeMillis()/1000;//define o novo tempo para o temporizador
lastTime = val;//define o valor do temporizador
//pauseTime = false;
}
void Time::setCurrentTime(int t)
{
// usa o tempo actual do sistema desde que o jogo começa
curTime= (ofGetElapsedTimeMillis()/1000) - startTime;
//pauseTime = false;
timer = t + curTime;
}
int Time::getCurrentTime()
{
return timer;
//pauseTime = false;
}
//int Time::stopCurrentTime()
//{
//pauseTime = true;
//}
Time::~Time(){}
timebola.h
#ifndef TIMEBOLA_H
#define TIMEBOLA_H
class Time
{
private:
int startTime;
int curTime;
int timer;
int lastTime;
//bool pauseTime;
public:
void setStartTime(int);
void setCurrentTime(int);
int getCurrentTime();
//int stopCurrentTime();
Time();
~Time();
};
#endif
Thanks
Susana