Package rectangles

Examples of rectangles.TankRectangle


  public synchronized boolean moveLeft() {
    LinkedList<Obstacle> obs = map.getObstacles();
    LinkedList<PlayerTank> players = map.getPlayers();
    d = Direction.WEST;
    p = new Point(p.row, p.col - this.speed);
    t = new TankRectangle(p.col - 25, p.row - 25);
    if(health == 1) {
      img = new ImageIcon("images/tankEnemyWest.png").getImage();
    }
    if(health == 2) {
      img = new ImageIcon("images/tankShieldWEST.png").getImage();
    }
    if(activeIceBlock) {
      img = new ImageIcon("images/tankFrozenWEST.png").getImage();
    }
    for (int i = 0; i < players.size(); i++) {
      PlayerTank e = players.get(i);
      if (e.getRectangle().intersects(t)) {
        p = new Point(p.row, p.col + this.speed);
        t = new TankRectangle(p.col - 25, p.row - 25);
        moveable = false;
        return false;
      }
    }
    for (int i = 0; i < obs.size(); i++) {
      Obstacle o = obs.get(i);
      if (o instanceof ImmovableBlock) {
        ImmovableBlock b = (ImmovableBlock) o;
        if (b.getRectangle().intersects(t)) {
          p = new Point(p.row, p.col + this.speed);
          t = new TankRectangle(p.col - 25, p.row - 25);
          moveable = false;
          return false;
        }

      }
      if(human == 0) {
      if (o instanceof SpikePit) {
        SpikePit b = (SpikePit) o;
        if (b.getRectangle().intersects(t)) {
          p = new Point(p.row, p.col + this.speed);
          t = new TankRectangle(p.col - 25, p.row - 25);
          moveable = false;
          return false;
        }

      }
      }
      if (o instanceof Crate) {
        Crate c = (Crate) o;
        if (c.getRectangle().intersects(t)) {
          if (!c.move(d)) {
            p = new Point(p.row, p.col + this.speed);
            t = new TankRectangle(p.col - 25, p.row - 25);
            moveable = false;
            return false;
          }
        }
      }
      if (o instanceof TNT) {
        TNT c = (TNT) o;
        if (c.getRectangle().intersects(t)) {
          if (!c.move(d)) {
            p = new Point(p.row, p.col + this.speed);
            t = new TankRectangle(p.col - 25, p.row - 25);
            moveable = false;
            return false;
          }
        }
      }
        if(human == 0) {
        if (o instanceof FireRing) {
          FireRing c = (FireRing) o;
          if (c.getRectangle().intersects(t)) {
            if (!c.move(d)) {
              p = new Point(p.row, p.col + this.speed);
              t = new TankRectangle(p.col - 25, p.row - 25);
              moveable = false;
              return false;
            }
          }
        }
      }

    }

    if (p.col < 30) {
      p = new Point(p.row, p.col + this.speed);
      t = new TankRectangle(p.col - 25, p.row - 25);
      moveable = false;
      return false;
    }
    notifyObservers(this);
    setChanged();
View Full Code Here


    IceBlockRectangle rect = ice.getRectangle();
    LinkedList<Obstacle> obs = map.getObstacles();
    LinkedList<PlayerTank> tank = map.getPlayers();
    LinkedList<Item> item = map.getItems();
    for (PlayerTank p : tank) {
      TankRectangle tRect = p.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
    }
    for (Item p : item) {
      if(p instanceof BubbleShield) {
      BubbleShield s = (BubbleShield)p;
      BubbleShieldRectangle tRect = s.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
     
    }
      if(p instanceof SpeedBoost) {
        SpeedBoost s = (SpeedBoost)p;
        SpeedBoostRectangle tRect = s.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
     
    }
    for (int i = 0; i < obs.size(); i++) {
      Obstacle p = obs.get(i);
      if (p instanceof Crate) {// for instance of crate
        Crate c = (Crate) p;
        CrateRectangle tRect = c.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof ImmovableBlock) {// for instance of immovableBlock
        ImmovableBlock ib = (ImmovableBlock) p;
        ImmovableBlockRectangle tRect = ib.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof SpikePit) {// for instance of SpikePit
        SpikePit sp = (SpikePit) p;
        SpikePitRectangle tRect = sp.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof FireRing) {// for instance of fireRing
        FireRing fr = (FireRing) p;
        FireRingRectangle tRect = fr.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof TNT) {// for instance of TNT
        TNT tnt = (TNT) p;
        TNTRectangle tRect = tnt.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
View Full Code Here

    SpeedBoostRectangle rect = s.getRectangle();
    LinkedList<Obstacle> obs = map.getObstacles();
    LinkedList<PlayerTank> tank = map.getPlayers();
    LinkedList<Item> item = map.getItems();
    for (PlayerTank p : tank) {
      TankRectangle tRect = p.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
    }
    for (Item p : item) {
      if(p instanceof SpeedBoost) {
      SpeedBoost s = (SpeedBoost)p;
      SpeedBoostRectangle tRect = s.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
    }
      if(p instanceof IceBlock) {
        IceBlock s = (IceBlock)p;
        IceBlockRectangle tRect = s.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
     
    }
    for (int i = 0; i < obs.size(); i++) {
      Obstacle p = obs.get(i);
      if (p instanceof Crate) {// for instance of crate
        Crate c = (Crate) p;
        CrateRectangle tRect = c.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof ImmovableBlock) {// for instance of immovableBlock
        ImmovableBlock ib = (ImmovableBlock) p;
        ImmovableBlockRectangle tRect = ib.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof SpikePit) {// for instance of SpikePit
        SpikePit sp = (SpikePit) p;
        SpikePitRectangle tRect = sp.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof FireRing) {// for instance of fireRing
        FireRing fr = (FireRing) p;
        FireRingRectangle tRect = fr.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof TNT) {// for instance of TNT
        TNT tnt = (TNT) p;
        TNTRectangle tRect = tnt.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
View Full Code Here

    BubbleShieldRectangle rect = b.getRectangle();
    LinkedList<Obstacle> obs = map.getObstacles();
    LinkedList<PlayerTank> tank = map.getPlayers();
    LinkedList<Item> item = map.getItems();
    for (PlayerTank p : tank) {
      TankRectangle tRect = p.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
    }
    for (Item p : item) {
      if(p instanceof SpeedBoost) {
      SpeedBoost s = (SpeedBoost)p;
      SpeedBoostRectangle tRect = s.getRectangle();
      if(tRect.intersects(rect)) {
        return false;
      }
     
    }
      if(p instanceof IceBlock) {
        IceBlock s = (IceBlock)p;
        IceBlockRectangle tRect = s.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
     
    }
    for (int i = 0; i < obs.size(); i++) {
      Obstacle p = obs.get(i);
      if (p instanceof Crate) {// for instance of crate
        Crate c = (Crate) p;
        CrateRectangle tRect = c.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof ImmovableBlock) {// for instance of immovableBlock
        ImmovableBlock ib = (ImmovableBlock) p;
        ImmovableBlockRectangle tRect = ib.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof SpikePit) {// for instance of SpikePit
        SpikePit sp = (SpikePit) p;
        SpikePitRectangle tRect = sp.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof FireRing) {// for instance of fireRing
        FireRing fr = (FireRing) p;
        FireRingRectangle tRect = fr.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
      if (p instanceof TNT) {// for instance of TNT
        TNT tnt = (TNT) p;
        TNTRectangle tRect = tnt.getRectangle();
        if(tRect.intersects(rect)) {
          return false;
        }
       
      }
View Full Code Here

    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof EnemyTank) {
      EnemyTank p = (EnemyTank) o;
      TankRectangle rect = p.getRectangle();
     
      // When the EnemyTank collides with an item it will activate the item's effect on that EnemyTank
     
      for (Item i : itemList) {
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            // Can not have more than one BubbleShield active at a time
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // This tank will push the crate if the crate is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // This tank will push the TNT if the TNT is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // FireRing's can not kill the AI for difficulty purposes
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(1);
            notifyObservers();
            setChanged();
           
          }
        }
        // SpikePit's can not kill the AI either for difficulty purposes
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(1);
            notifyObservers();
            setChanged();
          }
        }
      }
      notifyObservers();
      setChanged();
    }
   
    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof PlayerTank) {
      PlayerTank p = (PlayerTank) o;
      TankRectangle rect = p.getRectangle();
      for (Item i : itemList) {
        // Only one BubbleShield can be active at a time
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if(!p.isActiveBoost()) {
            c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // The PlayerTank will push the crate if it is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // The PlayerTank will push the TNT if it is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // If the PlayerTank collides with a FireRing it will die
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
        // If the PlayerTank collides with a SpikePit it will die
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
      }
View Full Code Here

    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof EnemyTank) {
      EnemyTank p = (EnemyTank) o;
      TankRectangle rect = p.getRectangle();
     
      // When the EnemyTank collides with an item it will activate the item's effect on that EnemyTank
     
      for (Item i : itemList) {
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            // Can not have more than one BubbleShield active at a time
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // This tank will push the crate if the crate is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // This tank will push the TNT if the TNT is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // FireRing's can not kill the AI for difficulty purposes
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(0);
           
          }
        }
        // SpikePit's can not kill the AI either for difficulty purposes
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            p.recieveDamage(0);
          }
        }
      }
      notifyObservers();
      setChanged();
    }
   
    // Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
    // on the object it has collided with the proper action will occur.
   
    if (o instanceof PlayerTank) {
      PlayerTank p = (PlayerTank) o;
      TankRectangle rect = p.getRectangle();
      for (Item i : itemList) {
        // Only one BubbleShield can be active at a time
        if (i instanceof BubbleShield) {
          BubbleShield c = (BubbleShield) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if (p.getHealth() == 1) {
              c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof SpeedBoost) {
          SpeedBoost c = (SpeedBoost) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            if(!p.isActiveBoost()) {
            c.activateEffect(p);
            }
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
        if (i instanceof IceBlock) {
          IceBlock c = (IceBlock) i;
          if (c.getRectangle().intersects(p.getRectangle())) {
            c.activateEffect(p);
            itemList.remove(c);
            notifyObservers();
            setChanged();
            break;
          }
        }
      }
      for (Obstacle obs : obstacleList) {
        // The PlayerTank will push the crate if it is movable
        if (obs instanceof Crate) {
          Crate c = (Crate) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // The PlayerTank will push the TNT if it is movable
        if (obs instanceof TNT) {
          TNT c = (TNT) obs;
          if (rect.intersects(c.getRectangle())) {
            c.move(tankList.getFirst().getDirection());
          }
        }
        // If the PlayerTank collides with a FireRing it will die
        if (obs instanceof FireRing) {
          FireRing c = (FireRing) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
        // If the PlayerTank collides with a SpikePit it will die
        if (obs instanceof SpikePit) {
          SpikePit c = (SpikePit) obs;
          if (rect.intersects(c.getRectangle())) {
            notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
            p.recieveDamage(1);
          }
        }
      }
View Full Code Here

TOP

Related Classes of rectangles.TankRectangle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.