public void drawItem(int ind, Graphics g) {
   Rectangle rect = getItemRect(ind);
   rect.setX(rect.getX() + 4);
   rect.setWidth(rect.getWidth() - 8);
   Item item = inven.items.get(ind);
   int number = inven.getItemAmount(item);
   Sprite.drawSpriteFrame(
       Cache.getImage("IconSet.png"),
       g,
       x + 16 + rect.getX() + 8,
       y + 16 + rect.getY(),
       16,
       item.getIndex(),
       24,
       24);
   Cache.getFont().drawString(x + 24 + 16 + rect.getX() + 8, y + 16 + rect.getY(), item.getName());
   Cache.getFont()
       .drawString(
           x
               + (rect.getWidth())
               + rect.getX()
               + 8
               - Cache.getFont().getWidth(String.format(":%2d", number)),
           y + 16 + rect.getY(),
           String.format(":%2d", number));
 }
Beispiel #2
0
  public void createEffect(String fileName) {
    Sprite effectSprite = new Sprite(xPos, yPos, 128, 128, fileName, 0, 0, false, 22, true);

    ArrayList<Point> animPoints = new ArrayList<Point>();
    int y = 0;

    for (int i = 0; i < 6; i++) {
      if (i * 128 == 768) {
        y += height;
        i = 0;
      }
      animPoints.add(new Point(i * 128, y));
    }

    effectSprite.createAnimation(90, animPoints, "effect");
    TemporaryObject effectObject = new TemporaryObject(xPos, yPos, 0, 0, 128, 128, 450, false);
    effectObject.attachSprite(effectSprite);

    Loader.getLoader().addLevelObject(effectSprite);
    Loader.getLoader().addLevelObject(effectObject);
  }
Beispiel #3
0
  public void update(long deltaTime) {
    timePassed += deltaTime;

    // Objektet lever bara i 5 sekunder
    if (timePassed >= 5000) {
      PhysicsEngine.getPhysicsEngine().getCollisionObjects().remove(this);
      PhysicsEngine.getPhysicsEngine().removePhysicsObject(this);
      Renderer.getRenderer().getSprites().remove(sprite);
      Renderer.getRenderer().getSprites().remove(shadow);
      gameListener.setUpdateCollidables(true);
    }

    if (!gravity) {
      shadow.setXPos(xPos + 5);
      shadow.setYPos(yPos + 5);
    } else {
      if (shadow.getYPos() >= landingY + 5) shadow.setYPos(landingY + 5);
      else shadow.setYPos(shadow.getYPos() + yVel * 3 * (deltaTime / 1000.0));

      xPos += (xVel * (deltaTime / 1000.0));
      yPos += (yVel * (deltaTime / 1000.0));

      xVel += (-1 * (xVel / 100));

      if (yPos > landingY) {
        yPos = landingY;
        this.setGravity(false);
        xVel = 0;
        yVel = 0;
      }
    }

    boundingBox.setLocation((int) (xPos), (int) (yPos));

    if (sprite != null) sprite.updatePos(xPos, yPos);
  }