コード例 #1
0
ファイル: Jugador.java プロジェクト: dani-garcia/bomber-game
  public void aplicarReglasDeMovimiento(Nivel nivel) {
    if (movimiento) {
      if (aMover > 0) {
        // Nos movemos con la velocidad
        double paso = Math.min(aMover, velocidadMovimiento + (buffosVelocidad * 5));
        aMover -= paso;

        switch (orientacion) {
          case Jugador.ARRIBA:
            y -= paso;
            break;
          case Jugador.ABAJO:
            y += paso;
            break;
          case Jugador.IZQUIERDA:
            x -= paso;
            break;
          case Jugador.DERECHA:
            x += paso;
            break;
        }

        // Se acabo el movimiento
      } else {
        movimiento = false;

        // Movemos el jugador a la casilla mas cercana (deberia estar ya ahi, pero por si acaso hay
        // errores de redondeo o lo que sea)
        x = Ar.x(nivel.getTileXFromCoord(x) * Tile.ancho + Tile.ancho / 2);
        y = Ar.y(nivel.getTileYFromCoord(y) * Tile.altura + Tile.altura / 2);
      }
    }
  }
コード例 #2
0
ファイル: Jugador.java プロジェクト: dani-garcia/bomber-game
  public void procesarOrdenes(Nivel nivel) {
    // Si no nos estamos moviendo, y nos envian un movimiento, nos movemos
    if (!movimiento) {
      int tileX = nivel.getTileXFromCoord(x);
      int tileY = nivel.getTileYFromCoord(y);

      if (moverAbajo) {
        sprite = sprites.get(CAMINANDO_ABAJO);
        orientacion = ABAJO;

        if (nivel.getMapaTiles()[tileX][tileY + 1].tipoColision == Tile.PASABLE
            && nivel.getBombaEnTile(tileX, tileY + 1) == null) {
          movimiento = true;
          aMover = Ar.alto(Tile.altura);
        }

      } else if (moverArriba) {
        sprite = sprites.get(CAMINANDO_ARRIBA);
        orientacion = ARRIBA;

        if (nivel.getMapaTiles()[tileX][tileY - 1].tipoColision == Tile.PASABLE
            && nivel.getBombaEnTile(tileX, tileY - 1) == null) {
          movimiento = true;
          aMover = Ar.alto(Tile.altura);
        }

      } else if (moverDerecha) {
        sprite = sprites.get(CAMINANDO_DERECHA);
        orientacion = DERECHA;

        if (nivel.getMapaTiles()[tileX + 1][tileY].tipoColision == Tile.PASABLE
            && nivel.getBombaEnTile(tileX + 1, tileY) == null) {
          movimiento = true;
          aMover = Ar.ancho(Tile.ancho);
        }

      } else if (moverIzquierda) {
        sprite = sprites.get(CAMINANDO_IZQUIERDA);
        orientacion = IZQUIERDA;

        if (nivel.getMapaTiles()[tileX - 1][tileY].tipoColision == Tile.PASABLE
            && nivel.getBombaEnTile(tileX - 1, tileY) == null) {
          movimiento = true;
          aMover = Ar.ancho(Tile.ancho);
        }
      }
    }

    // Explotar todas las bombas del jugador si procede
    if (buffoExplosionDistanciaBombas && explosionDistancia) {
      nivel.explotarBombas(this);
    }

    // Poner bomba si procede
    if (ponerBomba) {
      ponerBomba = false;

      if (bombasColocadas < bombasLimite) {
        if (nivel.getBombaEnCoords(x, y) == null) {
          Bomba b = new Bomba(context, this, nivel);
          nivel.bombas.add(b);
          nivel.addBombaEnTile(b);
        }
      }
    }

    // Patear bomba si procede
    if (buffoPateaBombas && pateaBomba) {

      int xAxisOffset = 0;
      int yAxisOffset = 0;
      switch (orientacion) {
        case ARRIBA:
          yAxisOffset = -1;
          break;

        case ABAJO:
          yAxisOffset = 1;
          break;

        case IZQUIERDA:
          xAxisOffset = -1;
          break;

        case DERECHA:
          xAxisOffset = 1;
          break;
      }
      int xTile = nivel.getTileXFromCoord(x);
      int yTile = nivel.getTileYFromCoord(y);
      int xTileEnFrente = xTile + xAxisOffset;
      int yTileEnFrente = yTile + yAxisOffset;
      Bomba bombaEnFrente = nivel.getBombaEnTile(xTileEnFrente, yTileEnFrente);

      if (bombaEnFrente != null) {
        bombaEnFrente.velocidadMovimiento = bombaEnFrente.velocidadLimite;
        bombaEnFrente.orientacion = orientacion;
      }
    }
  }