Permalink
Browse files

Show and update time in controlUI

  • Loading branch information...
amotta committed May 28, 2012
1 parent 5ba68a0 commit 3438f47a5eccfeeeb37ff3177a6f502cf5714f1c
Showing with 40 additions and 4 deletions.
  1. +7 −3 controlui.cpp
  2. +25 −0 game.c
  3. +3 −0 game.h
  4. +5 −1 main.cpp
View
@@ -217,6 +217,7 @@ void ctrlUIUpdate(){
// NOTE
// works with currentGame = NULL too
deltaSpinner->set_float_val(gameGetInterval(currentGame));
+ timeText->set_float_val(gameGetTime(currentGame));
scoreText->set_int_val(gameGetScore(currentGame));
}
@@ -251,9 +252,12 @@ void ctrlUIHandleEvent(int id){
break;
case UI_ID_INTERVAL:
- // TODO
- // gameSetCurrentInterval(deltaSpinner->get_float_val());
- printf("Interval changed\n");
+ if(currentGame){
+ gameSetInterval(
+ currentGame,
+ deltaSpinner->get_float_val()
+ );
+ }
break;
case UI_ID_STEP:
View
25 game.c
@@ -22,13 +22,15 @@
struct GAME {
unsigned int score;
+ double time;
double interval;
vect_t target;
circ_t disc;
emitterSet_t* emitters;
groupSet_t* groups;
};
+static void gameIncrTime(game_t* game);
static void gameDrawBackground();
static void gameHandleEmitters(game_t* game);
static void gameMoveDisc(game_t* game);
@@ -38,6 +40,7 @@ game_t* gameNew(){
if((game = malloc(sizeof(game_t)))){
game->score = 0;
+ game->time = 0;
game->interval = 0;
game->target = vectGetNull();
game->disc = circGetNull();
@@ -61,6 +64,7 @@ game_t* gameCopy(game_t* game){
// copy values
copy->score = game->score;
+ copy->time = game->time;
copy->interval = game->interval;
copy->target = game->target;
copy->disc = game->disc;
@@ -82,6 +86,24 @@ void gameSetScore(game_t* game, unsigned int score){
game->score = score;
}
+void gameResetTime(game_t* game){
+ if(!game) return;
+
+ game->time = 0;
+}
+
+void gameIncrTime(game_t* game){
+ if(!game) return;
+
+ game->time += game->interval;
+}
+
+double gameGetTime(game_t* game){
+ if(!game) return 0;
+
+ return game->time;
+}
+
double gameGetInterval(const game_t* game){
if(!game) return 0;
@@ -158,6 +180,9 @@ bool gameUpdate(game_t* game){
// 5 And finally collect trophies
points = groupSetCheckDisc(game->groups, game->disc);
+ // 6 Update time
+ gameIncrTime(game);
+
if(points < 0){
return false;
}else{
View
3 game.h
@@ -22,6 +22,9 @@ extern game_t* gameCopy(game_t* game);
extern unsigned int gameGetScore(const game_t* game);
extern void gameSetScore(game_t* game, unsigned int score);
+extern void gameResetTime(game_t* game);
+extern double gameGetTime(game_t* game);
+
extern double gameGetInterval(const game_t* game);
extern void gameSetInterval(game_t* game, double timeDiff);
View
@@ -167,11 +167,15 @@ void playGame(){
state != STATE_RESET
&& state != STATE_FILE_OK
&& state != STATE_STOPPED
- ) return;
+ ) return;
// change state
setState(STATE_PLAYING);
+ // reset score and time
+ gameResetTime(currentGame);
+ gameSetScore(currentGame, 0);
+
// prepare timer
setTimer();
}

0 comments on commit 3438f47

Please sign in to comment.