@Override public void update() { if (!isActive()) return; posCpy.set(GameModel.getPlayer().position); diffToPlayer.set(posCpy.sub(position)); float wantedAngle = MathUtils.atan2(diffToPlayer.y, diffToPlayer.x); /* ^ 3,14 <--- |----> 0 */ if (direction == AbstractMap.N && (wantedAngle > MathUtils.PI || wantedAngle < 0)) return; else if (direction == AbstractMap.S && wantedAngle > 0) return; else if (direction == AbstractMap.W && (!(wantedAngle < MathUtils.PI / 2f && wantedAngle > -MathUtils.PI / 2f))) return; else if (direction == AbstractMap.E && (!(wantedAngle > MathUtils.PI / 2f || wantedAngle < -MathUtils.PI / 2f))) return; body.setTransform(position.x, position.y, wantedAngle); if (diffToPlayer.len() < Config.getDimensions().WORLD_WIDTH / 2f) if (MathUtils.random() < (type == CANNON_TYPE.SINGLE ? Config.BULLET_RATE_LOW : Config.BULLET_RATE_MEDIUM)) { float angle = body.getAngle() * MathUtils.radiansToDegrees; origin.set(position).add(diffToPlayer.scl(.1f)); posCpy.set(GameModel.getPlayer().position); if (type == CANNON_TYPE.SINGLE) { weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1))); createGunSmoke(angle); } else if (type == CANNON_TYPE.DOUBLE) { weapon.fire1(origin, posCpy.rotate(MathUtils.random(-1, 1))); weapon.fire2(origin, posCpy.rotate(MathUtils.random(-1, 1))); } } }