190 asc_ui_add_node(node); |
190 asc_ui_add_node(node); |
191 return node; |
191 return node; |
192 } |
192 } |
193 |
193 |
194 static void game_over_text_keep_centered(AscBehavior *behavior) { |
194 static void game_over_text_keep_centered(AscBehavior *behavior) { |
195 if (!asc_active_window->resized) return; |
195 if (!behavior->unpaused && !asc_active_window->resized) return; |
196 |
|
197 // TODO: if we could react on some sort of "unhidden" event, we could pause this behavior while hidden |
|
198 |
196 |
199 AscSceneNode *node = behavior->node; |
197 AscSceneNode *node = behavior->node; |
200 // center the "game over" text in the game field viewport |
198 // center the "game over" text in the game field viewport |
201 const asc_rect main_scene_viewport = MAIN_SCENE->camera.viewport; |
199 const asc_rect main_scene_viewport = MAIN_SCENE->camera.viewport; |
202 asc_scene_node_set_position2f(node, ASC_VEC2F( |
200 asc_scene_node_set_position2f(node, ASC_VEC2F( |
205 )); |
203 )); |
206 } |
204 } |
207 |
205 |
208 static AscSceneNode *game_over_create_text(void) { |
206 static AscSceneNode *game_over_create_text(void) { |
209 AscSceneNode *node = asc_text( |
207 AscSceneNode *node = asc_text( |
210 .name = "game_over_text", |
208 .name = "game_over_text", |
211 .text = "Game Over\nPress R to Restart", |
209 .text = "Game Over\nPress R to Restart", |
212 .color = ASC_RGB(1, 1, 1), |
210 .color = ASC_RGB(1, 1, 1), |
213 .font = asc_font(ASC_FONT_REGULAR, 36), |
211 .font = asc_font(ASC_FONT_REGULAR, 36), |
214 .alignment = ASC_TEXT_ALIGN_CENTER, |
212 .alignment = ASC_TEXT_ALIGN_CENTER, |
215 .centered = true, |
213 .centered = true, |
216 ); |
214 ); |
217 |
215 |
218 asc_scene_node_hide(node); |
216 asc_scene_node_hide(node); |
219 asc_behavior_add(node, game_over_text_keep_centered); |
217 asc_behavior_add(node, game_over_text_keep_centered, .pause_while_hidden = true); |
220 asc_ui_add_node(node); |
218 asc_ui_add_node(node); |
221 |
219 |
222 return node; |
220 return node; |
223 } |
221 } |
224 |
222 |