Search in sources :

Example 1 with Body

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;
}
Also used : Position(de.adesso.anki.battle.util.Position) ArrayList(java.util.ArrayList) World(de.adesso.anki.battle.world.World) Body(de.adesso.anki.battle.world.Body)

Example 2 with Body

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");
        }
    }
}
Also used : Rocket(de.adesso.anki.battle.world.bodies.Rocket) DynamicBody(de.adesso.anki.battle.world.DynamicBody) Body(de.adesso.anki.battle.world.Body)

Aggregations

Body (de.adesso.anki.battle.world.Body)2 Position (de.adesso.anki.battle.util.Position)1 DynamicBody (de.adesso.anki.battle.world.DynamicBody)1 World (de.adesso.anki.battle.world.World)1 Rocket (de.adesso.anki.battle.world.bodies.Rocket)1 ArrayList (java.util.ArrayList)1