| 137 } |
137 } |
| 138 |
138 |
| 139 static void main_scene_frame_scale(AscBehavior *behavior) { |
139 static void main_scene_frame_scale(AscBehavior *behavior) { |
| 140 if (!asc_active_window->resized) return; |
140 if (!asc_active_window->resized) return; |
| 141 asc_ptr_cast(AscRectangle, frame, behavior->node); |
141 asc_ptr_cast(AscRectangle, frame, behavior->node); |
| 142 asc_rectangle_set_bounds(frame, MAIN_SCENE->camera.viewport); |
142 asc_rectangle_set_bounds(frame, asc_scene_viewport(MAIN_SCENE)); |
| 143 } |
143 } |
| 144 |
144 |
| 145 static void backdrop_create(void) { |
145 static void backdrop_create(void) { |
| 146 const float scale = 1.f / asc_active_window->ui_scale; |
146 const float scale = 1.f / asc_active_window->ui_scale; |
| 147 AscSceneNode *node = asc_sprite( |
147 AscSceneNode *node = asc_sprite( |
| 194 static void game_over_text_keep_centered(AscBehavior *behavior) { |
194 static void game_over_text_keep_centered(AscBehavior *behavior) { |
| 195 if (!behavior->reactivated && !asc_active_window->resized) return; |
195 if (!behavior->reactivated && !asc_active_window->resized) return; |
| 196 |
196 |
| 197 AscSceneNode *node = behavior->node; |
197 AscSceneNode *node = behavior->node; |
| 198 // center the "game over" text in the game field viewport |
198 // center the "game over" text in the game field viewport |
| 199 const asc_rect main_scene_viewport = MAIN_SCENE->camera.viewport; |
199 const asc_rect main_scene_viewport = asc_scene_viewport(MAIN_SCENE); |
| 200 asc_scene_node_set_position2f(node, ASC_VEC2F( |
200 asc_scene_node_set_position2f(node, ASC_VEC2F( |
| 201 main_scene_viewport.pos.x + main_scene_viewport.size.x / 2.f, |
201 main_scene_viewport.pos.x + main_scene_viewport.size.x / 2.f, |
| 202 main_scene_viewport.pos.y + main_scene_viewport.size.y / 2.f - 36 |
202 main_scene_viewport.pos.y + main_scene_viewport.size.y / 2.f - 36 |
| 203 )); |
203 )); |
| 204 } |
204 } |
| 541 |
541 |
| 542 // create the window |
542 // create the window |
| 543 asc_window_initialize(0, asc_gl_context_settings_default(4, 0)); |
543 asc_window_initialize(0, asc_gl_context_settings_default(4, 0)); |
| 544 asc_window_set_title(0, "Snake"); |
544 asc_window_set_title(0, "Snake"); |
| 545 asc_window_set_size(0, asc_vec2_ftou( |
545 asc_window_set_size(0, asc_vec2_ftou( |
| 546 asc_vec2f_scale(ASC_VEC2F(1000+HUD_WIDTH, 1000), asc_ui_scale_auto()))); |
546 asc_vec2f_scale(ASC_VEC2F(600+HUD_WIDTH, 600), asc_ui_scale_auto()))); |
| 547 asc_window_center(0); |
547 asc_window_center(0); |
| 548 |
548 |
| 549 // load textures |
549 // load textures |
| 550 textures_init(); |
550 textures_init(); |
| 551 |
551 |
| 552 // initialize backdrop scene |
552 // initialize backdrop scene |
| 553 asc_scene_init(BACKDROP_SCENE, "backdrop", |
553 AscCamera backdrop_camera; |
| |
554 asc_camera_init(&backdrop_camera, |
| 554 .type = ASC_CAMERA_ORTHO, |
555 .type = ASC_CAMERA_ORTHO, |
| 555 .projection_update_func = asc_camera_ortho_update_size |
556 .projection_update_func = asc_camera_ortho_update_size |
| 556 ); |
557 ); |
| |
558 asc_scene_init(BACKDROP_SCENE, "backdrop", &backdrop_camera); |
| 557 backdrop_create(); |
559 backdrop_create(); |
| 558 |
560 |
| 559 // Initialize main scene |
561 // Initialize the main scene |
| 560 asc_scene_init(MAIN_SCENE, "main", |
562 const unsigned initial_view_distance = 10; |
| |
563 AscCamera main_camera; |
| |
564 asc_camera_init(&main_camera, |
| 561 .type = ASC_CAMERA_ORTHO, |
565 .type = ASC_CAMERA_ORTHO, |
| 562 .ortho.rect = ASC_RECT( |
566 .ortho.rect = ASC_RECT(0, 0, |
| 563 -GAME_FIELD_TILE_SIZE, |
567 initial_view_distance*2*GAME_FIELD_TILE_SIZE, |
| 564 -GAME_FIELD_TILE_SIZE, |
568 initial_view_distance*2*GAME_FIELD_TILE_SIZE |
| 565 (GAME_FIELD_SIZE+2)*GAME_FIELD_TILE_SIZE, |
|
| 566 (GAME_FIELD_SIZE+2)*GAME_FIELD_TILE_SIZE |
|
| 567 ), |
569 ), |
| 568 .viewport_clear = true, |
570 .viewport_clear = true, |
| 569 .clear_color = ASC_RGBi(0, 32, 16), |
571 .clear_color = ASC_RGBi(0, 32, 16), |
| 570 .viewport_update_func = main_scene_viewport_update |
572 .viewport_update_func = main_scene_viewport_update |
| 571 ); |
573 ); |
| |
574 asc_scene_init(MAIN_SCENE, "main", &main_camera); |
| 572 |
575 |
| 573 // create the fps counter |
576 // create the fps counter |
| 574 AscSceneNode *fps_counter = fps_counter_create(); |
577 AscSceneNode *fps_counter = fps_counter_create(); |
| 575 asc_scene_node_hide(fps_counter); |
578 asc_scene_node_hide(fps_counter); |
| 576 |
579 |