Ejemplo n.º 1
0
 private void updatePosition(Projectile projectile) {
   double distance = projectile.getRadius() * Context.TICK_DELAY / projectile.getLifeTime();
   double angle = projectile.getAngle() * Math.PI / 180;
   double y = distance * Math.sin(angle);
   double x = distance * Math.cos(angle);
   projectile.setxStart(projectile.getxStart() + x);
   projectile.setyStart(projectile.getyStart() + y);
 }
Ejemplo n.º 2
0
  private void fire(Person person, Room room) {
    AbstractWeapon gun = person.getWeapon();
    person.setShotCooldown(System.currentTimeMillis() + gun.getShotTimeout());

    gun.setTotalClip(gun.getTotalClip() - 1);
    gun.setCurrentClip(gun.getCurrentClip() - 1);

    Integer id = gameContext.getProjectilesIds().getAndIncrement();
    Projectile[] projectilesBatch = new Projectile[gun.getBulletsPerShot()];
    for (int i = 0; i < projectilesBatch.length; i++) {
      Projectile projectile = getCompatibleProjectile(person);
      projectile.setId(i);
      projectilesBatch[i] = projectile;

      float angle = projectile.getAngle();
      if (angle == 90) {
        projectile.setxEnd((int) person.getX());
        int gunLimit = (int) (projectile.getRadius() + person.getY());
        projectile.setyEnd(gunLimit > room.getMap().getY() ? room.getMap().getY() : gunLimit);
      } else if (angle == 180) {
        projectile.setyEnd((int) person.getY());
        int gunLimit = (int) person.getX() - (int) projectile.getRadius();
        projectile.setyEnd(gunLimit > 0 ? gunLimit : 0);
      } else if (angle == 270) {
        projectile.setxEnd((int) person.getX());
        int gunLimit = (int) person.getY() - (int) projectile.getRadius();
        projectile.setyEnd(gunLimit > 0 ? gunLimit : 0);
      } else if (angle == 0) {
        projectile.setyEnd((int) person.getY());
        int gunLimit = (int) person.getX() + (int) projectile.getRadius();
        projectile.setyEnd(gunLimit > room.getMap().getX() ? room.getMap().getX() : gunLimit);
      } else {
        double y = projectile.getRadius() * Math.sin(angle * Math.PI / 180);
        double x = projectile.getRadius() * Math.cos(angle * Math.PI / 180);
        projectile.setxEnd((int) x + (int) person.getX());
        projectile.setyEnd((int) y + (int) person.getY());
      }
      if (projectile.isInstant()) {
        calculateInstantImpacts(person, projectile, room);
      }
    }

    room.getProjectiles().put(id, projectilesBatch);
  }