test/snake.c

changeset 58
26ebb2f1e6e6
parent 48
6e5b5ba2752c
child 59
764fbb013252
equal deleted inserted replaced
57:7daec2f067a9 58:26ebb2f1e6e6
39 debounce = 0; 39 debounce = 0;
40 uint64_t fps = ASC_NANOS_SECOND; 40 uint64_t fps = ASC_NANOS_SECOND;
41 fps /= asc_context.frame_nanos; 41 fps /= asc_context.frame_nanos;
42 if (fps != last_fps) { 42 if (fps != last_fps) {
43 last_fps = fps; 43 last_fps = fps;
44 snprintf(asc_text_data(node)->text, 11, "%"PRIu64" FPS", fps); 44 asc_text_printf(node, "%"PRIu64" FPS", fps);
45 asc_node_update(node);
46 } 45 }
47 } 46 }
48 } 47 }
49 48
50 static void create_fps_counter(void) { 49 static void create_fps_counter(void) {
51 asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); 50 asc_set_font(asc_font(ASC_FONT_REGULAR, 24));
52 asc_ink_rgb(255, 0, 0); 51 asc_ink_rgb(255, 0, 0);
53 AscSceneNode* node = asc_text(10, 10, "XXXXXXX FPS"); 52 AscSceneNode* node = asc_text(10, 10, NULL);
54 asc_scene_add_behavior(node, update_fps_counter); 53 asc_scene_add_behavior(node, update_fps_counter);
55 asc_scene_node_link(asc_window_active->ui, node); 54 asc_add_ui_node(node);
56 } 55 }
57 56
58 static void update_score_counter(AscSceneNode *node) { 57 static void update_score_counter(AscSceneNode *node) {
59 // tie to bottom left of the screen 58 // tie to bottom left of the screen
60 if (asc_window_active->resized) { 59 if (asc_window_active->resized) {
71 static void create_score_counter(void) { 70 static void create_score_counter(void) {
72 asc_set_font(asc_font(ASC_FONT_BOLD, 14)); 71 asc_set_font(asc_font(ASC_FONT_BOLD, 14));
73 asc_ink_rgb(0, 255, 0); 72 asc_ink_rgb(0, 255, 0);
74 AscSceneNode* node = asc_text(0, 0, "Score: 0"); 73 AscSceneNode* node = asc_text(0, 0, "Score: 0");
75 asc_scene_add_behavior(node, update_score_counter); 74 asc_scene_add_behavior(node, update_score_counter);
76 asc_scene_node_link(asc_window_active->ui, node); 75 asc_add_ui_node(node);
77 } 76 }
78 77
79 int main(int argc, char** argv) { 78 int main(int argc, char** argv) {
80 asc_context_initialize(); 79 asc_context_initialize();
81 if (asc_has_error()) { 80 if (asc_has_error()) {
92 91
93 // create UI elements 92 // create UI elements
94 create_fps_counter(); 93 create_fps_counter();
95 create_score_counter(); 94 create_score_counter();
96 95
97
98 // Main Loop 96 // Main Loop
99 do { 97 do {
100 // quit application on any error 98 // quit application on any error
101 if (asc_has_error()) { 99 if (asc_has_error()) {
102 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, 100 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,

mercurial