package { import flash.display.Bitmap; import flash.filters.ColorMatrixFilter; public class WorkerView extends EntityView { private static const EMOTE_OFFSET_Y:Number = -48; private var facingBitmaps:Vector.; private var emote:Bitmap; private var animationTime:Number = 0; private var currentEmote:int; public function WorkerView(model:WorkerModel) { super(model); facingBitmaps = new Vector.(4, true); for (var facing:int = 0; facing < 4; facing++) { var bitmap:Bitmap; bitmap = new (Embeds.worker(facing, model.gender))(); bitmap.x = -bitmap.width / 2; bitmap.y = 0;//-bitmap.height + TileView.HEIGHT / 2; facingBitmaps[facing] = bitmap; } addChildAt(facingBitmaps[model.facing], 0); currentEmote = WorkerModel.EMOTE_NONE; } override public function draw(delta:Number):void { var screenPosition:Vector2; var workerModel:WorkerModel = model as WorkerModel; removeChildAt(0); addChildAt(facingBitmaps[workerModel.facing], 0); visible = workerModel.inVisibleOffice; screenPosition = IsoMath.localToScreen(workerModel.position); x = Math.round(screenPosition.x); y = Math.round(screenPosition.y); if (workerModel.currentEmote != currentEmote) { currentEmote = workerModel.currentEmote; switch (currentEmote) { case WorkerModel.EMOTE_NONE: removeChild(emote); emote = null; break; case WorkerModel.EMOTE_CRY: if (emote != null) { removeChild(emote); } emote = new (Embeds.embedEmoteCrying)(); emote.x = -emote.width / 2; addChild(emote); animationTime = 0; break; case WorkerModel.EMOTE_DEVIL: if (emote != null) { removeChild(emote); } emote = new (Embeds.embedEmoteDevil)(); emote.x = -emote.width / 2; addChild(emote); animationTime = 0; break; } } if (currentEmote != WorkerModel.EMOTE_NONE && emote != null) { animationTime += delta; emote.y = EMOTE_OFFSET_Y + GraphicsConstants.EMOTE_BOUNCE_HEIGHT - Math.abs(Math.sin(Math.PI * animationTime / GraphicsConstants.EMOTE_BOUNCE_INTERVAL)) * GraphicsConstants.EMOTE_BOUNCE_HEIGHT; } } } }