|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.globalse.arena.frag.objects.FRAGObject
FRAGObject is the abstract superclass for creating and dealing with entities in the game; entities are e.g. Adventurers, Items (sword, spell, parts of the landscape). It contains general object state information and methods for state update management. In order to create/implement an entity, FRAGObject has to be subclassed. To specify custom behavior and functionality, some methodes needs to be implemented, and some variables needs to be overwritten, which are specified later in this text. Modified objects can only be detected, when the changes are done during handling an ObjectActionEvent (e.g. PickUpItemEvent or TimerEvent). Detection of changes are done by the ObjectManager, which broads them. It's very important, that subclasses of FRAGObject never reference to e.g. any other subclass of FRAGObject or to not unserializable object (e.g. ObjectManager, GameManager, any object from the visualisation package). This reference would be followed by the serialization algorithm of java, and therefore these objects would also be broadcasted on every state update or an Exception during serialization would occur. To bypass the reference probleme, other FRAGObjects can simply be stored as strings and obtained from the ObjectManager, which can be accessed by, as well as the GameManager, the getter methods in FRAGObject. controlAccquired and controLost methods: When a peer accquires control over a FRAGObject this methode is called. To create independently (from the player) moving objects or objects with a static speed (as done in Adventurer), timers, which are subclasses of ObjectActionEvent, should be set on this object. Timer send periodically ObjectActionEvents and the corresponding object can act. To set a timer on an object the getTimer() methode of TimerRegistry should be called and after that, the enable method from timer. The oppositional way need to be done in controlLost, where the disable method of the timer need to be called. checkCollision This method is used to avoid collisions of objects or to climb mountains. In abstraction it is used to interact with other objects. It is called, when one object changes its position on all other objects and returns the distance the moved object is allowed to go. The simplest way to keep objects from running over other objects, is to use a sphere (as done in SWORD), that can't be crossed from others. As the landscape is divided into tiles, which are FRAGObjects, these objects should keep other objects from running over water. draw Each FRAGObject needs to specify, what and where it should be drawn. This methode is called periodically from the DrawManager. To draw the object methods from DrawManager need to be used (e.g. drawImage or drawArea). actionEvent This method is called when an ObjectActionEvent (or a subclass) addressed to this object arrives at the ObjectManager. As mentioned before, changes to a FRAGObject are only noticed, when done during this method and the mark method is called at the end of the method. To control e.g. the Adventurer, comands from the GUI should be passed to it by using ObjectActionEvents. Now let's face to the attributs and there use. The gameName and objectName need to be set at initialization. The objectName need to be unique in the game and objects are stored in the ObjectManager's hashtable with the key: objectName The owner attribute is just set, when an object is owned by a peer (e.g. Adventurer) and other peers aren't allowed to take over control. In order to manipulate an object the peer needs to be the controller of that object. The visibiltyRange should indicate, the distance this object can be seen. Maybe the most important variable is the influenceRange. When a peer is in this range and it is not yet controlled by another peer, it takes over control. For further ideas look at the implemented subclasses of FRAGObject: Adventurer, Item in the engine package.
Field Summary | |
java.lang.String |
controller
|
java.lang.String |
gameName
|
protected double |
influenceRange
|
java.lang.String |
objectName
|
java.lang.String |
owner
|
protected MathVector |
position
member for the position for the object. |
protected double |
visibilityRange
|
Constructor Summary | |
FRAGObject()
|
Method Summary | |
abstract void |
actionEvent(ObjectActionEvent event)
Processes the ObjectActionEvent s that the ObjectManager
receives for this object. |
boolean |
checkAndResetMark()
Returns a boolean value, wether the object data was modified and sets the new status to false. |
abstract MathVector |
checkCollision(java.lang.String other,
MathVector oldPos,
MathVector delta)
Called whenever another object has changed its position to allow the current object to react. |
boolean |
checkMark()
Returns a boolean value, wether the object data was modified. |
java.lang.Object |
clone()
Returns a copy of the object data |
void |
controlAcquired()
Called whenever the current peer has acquired control over the object. |
void |
controlLost()
Called when the peer decides or is forced to release control over an object. |
void |
draw(DrawManager drawManager)
THIS METHOD MUST BE IMPLEMENTED FROM THE REAL OBJECT E.G. |
GameManager |
getGameManager()
Returns the GameManager of the current game. |
double |
getInfluenceRange()
Returns the actual InfluenceRange 0 for none and MAX_VALUE for all |
ObjectManager |
getObjectManager()
Returns the ObjectManager of the current game. |
java.lang.String |
getObjectName()
returns the name of the object as string |
MathVector |
getPosition()
Returns a copy of the coordinates of the object. |
void |
killed()
Called when the object is killed. |
void |
mark()
Increments the version number. |
boolean |
newerVersion(FRAGObject other)
Checks if the passed FRAGObject is newer than this object. |
void |
setInfluenceRange(double d)
Sets the actual InfluenceRange of the Object |
void |
setPosition(MathVector position)
Sets the coordinates of the object. |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public java.lang.String gameName
public java.lang.String objectName
public java.lang.String owner
public java.lang.String controller
protected double visibilityRange
protected double influenceRange
protected MathVector position
Constructor Detail |
public FRAGObject()
Method Detail |
public java.lang.Object clone()
public void mark()
public boolean checkMark()
public boolean checkAndResetMark()
public boolean newerVersion(FRAGObject other)
other
- FRAGObject object to checkpublic GameManager getGameManager()
GameManager
of the current game.GameManager
public ObjectManager getObjectManager()
ObjectManager
of the current game.ObjectManager
public MathVector getPosition()
public void setPosition(MathVector position)
position
- MathVector new position of the object.public void controlAcquired()
public void controlLost()
public abstract MathVector checkCollision(java.lang.String other, MathVector oldPos, MathVector delta)
other
- the name of the FRAGObject that changed its positionoldPos
- the old Position (instanceOf MathVector)delta
- the delta vector, that the other instance has movedpublic abstract void actionEvent(ObjectActionEvent event)
ObjectActionEvent
s that the ObjectManager
receives for this object.event
- the event, that took placepublic void killed()
public void draw(DrawManager drawManager)
drawManager
- INSTANCE OF DRAWMANAGER .public java.lang.String getObjectName()
public void setInfluenceRange(double d)
d
- The Influence Range: 0 for none and MAX_VALUE for allpublic double getInfluenceRange()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |