Exemple #1
0
  public Player(Point2D p) {
    super(p);
    direction = new Vector2D(0, -1);
    rotation = Rotation.NONE;

    double rotationSpeed = 0.17;
    sin = Math.sin(rotationSpeed);
    cos = Math.cos(rotationSpeed);

    boostingImage = ImageManager.getImage("boosting.png").getImage();
    ImageIcon icon = ImageManager.getImage("player.png");
    rectangle = new Rectangle(icon.getIconWidth(), icon.getIconHeight());
    rectangle.setLocation(p.getPoint());
    image = icon.getImage();

    shields = 255;
    weaponIndex = 0;
    weapons = new ArrayList<Weapon>();
    weapons.add(new SMP9(this));
    weapons.add(new X2Vulcan(this));
    weapons.add(new EM12Carbine(this));
    weapons.add(new Stinger2(this));
    weapons.add(new ALS22(this));
    weapons.add(new Solaris(this));

    weapon = weapons.get(weaponIndex);

    autoPilot = new AutoPilot(this);
  }
Exemple #2
0
  @Override
  public void update() {
    if (autoPilot.getStatus() == AutoPilot.SystemStatus.ON) {
      autoPilot.update();
    }

    switch (rotation) {
      case RIGHT:
        direction.x = (direction.x * cos) - (direction.y * sin);
        direction.y = (direction.x * sin) + (direction.y * cos);
        break;
      case LEFT:
        direction.x = (direction.x * cos) + (direction.y * sin);
        direction.y = -(direction.x * sin) + (direction.y * cos);
        break;
    }

    direction = direction.direction();

    if (boosting) {
      vel.add(direction);

      vel.x = (Math.abs(vel.x) > 35) ? Math.signum(vel.x) * 35 : vel.x;
      vel.y = (Math.abs(vel.y) > 35) ? Math.signum(vel.y) * 35 : vel.y;
    } else if (breaking) {
      slow();
    }

    pos.x += vel.x;
    pos.y += vel.y;
    rectangle.setLocation(pos.getPoint());

    // bounds checking:
    if (pos.x < 0) {
      pos.x = ViewFrame.size.width - 1;
    } else if (pos.x > ViewFrame.size.width - 1) {
      pos.x = 0;
    }

    if (pos.y < 0) {
      pos.y = ViewFrame.size.height - 1;
    } else if (pos.y > ViewFrame.size.height - 1) {
      pos.y = 0;
    }

    if (firing) {
      weapon.fire();
      displayAmmo();
    }
  }
Exemple #3
0
  @Override
  public void draw(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform at = g2.getTransform();
    heading = Math.atan2(direction.x, -direction.y);
    g2.rotate(heading, rectangle.getCenterX(), rectangle.getCenterY());
    if (boosting) {
      g2.drawImage(boostingImage, (int) pos.x, (int) pos.y, null);
    } else {
      g2.drawImage(image, (int) pos.x, (int) pos.y, null);
    }

    g2.setTransform(at);

    if (target != null) {
      if (target.isDead()) {
        target = null;
        return;
      }
      if (target instanceof Enemy) {
        g2.setColor(Color.RED);
        g2.draw(((Enemy) target).getRectangle());
      } else {
        g2.setColor(Color.CYAN);
        g2.draw(((Item) target).getRectangle());
      }
    }

    if (wasHit) {
      g2.setColor(new Color(0, shields >> 1, shields));
      g2.drawOval((int) pos.x, (int) pos.y, rectangle.width, rectangle.height);
      wasHit = false;
    }

    //        if(weapon instanceof Solaris) {
    //            g2.setColor(Color.DARK_GRAY);
    //            java.awt.Point p = getCenterPoint().getPoint();
    //            g2.drawLine(p.x, p.y, p.x + (int)(600*direction.x), p.y + (int)(600*direction.y));
    //        }
  }