コード例 #1
0
ファイル: Player.java プロジェクト: propra13-orga/gruppe72
  @SuppressWarnings("incomplete-switch")
  @Override
  public void draw(Graphics2D graphics) {
    ElementalShield cs = spellManager.getCurrentShield();
    if (cs != null) {
      Color[] c = new Color[3];
      c[0] = new Color(0, 0, 0, 0);
      c[1] = new Color(0, 0, 0, 0);
      ElementType type = cs.getElementType();

      switch (type) {
        case Earth:
          c[2] = new Color(0.45f, 0.4f, 0.15f, 0.85f);
          break;
        case Fire:
          c[2] = new Color(1.0f, 0.0f, 0.0f, 0.7f);
          break;
        case Water:
          c[2] = new Color(0.3f, 0.3f, 0.8f, 0.7f);
          break;
      }

      float[] dist = {0.0f, 0.25f, 1f};
      RadialGradientPaint rgp =
          new RadialGradientPaint(
              new Point2D.Float((int) screenPosition.x + 16, (int) screenPosition.y + 16),
              20,
              dist,
              c);
      graphics.setPaint(rgp);
      graphics.fillOval((int) screenPosition.x - 4, (int) screenPosition.y - 4, 40, 40);
    }

    graphics.drawImage(getTexture(), (int) screenPosition.x, (int) screenPosition.y, null);
    if (controlled) {
      spellManager.draw(graphics);
      statusbar.draw(graphics);
    }

    if (isInNetwork && controllerActive) {
      if (controller.isPressed(KeyEvent.VK_T)) DeathMatchStatistics.getInstance().draw(graphics);
    }
  }
コード例 #2
0
ファイル: Player.java プロジェクト: propra13-orga/gruppe72
  /** Initializes all animations for the player. */
  private void initAnimations() {
    // Setup Animations
    try {
      BufferedImage wl, wr, wu, wd;
      wl = ImageIO.read(new File("res/plWleft.png"));
      wr = ImageIO.read(new File("res/plWright.png"));
      wd = ImageIO.read(new File("res/plWdown.png"));
      wu = ImageIO.read(new File("res/plWup.png"));

      int frameDuration = 150;
      Animation aWalkLeft = Animation.createWalkingAnimation(wl, frameDuration);
      Animation aWalkRight = Animation.createWalkingAnimation(wr, frameDuration);
      Animation aWalkDown = Animation.createWalkingAnimation(wd, frameDuration);
      Animation aWalkUp = Animation.createWalkingAnimation(wu, frameDuration);

      walkAnim = new HashMap<Heading, Animation>();
      walkAnim.put(Heading.Left, aWalkLeft);
      walkAnim.put(Heading.Right, aWalkRight);
      walkAnim.put(Heading.Down, aWalkDown);
      walkAnim.put(Heading.Up, aWalkUp);

      BufferedImage[] iLeft = {aWalkLeft.getTextureByFrame(1)};
      BufferedImage[] iRight = {aWalkRight.getTextureByFrame(1)};
      BufferedImage[] iDown = {aWalkDown.getTextureByFrame(1)};
      BufferedImage[] iUp = {aWalkUp.getTextureByFrame(1)};

      idleAnim = new HashMap<Heading, Animation>();
      idleAnim.put(Heading.Left, new Animation(iLeft, 1));
      idleAnim.put(Heading.Right, new Animation(iRight, 1));
      idleAnim.put(Heading.Down, new Animation(iDown, 1));
      idleAnim.put(Heading.Up, new Animation(iUp, 1));

      // Only for debugging.
      simpleAttackAnim = new HashMap<Heading, Animation>();
      BufferedImage[] iSALeft = new BufferedImage[1];
      iSALeft[0] = new BufferedImage(32, 32, iLeft[0].getType());
      Graphics2D g2 = (Graphics2D) iSALeft[0].getGraphics();
      g2.setColor(new Color(0.0f, 0.0f, 1.0f));
      g2.fillRect(0, 0, 32, 32);
      simpleAttackAnim.put(Heading.Left, new Animation(iSALeft, 1));

      BufferedImage[] iSARight = new BufferedImage[1];
      iSARight[0] = new BufferedImage(32, 32, iLeft[0].getType());
      g2 = (Graphics2D) iSARight[0].getGraphics();
      g2.setColor(new Color(1.0f, 0.0f, 0.0f));
      g2.fillRect(0, 0, 32, 32);
      simpleAttackAnim.put(Heading.Right, new Animation(iSARight, 1));

      BufferedImage[] iSAUp = new BufferedImage[1];
      iSAUp[0] = new BufferedImage(32, 32, iLeft[0].getType());
      g2 = (Graphics2D) iSAUp[0].getGraphics();
      g2.setColor(new Color(0.0f, 1.0f, 0.0f));
      g2.fillRect(0, 0, 32, 32);
      simpleAttackAnim.put(Heading.Up, new Animation(iSAUp, 1));

      BufferedImage[] iSADown = new BufferedImage[1];
      iSADown[0] = new BufferedImage(32, 32, iLeft[0].getType());
      g2 = (Graphics2D) iSADown[0].getGraphics();
      g2.setColor(new Color(1.0f, 0.0f, 1.0f));
      g2.fillRect(0, 0, 32, 32);
      simpleAttackAnim.put(Heading.Down, new Animation(iSADown, 1));
      HashMap<Integer, Rectangle> atRects = new HashMap<Integer, Rectangle>();
      atRects.put(0, new Rectangle(-16, 0, 16, 32));
      int frameDur = 44;
      simpleAttack = new Attack(15, simpleAttackAnim, atRects, frameDur, this);

      curAnim = idleAnim.get(heading);
    } catch (IOException e) {
      System.err.print("Couldn't load Players texture!");
      System.exit(1);
    }
  }