package { import flash.geom.Rectangle; public class WorkerModel extends EntityModel { public static const ACCELERATION_SPEED:Number = 0.02; public static const DECELERATION_SPEED:Number = 0.04; public static const MAX_SPEED:Number = 0.1; public static const EMOTE_NONE:int = 0; public static const EMOTE_CRY:int = 1; public static const EMOTE_DEVIL:int = 2; public static const EMOTE_SANDWICH:int = 3; private var _gender:int; private var _workerID:int; private var moving:Boolean; public var velocity:Vector2; public var lastPosition:Vector2; public var workerIDsInLineOfSight:Vector.; public var ownerOfOccupiedTile:int; public var hasSandwich:Boolean; public var hasKeys:Boolean; public var inVisibleOffice:Boolean; public var currentEmote:int; protected var emoteTimeLeft:int; public function WorkerModel(gender:int, workerID:int) { super(); _gender = gender; _workerID = workerID; velocity = new Vector2(); lastPosition = new Vector2(); workerIDsInLineOfSight = new Vector.; ownerOfOccupiedTile = -1; inVisibleOffice = false; hasSandwich = false; hasKeys = true; currentEmote = EMOTE_NONE; } public function get gender():int { return _gender; } public function get workerID():int { return _workerID; } public function startMoving(direction:int):void { moving = true; facing = direction; } public function stopMoving(direction:int):void { if (facing == direction) { moving = false; } } public function get canSeePlayer():Boolean { return workerIDsInLineOfSight.indexOf(0) != -1; } public function get isInOwnOffice():Boolean { return _workerID == ownerOfOccupiedTile; } public function showEmote(emote:int):void { currentEmote = emote; emoteTimeLeft = 180; } override public function update():void { var moveX:int = 0, moveZ:int = 0; if (emoteTimeLeft > 0) { emoteTimeLeft--; if (emoteTimeLeft == 0) { currentEmote = EMOTE_NONE; } } if (moving) { switch (facing) { case Direction.WEST: moveX = -1; break; case Direction.EAST: moveX = 1; break; case Direction.NORTH: moveZ = -1; break; case Direction.SOUTH: moveZ = 1; break; } } if (velocity.x > 0 && moveX <= 0) { velocity.x -= DECELERATION_SPEED; if (velocity.x < 0) { velocity.x = 0; } } else if (velocity.x < 0 && moveX >= 0) { velocity.x += DECELERATION_SPEED; if (velocity.x > 0) { velocity.x = 0; } } if (velocity.z > 0 && moveZ <= 0) { velocity.z -= DECELERATION_SPEED; if (velocity.z < 0) { velocity.z = 0; } } else if (velocity.z < 0 && moveZ >= 0) { velocity.z += DECELERATION_SPEED; if (velocity.z > 0) { velocity.z = 0; } } if (moveX < 0) { velocity.x -= ACCELERATION_SPEED; if (velocity.x < -MAX_SPEED) { velocity.x = -MAX_SPEED; } } else if (moveX > 0) { velocity.x += ACCELERATION_SPEED; if (velocity.x > MAX_SPEED) { velocity.x = MAX_SPEED; } } if (moveZ < 0) { velocity.z -= ACCELERATION_SPEED; if (velocity.z < -MAX_SPEED) { velocity.z = -MAX_SPEED; } } else if (moveZ > 0) { velocity.z += ACCELERATION_SPEED; if (velocity.z > MAX_SPEED) { velocity.z = MAX_SPEED; } } lastPosition.x = position.x; lastPosition.z = position.z; position.x += velocity.x; position.z += velocity.z; } override public function get bounds():Rectangle { return new Rectangle(position.x + 0.25, position.y + 0.25, 0.5, 0.5); } public function get lastBounds():Rectangle { return new Rectangle(lastPosition.x + 0.25, lastPosition.y + 0.25, 0.5, 0.5); } } }