Package org.gbcpainter.game.model.monsters

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

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 "Gremlin"
* <p/>
* The Gremlin moves randomly in the map at the same speed of the player
*
* @author Lorenzo Pellegrini
*/
public class Gremlin extends AnimatedSingleSlotMonster implements Monster {

  private static final int GREMLIN_SPEED = 1;

  @NonNls
  private static final String RESOURCE_ANIMATION_A = "GremlinA";
  @NonNls
  private static final String RESOURCE_ANIMATION_B = "GremlinB";

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

  /**
   * Creates the Gremlin at the given initial position
   *
   * @param position The initial position of the Gremlin
   *
   * @throws Exception If an error occurs while loading textures
   */
  public Gremlin( @NotNull Point position ) throws Exception {
    super( position, 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 = this.utilGetFilteredDirection( exclude );
      this.setDirection( direction );
      return direction;
    }
  }


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

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

  /**
   * Throws an {@link java.lang.UnsupportedOperationException}
   *
   * @return nothing
   *
   * @throws UnsupportedOperationException The Gremlin doesn't modify grid color
   *
   * @see org.gbcpainter.game.InGameEntity#isColoring()
   */
  @Override
  public boolean isColoring() throws UnsupportedOperationException {
    throw new UnsupportedOperationException();
  }

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

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

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.