Advertisement
Tkap1

Untitled

Aug 4th, 2022
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. constexpr int max_tiles = 128;
  2. constexpr int tile_size = 32;
  3. constexpr int panel_tile_size = 128;
  4. local_persist int tiles[max_tiles][max_tiles] = zero;
  5. local_persist s_v2 offset = zero;
  6.  
  7. local_persist float zoom = 1;
  8.  
  9. if(is_key_down(key_up, true))
  10. {
  11.     offset.y -= 10;
  12. }
  13. if(is_key_down(key_down, true))
  14. {
  15.     offset.y += 10;
  16. }
  17.  
  18. if(is_key_down(key_left, true))
  19. {
  20.     offset.x -= 10;
  21. }
  22. if(is_key_down(key_right, true))
  23. {
  24.     offset.x += 10;
  25. }
  26.  
  27. zoom += input->wheel_movement * 0.1f;
  28.  
  29. draw_rect_ui(v2(0), -5, c_world_size, color(0.1f).rgb);
  30. draw_rect_ui(v2(0), -4, v2(800, c_world_size.y), color(0.5f).rgb);
  31.  
  32. local_persist b8 once = false;
  33. if(!once)
  34. {
  35.     once = true;
  36.     for(int y = 0; y < max_tiles; y++)
  37.     {
  38.         for(int x = 0; x < max_tiles; x++)
  39.         {
  40.             tiles[y][x] = game->client_rng.randu() % 2;
  41.         }
  42.     }
  43. }
  44.  
  45.  
  46. for(int y = 0; y < 10; y++)
  47. {
  48.     for(int x = 0; x < 10; x++)
  49.     {
  50.         s_v2 pos = v2(
  51.             (x * panel_tile_size - offset.x) * zoom,
  52.             (y * panel_tile_size - offset.y) * zoom
  53.         );
  54.         s_v2 size = v2(panel_tile_size * zoom);
  55.         if(pos.x + size.x > 800) { continue; }
  56.  
  57.         draw_texture_ui(
  58.             e_texture_atlas,
  59.             pos,
  60.             0.0f,
  61.             size,
  62.             color(1).rgb,
  63.             v2i(x, y)
  64.         );
  65.     }
  66. }
  67.  
  68. for(int y = 0; y < max_tiles; y++)
  69. {
  70.     for(int x = 0; x < max_tiles; x++)
  71.     {
  72.         s_v2i index = tiles[y][x] == 0 ? v2i(0, 0) : v2i(0, 1);
  73.         draw_texture_ui(
  74.             e_texture_atlas,
  75.             v2(
  76.                 800 + tile_size * x,
  77.                 tile_size * y
  78.             ),
  79.             0.0f,
  80.             v2(tile_size),
  81.             color(1).rgb,
  82.             index
  83.         );
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement