private void drawGameOverUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.gameOver, 62, 100); g.drawPixmap(Assets.buttons, 128, 200, 0, 128, 64, 64); g.drawLine(0, 416, 480, 416, Color.BLACK); }
private void drawWorld(World world) { Graphics g = game.getGraphics(); Snake snake = world.snake; SnakePart head = snake.parts.get(0); Stain stain = world.stain; Pixmap stainPixmap = null; if (stain.type == Stain.TYPE_1) stainPixmap = Assets.stain1; if (stain.type == Stain.TYPE_2) stainPixmap = Assets.stain2; if (stain.type == Stain.TYPE_3) stainPixmap = Assets.stain3; int x = stain.x * 32; int y = stain.y * 32; g.drawPixmap(stainPixmap, x, y); int len = snake.parts.size(); for (int i = 1; i < len; i++) { SnakePart part = snake.parts.get(i); x = part.x * 32; y = part.y * 32; g.drawPixmap(Assets.tail, x, y); } Pixmap headPixmap = null; if (snake.direction == Snake.UP) headPixmap = Assets.headUp; if (snake.direction == Snake.LEFT) headPixmap = Assets.headLeft; if (snake.direction == Snake.DOWN) headPixmap = Assets.headDown; if (snake.direction == Snake.RIGHT) headPixmap = Assets.headRight; x = head.x * 32 + 16; y = head.y * 32 + 16; g.drawPixmap(headPixmap, x - headPixmap.getWidth() / 2, y - headPixmap.getHeight() / 2); }
private void drawRunningUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.buttons, 0, 0, 64, 128, 64, 64); g.drawLine(0, 416, 480, 416, Color.BLACK); g.drawPixmap(Assets.buttons, 0, 416, 64, 64, 64, 64); g.drawPixmap(Assets.buttons, 256, 416, 0, 64, 64, 64); }
@Override public void present(float deltaTime) { Graphics g = game.getGraphics(); g.drawPixmap(Assets.background, 0, 0); drawWorld(world); if (state == GameState.Ready) drawReadyUI(); if (state == GameState.Running) drawRunningUI(); if (state == GameState.Paused) drawPausedUI(); if (state == GameState.GameOver) drawGameOverUI(); drawText(g, score, g.getWidth() / 2 - score.length() * 20 / 2, g.getHeight() - 42); }
public void drawText(Graphics g, String line, int x, int y) { int len = line.length(); for (int i = 0; i < len; i++) { char character = line.charAt(i); if (character == ' ') { x += 20; continue; } int srcX = 0; int srcWidth = 0; if (character == '.') { srcX = 200; srcWidth = 10; } else { srcX = (character - '0') * 20; srcWidth = 20; } g.drawPixmap(Assets.numbers, x, y, srcX, 0, srcWidth, 32); x += srcWidth; } }
private void drawPausedUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.pause, 80, 100); g.drawLine(0, 416, 480, 416, Color.BLACK); }
private void drawReadyUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.ready, 47, 100); g.drawLine(0, 416, 480, 416, Color.BLACK); }