use of de.adesso.anki.battle.util.Position 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.util.Position in project anki-battle-showcase by adessoAG.
the class Mine method checkCollision.
private boolean checkCollision(Body weapon, World world) {
// merge into weapon superclass
if (weapon instanceof Mine && !((Mine) weapon).isActive()) {
return false;
}
List<Vehicle> vehicles = world.getVehicles();
Position pos1 = weapon.getPosition();
boolean destroy = false;
// TODO find damage values for weapon types
int damage = 20;
for (Vehicle vehicle : vehicles) {
Position pos2 = vehicle.getPosition();
double distance = pos1.distance(pos2);
// TODO find distance value that indicates a collision
double dummyValue = 30;
if (distance < dummyValue) {
vehicle.setEnergy(vehicle.getEnergy() - damage);
destroy = true;
}
}
return destroy;
}
use of de.adesso.anki.battle.util.Position in project anki-battle-showcase by adessoAG.
the class Rocket method checkCollision.
// maybe uplift
private boolean checkCollision(Body weapon, World world) {
// merge into weapon superclass
if (weapon instanceof Rocket && !((Rocket) weapon).isActive()) {
return false;
}
List<Vehicle> vehicles = world.getVehicles();
Position pos1 = weapon.getPosition();
boolean destroy = false;
// TODO find damage values for weapon types
int damage = 10;
for (Vehicle vehicle : vehicles) {
Position pos2 = vehicle.getPosition();
double distance = pos1.distance(pos2);
// TODO find distance value that indicates a collision
double dummyValue = 30;
if (distance < dummyValue) {
vehicle.setEnergy(vehicle.getEnergy() - damage);
destroy = true;
}
}
return destroy;
}
use of de.adesso.anki.battle.util.Position in project anki-battle-showcase by adessoAG.
the class GameEngine method checkCollision.
private boolean checkCollision(Body weapon) {
if (weapon instanceof Vehicle) {
return false;
}
// merge into new superclass weapon ?
if (weapon instanceof Rocket && !((Rocket) weapon).isActive()) {
return false;
}
if (weapon instanceof Mine && !((Mine) weapon).isActive()) {
return false;
}
List<Vehicle> vehicles = world.getVehicles();
Position pos1 = weapon.getPosition();
boolean succesfulHit = false;
// TODO find damage values for weapon types
int damage = ((weapon instanceof Rocket) ? 10 : 20);
for (Vehicle vehicle : vehicles) {
Position pos2 = vehicle.getPosition();
double distance = pos1.distance(pos2);
// TODO find distance value that indicates a collision
double dummyValue = 30;
if (distance < dummyValue) {
System.out.println("BOOM: " + weapon.getClass().getSimpleName());
vehicle.setEnergy(vehicle.getEnergy() - damage);
System.out.println(vehicle.getEnergy());
succesfulHit = true;
}
}
return succesfulHit;
}
Aggregations