private void drawGameOverUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.gameOver, 32, 100); g.drawPixmap(Assets.buttons, 128, 200, 0, 128, 64, 64); g.drawLine(0, 416, 480, 416, Color.BLACK); }
private void drawRunningUI() { Graphics g = game.getGraphics(); g.drawPixmap(Assets.buttons, 0, 0, 64, 128, 64, 64); // la linea no parece servir mas // 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(); tickTime += deltaTime; g.drawPixmap(Assets.background, 0, 0); // Si delta llega hasta 1, regula la velocidad de refresco de sprites /*if(tickTime > tick){ tickTime = tickTime-tick; System.out.println(tickTime);*/ if (state == GameState.Running) { 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 = 27; } 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); }
private void drawWorld(World world) { Graphics g = game.getGraphics(); Pixmap aircraftPixmap = Assets.aircraft; Pixmap eAircraftPixmap = Assets.enemyAircraft; // Probablemente deban ser un vector las 2 lineas siguientes Aircraft aircraft = world.aircraft; EnemyAircraft eAircraft = world.enemyAircraft; /*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); if (spriteCounter == 0) { g.drawPixmap(aircraftPixmap, aircraft.getX(), aircraft.getY(), 0, 0, 64, 29); } if (spriteCounter == 1) { g.drawPixmap(aircraftPixmap, aircraft.getX(), aircraft.getY(), 0, 29, 64, 29); } if (spriteCounter == 2) { g.drawPixmap(aircraftPixmap, aircraft.getX(), aircraft.getY(), 0, 58, 64, 29); } if (spriteCounter == 3) { g.drawPixmap(aircraftPixmap, aircraft.getX(), aircraft.getY(), 0, 87, 64, 29); spriteCounter = 0; } spriteCounter++; g.drawPixmap(eAircraftPixmap, eAircraft.getX(), eAircraft.getY()); }