Package org.gbcpainter.game.model.monsters

Source Code of org.gbcpainter.game.model.monsters.Sponge

package org.gbcpainter.game.model.monsters;

import org.gbcpainter.game.model.Monster;
import org.gbcpainter.game.view.animations.AnimatedSingleSlotMonster;
import org.gbcpainter.geom.PERPENDICULAR_DIRECTION;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.Arrays;

/**
* Implementation of the monster named "Sponge"
* <p/>
* The Sponge moves randomly in the map erasing the color of pipes.
*
* @author Lorenzo Pellegrini
*/
public class Sponge extends AnimatedSingleSlotMonster implements Monster {

  private static final int SPONGE_SPEED = 1;

  @NonNls
  private static final String RESOURCE_ANIMATION_A = "SpongeA";
  @NonNls
  private static final String RESOURCE_ANIMATION_B = "SpongeB";
  @NonNls
  private static final String RESOURCE_ANIMATION_C = "SpongeC";

  private static final Iterable<String> SPONGE_TEXTURE_ROTATION = Arrays.asList( RESOURCE_ANIMATION_B, RESOURCE_ANIMATION_A, RESOURCE_ANIMATION_C, RESOURCE_ANIMATION_A );

  /**
   * Creates the Sponge at the given initial position
   *
   * @param position The initial position of the Sponge
   *
   * @throws Exception If an error occurs while loading textures
   */
  public Sponge( @NotNull Point position ) throws Exception {
    super( position, SPONGE_TEXTURE_ROTATION );
  }

  @NotNull
  @Override
  public PERPENDICULAR_DIRECTION getNewDirection( @Nullable final PERPENDICULAR_DIRECTION previousDirection, final boolean shouldReset ) {
    final PERPENDICULAR_DIRECTION exclude;
    if ( shouldReset ) {
      exclude = previousDirection;
    } else if ( previousDirection != null ) {
      exclude = previousDirection.getOpposite();
    } else {
      exclude = null;
    }

    synchronized (this) {
      final PERPENDICULAR_DIRECTION direction = utilGetFilteredDirection( exclude );
      setDirection( direction );
      return direction;
    }
  }

  @Override
  public int getSpeed() {
    return SPONGE_SPEED;
  }

  /**
   * Returns true
   *
   * @return true
   *
   * @see org.gbcpainter.game.InGameEntity#modifiesColor()
   */
  @Override
  public boolean modifiesColor() {
    return true;
  }

  /**
   * Returns false
   *
   * @return false
   *
   * @see org.gbcpainter.game.InGameEntity#isColoring()
   */
  @Override
  public boolean isColoring() {
    return false;
  }

  @Override
  @NonNls
  public synchronized String toString() {
    return "Sponge{" +
           "} " + super.toString();
  }
}

TOP

Related Classes of org.gbcpainter.game.model.monsters.Sponge

TOP
Copyright © 2018 www.massapi.com. 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.