Advertisement
Guest User

Advent of Code - Year 2024 - Day 15 - Java - libGDX Runtime

a guest
Dec 15th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. new Lwjgl3Application(new ApplicationAdapter() {
  2.   ShapeRenderer shaper;
  3.   OrthographicCamera ortho;
  4.   Viewport viewport;
  5.   float tileWidth, tileHeight;
  6.  
  7.   @Override public void create () {
  8.     shaper = new ShapeRenderer();
  9.     ortho = new OrthographicCamera();
  10.     viewport = new FitViewport(640f, 480f, ortho);
  11.     Gdx.input.setInputProcessor(new InputAdapter() {
  12.       @Override public boolean keyDown (int keycode) {
  13.         grid.print();
  14.         switch (keycode) {
  15.           case Keys.A -> useRobotCommand2(grid, robot, '<');
  16.           case Keys.D -> useRobotCommand2(grid, robot, '>');
  17.           case Keys.S -> useRobotCommand2(grid, robot, '^');
  18.           case Keys.W -> useRobotCommand2(grid, robot, 'v');
  19.           default -> {
  20.             /*ignore*/}
  21.         }
  22.         grid.print();
  23.         return false;
  24.       };
  25.     });
  26.     tileWidth = Fn.ratio(Gdx.graphics.getWidth(), grid.columns);
  27.     tileHeight = Fn.ratio(Gdx.graphics.getHeight(), grid.rows);
  28.   }
  29.  
  30.   @Override public void render () {
  31.     viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
  32.     ScreenUtils.clear(Color.BLACK);
  33.     shaper.setProjectionMatrix(ortho.combined);
  34.     shaper.begin(ShapeType.Filled);
  35.     grid.scan(shaper, (c, g, x, y, v) -> {
  36.       switch (v) {
  37.         case '.' -> {
  38.           /*ignore*/}
  39.         case '#' -> {
  40.           c.setColor(Color.DARK_GRAY);
  41.           c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
  42.           c.setColor(Color.WHITE);
  43.         }
  44.         case '[', ']' -> {
  45.           c.setColor(Color.GRAY);
  46.           c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
  47.           c.setColor(Color.WHITE);
  48.         }
  49.         case '@' -> {
  50.             c.setColor(Color.YELLOW);
  51.             c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
  52.             c.setColor(Color.WHITE);
  53.           }
  54.           default -> throw Fn.notExhaustive(v);
  55.         }
  56.         return true;
  57.       });
  58.       shaper.end();
  59.     }
  60.   });
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement