Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Draws the items that are on screen on the canvas and
- * executes their moving animation.
- * @param inpx The horizontal direction on which the player moves.
- * @param inpy The vertical direction on which the player moves.
- */
- private void drawEnemies(int inpx, int inpy) {
- ArrayList<Enemy> enemies = mapClass.getEnemyArray();
- for (Enemy enemy : enemies) {
- Point2D coord = enemy.getPosition();
- int y = (int) coord.getY(), x = (int) coord.getX();
- Point2D enemyNextMove = new Point2D(0,0);
- if (!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
- enemyNextMove = enemy.getNextMove();
- }
- if (isToBeRendered(x, y)) {
- ImageView enemyImage = new ImageView();
- enemyImage.setImage(enemy.getImage());
- enemiesParent.getChildren().add(enemyImage);
- double xCoord = (x - playerX + RENDERED_CELLS_X / 2 - 1) * GRID_CELL_SIDE;
- double yCoord = (y - playerY + RENDERED_CELLS_Y / 2 - 1) * GRID_CELL_SIDE;
- enemyImage.setTranslateX(xCoord);
- enemyImage.setTranslateY(yCoord);
- if(!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
- animateEnemies(enemyImage, enemyNextMove);
- }
- }
- if (!game.isTeleporting() && (inpx != 0 || inpy != 0)) {
- enemy.updatePosition(enemyNextMove);
- }
- }
- }
- /**
- * Execute the transition animation for the player
- * movement.
- *
- * @param enemy The render of the enemy we are animating.
- * @param movingCoords The enemy's move direction.
- */
- private void animateEnemies(ImageView enemy, Point2D movingCoords) {
- TranslateTransition t = new TranslateTransition();
- t.setDuration(Duration.seconds(animationTime));
- double destX = enemy.getTranslateX() + (movingCoords.getX()) * GRID_CELL_SIDE;
- double destY = enemy.getTranslateY() + (movingCoords.getY()) * GRID_CELL_SIDE;
- t.setInterpolator(Interpolator.LINEAR);
- t.setToX(destX);
- t.setToY(destY);
- t.setNode(enemy);
- t.play();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement