Search in sources :

Example 1 with Rocket

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

Example 2 with Rocket

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;
}
Also used : Vehicle(de.adesso.anki.battle.world.bodies.Vehicle) Position(de.adesso.anki.battle.util.Position) Mine(de.adesso.anki.battle.world.bodies.Mine) Rocket(de.adesso.anki.battle.world.bodies.Rocket)

Example 3 with Rocket

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");
        }
    }
}
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

Rocket (de.adesso.anki.battle.world.bodies.Rocket)3 Position (de.adesso.anki.battle.util.Position)1 Body (de.adesso.anki.battle.world.Body)1 DynamicBody (de.adesso.anki.battle.world.DynamicBody)1 World (de.adesso.anki.battle.world.World)1 Mine (de.adesso.anki.battle.world.bodies.Mine)1 Vehicle (de.adesso.anki.battle.world.bodies.Vehicle)1