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

The following examples show how to use com.badlogic.gdx.utils.Array#first() . 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: AiWarriorTurnProcessor.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public static float getWarriorValue(Creature creature, int x, int y) {
    float value = Attack.findTargets(creature, creature.world).size * 1000;
    if (creature.getX() == x && creature.getY() == y)
        value += 100;
    for (WorldObject o : creature.world) {
        if (o instanceof Creature) {
            Creature c = (Creature) o;
            if (!creature.inRelation(Creature.CreatureRelation.enemy, c))
                continue;
            Array<Coordinate> result = AStar.search(creature.world, creature, c, true);
            if (result == null || result.size == 0)
                continue;
            if (result.first().x == x && result.first().y == y) {
                float pathValue = 30 - result.size;
                pathValue = pathValue < 0 ? 0 : pathValue;
                pathValue *= 200;
                value += pathValue;
            }
            Coordinate.freeAll(result);
        }
    }
    return value;
}
 
Example 2
Source File: TerrainShader.java    From Mundus with Apache License 2.0 6 votes vote down vote up
protected void setLights(MundusEnvironment env) {
    // ambient
    set(UNIFORM_AMBIENT_LIGHT_COLOR, env.getAmbientLight().color);
    set(UNIFORM_AMBIENT_LIGHT_INTENSITY, env.getAmbientLight().intensity);

    // TODO light array for each light type

    // directional lights
    final DirectionalLightsAttribute dirLightAttribs = env.get(DirectionalLightsAttribute.class,
            DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirLights = dirLightAttribs == null ? null : dirLightAttribs.lights;
    if (dirLights != null && dirLights.size > 0) {
        final DirectionalLight light = dirLights.first();
        set(UNIFORM_DIRECTIONAL_LIGHT_COLOR, light.color);
        set(UNIFORM_DIRECTIONAL_LIGHT_DIR, light.direction);
        set(UNIFORM_DIRECTIONAL_LIGHT_INTENSITY, light.intensity);
    }

    // TODO point lights, spot lights
}
 
Example 3
Source File: ModelShader.java    From Mundus with Apache License 2.0 6 votes vote down vote up
private void setLights(MundusEnvironment env) {
    // ambient
    set(UNIFORM_AMBIENT_LIGHT_COLOR, env.getAmbientLight().color);
    set(UNIFORM_AMBIENT_LIGHT_INTENSITY, env.getAmbientLight().intensity);

    // TODO light array for each light type

    // directional lights
    final DirectionalLightsAttribute dirLightAttribs = env.get(DirectionalLightsAttribute.class,
            DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirLights = dirLightAttribs == null ? null : dirLightAttribs.lights;
    if (dirLights != null && dirLights.size > 0) {
        final DirectionalLight light = dirLights.first();
        set(UNIFORM_DIRECTIONAL_LIGHT_COLOR, light.color);
        set(UNIFORM_DIRECTIONAL_LIGHT_DIR, light.direction);
        set(UNIFORM_DIRECTIONAL_LIGHT_INTENSITY, light.intensity);
    }

    // TODO point lights, spot lights
}
 
Example 4
Source File: LinePath.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
/** Sets up this {@link Path} using the given way points.
 * @param waypoints The way points of this path.
 * @throws IllegalArgumentException if {@code waypoints} is {@code null} or empty. */
public void createPath (Array<T> waypoints) {
	if (waypoints == null || waypoints.size < 2)
		throw new IllegalArgumentException("waypoints cannot be null and must contain at least two (2) waypoints");

	segments = new Array<Segment<T>>(waypoints.size);
	pathLength = 0;
	T curr = waypoints.first();
	T prev = null;
	for (int i = 1; i <= waypoints.size; i++) {
		prev = curr;
		if (i < waypoints.size)
			curr = waypoints.get(i);
		else if (isOpen)
			break; // keep the path open
		else
			curr = waypoints.first(); // close the path
		Segment<T> segment = new Segment<T>(prev, curr);
		pathLength += segment.length;
		segment.cumulativeLength = pathLength;
		segments.add(segment);
	}
}
 
Example 5
Source File: Invaders.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void create () {
	Array<Controller> controllers = Controllers.getControllers();
	if (controllers.size > 0) {
		controller = controllers.first();
	}
	Controllers.addListener(controllerListener);

	setScreen(new MainMenu(this));
	music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal));
	music.setLooping(true);
	music.play();
	Gdx.input.setInputProcessor(new InputAdapter() {
		@Override
		public boolean keyUp (int keycode) {
			if (keycode == Keys.ENTER && Gdx.app.getType() == ApplicationType.WebGL) {
				if (!Gdx.graphics.isFullscreen()) Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayModes()[0]);
			}
			return true;
		}
	});

	fps = new FPSLogger();
}
 
Example 6
Source File: LmlUtils.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public static <T extends Actor> T parseLmlTemplate(LmlParser lmlParser, LmlView viewController, FileHandle fileHandle) {
    // Check if the view controller was added as an action container already.
    final ActionContainerWrapper acw = lmlParser.getData().getActionContainer(viewController.getViewId());
    final ActionContainer actionContainer;
    if (acw != null) {
        actionContainer = acw.getActionContainer();
    } else {
        actionContainer = null;
    }

    Array<Actor> actors = lmlParser.createView(viewController, fileHandle);

    if (actionContainer != null) {
        // LmlParser removes action container after layout parsing. Let's add it back.
        lmlParser.getData().addActionContainer(viewController.getViewId(), actionContainer);
    }

    if (viewController.getStage() != null) {
        // LmlParser adds created actors directly to the stage after layout parsing.
        // Now we should remove them manually...
        for (Actor actor : actors) {
            actor.remove();
        }
    }

    return (T) actors.first();
}
 
Example 7
Source File: Messager.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void update (Position group) {
	Array<Message> msgs = messages.get(group.ordinal());

	for (Message msg : msgs) {
		// any message?
		if (msg == null && (msgs.size > 0 && msgs.first() != null)) {
			// schedule next message to process
			msg = msgs.first();
			msgs.removeValue(msg, true);
		}

		// busy or became busy?
		if (msg != null && !msg.isCompleted()) {
			// start message if needed
			if (!msg.started) {
				msg.started = true;
				msg.startMs = System.currentTimeMillis();
				msg.show();
			}

			// check if finished
			long much = (long)((System.currentTimeMillis() - msg.startMs) /* URacer.timeMultiplier */);
			if (msg.isShowComplete() && much >= msg.durationMs) {
				// message should end
				msg.hide();
			}
		}
	}
}
 
Example 8
Source File: AnimationSubView.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public AnimationSubView(float frameDuration, Array<? extends TextureRegion> regions, Animation.PlayMode playType) {
    this.animation = new Animation(frameDuration, regions, playType);
    this.regions = regions;
    if (regions.size > 0) {
        TextureRegion region = regions.first();
        actor.setSize(region.getRegionWidth(), region.getRegionHeight());
    }
}
 
Example 9
Source File: AiDefaultTurnProcessor.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static <T> T selectBest(Array<T> elements, Function<T, Float> calc) {
    BinaryHeap<TypedNode<T>> heap = new BinaryHeap<TypedNode<T>>(9, true);
    for (T t : elements) {
        float value = calc.apply(t);
        heap.add(new TypedNode<T>(t, value));
    }
    if (heap.size == 0)
        return elements.first();
    return heap.peek().t;
}
 
Example 10
Source File: PvpMessageListener.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private void checkQueue(IParticipant from) {
    Array<IPvpMessage> messages = queue.get(from);
    if (messages == null || messages.size == 0)
        return;
    int neededIndex = receivedMessagesIndexes.get(from, 0);
    if (messages.first().packetIdx == neededIndex) {
        IPvpMessage m = messages.removeIndex(0);
        receiveMessage(from, m);
        checkQueue(from);
    }
}
 
Example 11
Source File: CreatureQueueWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void doShow(Array<Creature> array) {
    this.array = array;
    Creature curr = array.first();
    creaturesList.clearChildren();
    for (int i = 0, n = array.size; i < n; i++) {
        Creature creature = array.get(i);
        WorldObjectView view = ViewController.createView(curr.world.viewer, curr.world.playerColors, creature);
        view.addListener(createListener(creature));
        creaturesList.add(view);
        if (i != n - 1) {
            creaturesList.add(">>").padTop(-2);
        }
    }
}
 
Example 12
Source File: Messager.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
public boolean isBusy (Position group) {
	Array<Message> msgs = messages.get(group.ordinal());
	return (msgs.size > 0 && msgs.first() != null);
}
 
Example 13
Source File: PackListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public PackModel getSelected() {
Array<PackModel> selection = getSelectionManager().getSelection();
    if (selection.size == 0) return null;
    return selection.first();
}
 
Example 14
Source File: InputFileListAdapter.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public InputFile getSelected() {
    Array<InputFile> selection = getSelectionManager().getSelection();
    if (selection.size == 0) return null;
    return selection.first();
}