com.theoworlds.builder.Character |
Character class -- character/avatar main class
1.0
© TheoWorlds.com, 2007--2009.
| com. | Character class -- character/avatar main class |
| Variables | |
| _stackable | stacks on top of other tiles, taking elevation in consideration overwriting the parent class value (MapObject._stackable) |
| _walkable | flag(Boolean) that tells if characters(Character) can walk on top of this object overwriting the parent class value (MapObject._walkable) |
| _netID | id(String) for network characters (in multi--user envirorment). |
| _chatColor | predefined chat message color borders. |
| _phasesMC | MovieClip that contains all the characters animation phases |
| _an_frames | number(Number) of animation phases per step of animation |
| _usesLeftRightSteps | flag(Boolean) -- the step animation is made of left and right step parts |
| IGNORES_TERRAIN_ELEVATIONS | flag(Boolean) -- ignores floor tiles elevations |
| SMOOTH_ELEVATION | flag(Boolean) -- elevates gradually from tile to tile, instead of “jumping” on top of the elevated tile |
| _speed | animation speed(Number). |
| _moveToDirection | remembers the direction(Number) the character should move to WHEN IT CAN (it can’t change direction in the middle of the stepping animation). |
| _isMoving | flag (Boolean) |
| _isDoingAnAction | flag (Boolean) |
| _isICharacter | main character (“I”) |
| _displayName | character’s name (String) |
| _direction | the direction(Number) the character is turned to |
| _cActionToDo | the action the character has to do (whenever possible. |
| _cActionEndFrame | the number of phases/frames of the current action animation; 1 by default |
| _cCurrentTileElevation | the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different |
| _cFutureTileElevation | the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different |
| _phase | character animation phase (Number) |
| _brain | the reference to the CharacterLogin object |
| _autoPilot | flag(Boolean) -- if the character is in autoPilot mode, he decides himself were to move, for example random monster movements |
| _anInt | used to store animation interval function (setInterval:Function) id |
| _layersXMLNode | [node:XMLNode] stores the XML nodes(XMLNode) -- this way we can store all the possible parametters, and we can also extend the functionality easily |
| _layers | to access the parametters just use -- _layers[XMLNode.attributes.name] |
| _visibleLayers | visible layers (clothes and accessories) |
| LAYERS_PROTOCOL_GROUP | |
| LAYERS_PROTOCOL_LAYER | |
| LAYERS_PROTOCOL_NAME | |
| LAYERS_PROTOCOL_REQUIRED | |
| _pShiftX | the shift by X(Number) for each walking/moving animation frame |
| _pShiftY | the shift by Y(Number) for each walking/moving animation frame |
| _dShiftX | the diagonal X(Number) shift for each walking/moving animation frame |
| _dShiftY | the diagonal Y(Number) shift for each walking/moving animation frame |
| _tileDiagonal | distance(Number) between diagonal tiles (Tile) |
| nameTxt | the text field for displaying the character name |
| debugTxt | debugging text field (TextField) |
| _libSpeed | the speed(Number) of the character from the Library stored locally for better performance TODO -- add the possibility to accelerate the characters at will. |
| _selectable | flag(Boolean)is the character selectable or not |
| _hitTestBitmap | the bitmap used for hit test (detect the clicks on the character). |
| _hitTestBitmapFirstPoint | the parametter used for BitmapData.hitTest(firstPoint:Point, firstAlphaThreshold:Number, secondObject:Object) stored for optimizing the hit test |
| Functions and Properties | |
| Character | |
| init | initialization |
| onLoadInitLibrarySymbol | called when the character is loaded -- overwrites the parent method |
| onLoadCompleteLibrarySymbol | characters are more complex then other map objects (floor tiles, furniture) and need to finish the initialization after the locading |
| activate | activating the character -- dress and make it move |
| place | placing the character on the map |
| doAction | makes the character perform an action (ex: dance) |
| actionAn | step animation actionFrameLabel -- first frame of the action nonStop -- loop |
| setCurrentAction | sets the current action. |
| isMovableAction | movable -- the action used to movements |
| isNonStopAction | nonStopAction -- “looping” action |
| isSnapToAction | snapToAction -- switches to this action instantly (like sitting on a chair after wakling, without walking on the chair |
| getActionFrameNumber | |
| isUsesLeftRightSteps | used for movable actions to distinguish movements that use left and right steps (walking) from the ones that don’t (sliding, floating...) |
| stopAction | stops the character action |
| stand | stand still |
| freeze | unlike the stopMoving, that makes the character to come to a stop naturally (finishing the step, for example), this method forces the character to freeze right away. |
| turn | makes the character turn to a given direction |
| moveToTile | makes the character move to the indicated tile |
| moveToDir | makes the character start to move in a specific direction // TODO -- implement the same for network characters |
| moveDirProcessing | moves the character to a given direction this function is used to emulate the keyboard control. |
| stopMoving | stops the character movement |
| stepAn | used for step animation |
| changeInterval | method is used for dead reconing only now. |
| scrollMap | calls the map scroll function, if needed |
| isStepEnded | checks if the step animation ended |
| testLayers | |
| initLayers | parcing the XML from the Library RECOMMENDED! |
| takeAllLayersOn | shows all layers of clothes |
| takeAllLayersOff | hides all layers of clothes |
| takeGroupClothesOff | hides the layers of a given group (if it is declared in the XML) |
| putGroupClothesOn | shows the layers of a given group (if it is declared in the XML) |
| takeClothesOff | hides layers of clothes the (String) parametter is passed with the names of the layers, separated by commas: takeLayersOff(“top1”, “bottom24”); |
| putClothesOn | shows layers of clothes the (String) parametter is passed with the names of the layers, separated by commas: takeLayersOn(“top1”, “bottom24”); |
| getGroupClothesList | get the list of the layer groups |
| getDressedClothes | [XMLNode] |
| getGroupNode | this function makes it easier to get through the XML. |
| getLayersFromNode | |
| updateClothesPhase | synchronize clothes animation with character animation |
| dressRandomClothes | dresses a character in random clothes paces all the clothes groups -- same as with CHARACTER_CLOTHES_TYPES |
| getHeight | character height(Number) (the size of the non--transparent area of the bitmap -- not the movieclip) |
| getCrown | the height(Number) of the character from the registration point till its top (the bimap) Example -- a character sits on the floor -- it means his height above the floor is lower than if he would stand up |
| attachBrain | connects a CharacterLogic object to a character |
| detachBrain | disconnects the CharacterLogic object from a character |
| clear | cleans the assets |
| getSettings | returns character settings |
| onClickSpriteMC | this event is called only when _selectable (Character._selectable) == true; it triggers a method in the World that takes action |
| onRollOverSpriteMC | this event is called only when selectable(Character._selectable) == true; it calls hitTestMode to find out if the area clicked is not transparent (empty) |
| onRollOutSpriteMC | called when selectable(Character._selectable) == true; turns off hitTestMode |
| hitTestMode | detects if the click is made on actual non--transparent part of the furniture |
| setHighlight | called when selectable(Character._selectable) == true; highlights on un/highlights a furniture |
| selectable | checks if the furniture is selectable (Character._selectable) |
| selectable | makes the Character object selectable or not |
| speed | speed of character animation. |
| speed | used by CharacterLogic(CharacterLogic) when doing deadReconing the character changes the speed when it can TODO optional |
| getLibSpeed | Library (Library) speed of the character (the base speed he should use when no compensation is applied on top of it) |
| isDoingAnAction | Boolean. |
| getDirection | the direction(Number) the character is turned to Character._direction |
| isMoving | Character._isMoving |
| getDestinationTile | coordinates ( Point(col, row) ) of the tile that the character moves to |
| isICharacter | Boolean -- is the character controllable (mouse, keyboard) -- the main character |
| isICharacter | |
| currentActionName | the name of the current action String |
| netID | the network ID (String) |
| chatColor | the color for chat messages |
| displayName | the character name for chat |
| DIDNT_ACHIEVED_DESTINATION_TILE |
private var _stackable: Boolean
stacks on top of other tiles, taking elevation in consideration overwriting the parent class value (MapObject._stackable)
private var _walkable: Boolean
flag(Boolean) that tells if characters(Character) can walk on top of this object overwriting the parent class value (MapObject._walkable)
private var _cCurrentTileElevation: Number
the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different
private var _cFutureTileElevation: Number
the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different
private var _tileDiagonal: Number
distance(Number) between diagonal tiles (Tile)
private var _libSpeed: Number
the speed(Number) of the character from the Library stored locally for better performance TODO -- add the possibility to accelerate the characters at will. Right now just the dead reconing changes its speed
private var _hitTestBitmap: BitmapData
the bitmap used for hit test (detect the clicks on the character). Since we use bitmaps, the standart MovieClip.hitTest will react to the clicks on the transparent areas as well Is created just on Character._spriteMC#onRollOver() deleted on Character._spriteMC.#nRollOut()
public function Character( target: MovieClip, spriteMCName: String, spriteMCZOrder: Number, tileX: Number, tileY: Number, cs: CharacterSettings, withoutValidation: Boolean )
| target | MovieClip to wich the character object is attached to |
| spriteMCName | the name of the Character._spriteMC (if it’s created) |
| spriteMCZOrder | z--order of the Character._spriteMC (if it’s created) |
| tileX | position on the map -- column(Number) (also storred in CharacterSettings) |
| tileY | position on the map -- row(Number)... |
| cs | (CharacterSettings) |
private function onLoadInitLibrarySymbol( cs: CharacterSettings ):Void
called when the character is loaded -- overwrites the parent method
| cs | (CharacterSettings) |
private function onLoadCompleteLibrarySymbol( cs: CharacterSettings ):Void
characters are more complex then other map objects (floor tiles, furniture) and need to finish the initialization after the locading
| cs | (CharacterSettings) |
private function activate( cs: CharacterSettings ):Void
activating the character -- dress and make it move
| cs | (CharacterSettings) |
public function place( tileX: Number, tileY: Number, dir: Number, phase: Number, elevation: Number, action: String, actionParams: Object ):Void
placing the character on the map
| tileX | -- position on the map -- column(Number) (also storred in CharacterSettings) |
| tileY | -- position on the map -- row(Number)... |
| dir | -- the direction(Number) the character should turn to |
| phase | -- the movement animation phase (frame)(Number) |
| elevation | -- elevation(Number) above the zero level |
| action | -- the action name(String), if any |
| actionParams | -- action parametters. This would be used just when we want to modify a standart action since the action parametters are already stored in _actions This is NOT being used at this point |
public function doAction( action: String, params: Object ):Void
makes the character perform an action (ex: dance)
| action | -- the name of the action(String) |
| params | -- attributes -- the action parametters(Object). his would be used just when we want to modify a standart action since the action parametters are already stored in _actions This is NOT being used at this point |
private function isUsesLeftRightSteps( action: String ):Boolean
used for movable actions to distinguish movements that use left and right steps (walking) from the ones that don’t (sliding, floating...).
| action | -- the action name (String) |
Boolean. Default value is false
public function moveToTile( tileX: Number, tileY: Number, latency: Number ):Void
makes the character move to the indicated tile
| tileX | -- position on the map -- column (also storred in CharacterSettings) |
| tileY | -- position on the map -- row... |
| latency | (Number) -- lag, if it’s too big, the character accelerates |
public function moveToDir( dir: Number, nonStop: Boolean ):Void
makes the character start to move in a specific direction // TODO -- implement the same for network characters
| dir | -- the direction(Number) the character should turn to |
| nonStop | -- flag(Boolean) that tell the character to stop after this step or move on |
public function moveDirProcessing( dir: Number, nonStop: Boolean ):Void
moves the character to a given direction this function is used to emulate the keyboard control. CharacterLogic takes care of it -- it calls this method to make a character move, stop and keep moving // TMP public for CharacterLogic
| dir | -- the direction(Number) the character should turn to |
| nonStop | -- if this flag is true -- keeps moving in that directions untill stopped. if not -- makes just one step. |
public function takeGroupClothesOff():Void
hides the layers of a given group (if it is declared in the XML)
if sub--groups are used, the string value can be passed as grop.subgroup (dot--syntax)
multiple groups can be passed, separated by commas, like takeClothesOffByGroup(“clothes.tops”, “clothes.bottoms”, “hair”);
if you have a tree of groups (“clothes.tops, “clothes.bottoms” ), you can call takeClothesOffByGroup(“clothes”), and it will hide all the sub--groups
public function getGroupClothesList( chain: String, deep: Boolean ):Object
get the list of the layer groups
| chain | -- string is a dot--syntax -- “clothes.tops” |
| deep | -- same as in XMLNode.cloneNode(deep) -- a flag that tells it to include the sub--groups or not. By default deep = true |
Object of this type: {layerName1:XMLNode, layerName2:XMLNode, layerName3:XMLNode...}
public function dressRandomClothes( requiredOn: Boolean ):Void
dresses a character in random clothes paces all the clothes groups -- same as with CHARACTER_CLOTHES_TYPES
| requiredOn | (Boolean) -- if there is a CHARACTER_CLOTHES_TYPES_REQUIRED in the group -- one layer is left visible |
private function onClickSpriteMC():Void
this event is called only when _selectable (Character._selectable) == true; it triggers a method in the World that takes action
private function onRollOverSpriteMC():Void
this event is called only when selectable(Character._selectable) == true; it calls hitTestMode to find out if the area clicked is not transparent (empty)
private function onRollOutSpriteMC():Void
called when selectable(Character._selectable) == true; turns off hitTestMode
private function setHighlight( b: Boolean ):Void
called when selectable(Character._selectable) == true; highlights on un/highlights a furniture
| param | Boolean |
public function get selectable():Boolean
checks if the furniture is selectable (Character._selectable)
Boolean
public function set speed( speed: Number ):Void
used by CharacterLogic(CharacterLogic) when doing deadReconing the character changes the speed when it can TODO optional
public function getLibSpeed():Number
Library (Library) speed of the character (the base speed he should use when no compensation is applied on top of it)
public function getDirection():Number
the direction(Number) the character is turned to Character._direction
stacks on top of other tiles, taking elevation in consideration overwriting the parent class value (MapObject._stackable)
private var _stackable: Boolean
stacks on top of other tiles, taking elevation in consideration
private var _stackable: Boolean
flag(Boolean) that tells if characters(Character) can walk on top of this object overwriting the parent class value (MapObject._walkable)
private var _walkable: Boolean
public function Character( target: MovieClip, spriteMCName: String, spriteMCZOrder: Number, tileX: Number, tileY: Number, cs: CharacterSettings, withoutValidation: Boolean )
flag(:Boolean) that tells if characters(Character) can walk on top of this object
private var _walkable: Boolean
id(String) for network characters (in multi--user envirorment).
private var _netID: String
predefined chat message color borders.
private var _chatColor: Number
MovieClip that contains all the characters animation phases
private var _phasesMC: MovieClip
number(Number) of animation phases per step of animation
private var _an_frames: Number
flag(Boolean) -- the step animation is made of left and right step parts
private var _usesLeftRightSteps: Boolean
flag(Boolean) -- ignores floor tiles elevations
private var IGNORES_TERRAIN_ELEVATIONS: Boolean
flag(Boolean) -- elevates gradually from tile to tile, instead of “jumping” on top of the elevated tile
private var SMOOTH_ELEVATION: Boolean
animation speed(Number).
private var _speed: Number
remembers the direction(Number) the character should move to WHEN IT CAN (it can’t change direction in the middle of the stepping animation).
private var _moveToDirection: Number
flag (Boolean)
private var _isMoving: Boolean
flag (Boolean)
private var _isDoingAnAction: Boolean
main character (“I”)
private var _isICharacter: Boolean
character’s name (String)
private var _displayName: String
the direction(Number) the character is turned to
private var _direction: Number
the action the character has to do (whenever possible.
private var _cActionToDo: Object
the number of phases/frames of the current action animation; 1 by default
private var _cActionEndFrame: Number
the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different
private var _cCurrentTileElevation: Number
the elevation(Number) of the current tile (Tile) -- elevation is the character own elevation -- can be different
private var _cFutureTileElevation: Number
character animation phase (Number)
private var _phase: Number
the reference to the CharacterLogin object
private var _brain: CharacterLogic
flag(Boolean) -- if the character is in autoPilot mode, he decides himself were to move, for example random monster movements
private var _autoPilot: Boolean
used to store animation interval function (setInterval:Function) id
private var _anInt: Number
[node:XMLNode] stores the XML nodes(XMLNode) -- this way we can store all the possible parametters, and we can also extend the functionality easily
private var _layersXMLNode: XMLNode
to access the parametters just use -- _layers[XMLNode.attributes.name]
private var _layers: Object
visible layers (clothes and accessories)
private var _visibleLayers: Object
private static var LAYERS_PROTOCOL_GROUP: String
private static var LAYERS_PROTOCOL_LAYER: String
private static var LAYERS_PROTOCOL_NAME: String
private static var LAYERS_PROTOCOL_REQUIRED: String
the shift by X(Number) for each walking/moving animation frame
private var _pShiftX: Number
the shift by Y(Number) for each walking/moving animation frame
private var _pShiftY: Number
the diagonal X(Number) shift for each walking/moving animation frame
private var _dShiftX: Number
the diagonal Y(Number) shift for each walking/moving animation frame
private var _dShiftY: Number
distance(Number) between diagonal tiles (Tile)
private var _tileDiagonal: Number
the text field for displaying the character name
private var nameTxt: TextField
debugging text field (TextField)
private var debugTxt: TextField
the speed(Number) of the character from the Library stored locally for better performance TODO -- add the possibility to accelerate the characters at will.
private var _libSpeed: Number
flag(Boolean)is the character selectable or not
private var _selectable: Boolean
the bitmap used for hit test (detect the clicks on the character).
private var _hitTestBitmap: BitmapData
the parametter used for BitmapData.hitTest(firstPoint:Point, firstAlphaThreshold:Number, secondObject:Object) stored for optimizing the hit test
private var _hitTestBitmapFirstPoint: Point
initialization
private function init( cs: CharacterSettings ):Void
called when the character is loaded -- overwrites the parent method
private function onLoadInitLibrarySymbol( cs: CharacterSettings ):Void
characters are more complex then other map objects (floor tiles, furniture) and need to finish the initialization after the locading
private function onLoadCompleteLibrarySymbol( cs: CharacterSettings ):Void
activating the character -- dress and make it move
private function activate( cs: CharacterSettings ):Void
placing the character on the map
public function place( tileX: Number, tileY: Number, dir: Number, phase: Number, elevation: Number, action: String, actionParams: Object ):Void
makes the character perform an action (ex: dance)
public function doAction( action: String, params: Object ):Void
step animation actionFrameLabel -- first frame of the action nonStop -- loop
private function actionAn( action: String, params: Object ):Void
sets the current action.
private function setCurrentAction( action: String ):Void
movable -- the action used to movements
private function isMovableAction( action: String ):Boolean
nonStopAction -- “looping” action
private function isNonStopAction( action: String ):Boolean
snapToAction -- switches to this action instantly (like sitting on a chair after wakling, without walking on the chair
private function isSnapToAction( action: String ):Boolean
private function getActionFrameNumber( action: String ):Number
used for movable actions to distinguish movements that use left and right steps (walking) from the ones that don’t (sliding, floating...)
private function isUsesLeftRightSteps( action: String ):Boolean
stops the character action
public function stopAction():Void
stand still
public function stand():Void
unlike the stopMoving, that makes the character to come to a stop naturally (finishing the step, for example), this method forces the character to freeze right away.
public function freeze():Void
makes the character turn to a given direction
public function turn( dir: Number, phase: Number ):Void
makes the character move to the indicated tile
public function moveToTile( tileX: Number, tileY: Number, latency: Number ):Void
makes the character start to move in a specific direction // TODO -- implement the same for network characters
public function moveToDir( dir: Number, nonStop: Boolean ):Void
moves the character to a given direction this function is used to emulate the keyboard control.
public function moveDirProcessing( dir: Number, nonStop: Boolean ):Void
stops the character movement
private function stopMoving():Void
used for step animation
private function stepAn( nonStop: Boolean ):Void
method is used for dead reconing only now.
private function changeInterval( speed: Number ):Void
calls the map scroll function, if needed
private function scrollMap( mapShiftX: Number, mapShiftY: Number ):Void
checks if the step animation ended
private function isStepEnded( phase: Number ): Boolean
private function testLayers():Void
parcing the XML from the Library RECOMMENDED!
private function initLayers():Void
shows all layers of clothes
public function takeAllLayersOn():Void
hides all layers of clothes
public function takeAllLayersOff():Void
hides the layers of a given group (if it is declared in the XML)
public function takeGroupClothesOff():Void
shows the layers of a given group (if it is declared in the XML)
public function putGroupClothesOn():Void
hides layers of clothes the (String) parametter is passed with the names of the layers, separated by commas: takeLayersOff(“top1”, “bottom24”);
public function takeClothesOff():Void
shows layers of clothes the (String) parametter is passed with the names of the layers, separated by commas: takeLayersOn(“top1”, “bottom24”);
public function putClothesOn():Void
get the list of the layer groups
public function getGroupClothesList( chain: String, deep: Boolean ):Object
[XMLNode]
public function getDressedClothes():Object
this function makes it easier to get through the XML.
public function getGroupNode( chain: String, source: XMLNode ):XMLNode
private function getLayersFromNode( node: XMLNode, deep: Boolean ):Object
synchronize clothes animation with character animation
private function updateClothesPhase():Void
dresses a character in random clothes paces all the clothes groups -- same as with CHARACTER_CLOTHES_TYPES
public function dressRandomClothes( requiredOn: Boolean ):Void
character height(Number) (the size of the non--transparent area of the bitmap -- not the movieclip)
public function getHeight(): Number
the height(Number) of the character from the registration point till its top (the bimap) Example -- a character sits on the floor -- it means his height above the floor is lower than if he would stand up
public function getCrown():Number
connects a CharacterLogic object to a character
public function attachBrain( brainType: String, autoStart: Boolean, initObj: Object ):Void
disconnects the CharacterLogic object from a character
private function detachBrain():Void
cleans the assets
public function clear():Void
returns character settings
public function getSettings( type: Number ):CharacterSettings
this event is called only when _selectable (Character._selectable) == true; it triggers a method in the World that takes action
private function onClickSpriteMC():Void
this event is called only when selectable(Character._selectable) == true; it calls hitTestMode to find out if the area clicked is not transparent (empty)
private function onRollOverSpriteMC():Void
called when selectable(Character._selectable) == true; turns off hitTestMode
private function onRollOutSpriteMC():Void
detects if the click is made on actual non--transparent part of the furniture
private function hitTestMode():Void
called when selectable(Character._selectable) == true; highlights on un/highlights a furniture
private function setHighlight( b: Boolean ):Void
checks if the furniture is selectable (Character._selectable)
public function get selectable():Boolean
speed of character animation.
public function get speed():Number
Library (Library) speed of the character (the base speed he should use when no compensation is applied on top of it)
public function getLibSpeed():Number
Boolean.
public function isDoingAnAction(): Boolean
the direction(Number) the character is turned to Character._direction
public function getDirection():Number
Character._isMoving
public function get isMoving(): Boolean
coordinates ( Point(col, row) ) of the tile that the character moves to
public function getDestinationTile():Point
Boolean -- is the character controllable (mouse, keyboard) -- the main character
public function get isICharacter(): Boolean
the name of the current action String
public function get currentActionName():String
the network ID (String)
public function get netID ():String
the color for chat messages
public function get chatColor():Number
the character name for chat
public function get displayName():String
public static function get DIDNT_ACHIEVED_DESTINATION_TILE():String