void game_ui_update(sfRenderWindow *main_window, sfView *view, game_object *player,jnx_list *draw_queue) { sfVector2f pos = sfView_getCenter(view); sfVector2f view_size = sfView_getSize(view); sfVector2f newpos; newpos.x = pos.x - (view_size.x /2); newpos.y = pos.y - (view_size.y /2); sfText_setPosition(player_health_text,newpos); newpos.y = pos.y + (view_size.y /2) - 40; sfText_setPosition(current_kill_count,newpos); char killbuf[1024]; sprintf(killbuf,"Current kills %d",score_get_current()); sfText_setString(current_kill_count,killbuf); char stringbuf[1024]; int health = player->health; if(health <= 0) { health = 0; } sprintf(stringbuf,"Health %d",health); sfText_setString(player_health_text,stringbuf); /*----------------------------------------------------------------------------- * Update current_level_ui *-----------------------------------------------------------------------------*/ char levelbuf[1024]; sprintf(levelbuf,"Current level %d",current_level); sfText_setString(current_level_count,levelbuf); newpos.y = newpos.y + 20; sfText_setPosition(current_level_count,newpos); /*----------------------------------------------------------------------------- * Update radar *-----------------------------------------------------------------------------*/ radar_update(view,main_window); }
/** Main (and infinite) loop. */ static void main_loop (void) { while (1) { /* Wait until next cycle. */ timer_wait (); /* Update chrono. */ chrono_update (); /* Is match over? */ if (chrono_is_match_over ()) { /* Power off doors. */ pwm_set (BOT_PWM_DOOR_FRONT_BOTTOM, 0); pwm_set (BOT_PWM_DOOR_FRONT_TOP, 0); pwm_set (BOT_PWM_DOOR_BACK_BOTTOM, 0); pwm_set (BOT_PWM_DOOR_BACK_TOP, 0); pwm_set (BOT_PWM_CLAMP, 0); /* End it and block here indefinitely. */ chrono_end_match (42); return; } /* Handle commands from UART. */ while (uart0_poll ()) proto_accept (uart0_getc ()); /* Update IO modules. */ pwm_update (); contact_update (); pawn_sensor_update (); if (usdist_update ()) { position_t robot_pos; asserv_get_position (&robot_pos); main_obstacles_nb = radar_update (&robot_pos, main_obstacles_pos); move_obstacles_update (); simu_send_pos_report (main_obstacles_pos, main_obstacles_nb, 0); } /* Update AI modules. */ logistic_update (); path_decay (); /* Only manage events if slaves are synchronised. */ if (twi_master_sync ()) main_event_to_fsm (); /* Send stats if requested. */ if (main_stats_asserv_ && !--main_stats_asserv_cpt_) { /* Get current position */ position_t cur_pos; asserv_get_position (&cur_pos); /* Send stats */ proto_send3w ('A', cur_pos.v.x, cur_pos.v.y, cur_pos.a); /* Reset stats counter */ main_stats_asserv_cpt_ = main_stats_asserv_; } if (main_stats_contact_ && !--main_stats_contact_cpt_) { proto_send1d ('P', contact_all () | (uint32_t) mimot_get_input () << 24); main_stats_contact_cpt_ = main_stats_contact_; } if (main_stats_codebar_ && !--main_stats_codebar_cpt_) { proto_send2b ('B', codebar_get (DIRECTION_FORWARD), codebar_get (DIRECTION_BACKWARD)); main_stats_codebar_cpt_ = main_stats_codebar_; } if (main_stats_usdist_ && !--main_stats_usdist_cpt_) { proto_send4w ('U', usdist_mm[0], usdist_mm[1], usdist_mm[2], usdist_mm[3]); main_stats_usdist_cpt_ = main_stats_usdist_; } } }