public bool Use(ActiveBody consumerBody)
        {
            consumerBody.Heal(_lifeContent);

            _lifeContent = 0;

            return(true);
        }
Exemplo n.º 2
0
        private bool isEnemy(ActiveBody body)
        {
            if (body is PlayerBody)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public override void UpdateState()
        {
            var frame = _mechanicEngine.ViewPort.GetFrame(this.Id, null);

            ActiveBody enemy       = null;
            double     minDistance = -1;

            var newDirection = new Vector();

            //Find enemy
            foreach (var body in frame.Bodies.Where(v => v is ActiveBody))
            {
                // Only PlayerBodies can be enemies
                if (isEnemy(body as ActiveBody))
                {
                    var    _newDirection = Vector.Subtract(body.Shape.Position, this.Shape.Position);
                    double distance      = calculateDistance(_newDirection);
                    if (distance < minDistance || minDistance == -1)
                    {
                        enemy        = body as ActiveBody;
                        minDistance  = distance;
                        newDirection = _newDirection;
                    }
                }
            }

            if (enemy != null)
            {
                if (Direction != newDirection)
                {
                    _mechanicEngine.ProcessGameCommand(
                        new GameCommandChangeDirection(
                            1,
                            newDirection,
                            _mechanicEngine, this
                            ));
                }

                Shoot();

                //Run to enemy
                if (_startMove == DateTime.MinValue)
                {
                    _startMove = DateTime.Now;
                }
                else
                {
                    var duration = DateTime.Now - _startMove;

                    if (duration.TotalMilliseconds > 10)
                    {
                        _mechanicEngine.AddCommand(new GameCommandMove(0, newDirection, _mechanicEngine, this, duration));

                        _startMove = DateTime.Now;
                    }
                }
            }
            else
            {
                _startMove = DateTime.MinValue;
            }
        }