}
@Override
public void collided(CollisionEvent event) {
this.radius = currentPlayer.getCurrentBeaver().getCurrentWeapon().getBlastRadius();
Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
Beaver[] p1Team = p1.getTeam();
Beaver[] p2Team = p2.getTeam();
if (event.contains(bullet)) {
WorldManifold worldManifold = new WorldManifold();
event.getContact().jboxContact.getWorldManifold(worldManifold);
drawCircle = true;
collisionX = worldManifold.points[0].x;
collisionY = worldManifold.points[0].y;
float bulletX = bullet.getX();
float bulletY = bullet.getY();
//mark the bullet to be killed on the next update cycle
killBullet = true;
//mark the turn to be ended
endTurn = 2000;
//How much damage to do?
for(int i = 0;i<Constants.BEAVERS_PER_TEAM;i++){
double x1 = p1Team[i].getBody().getX();
double y1 = p1Team[i].getBody().getY();
double x2 = p2Team[i].getBody().getX();
double y2 = p2Team[i].getBody().getY();
double distanceB1 = distance(x1,y1,bulletX,bulletY);
double distanceB2 = distance(x2,y2,bulletX,bulletY);
if(distanceB1 < this.radius ){
int damage = calculateDMG(distanceB1);
p1Team[i].reduceHP(damage);
}
if(distanceB2 < this.radius){
int damage = calculateDMG(distanceB1);
p2Team[i].reduceHP(damage);
}
}
}
//if a body hits the boundary and it's a bullet, remove it.
//it a beaver hits it, kill the beaver.
if (event.contains(boundary)) {
Body otherBody;
if (event.getBodyA().equals(boundary)) otherBody = event.getBodyB();
else otherBody = event.getBodyA();
for(int i=0;i<Constants.BEAVERS_PER_TEAM;i++){
if(p1Team[i].getBody()==otherBody){
p1Team[i].reduceHP(1000);
endTurn = 2000;
//break;
}
if(p2Team[i].getBody()==otherBody){
p2Team[i].reduceHP(1000);
endTurn = 2000;
//break;
}
}
if (otherBody.equals(bullet)) {
killBullet = true;
endTurn = 2000;
}
}
//if the current beaver collects a health pack or ammo