/**********************************
 * Assignment 5: Pacman
 * Date: 5/5/2006
 *
 * Jenna Holloway: jh382, 563324
 * Benji Shultz: bas67, 1786511
 **********************************/
package game.actor;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Point2D;

/**
 * Class to represent the little tokens that get eaten by pacman
 * @author Alec Berntson
 *
 */
public class Token extends Actor {
 // should we draw the token?
   private boolean isVisible = true;
   // is this a super, invincibility giving token?
   private boolean isSuperToken;
  /*
    * create a new token
    * @param initialLocation
    * @param isSuperToken
    */
   public Token(Point2D initialLocation, boolean isSuperToken) {
      super("token", 0, initialLocation, tokenImageNames);
      this.isSuperToken = isSuperToken;
    }
   
   /**
    *  eat the token is we haven't already (make it Not visible)
    * plays the annoying sound if the token is eaten
    * MODFIED to play the mode appropriate sound 
    * */
   public boolean eat() {
   boolean b=isVisible;
      if (isVisible) {
         if (isSuperToken()&&!game.isPoo()&&!game.isMario()) 
         game.gui.eatBigDot.play();
         else if (isSuperToken&&game.isMario()) game.gui.mushroom.play();
         else{  
          if(!game.isMario()) game.gui.eatDot.play();
          else {game.gui.coin.play();}
         }
      isVisible = false;
      }
      return b;
   }

   /**
    * resets the token to being visible again
    */
   public void reset() {
      isVisible = true;
   }

   /**
    * returns true if the token is visible and a super token
    * @return
    */
   public boolean isSuperToken() {
      return isVisible && isSuperToken;
   }
   /**
    * using graphics g, draw the token to the screen
    * Modified to draw mode appropriate tokens
    */
   public void draw(Graphics g) {
      if (isVisible) {
       
         int x = (int) getCurrentPosition().getX()/CELL;
         int y = (int) getCurrentPosition().getY()/CELL;
         if(!game.isMario())
          g.setColor(Color.WHITE);
         else
          g.setColor(Color.YELLOW);
         if (isSuperToken&&!game.isMario()) {
            g.fillOval(x * CELL + CELL/2 - 7, y * CELL + CELL/2 - 7, 13, 13);
         } else {
          if(isSuperToken&&game.isMario()){
           super.draw(g);           
          }
          else{
            g.fillRect(x * CELL + CELL/2 - 1, y * CELL + CELL/2 - 1, 3, 3);
         }}}
      
      }
   /**
    * returns the bouding box around the token to use for hit detection
    */
   public Rectangle getBoundingBox() {
      return new Rectangle((int) getCurrentPosition().getX() + CELL/4,
            (int) getCurrentPosition().getY() + CELL/4, CELL/4, CELL/4);
   }
}
