Пример #1
0
  public void checkDrag() {
    Land land = (Land) getWorld();
    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      if (cost <= land.getMoneyAmount()) {
        if (hasTurret == false) {
          land.removeObjects(land.getObjects(Radius.class));

          machineGun = new MachineGun_Turret();
          getWorld().addObject(machineGun, mouse.getX(), mouse.getY());
          hasTurret = true;
          land.setMoneyCounter(-cost);
        }
      }
      if (hasTurret == true) machineGun.setLocation(mouse.getX(), mouse.getY());
    }
    if ((Greenfoot.mouseDragEnded(null)) && (machineGun != null)) {
      grid();
      if (machineGun.checkLocation()) {
        machineGun.placed = true;
        hasTurret = false;
        machineGun = null;
      } else {
        land.removeObject(machineGun);
        machineGun = null;
        land.setMoneyCounter(cost);
        hasTurret = false;
      }
    }
  }
Пример #2
0
  public void act() {
    int mouseX, mouseY;

    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      mouseX = mouse.getX();
      mouseY = mouse.getY();
      setLocation(mouseX, mouseY);
    }
  }
Пример #3
0
 private boolean clickingInventory() {
   List<Inventory> invList = getWorld().getObjects(Inventory.class);
   List<Slots> slotList = getWorld().getObjects(Slots.class);
   List<Buttons> buttonList = getWorld().getObjects(Buttons.class);
   if (invList.size() != 0) {
     for (Inventory inven : invList) {
       if (Greenfoot.getMouseInfo() != null
           && inven != null
           && Greenfoot.getMouseInfo().getActor() == (Inventory) inven) return true;
     }
   }
   if (slotList.size() != 0) {
     for (Slots slots : slotList) {
       if (Greenfoot.getMouseInfo() != null
           && slots != null
           && Greenfoot.getMouseInfo().getActor() == (Slots) slots) return true;
     }
   }
   if (buttonList.size() != 0) {
     for (Buttons buttons : buttonList) {
       if (Greenfoot.getMouseInfo() != null
           && buttons != null
           && Greenfoot.getMouseInfo().getActor() == (Buttons) buttons) return true;
     }
   }
   return false;
 }
Пример #4
0
 public void action() {
   MouseInfo mouse = Greenfoot.getMouseInfo();
   if (!clickingInventory()) {
     if (mouse != null) {
       if (mouse.getButton() == 1) {
         toolbar.action(getX(), getY());
       }
       if (mouse.getButton() == 3) {
         toolbar.altAction(getX(), getY());
       }
     }
   }
 }
 /**
  * Act - do whatever the Desicion wants to do. This method is called whenever the 'Act' or 'Run'
  * button gets pressed in the environment.
  */
 public void act() {
   MouseInfo mouse = Greenfoot.getMouseInfo();
   if (Greenfoot.mouseClicked(this)) {
     if (mouse.getButton() == 3) // right-click
     {
       construyeDialogo();
     } else {
       if (((WActividades) getWorld()).mousePresionado) {
         ((WActividades) getWorld()).agregaPunto(getX(), getY(), true);
         ((WActividades) getWorld()).mousePresionado = false;
       }
     }
   } else if (Greenfoot.mousePressed(this)) {
     ((WActividades) getWorld()).agregaPunto(getX(), getY(), false);
     ((WActividades) getWorld()).mousePresionado = true;
   }
 }
Пример #6
0
 public void act() {
   if (Greenfoot.mouseDragged(this)) {
     if (!scaled) {
       board.setFront(this);
       scaled = true;
       scale();
     }
     MouseInfo info = Greenfoot.getMouseInfo();
     toSpace = board.getFeld(info.getY(), info.getX());
     if (toSpace != null) {
       setLocation(info.getX(), info.getY());
     }
   } else if (Greenfoot.mouseDragEnded(this)) {
     this.getImage().scale(origWidth, origHeight);
     scaled = false;
     if (isA && toSpace != null && toSpace.getReihe() == 1 && toSpace.getSpalte() == 'd') {
       board.setPlayerAChoice(staerke);
     } else if (!isA && toSpace != null && toSpace.getReihe() == 8 && toSpace.getSpalte() == 'd') {
       board.setPlayerBChoice(staerke);
     } else {
       setLocation(space.getWorldColumn(), space.getWorldRow());
     }
   }
 }
Пример #7
0
  /**
   * Update the lastState property. Should ideally be called on each World.act(), or at least before
   * getState() in a frame where mouse info is wanted.
   */
  public void act() {
    MouseInfo mouseinfo = Greenfoot.getMouseInfo();

    /* To-be properties of MouseState */
    boolean held = lastState.held;
    boolean down = false;
    boolean up = false;
    boolean moved;
    Vector position;

    if (mouseinfo != null) {
      /* Get the new mouse position */
      position = new Vector(mouseinfo.getX(), mouseinfo.getY());
      /* We have moved if there is a difference between this mouse position and
       * the previous mouse position. */
      moved = lastState.position == null || position.subtract(lastState.position).length() > 0.5;

    } else {
      /* mouseinfo == null */

      /* Use the previous mouse position */
      position = lastState.position;
      /* We haven't moved the mouse pointer. */
      moved = false;
    }

    if (lastState.held) {
      /* Figure out if the mouse has been released. This has to be done
       * differently on Mac OS X, as MouseInfo contains different info in case
       * of mouse release on that platform. */
      if (System.getProperty("os.name").equals("Mac OS X")) {
        if (Greenfoot.mouseClicked(null)
            || mouseinfo != null
                && (mouseinfo.getActor() != concerning || mouseinfo.getButton() != 1)) {
          up = true;
          held = false;
        }
      } else {
        /* TODO: Check if this behaves correctly in Windows */
        if (Greenfoot.mouseClicked(concerning)
            || mouseinfo != null
                && (mouseinfo.getActor() != concerning || mouseinfo.getButton() != 0)) {
          up = true;
          held = false;
        }
      }

    } else {
      /* !lastState.held */

      /* Figure out if mouse has been pressed. This is thankfully
       * cross-platform consistent. */
      if (Greenfoot.mousePressed(concerning)) {
        down = true;
        held = true;
      }
    }

    /* Store the state in the lastState property. */
    lastState = new MouseState(held, down, up, moved, position);
  }