wyvern.kernel.motion
Class AxisShapeChanger

java.lang.Object
  extended bywyvern.kernel.motion.AxisShapeChanger
All Implemented Interfaces:
AddRemoveNotify, Command, Deformer, DirectionChooser
Direct Known Subclasses:
NoOpShapeChanger

public class AxisShapeChanger
extends java.lang.Object
implements Deformer, DirectionChooser, Command, AddRemoveNotify

This class implements a standard deformation used by monsters that switch from horizontal to vertical when they change directions. This includes sharks, Nagas, and any 1x2/2x1 monster that needs to change shape in the "standard" way when it moves.

To use this class, have your monster add a "deformer" property whose value is an instance of this class, and all will be well.

Version:
1.0, Oct 13, 1998
Author:
Steve Yegge

Constructor Summary
AxisShapeChanger()
           
 
Method Summary
 CommandEvent createEvent(CommandEvent initial)
          Creates the event.
 boolean execute(CommandEvent event)
          Executes the event (by refusing).
 java.util.List getDestination(GameObject agent, int dir, Point offsets)
          A stateless (and therefore unsynchronized) implementation of getDestination that objects can delegate to.
static boolean horizontal(java.util.List source)
          Returns true if the agent is currently horizontal.
 boolean knowsCommand(java.lang.String command)
          We know the command if it's turn + direction.
 java.lang.String mapDirection(int dir, GameObject obj)
          Chooses a direction for the specified object.
 void notifyAdd(PropertyList obj)
          Notifies the property that it's being added.
 void notifyRemove(PropertyList obj)
          Notifies the property that it's being removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AxisShapeChanger

public AxisShapeChanger()
Method Detail

getDestination

public java.util.List getDestination(GameObject agent,
                                     int dir,
                                     Point offsets)
A stateless (and therefore unsynchronized) implementation of getDestination that objects can delegate to.

Specified by:
getDestination in interface Deformer
Parameters:
agent - the object to move
dir - a wyvern.lib.Direction constant (movement direction)
offsets - the results of calling Direction.getXYOffsets(dir), passed in so you don't have to do it.
Returns:
a List of Point objects corresponding to the absolute map locations the object should occupy after the move. Even if the object doesn't change shape, it needs to return a list containing the object's current locations translated by the passed offsets.

horizontal

public static boolean horizontal(java.util.List source)
Returns true if the agent is currently horizontal. This isn't as simple as checking if they're facing east or west, because if they're going one of the four diagonal directions, they could be either horizontal or vertical.

Parameters:
source - the agent's location list
Returns:
true if the agent is horizontal.

mapDirection

public java.lang.String mapDirection(int dir,
                                     GameObject obj)
Chooses a direction for the specified object. We pass in the object with the expectation that in the future, this class will be a Singleton shared by all Commandables that move this way.

Specified by:
mapDirection in interface DirectionChooser
Parameters:
dir - the direction the object is currently facing
obj - the object to choose for.
Returns:
the appropriate String suffix for the bitmap, usually one of: "N", "S", "E", "W", "NW", "NE", "SE", or "SW".

knowsCommand

public boolean knowsCommand(java.lang.String command)
We know the command if it's turn + direction.

Specified by:
knowsCommand in interface Command
Parameters:
command - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates the event.

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Executes the event (by refusing).

Specified by:
execute in interface Command
Parameters:
event - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.

notifyAdd

public void notifyAdd(PropertyList obj)
Notifies the property that it's being added.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being added to

notifyRemove

public void notifyRemove(PropertyList obj)
Notifies the property that it's being removed.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being removed from