Exemplo n.º 1
0
        public override void HasCollidedWith(HackGameAgent otherAgent, HackGameBoard board)
        {
            if (otherAgent is HackGameAgent_AI && IsActive() && otherAgent.IsActive())
            {
                //KABOOM!
                otherAgent.Kill(0);
                //DON'T KILL SELF, KEEP GOING
                board.AddBackgroundTextAward(new StringBuilder("000000 000000 000000 00  00"), 0);
                board.AddBackgroundTextAward(new StringBuilder("0    0 0    0 0    0 0 00 0"), 0.1f);
                board.AddBackgroundTextAward(new StringBuilder("00000  0    0 0    0 0    0"), 0.1f);
                board.AddBackgroundTextAward(new StringBuilder("0    0 0    0 0    0 0    0"), 0.1f);
                board.AddBackgroundTextAward(new StringBuilder("000000 000000 000000 0    0"), 0.1f);
            }

            base.HasCollidedWith(otherAgent, board);
        }
Exemplo n.º 2
0
        public virtual bool IsCollidingWith(HackGameAgent otherAgent)
        {
            if (otherAgent == this)
            {
                return false;
            }

            if (!this.IsActive() || !otherAgent.IsActive())
            {
                return false;
            }

            else
            {
                //start with the simplest case
                if (this.getMovementDirection() == MovementDirection.MovementDirection_None && otherAgent.getMovementDirection() == MovementDirection.MovementDirection_None
                    && this.currentBoardElementLocation == otherAgent.currentBoardElementLocation)
                {
                    return true;

                }
                else if (otherAgent.getMovementDirection() == MovementDirection.MovementDirection_None)
                {
                    //he's stationary, we just need to see if we're imminent to him and our distance to him is in tolerance
                    if (this.getMovementDirection() != MovementDirection.MovementDirection_None &&
                        this.currentBoardElementDestination == otherAgent.currentBoardElementLocation &&
                        this.getTtoDestination() > 1.0 - HackGameAgent.CollideTWindow)
                    {
                        return true;
                    }
                    return false;

                }
                else if (this.getMovementDirection() == MovementDirection.MovementDirection_None)
                {
                    //we're stationary, we just need to see if he's imminent to use and his distance to us is in tolerance
                    if (otherAgent.getMovementDirection() != MovementDirection.MovementDirection_None &&
                        otherAgent.currentBoardElementDestination == this.currentBoardElementLocation &&
                        otherAgent.getTtoDestination() > 1.0 - HackGameAgent.CollideTWindow)
                    {
                        return true;
                    }
                    return false;
                }
                else
                {
                    //well, we're both moving.
                    //so - if source and destination are both the same..
                    if (this.getCurrentBoardLocation() == otherAgent.getCurrentBoardLocation() &&
                        this.getDestinationBoardLocation() == otherAgent.getDestinationBoardLocation())
                    {
                        if (Math.Abs(this.getTtoDestination() - otherAgent.getTtoDestination()) < HackGameAgent.CollideTWindow)
                        {
                            return true;
                        }
                        return false;
                    }

                    //if we're coming from different places but destination is the same...
                    else if (this.getDestinationBoardLocation() == otherAgent.getDestinationBoardLocation())
                    {
                        //then two things must be true - we must each be w/in threshhold of destination and of each other.
                        if (this.getTtoDestination() < HackGameAgent.CollideTWindowCrossing && otherAgent.getTtoDestination() < HackGameAgent.CollideTWindowCrossing &&
                            Math.Abs(this.getTtoDestination() - otherAgent.getTtoDestination()) < HackGameAgent.CollideTWindowCrossing)
                        {
                            return true;
                        }
                        return false;

                    }

                    //if we're "swapping places" - a head-on collision
                    else if (this.getDestinationBoardLocation() == otherAgent.getCurrentBoardLocation() &&
                        otherAgent.getDestinationBoardLocation() == this.getCurrentBoardLocation())
                    {
                        //now you have to measure your T vs his 1.0 - T.
                        float fixedT = 1.0f - otherAgent.getTtoDestination();
                        if (Math.Abs(this.getTtoDestination() - fixedT) < HackGameAgent.CollideTWindow)
                        {
                            return true;
                        }
                        return false;
                    }

                    else
                    {
                        return false;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void AlignToTarget(HackGameAgent target, HackGameBoard ourBoard)
        {
            if (target == null || !target.IsActive())
            {
                //WACKY MISSILE!
                target = null;
                SetRandomDestination(ourBoard);
            }
            else
            {
                //easy case - enemy is going to be at a node as his next immediate destination
                if (ourBoard.GetElementAtPoint(target.getDestinationBoardLocation()).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node)
                {
                    TryDestination(target.getDestinationBoardLocation(), ourBoard);
                }

                //harder case - enemy is on a bridge somewhere, not immediately headed for a node
                else
                {
                    //you need to find the target's next NODE it's going to hit.
                    bool found = false;
                    Stack<Point> nextDestinations = target.GetNextDestinations();
                    foreach (Point p in nextDestinations.Reverse())
                    {
                        if (ourBoard.GetElementAtPoint(p).type == HackGameBoardElementBaseType.HackGameBoardElementBaseType_Node)
                        {
                            TryDestination(p, ourBoard);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        //WACKY MISSILE!
                        target = null;
                        SetRandomDestination(ourBoard);
                    }
                }
            }
        }