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

The following examples show how to use com.badlogic.gdx.utils.Array#get() . 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: DungeonUtils.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private static void squashRooms (Array<Room> rooms) {
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < rooms.size; j++) {
			Room room = rooms.get(j);
			while (true) {
				int oldX = room.x;
				int oldY = room.y;
				if (room.x > 1) room.x--;
				if (room.y > 1) room.y--;
				if ((room.x == 1) && (room.y == 1)) break;
				if (collides(rooms, room, j)) {
					room.x = oldX;
					room.y = oldY;
					break;
				}
			}
		}
	}
}
 
Example 2
Source File: MaxRectsPacker.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
private void pruneFreeList () {
	// Go through each pair and remove any rectangle that is redundant.
	Array<Rect> freeRectangles = this.freeRectangles;
	for (int i = 0, n = freeRectangles.size; i < n; i++)
		for (int j = i + 1; j < n; ++j) {
			Rect rect1 = freeRectangles.get(i);
			Rect rect2 = freeRectangles.get(j);
			if (isContainedIn(rect1, rect2)) {
				freeRectangles.removeIndex(i);
				--i;
				--n;
				break;
			}
			if (isContainedIn(rect2, rect1)) {
				freeRectangles.removeIndex(j);
				--j;
				--n;
			}
		}
}
 
Example 3
Source File: DungeonUtils.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private static Room findClosestRoom (Array<Room> rooms, Room room) {
	float midX = room.x + (room.w / 2f);
	float midY = room.y + (room.h / 2f);
	Room closest = null;
	float closestDistance = Float.POSITIVE_INFINITY;
	for (int i = 0; i < rooms.size; i++) {
		Room check = rooms.get(i);
		if (check == room) continue;
		float checkMidX = check.x + (check.w / 2f);
		float checkMidY = check.y + (check.h / 2f);
		float distance = Math.min(Math.abs(midX - checkMidX) - (room.w / 2f) - (check.w / 2f), Math.abs(midY - checkMidY)
			- (room.h / 2f) - (check.h / 2f));
		if (distance < closestDistance) {
			closestDistance = distance;
			closest = check;
		}
	}
	return closest;
}
 
Example 4
Source File: TimelineWidget.java    From talos with Apache License 2.0 6 votes vote down vote up
public void moveWrapperSortingPosition(ParticleEmitterWrapper wrapper, int changeBy) { // -1 or 1
    try {
        if(changeBy < -1) changeBy = -1;
        if(changeBy > 1) changeBy = 1;

        int pos = wrapper.getEmitter().getSortPosition();
        int newPos = pos + changeBy;

        Array<ParticleEmitterInstance> emitters = TalosMain.Instance().TalosProject().getParticleEffect().getEmitters();

        if(pos < 0 || pos > emitters.size-1) return;
        if(newPos < 0 || newPos > emitters.size-1) return;

        // let's swap
        ParticleEmitterInstance emOne = emitters.get(pos);
        ParticleEmitterInstance emTwo = emitters.get(newPos);
        int tmp = emOne.emitterGraph.getSortPosition();
        emOne.emitterGraph.setSortPosition(emTwo.emitterGraph.getSortPosition());
        emTwo.emitterGraph.setSortPosition(tmp);

        TalosMain.Instance().TalosProject().sortEmitters();
    } catch (Exception e) {
        TalosMain.Instance().reportException(e);
    }
}
 
Example 5
Source File: OptionList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private void up() {
	int pos = list.getSelectedIndex();

	if (pos == -1 || pos == 0)
		return;

	Array<DialogOption> items = list.getItems();
	DialogOption e = items.get(pos);
	DialogOption e2 = items.get(pos - 1);

	items.set(pos - 1, e);
	items.set(pos, e2);

	parent.getOptions().set(pos - 1, e);
	parent.getOptions().set(pos, e2);

	list.setSelectedIndex(pos - 1);
	upBtn.setDisabled(list.getSelectedIndex() == 0);
	downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);

	Ctx.project.setModified();
}
 
Example 6
Source File: Moveset.java    From Unlucky with MIT License 6 votes vote down vote up
/**
 * Returns a Move array with 4 unique moves from a boss's movepool
 *
 * @param bossId
 * @return
 */
private Move[] getBossMoves(int bossId) {
    Array<Move> pool = rm.bossMoves.get(bossId);
    Move[] ret = new Move[4];
    int index;
    for (int i = 0; i < ret.length; i++) {
        index = MathUtils.random(pool.size - 1);
        Move randMove = pool.get(index);
        Move temp = null;

        if (randMove.type < 2)
            temp = new Move(randMove.type, randMove.name, randMove.minDamage, randMove.maxDamage);
        else if (randMove.type == 2)
            temp = new Move(randMove.name, randMove.minDamage, randMove.crit);
        else if (randMove.type == 3)
            temp = new Move(randMove.name, randMove.minHeal, randMove.maxHeal, randMove.dmgReduction);

        ret[i] = temp;
        //pool.removeIndex(index);
    }

    return ret;
}
 
Example 7
Source File: FilteredTree.java    From talos with Apache License 2.0 6 votes vote down vote up
public void selectFilteredNodeByIndex() {
    Array<Node<T>> result = new Array<>();
    collectFilteredNodes(rootNodes, result);

    if(result.size == 0) return;

    if(autoSelectionIndex < 0) autoSelectionIndex = result.size - 1;
    if(autoSelectionIndex > result.size - 1) autoSelectionIndex = 0;

    selection.clear();
    Node node = result.get(autoSelectionIndex);
    selection.add(node);
    if(node.parent != null) node.parent.setExpanded(true);

    if(itemListener != null) {
        itemListener.selected(node);
    }
}
 
Example 8
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 9
Source File: SpineRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public String[] getInternalAnimations(AnimationDesc anim) {
	try {
		retrieveSource(anim.source, ((SpineAnimationDesc) anim).atlas);
	} catch (GdxRuntimeException e) {
		sourceCache.remove(anim.source);
		Array<String> dependencies = EngineAssetManager.getInstance().getDependencies(getFileName(anim.source));
		if (dependencies.size > 0)
			dependencies.removeIndex(dependencies.size - 1);
		return new String[0];
	}

	Array<Animation> animations = ((SkeletonCacheEntry) sourceCache.get(anim.source)).skeleton.getData()
			.getAnimations();

	String[] result = new String[animations.size];

	for (int i = 0; i < animations.size; i++) {
		Animation a = animations.get(i);
		result[i] = a.getName();
	}

	return result;
}
 
Example 10
Source File: MessageDispatcher.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
/** Registers a listener for the specified message code. Messages without an explicit receiver are broadcasted to all its
 * registered listeners.
 * @param listener the listener to add
 * @param msg the message code */
public void addListener (Telegraph listener, int msg) {
	Array<Telegraph> listeners = msgListeners.get(msg);
	if (listeners == null) {
		// Associate an empty unordered array with the message code
		listeners = new Array<Telegraph>(false, 16);
		msgListeners.put(msg, listeners);
	}
	listeners.add(listener);

	// Dispatch messages from registered providers
	Array<TelegramProvider> providers = msgProviders.get(msg);
	if (providers != null) {
		for (int i = 0, n = providers.size; i < n; i++) {
			TelegramProvider provider = providers.get(i);
			Object info = provider.provideMessageInfo(msg, listener);
			if (info != null) {
				Telegraph sender = ClassReflection.isInstance(Telegraph.class, provider) ? (Telegraph)provider : null;
				dispatchMessage(0, sender, listener, msg, info, false);
			}
		}
	}
}
 
Example 11
Source File: FilteredTree.java    From talos with Apache License 2.0 5 votes vote down vote up
private void smartFilter (Array<MatchingNode<T>> nodes) {
    for (int i = 0; i < nodes.size; i++) {
        if (nodes.get(i).filterPositive()) {
            nodes.get(i).node.filtered = false;
            nodes.get(i).node.actor.setVisible(true);
            setAllParentsNotFiltered(nodes.get(i).node);
            setAllChildrenNotFiltered(nodes.get(i).node);
        } else {
            nodes.get(i).node.filtered = true;
            nodes.get(i).node.actor.setVisible(false);
        }
    }
}
 
Example 12
Source File: Group3d.java    From Scene3d with Apache License 2.0 5 votes vote down vote up
/** Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group. */
public Actor3d findActor (String name) {
        Array<Actor3d> children = this.children;
        for (int i = 0, n = children.size; i < n; i++)
                if (name.equals(children.get(i).getName())) return children.get(i);
        for (int i = 0, n = children.size; i < n; i++) {
                Actor3d child = children.get(i);
                if (child instanceof Group3d) {
                        Actor3d actor = ((Group3d)child).findActor(name);
                        if (actor != null) return actor;
                }
        }
        return null;
}
 
Example 13
Source File: MaterialLoaderBase.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void loadMaterials(Array<GLTFMaterial> glMaterials) {
	if(glMaterials != null){
		for(int i=0 ; i<glMaterials.size ; i++){
			GLTFMaterial glMaterial = glMaterials.get(i);
			Material material = loadMaterial(glMaterial);
			materials.add(material);
		}
	}
}
 
Example 14
Source File: Moveset.java    From Unlucky with MIT License 5 votes vote down vote up
/**
 * Returns a Move array with 4 unique moves chosen from all possible Moves
 *
 * @return
 */
private Move[] getRandomMoves() {
    Array<Move> all = new Array<Move>();
    all.addAll(rm.accurateMoves);
    all.addAll(rm.wideMoves);
    all.addAll(rm.critMoves);
    all.addAll(rm.healMoves);

    Move[] ret = new Move[4];

    int index;
    for (int i = 0; i < ret.length; i++) {
        index = MathUtils.random(all.size - 1);
        Move randMove = all.get(index);
        Move temp = null;

        if (randMove.type < 2)
            temp = new Move(randMove.type, randMove.name, randMove.minDamage, randMove.maxDamage);
        else if (randMove.type == 2)
            temp = new Move(randMove.name, randMove.minDamage, randMove.crit);
        else if (randMove.type == 3)
            temp = new Move(randMove.name, randMove.minHeal, randMove.maxHeal, randMove.dmgReduction);

        ret[i] = temp;
        all.removeIndex(index);
    }

    return ret;
}
 
Example 15
Source File: DungeonUtils.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private static boolean collides (Array<Room> rooms, Room room, int ignore) {
	for (int i = 0; i < rooms.size; i++) {
		if (i == ignore) continue;
		Room check = rooms.get(i);
		if (!((room.x + room.w < check.x) || (room.x > check.x + check.w) || (room.y + room.h < check.y) || (room.y > check.y
			+ check.h))) return true;
	}

	return false;
}
 
Example 16
Source File: FilteredTree.java    From talos with Apache License 2.0 5 votes vote down vote up
static <T> void collapseAll (Array<Node<T>> nodes) {
    for (int i = 0, n = nodes.size; i < n; i++) {
        Node<T> node = nodes.get(i);
        node.setExpanded(false);
        collapseAll(node.children);
    }
}
 
Example 17
Source File: OperationSystem.java    From artemis-odb-orion with Apache License 2.0 5 votes vote down vote up
private void process(Array<OperationTree> operations) {
	for (int i = 0; operations.size > i; i++) {
		OperationTree ot = operations.get(i);
		ot.act(world.delta);
		if (ot.isComplete()) {
			OperationTree node = operations.removeIndex(i--);
			node.clear();
		}
	}
}
 
Example 18
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 19
Source File: GUIConsole.java    From libgdx-inGameConsole with Apache License 2.0 5 votes vote down vote up
void refresh () {
	Array<LogEntry> entries = log.getLogEntries();
	logEntries.clear();

	// expand first so labels start at the bottom
	logEntries.add().expand().fill().row();
	int size = entries.size;
	for (int i = 0; i < size; i++) {
		LogEntry le = entries.get(i);
		Label l;
		// recycle the labels so we don't create new ones every refresh
		if (labels.size > i) {
			l = labels.get(i);
		} else {
			try {
				l = labelClass.getConstructor(CharSequence.class, Skin.class, String.class, Color.class)
					.newInstance("", skin, fontName, LogLevel.DEFAULT.getColor());
			} catch (Exception e) {
				try {
					l = labelClass.getConstructor(CharSequence.class, String.class, Color.class)
						.newInstance("", fontName, LogLevel.DEFAULT.getColor());
				} catch (Exception e2) {
					throw new RuntimeException(
						"Label class does not support either (<String>, <Skin>, <String>, <Color>) or (<String>, <String>, <Color>) constructors.");
				}
			}
			l.setWrap(true);
			labels.add(l);
			l.addListener(new LogListener(l, skin.getDrawable(tableBackground)));
		}
		// I'm not sure about the extra space, but it makes the label highlighting look much better with VisUI
		l.setText(" " + le.toConsoleString());
		l.setColor(le.getColor());
		logEntries.add(l).expandX().fillX().top().left().row();
	}
	scroll.validate();
	scroll.setScrollPercentY(1);
}
 
Example 20
Source File: RandomNumbers.java    From libgdx-snippets with MIT License 5 votes vote down vote up
/**
 * Pick a random array member. Returns null if the array is empty.
 */
public <T> T nextInArray(Array<T> array) {

	if (array.size == 0) {
		return null;
	}

	return array.get(nextInt(array.size - 1));
}