use of de.adesso.anki.battle.world.Body in project anki-battle-showcase by adessoAG.
the class VehicleStateProvider method getObstacleFacts.
public List<GameState> getObstacleFacts(Vehicle vehicle) {
ArrayList<GameState> facts = new ArrayList<>();
World world = vehicle.getWorld();
for (Body body : world.getBodies()) {
if (vehicle == body) {
// skip self
continue;
}
// generating facts for vehicle
// body all other in the current world
String obstacleType = body.getClass().getSimpleName();
Position position1 = vehicle.getPosition();
Position position2 = body.getPosition();
double distance = position1.distance(position2);
double angle1 = position1.angle();
// blickrichtung x cos(angle) y sine (angle)
double angleRad = Math.toRadians(angle1);
double viewVectorX = Math.cos(angleRad);
double viewVectorY = Math.sin(angleRad);
double transX = position2.getX() - position1.getX();
double transY = position2.getY() - position1.getY();
double dotProduct = viewVectorX * transX + viewVectorY * transY;
if (dotProduct < 0) {
ObjectBehind obstacle = new ObjectBehind(distance, obstacleType);
facts.add(obstacle);
} else {
ObjectInFront obstacle = new ObjectInFront(distance, obstacleType);
facts.add(obstacle);
}
}
return facts;
}
use of de.adesso.anki.battle.world.Body in project anki-battle-showcase by adessoAG.
the class GameEngine method collectOrphanedWeapons.
private void collectOrphanedWeapons() {
Iterator<Body> it = world.getBodiesModifiable().iterator();
while (it.hasNext()) {
Body weapon = it.next();
if (weapon instanceof Rocket && ((Rocket) weapon).shouldExplode()) {
it.remove();
System.out.println("Delete orphaned rocket");
}
}
}