Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. /**
  2.      * Draws the items that are on screen on the canvas and
  3.      * executes their moving animation.
  4.      * @param inpx The horizontal direction on which the player moves.
  5.      * @param inpy The vertical direction on which the player moves.
  6.      */
  7.     private void drawEnemies(int inpx, int inpy) {
  8.         ArrayList<Enemy> enemies = mapClass.getEnemyArray();
  9.  
  10.         for (Enemy enemy : enemies) {
  11.             Point2D coord = enemy.getPosition();
  12.             int y = (int) coord.getY(), x = (int) coord.getX();
  13.  
  14.             Point2D enemyNextMove = new Point2D(0,0);
  15.             if (!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
  16.                 enemyNextMove = enemy.getNextMove();
  17.             }
  18.  
  19.             if (isToBeRendered(x, y)) {
  20.                 ImageView enemyImage = new ImageView();
  21.                 enemyImage.setImage(enemy.getImage());
  22.                 enemiesParent.getChildren().add(enemyImage);
  23.  
  24.                 double xCoord = (x - playerX + RENDERED_CELLS_X / 2 - 1) * GRID_CELL_SIDE;
  25.                 double yCoord = (y - playerY + RENDERED_CELLS_Y / 2 - 1) * GRID_CELL_SIDE;
  26.  
  27.                 enemyImage.setTranslateX(xCoord);
  28.                 enemyImage.setTranslateY(yCoord);
  29.  
  30.                 if(!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
  31.                     animateEnemies(enemyImage, enemyNextMove);
  32.                 }
  33.             }
  34.  
  35.             if (!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
  36.                 enemy.updatePosition(enemyNextMove);
  37.             }
  38.         }
  39.     }
  40.  
  41.     /**
  42.      * Execute the transition animation for the player
  43.      * movement.
  44.      *
  45.      * @param enemy The render of the enemy we are animating.
  46.      * @param movingCoords The enemy's move direction.
  47.      */
  48.     private void animateEnemies(ImageView enemy, Point2D movingCoords) {
  49.         TranslateTransition t = new TranslateTransition();
  50.         t.setDuration(Duration.seconds(animationTime));
  51.  
  52.         double destX = enemy.getTranslateX() + (movingCoords.getX()) * GRID_CELL_SIDE;
  53.         double destY = enemy.getTranslateY() + (movingCoords.getY()) * GRID_CELL_SIDE;
  54.  
  55.         t.setInterpolator(Interpolator.LINEAR);
  56.         t.setToX(destX);
  57.         t.setToY(destY);
  58.         t.setNode(enemy);
  59.         t.play();
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement