Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new Lwjgl3Application(new ApplicationAdapter() {
- ShapeRenderer shaper;
- OrthographicCamera ortho;
- Viewport viewport;
- float tileWidth, tileHeight;
- @Override public void create () {
- shaper = new ShapeRenderer();
- ortho = new OrthographicCamera();
- viewport = new FitViewport(640f, 480f, ortho);
- Gdx.input.setInputProcessor(new InputAdapter() {
- @Override public boolean keyDown (int keycode) {
- grid.print();
- switch (keycode) {
- case Keys.A -> useRobotCommand2(grid, robot, '<');
- case Keys.D -> useRobotCommand2(grid, robot, '>');
- case Keys.S -> useRobotCommand2(grid, robot, '^');
- case Keys.W -> useRobotCommand2(grid, robot, 'v');
- default -> {
- /*ignore*/}
- }
- grid.print();
- return false;
- };
- });
- tileWidth = Fn.ratio(Gdx.graphics.getWidth(), grid.columns);
- tileHeight = Fn.ratio(Gdx.graphics.getHeight(), grid.rows);
- }
- @Override public void render () {
- viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
- ScreenUtils.clear(Color.BLACK);
- shaper.setProjectionMatrix(ortho.combined);
- shaper.begin(ShapeType.Filled);
- grid.scan(shaper, (c, g, x, y, v) -> {
- switch (v) {
- case '.' -> {
- /*ignore*/}
- case '#' -> {
- c.setColor(Color.DARK_GRAY);
- c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
- c.setColor(Color.WHITE);
- }
- case '[', ']' -> {
- c.setColor(Color.GRAY);
- c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
- c.setColor(Color.WHITE);
- }
- case '@' -> {
- c.setColor(Color.YELLOW);
- c.rect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
- c.setColor(Color.WHITE);
- }
- default -> throw Fn.notExhaustive(v);
- }
- return true;
- });
- shaper.end();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement