com.theoworlds.builder.CharacterLogic

CharacterLogic class - stores the character logic.  This is a base class that is extended by other CharacterLogic classes that implement different logics

Version

1.0

Author

© TheoWorlds.com, 2007-2009.

Summary
com.theoworlds.builder.CharacterLogicCharacterLogic class - stores the character logic.
Variables
_intThinkingfor setInterval -- thinkingLoop
_intMovingfor setInterval -- moving
_characterlink to the Character
_destinationTilethe destination tile coordinates (where the characters moves to)
_intermediateTilethe current tile -- the one the character is stepping on now
_minLatencyfor dead--reconing -- the minimum lag value (between the client and the server), that can be ignored
_latencythe lag value (between the client and the server)
_smoothStepdead reconing corrects the movement of the character to compensate for the lag during the _maxSmoothSteps step.
_maxSmoothStepsthe maximum number of steps used for dead reconing correction.
_forkD“Fork” direction.
_prevTileremember previous walked tile
_maxStepsnumber of steps the character will try to go around before giving up
_aStepscounts the steps till _maxSteps
_libSpeedstores the character speed from the Library TODO -- add the method set libSpeed, because many actions are supported now and we will need to run them with different speed as well.
Functions and Properties
CharacterLogic
startThinkingadd the call to the thinkingLoop in the children function
stopThinkingstops the character “thinking” (the brain -- character logic).
stopMovingstops the path finding algorithm to be called on mouse clicks
thinkingLoopthis function keeps running, emulating the thinking process.
clearclear assets
movingthe method called by setInterval -- calls the path finding function
moveToTilemoves a character to the given tile
showShortestPathDEBUG
getNextDirectionProcessingpath finding function.
CHARACTER_THINKING_SPEEDleft from v1 -- not used right now
isMovingToTiledetects if the character is moving somewhere after a mouse click
getDestinationTilecoordinates ( Point(col, row) ) of the tile that the character moves to

Variables

_intThinking

private var _intThinking: Number

for setInterval -- thinkingLoop

_intMoving

private var _intMoving: Number

for setInterval -- moving

_character

private var _character: Character

link to the Character

_destinationTile

private var _destinationTile: Point

the destination tile coordinates (where the characters moves to)

_intermediateTile

private var _intermediateTile: Point

the current tile -- the one the character is stepping on now

_minLatency

private var _minLatency: Number

for dead--reconing -- the minimum lag value (between the client and the server), that can be ignored

_latency

private var _latency: Number

the lag value (between the client and the server)

_smoothStep

private var _smoothStep: Number

dead reconing corrects the movement of the character to compensate for the lag during the _maxSmoothSteps step.  This variable stores the number of the current step

_maxSmoothSteps

private var _maxSmoothSteps: Number

the maximum number of steps used for dead reconing correction.  It means that during those steps the character “catches up” with other clients by increasing his movement speed temporarely (creates a smooth correction)

_forkD

private var _forkD: Boolean

”Fork” direction.  Defines direction to go when there are 2 equal oportunities

_prevTile

private var _prevTile: Point

remember previous walked tile

_maxSteps

private var _maxSteps: Number

number of steps the character will try to go around before giving up

_aSteps

private var _aSteps: Number

counts the steps till _maxSteps

_libSpeed

private var _libSpeed: Number

stores the character speed from the Library TODO -- add the method set libSpeed, because many actions are supported now and we will need to run them with different speed as well.  So we will need to call the path finding algorithm with a different frequency (it is synhronized with the character movement)

Functions and Properties

CharacterLogic

public function CharacterLogic(character: Character,
autoStart: Boolean,
initObj: Object)

Parameters

character(Character)
autoStart
initObj

startThinking

public function startThinking():Void

add the call to the thinkingLoop in the children function

stopThinking

public function stopThinking():Void

stops the character “thinking” (the brain -- character logic).

stopMoving

public function stopMoving():Void

stops the path finding algorithm to be called on mouse clicks

thinkingLoop

private function thinkingLoop():Void

this function keeps running, emulating the thinking process.  To be extended in the child classes

clear

public function clear():Void

clear assets

moving

private function moving():Void

the method called by setInterval -- calls the path finding function

moveToTile

public function moveToTile(tileX: Number,
tileY: Number,
latency: Number):Void

moves a character to the given tile

Parameters

tileX-- destination tile row
tileY-- destination tile column
latency-- lag

showShortestPath

private function showShortestPath(ignoreCharacterCollision: Boolean):Void

DEBUG

getNextDirectionProcessing

private function getNextDirectionProcessing(
   ignoreCharacterCollision: Boolean
):Number

path finding function.  It’s called in a loop by CharacterLogic.moving()

Parameters

ignoreCharacterCollision, by default is false;

Returns

the direction of the next step (1--8).  0 -- means “stop”. 

CHARACTER_THINKING_SPEED

static function get CHARACTER_THINKING_SPEED():Number

left from v1 -- not used right now

isMovingToTile

public function isMovingToTile():Boolean

Returns

detects if the character is moving somewhere after a mouse click

getDestinationTile

public function getDestinationTile():Point

Returns

coordinates ( Point(col, row) ) of the tile that the character moves to

CharacterLogicControlled class - character logic that makes the character to be controlled (by mouse or keyboard) - used for “I” character
CharacterLogicRandom class - character logic that makes the character do random actions - usefull for “monsters” in game and bots in mult-iuser applications
private var _intThinking: Number
for setInterval -- thinkingLoop
private var _intMoving: Number
for setInterval -- moving
private var _character: Character
link to the Character
Character class -- character/avatar main class
private var _destinationTile: Point
the destination tile coordinates (where the characters moves to)
private var _intermediateTile: Point
the current tile -- the one the character is stepping on now
private var _minLatency: Number
for dead--reconing -- the minimum lag value (between the client and the server), that can be ignored
private var _latency: Number
the lag value (between the client and the server)
private var _smoothStep: Number
dead reconing corrects the movement of the character to compensate for the lag during the _maxSmoothSteps step.
private var _maxSmoothSteps: Number
the maximum number of steps used for dead reconing correction.
private var _forkD: Boolean
“Fork” direction.
private var _prevTile: Point
remember previous walked tile
private var _maxSteps: Number
number of steps the character will try to go around before giving up
private var _aSteps: Number
counts the steps till _maxSteps
private var _libSpeed: Number
stores the character speed from the Library TODO -- add the method set libSpeed, because many actions are supported now and we will need to run them with different speed as well.
public function CharacterLogic(character: Character,
autoStart: Boolean,
initObj: Object)
public function startThinking():Void
add the call to the thinkingLoop in the children function
public function stopThinking():Void
stops the character “thinking” (the brain -- character logic).
public function stopMoving():Void
stops the path finding algorithm to be called on mouse clicks
private function thinkingLoop():Void
this function keeps running, emulating the thinking process.
public function clear():Void
clear assets
private function moving():Void
the method called by setInterval -- calls the path finding function
public function moveToTile(tileX: Number,
tileY: Number,
latency: Number):Void
moves a character to the given tile
private function showShortestPath(ignoreCharacterCollision: Boolean):Void
DEBUG
private function getNextDirectionProcessing(
   ignoreCharacterCollision: Boolean
):Number
path finding function.
static function get CHARACTER_THINKING_SPEED():Number
left from v1 -- not used right now
public function isMovingToTile():Boolean
detects if the character is moving somewhere after a mouse click
public function getDestinationTile():Point
coordinates ( Point(col, row) ) of the tile that the character moves to
Close