Esempio n. 1
0
  // Utility methods
  protected void handleCollision(List<GameObject> gameObjects) {
    for (GameObject gameObject : gameObjects) {
      if (this.isTopColliding(gameObject) && gameObject != this) {
        this.setY((int) gameObject.getMaxY());
        this.setVely(0);
      }

      if (this.isBottomColliding(gameObject) && gameObject != this) {
        this.setY((int) gameObject.getMinY() - this.height);
        this.setFalling(false);
        if (gameObject instanceof Entity) this.setVely(-this.getJumpSpeed());
        else this.setVely(0);
      } else {
        this.setFalling(true);
      }

      if (this.isLeftColliding(gameObject) && gameObject != this) {
        this.setX((int) gameObject.getMaxX());
        this.setVelx(this.getSpeed());
        this.getSpriteSheet().setCurrentRow(this.getSpriteSheet().getRowRight());
      }

      if (this.isRightColliding(gameObject) && gameObject != this) {
        this.setX((int) gameObject.getMinX() - this.width);
        this.setVelx(-this.getSpeed());
        this.getSpriteSheet().setCurrentRow(this.getSpriteSheet().getRowLeft());
      }
    }
  }
Esempio n. 2
0
  public void mouseEvent(MouseEvent mouseEvent) {
    Point point;

    if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
      if (this.isDeleting) {
        for (int i = 0; i < this.gameObjectsNum; i++) {
          this.getMap()
              .removeGameObject(
                  this.getMap()
                      .getGameObject(
                          mouseEvent.getX()
                              + this.getCamera().getCurrentOffsetX()
                              + (int) (i * this.getMap().getMinItemWidth()),
                          mouseEvent.getY() + this.getCamera().getCurrentOffsetY()));
        }
      } else {
        if (this.listingThings) {
          for (int i = 0; i < this.gameObjectsNum; i++) {
            GameObject gameObject = (GameObject) this.selectedGameObject.clone();
            gameObject.setX(
                (mouseEvent.getX() + this.getCamera().getCurrentOffsetX())
                    + (int) (i * gameObject.getWidth()));
            gameObject.setY(mouseEvent.getY() + this.getCamera().getCurrentOffsetY());
            gameObject.setSpriteSheet(this.selectedGameObject.getSpriteSheet().clone());
            this.getMap().addGameObject(gameObject);
          }
        } else {
          GameObject gameObject = (GameObject) this.selectedGameObject.clone();
          gameObject.setX(mouseEvent.getX() + this.getCamera().getCurrentOffsetX());
          gameObject.setY(mouseEvent.getY() + this.getCamera().getCurrentOffsetY());
          gameObject.setSpriteSheet(this.selectedGameObject.getSpriteSheet().clone());
          this.getMap().addGameObject(gameObject);
        }
      }
    } else if (mouseEvent.getButton() == MouseEvent.BUTTON2) {
      this.listingThings = !this.listingThings;
      this.currentSelectionIndex = 0;
      if (this.listingThings) {
        this.selectedGameObject = this.things.get(this.currentSelectionIndex);
      } else {
        this.selectedGameObject = this.entities.get(this.currentSelectionIndex);
      }

    } else if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
      if (this.listingThings == true) {
        try {
          this.selectedGameObject = this.things.get(++this.currentSelectionIndex);
        } catch (IndexOutOfBoundsException e) {
          this.currentSelectionIndex = 0;
          this.selectedGameObject = this.things.get(this.currentSelectionIndex);
        }
      } else {
        try {
          this.selectedGameObject = this.entities.get(++this.currentSelectionIndex);
        } catch (IndexOutOfBoundsException e) {
          this.currentSelectionIndex = 0;
          this.selectedGameObject = this.entities.get(this.currentSelectionIndex);
        }
      }
    }
  }