private void spawnRandomers() { for (int i = 0; i < randomN; i++) { float x = (float) Math.random() * width; float y = (float) Math.random() * height; float r = (float) Math.sqrt( Math.pow(((Player) players.get(0)).getX() - x, 2) + Math.pow(((Player) players.get(0)).getY() - x, 2)); while (r < distanceLimit) { x = (float) Math.random() * width; y = (float) Math.random() * height; r = (float) Math.sqrt( Math.pow(((Player) players.get(0)).getX() - x, 2) + Math.pow(((Player) players.get(0)).getY() - y, 2)); } enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders)); } spawnRandomersB = false; }
private double distanceTo(Actor opponent) { double actorToMoveX = opponent.getAvatar().getTranslateX(); double actorToMoveY = opponent.getAvatar().getTranslateY(); double currentX = getAvatar().getTranslateX(); double currentY = getAvatar().getTranslateY(); double deltaX = actorToMoveX - currentX; double deltaY = actorToMoveY - currentY; double calculatedDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); return calculatedDistance; }