Java Code Examples for com.badlogic.gdx.utils.Array#sort()

The following examples show how to use com.badlogic.gdx.utils.Array#sort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AiShamanEnthrallmentProcessor.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override protected int preProcess(Creature creature, Ability ability) {
    Array<Creature> enemies = tmp;
    for (Creature c : creature.world.byType(Creature.class)) {
        if (!c.inRelation(Creature.CreatureRelation.enemy, creature))
            continue;
        enemies.add(c);
    }
    if (enemies.size == 0)
        return -1;
    enemies.sort(VALUE_COMPARATOR);
    if (enemies.size > 1) {
        enemies.truncate(enemies.size / 2);
    }
    for (Creature e : enemies) {
        if (tmpVec.set(e.getX(), e.getY()).dst2(creature.getX(), creature.getY()) <= radius * radius) {
            tmp.clear();
            return 3;
        }
    }
    tmp.clear();
    return -1;
}
 
Example 2
Source File: PvpPlayState.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void init() {
    Config.mobileApi.keepScreenOn(true);
    session.disconnectFuture().addListener(new IFutureListener<Tuple3<Boolean, Option<String>, Option<Throwable>>>() {
        @Override public void onHappened(Tuple3<Boolean, Option<String>, Option<Throwable>> reason) {
            callback.onCancel(session, reason, option(world), option(playersToParticipants));
        }
    });
    Array<String> ids = new Array<String>(session.getAll().size);
    for (IParticipant participant : session.getAll().values()) ids.add(participant.getId());
    ids.sort();
    listener = null;
    server = session.getAll().get(ids.first());
    showPrepareWindow();
    if (server == session.getMe()) {
        Logger.debug("I am a server!");
        listener = new ServerMessageListener(this);
    } else {
        Logger.debug("I am a client!");
        listener = new ClientMessageListener(this);
    }
    session.setMessageListener(listener);
}
 
Example 3
Source File: FileChooser.java    From gdx-soundboard with MIT License 6 votes vote down vote up
private void changeDirectory(FileHandle directory) {

        currentDir = directory;
        fileListLabel.setText(currentDir.path());

        final Array<FileListItem> items = new Array<FileListItem>();

        final FileHandle[] list = directory.list(filter);
        for (final FileHandle handle : list) {
            items.add(new FileListItem(handle));
        }

        items.sort(dirListComparator);

        if (directory.file().getParentFile() != null) {
            items.insert(0, new FileListItem("..", directory.parent()));
        }

        fileList.setSelected(null);
        fileList.setItems(items);
    }
 
Example 4
Source File: NewAlgorithmRandomizer.java    From SIFTrain with MIT License 6 votes vote down vote up
public void randomize(Array<CircleMark> marks) {
    marks.sort();

    double threshold = SongUtils.getDefaultNoteSpeedForApproachRate(GlobalConfiguration.noteSpeed) / 4.0;

    holding = false;
    // set the position for each note
    for (int i = 0; i < marks.size; i++) {
        CircleMark mark = marks.get(i);
        if (mark.getNote().timing_sec > holdEndTime) {
            holding = false;
        }
        boolean isLeft = Math.random() > 0.5;

        // this note is a hold
        if (mark.hold) {
            randomizeHold(marks, i, isLeft, threshold);
        } else
        // not a hold
        {
            randomizeNotHold(marks, i, isLeft, threshold);
        }
    }
}
 
Example 5
Source File: World.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void retrieveAssets() {
	if (getInventory().isDisposed())
		getInventory().retrieveAssets();

	if (uiActors.isDisposed())
		uiActors.retrieveAssets();

	getCurrentScene().retrieveAssets();

	// Print loaded assets for scene
	if (EngineLogger.debugMode()) {
		Array<String> assetNames = EngineAssetManager.getInstance().getAssetNames();

		assetNames.sort();

		EngineLogger.debug("Assets loaded for SCENE: " + currentScene.getId());

		for (String n : assetNames) {
			EngineLogger.debug("\t" + n);
		}
	}

	musicManager.retrieveAssets();
}
 
Example 6
Source File: KeepSidesRandomizer.java    From SIFTrain with MIT License 6 votes vote down vote up
public void randomize(Array<CircleMark> marks) {
    // sort marks by timing
    marks.sort();

    for (CircleMark mark : marks)
    {
        // we don't process notes which spawn in the middle
        if (mark.getNote().position == 5)
        {
            continue;
        }
        boolean left = isLeft(mark);
        Integer newPosition = getPositionWithoutMiddle(left);
        while (inUse(newPosition, mark.getNote().timing_sec))
        {
            newPosition = getPosition(left);
        }
        mark.updateDestination(newPosition);
        noteToReleaseTime.put(newPosition, mark.getNote().timing_sec + BUFFER_TIME);
    }
}
 
Example 7
Source File: ActionList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private Array<Action> getSortedSelection() {
	Array<Action> array = list.getSelection().toArray();

	array.sort(new Comparator<Action>() {

		@Override
		public int compare(Action arg0, Action arg1) {
			Integer i0 = list.getItems().indexOf(arg0, true);
			Integer i1 = list.getItems().indexOf(arg1, true);

			return i0.compareTo(i1);
		}

	});
	
	return array;
}
 
Example 8
Source File: WelcomeScreen.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void refreshProjects() {

	Array<String> items = new Array<String>();

	FileHandle[] projects = Gdx.files.local("projects").list();
	for (FileHandle project : projects) {
		if (project.child("uiskin.json").exists() == true) {
			items.add(project.name());
		}
	}
	items.sort();
	listProjects.setItems(items);
}
 
Example 9
Source File: ExtremeRandomizer.java    From SIFTrain with MIT License 5 votes vote down vote up
public void randomize(Array<CircleMark> marks) {
    // sort marks by timing
    marks.sort();

    double threshold = SongUtils.getDefaultNoteSpeedForApproachRate(GlobalConfiguration.noteSpeed) / 32.0;

    for (int i = 0 ; i < marks.size; i++)
    {
        CircleMark mark = marks.get(i);
        Integer pos = getFreePosition(mark.getNote().timing_sec);
        noteToReleaseTime.put(pos, mark.getNote().timing_sec + (mark.hold ? mark.getNote().effect_value : 0) + threshold);
        mark.updateDestination(pos);
    }
}
 
Example 10
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void setNodes(Array<Node> nodes) {
	nodeMap.clear();
	
	Array<String> names = new Array<String>();
	for(Node e : nodes){
		names.add(e.id);
		nodeMap.put(e.id, e);
	}
	names.sort();
	names.insert(0, "");
	nodeSelector.setItems();
	nodeSelector.setItems(names);
}
 
Example 11
Source File: LevelLoader.java    From ud406 with MIT License 5 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            final float x = safeGetFloat(platformObject, Constants.LEVEL_X_KEY);
            final float y = safeGetFloat(platformObject, Constants.LEVEL_Y_KEY);
            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();

            Gdx.app.log(TAG,
                    "Loaded a platform at x = " + x + " y = " + (y + height) + " w = " + width + " h = " + height);

            final Platform platform = new Platform(x, y + height, width, height);
            platformArray.add(platform);

            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);
            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                Gdx.app.log(TAG, "Loaded an enemy on that platform");
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }
        }

        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);
    }
 
Example 12
Source File: GpgsClient.java    From gdx-gamesvcs with Apache License 2.0 4 votes vote down vote up
/**
     * Blocking version of
     * {@link #fetchLeaderboardEntries(String, int, boolean, IFetchLeaderBoardEntriesResponseListener)}
     *
     * @param leaderBoardId
     * @throws IOException
     */
    public Array<ILeaderBoardEntry> fetchLeaderboardSync(String leaderBoardId, int limit, boolean aroundPlayer,
                                                         boolean friendsOnly) throws IOException {
        // TODO implement limit

        if (gpgsLeaderboardIdMapper != null)
            leaderBoardId = gpgsLeaderboardIdMapper.mapToGsId(leaderBoardId);

        if (leaderBoardId == null)
            return null;

        Array<ILeaderBoardEntry> result = new Array<ILeaderBoardEntry>();
        Leaderboard lb = GApiGateway.games.leaderboards().get(leaderBoardId).execute();

        // XXX no longer LB info ...
//		result.id = lb.getId();
//		result.name = lb.getName();
//		result.scores = new Array<LeaderBoard.Score>();
//		result.iconUrl = lb.getIconUrl();

        LeaderboardScores r;
        if (aroundPlayer) {
            r = GApiGateway.games.scores().listWindow(leaderBoardId, friendsOnly ? "SOCIAL" : "PUBLIC", "ALL_TIME")
                    .execute();
        } else {
            r = GApiGateway.games.scores().list(leaderBoardId, friendsOnly ? "SOCIAL" : "PUBLIC", "ALL_TIME").execute();
        }
        LeaderboardEntry playerScore = r.getPlayerScore();
        // player is null when not having a score yet.
        // we add it to the list because non-public profile won't appear in
        // the full list.
        if (playerScore != null) {
            GpgsLeaderBoardEntry ps = mapPlayerScore(r.getPlayerScore());
            ps.setCurrentPlayer(true);
            result.add(ps);
        }
        // r.getItems is null when no score has been submitted yet.
        if (r.getItems() != null) {
            for (LeaderboardEntry score : r.getItems()) {
                // when player is public it appear in this list as well, so we filter it.
                if (playerScore == null || !score.getPlayer().getPlayerId().equals(playerScore.getPlayer()
                        .getPlayerId())) {
                    GpgsLeaderBoardEntry s = mapPlayerScore(score);
                    s.setCurrentPlayer(false);
                    result.add(s);
                }
            }
        }

        // maybe already sorted but API doesn't say anything about it :
        // https://developers.google.com/games/services/web/api/scores/list
        // so we sort list depending of score meaning.
        final int order = "SMALLER_IS_BETTER".equals(lb.getOrder()) ? 1 : -1;
        result.sort(new Comparator<ILeaderBoardEntry>() {
            @Override
            public int compare(ILeaderBoardEntry o1, ILeaderBoardEntry o2) {
                return order * Long.compare(o1.getSortValue(), o2.getSortValue());
            }
        });
        return result;
    }
 
Example 13
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 14
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 15
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 16
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 17
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 18
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 19
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }
 
Example 20
Source File: LevelLoader.java    From ud406 with MIT License 2 votes vote down vote up
private static void loadPlatforms(JSONArray array, Level level) {

        Array<Platform> platformArray = new Array<Platform>();

        for (Object object : array) {
            final JSONObject platformObject = (JSONObject) object;

            Vector2 bottomLeft = extractXY(platformObject);

            final float width = ((Number) platformObject.get(Constants.LEVEL_WIDTH_KEY)).floatValue();
            final float height = ((Number) platformObject.get(Constants.LEVEL_HEIGHT_KEY)).floatValue();


            final Platform platform = new Platform(bottomLeft.x, bottomLeft.y + height, width, height);

            platformArray.add(platform);


            final String identifier = (String) platformObject.get(Constants.LEVEL_IDENTIFIER_KEY);


            if (identifier != null && identifier.equals(Constants.LEVEL_ENEMY_TAG)) {
                final Enemy enemy = new Enemy(platform);
                level.getEnemies().add(enemy);
            }


        }


        platformArray.sort(new Comparator<Platform>() {
            @Override
            public int compare(Platform o1, Platform o2) {
                if (o1.top < o2.top) {
                    return 1;
                } else if (o1.top > o2.top) {
                    return -1;
                }
                return 0;
            }
        });

        level.getPlatforms().addAll(platformArray);

    }