diff -r 2ea35c5f4760 -r e22abcd22e47 test/snake/snake.c --- a/test/snake/snake.c Fri Aug 01 18:18:57 2025 +0200 +++ b/test/snake/snake.c Fri Aug 01 18:19:33 2025 +0200 @@ -33,17 +33,19 @@ #include enum Textures2d { - TEX_SHIP = 0, + TEX_PLAYER = 0, TEX_BACKDROP, TEX2D_COUNT }; static AscTexture tex2d[TEX2D_COUNT]; -#define TEXTURE_SHIP &tex2d[TEX_SHIP] +#define TEXTURE_PLAYER &tex2d[TEX_PLAYER] #define TEXTURE_BACKDROP &tex2d[TEX_BACKDROP] #define BACKDROP_SCENE asc_window_scene(0) #define MAIN_SCENE asc_window_scene(1) +#define HUD_WIDTH 400 + enum MoveDirection { MOVE_UP, MOVE_LEFT, @@ -66,7 +68,7 @@ } Player; static const unsigned game_field_size = 16; -static const unsigned game_field_tile_size = 32; +static const unsigned game_field_tile_size = 64; static void globals_init(void) { asc_transform_identity(rotations[MOVE_UP]); @@ -85,7 +87,7 @@ static void textures_init(void) { asc_texture_init_2d(tex2d, TEX2D_COUNT); - asc_texture_from_file(TEXTURE_SHIP, "ship.png"); + asc_texture_from_file(TEXTURE_PLAYER, "player.png"); asc_texture_from_file(TEXTURE_BACKDROP, "backdrop.png"); asc_gl_context_add_cleanup_func(asc_active_glctx, textures_destroy); } @@ -100,9 +102,11 @@ } static void backdrop_create(void) { + const float scale = asc_active_window->ui_scale; AscSceneNode *node = asc_sprite( .texture = TEXTURE_BACKDROP, .texture_scale_mode = ASC_TEXTURE_SCALE_REPEAT, + .texture_scale_x = scale, .texture_scale_y = scale, ); asc_behavior_add(node, .func = backdrop_scale); asc_scene_add_node(BACKDROP_SCENE, node); @@ -214,7 +218,7 @@ static Player *player_create(void) { AscSceneNode *sprite = asc_sprite( .name = "Player", - .texture = TEXTURE_SHIP, + .texture = TEXTURE_PLAYER, .width = game_field_tile_size, .height = game_field_tile_size, .origin_x = game_field_tile_size / 2, @@ -250,10 +254,10 @@ static asc_rect main_scene_viewport_update(asc_vec2u window_size) { // margins - const unsigned margin = 10; + const unsigned margin = 16; // space for score, power-ups, etc. - const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200); + const unsigned left_area = (unsigned) (asc_active_window->ui_scale*HUD_WIDTH); // calculate how many pixels need to be removed from width and height const unsigned rw = 2*margin + left_area; @@ -300,8 +304,9 @@ asc_window_settings_init_defaults(&settings); asc_window_initialize(0, &settings); asc_window_set_title(0, "Snake"); - float ui_scale = asc_ui_scale_auto(); - asc_window_set_size(0, ASC_VEC2U(700+ui_scale*200, 700)); + asc_window_set_size(0, asc_vec2_ftou( + asc_vec2f_scale(ASC_VEC2F(1024+HUD_WIDTH, 1024), asc_ui_scale_auto()))); + asc_window_center(0); // load textures textures_init();