use of de.adesso.anki.battle.world.bodies.Rocket in project anki-battle-showcase by adessoAG.
the class FireRocketCommand method execute.
public void execute(Vehicle vehicle) {
// TODO: set Positions
if (!vehicle.isRocketReady()) {
return;
}
World world = vehicle.getWorld();
Rocket rocket = new Rocket(this.direction);
// TODO speed of rocket
rocket.setTargetSpeed(300);
rocket.setPosition(vehicle.getPosition());
// rocket.setCurrentRoadpiece(vehicle.getCurrentRoadpiece());
rocket.setWorld(world);
world.addBody(rocket);
vehicle.setRocketReady(false);
}
use of de.adesso.anki.battle.world.bodies.Rocket 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;
}
use of de.adesso.anki.battle.world.bodies.Rocket 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");
}
}
}
Aggregations