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);
}
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();
}
}
Aggregations