Search in sources :

Example 1 with DynamicBody

use of de.adesso.anki.battle.world.DynamicBody in project anki-battle-showcase by adessoAG.

the class UseReflectorCommand method execute.

public void execute(Vehicle vehicle) {
    /*TODO implement  reflection 
		*/
    World world = vehicle.getWorld();
    for (DynamicBody dbody : world.getDynamicBodies()) {
        // reverse  when near
        double distance = vehicle.getPosition().distance(dbody.getPosition());
        if (distance < 100) {
        // reverse roadmap
        }
    }
    vehicle.setReflectorReady(false);
}
Also used : DynamicBody(de.adesso.anki.battle.world.DynamicBody) World(de.adesso.anki.battle.world.World)

Example 2 with DynamicBody

use of de.adesso.anki.battle.world.DynamicBody in project anki-battle-showcase by adessoAG.

the class GameEngine method gameLoop.

@Scheduled(fixedRate = 50)
public void gameLoop() {
    VehicleStateProvider vehicleStateProvider = new VehicleStateProvider();
    if (running) {
        // Step 0: Calculate elapsed nanoseconds since last loop
        long step = System.nanoTime();
        long deltaNanos = step - lastStep;
        lastStep = step;
        // TODO: Synchronize with Anki vehicles
        if (stepCount == 0) {
            for (DynamicBody body : world.getDynamicBodies()) {
                if (body instanceof Vehicle)
                    anki.synchronizeState((Vehicle) body);
            }
        }
        // Step 2: Simulate movement
        updateSimulation(deltaNanos);
        // Step 3: Process input
        // TODO: Process input from frontend
        // Step 4: Evaluate behavior
        stepCount++;
        if (stepCount > 3) {
            List<DynamicBody> dynBodies = world.getDynamicBodies();
            for (DynamicBody body : dynBodies) {
                log.debug(body.toString());
                if (!(body instanceof Vehicle)) {
                    continue;
                }
                List<GameState> factsRoad = vehicleStateProvider.getRoadFacts((Vehicle) body);
                List<GameState> factsInventory = vehicleStateProvider.getInventoryFacts((Vehicle) body);
                List<GameState> factsObstacles = vehicleStateProvider.getObstacleFacts((Vehicle) body);
                body.setFacts(factsRoad, factsInventory, factsObstacles);
            }
            evaluateBehavior();
            stepCount = 0;
        }
        // Remove while iterating, leads to exception
        // java.util.ConcurrentModificationException: in renderer?
        // collisionHandling();
        collectOrphanedWeapons();
        // Step 5: Render world
        renderWorld();
        calculateLaptime();
    }
}
Also used : Vehicle(de.adesso.anki.battle.world.bodies.Vehicle) VehicleStateProvider(de.adesso.anki.battle.providers.VehicleStateProvider) DynamicBody(de.adesso.anki.battle.world.DynamicBody) GameState(com.states.GameState) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

DynamicBody (de.adesso.anki.battle.world.DynamicBody)2 GameState (com.states.GameState)1 VehicleStateProvider (de.adesso.anki.battle.providers.VehicleStateProvider)1 World (de.adesso.anki.battle.world.World)1 Vehicle (de.adesso.anki.battle.world.bodies.Vehicle)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1