com.ng.gdxutils.ai.formation.SquareFormationPattern Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gdx-utils Show documentation
Show all versions of gdx-utils Show documentation
A java library that used over libGdx game framework.
The newest version!
package com.ng.gdxutils.ai.formation;
import com.badlogic.gdx.ai.fma.FormationPattern;
import com.badlogic.gdx.ai.utils.Location;
import com.badlogic.gdx.math.Vector2;
/**
* (c) Abhishek Aryan
*
* @author Abhishek Aryan
* @since 14-12-2015.
*/
public class SquareFormationPattern implements FormationPattern {
private int numberOfSlots;
private float memberRadius;
private int columns;
public SquareFormationPattern (float memberRadius) {
this.memberRadius = memberRadius;
}
@Override
public void setNumberOfSlots (int numberOfSlots) {
this.numberOfSlots = numberOfSlots;
this.columns = (int)Math.sqrt(numberOfSlots);
}
@Override
public Location calculateSlotLocation (Location outLocation, int slotNumber) {
int x = slotNumber / columns;
int y = slotNumber % columns;
float memberDiameter = memberRadius + memberRadius;
float offset = memberRadius * (columns - 1);
outLocation.getPosition().set(x * memberDiameter - offset, y * memberDiameter - offset);
outLocation.setOrientation(0);
return outLocation;
}
@Override
public boolean supportsSlots (int slotCount) {
return true;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy