コード例 #1
0
        public NodeEntity GetNode(NobleQuestGame game, Vector2 position)
        {
            // Instantiate and Set Properties in GameEntity
            NodeEntity grassNode = new NodeEntity(game);

            grassNode.Position = position;
            grassNode.Velocity = new Vector2(0f, 0f);
            grassNode.Midpoint = new Vector2(grassNode.Texture.Width / 2, grassNode.Texture.Height / 2);
            //grassNode.Midpoint = new Vector2(0f, 0f);
            grassNode.Rotation        = 0.0f;
            grassNode.SrcRectangle    = new Rectangle(0, 0, grassNode.Texture.Width, grassNode.Texture.Height);
            grassNode.DestRectangle   = new Rectangle(0, 0, grassNode.Texture.Width, grassNode.Texture.Height);
            grassNode.DestRectangle.X = (int)(grassNode.Position.X - grassNode.Midpoint.X);
            grassNode.DestRectangle.Y = (int)(grassNode.Position.Y - grassNode.Midpoint.Y);
            grassNode.Owner           = Owners.NEUTRAL;

            // Set Properties in NodeEntity
            grassNode.HasResourceStructure = false;
            grassNode.LeftPaths            = new List <PathEntity>();
            grassNode.RightPaths           = new List <PathEntity>();
            grassNode.PreferredPathEntity  = null;
            grassNode.HasFort = false;
            grassNode.Fort    = null;
            grassNode.isTown  = false;

            return(grassNode);
        }
コード例 #2
0
        public void BuildLane(NodeEntity[] LaneArray, float xOffset, float yPosition,
                              NodeEntity startNode, NodeEntity endNode)
        {
            GameEntity ThisGameEntity = null;
            GameEntity LastGameEntity = null;

            LastGameEntity = startNode;

            for (int i = 0; i < LaneArray.Length; i++)
            {
                ThisGameEntity = EntityFactory.GetNode(
                    this.Game,
                    new Vector2(LastGameEntity.Position.X + xOffset, yPosition));
                LaneArray[i] = (NodeEntity)ThisGameEntity;
                this.Game.NodeEntityList.Add((NodeEntity)ThisGameEntity);
                this.Game.PathEntityList.Add(EntityFactory.GetPathEntity(this.Game, (NodeEntity)LastGameEntity, (NodeEntity)ThisGameEntity));
                LastGameEntity = ThisGameEntity;
            }

            if (this.Game.TopEnd == null)
            {
                this.Game.TopEnd = (NodeEntity)LastGameEntity;
            }
            else if (this.Game.MidEnd == null)
            {
                this.Game.MidEnd = (NodeEntity)LastGameEntity;
            }
            else if (this.Game.BotEnd == null)
            {
                this.Game.BotEnd = (NodeEntity)LastGameEntity;
            }

            this.Game.PathEntityList.Add(EntityFactory.GetPathEntity(this.Game, (NodeEntity)LastGameEntity, endNode));
        }
コード例 #3
0
        public void AddPathSelectionEntity()
        {
            PathSelectionEntity = new PathSelectionEntity(this.Game);

            PathSelectionEntity.Position      = this.Position;
            PathSelectionEntity.SrcRectangle  = new Rectangle(0, 0, PathSelectionEntity.Texture.Width, PathSelectionEntity.Texture.Height);
            PathSelectionEntity.DestRectangle = new Rectangle(
                (int)PathSelectionEntity.Position.X,
                (int)PathSelectionEntity.Position.Y,
                PathSelectionEntity.Texture.Width,
                PathSelectionEntity.Texture.Height);
            PathSelectionEntity.Midpoint = new Vector2(PathSelectionEntity.Texture.Width / 2, PathSelectionEntity.Texture.Height / 2);

            NodeEntity leftNode  = PreferredPathEntity.LeftNode;
            NodeEntity rightNode = PreferredPathEntity.RightNode;

            if (LeftPaths != null &&
                LeftPaths.Contains(PreferredPathEntity))
            {
                leftNode  = PreferredPathEntity.RightNode;
                rightNode = PreferredPathEntity.LeftNode;
            }
            float  nodeDistance = Vector2.Distance(leftNode.Position, rightNode.Position);
            double rotation     = Math.Atan2(rightNode.Position.Y - leftNode.Position.Y, rightNode.Position.X - leftNode.Position.X);

            PathSelectionEntity.Rotation = (float)rotation - (float)Math.PI * 0.5f;

            this.Game.PathSelectionList.Add(PathSelectionEntity);
        }
コード例 #4
0
 public void StopEntity()
 {
     State         = States.STOPPED;
     this.Location = this.Destination;
     //this.Position = this.Location.Position;
     this.Destination = null;
     IsAtDestination  = true;
 }
コード例 #5
0
 public void setSelectedNode(NodeEntity NewSelectedNode)
 {
     SelectedNode = NewSelectedNode;
     Position     = SelectedNode.Position;
     Position.Y  -= SelectedNode.Texture.Height / 3;
     Velocity     = ZERO_VELOCITY;
     Midpoint     = new Vector2(Texture.Width / 2, Texture.Height);
     Rotation     = 0.0f;
     Offset       = new Vector2(0.0f, 0.0f);
     SrcRectangle = new Rectangle(0, 0,
                                  Texture.Width, Texture.Height);
     DestRectangle = SelectedNode.DestRectangle;
 }
コード例 #6
0
        public override void HandleCollision(NodeEntity node)
        {
            if (node.isTown)
            {
                return;
            }

            if (node.Owner == this.Owner)
            {
                nodesVisited.Add(node);
            }
            else
            {
                StopEntity();
                ReverseDirection();
            }
        }
コード例 #7
0
        public PathEntity GetPathEntity(NobleQuestGame game, NodeEntity leftNode, NodeEntity rightNode)
        {
            // Get Distance Between Nodes
            float  nodeDistance = Vector2.Distance(leftNode.Position, rightNode.Position);
            double rotation     = Math.Atan2(rightNode.Position.Y - leftNode.Position.Y, rightNode.Position.X - leftNode.Position.X);

            // Instantiate and Set Properties in GameEntity
            PathEntity pathEntity = new Entity.PathEntity();

            pathEntity.Texture  = game.Content.Load <Texture2D>("Path");
            pathEntity.Position = leftNode.Position;
            pathEntity.Velocity = new Vector2(0f, 0f);
            // pathEntity.Midpoint = new Vector2(pathEntity.Texture.Width / 2, pathEntity.Texture.Height / 2);
            pathEntity.Midpoint      = new Vector2(0f, pathEntity.Texture.Height / 2);
            pathEntity.Rotation      = (float)rotation;
            pathEntity.SrcRectangle  = new Rectangle(0, 0, (int)nodeDistance, pathEntity.Texture.Height);
            pathEntity.DestRectangle = new Rectangle((int)pathEntity.Position.X, (int)pathEntity.Position.Y,
                                                     (int)(Math.Abs(rightNode.Position.X - leftNode.Position.X)),
                                                     (int)(Math.Abs(rightNode.Position.Y - leftNode.Position.Y)));
            pathEntity.Game        = game;
            pathEntity.PlayerOwned = false;
            pathEntity.EnemyOwned  = false;

            // Set Properties in PathEntity
            pathEntity.LeftNode  = leftNode;
            pathEntity.RightNode = rightNode;

            // Set Properties in Nodes
            if (leftNode.RightPaths != null)
            {
                leftNode.RightPaths.Add(pathEntity);
            }
            if (rightNode.LeftPaths != null)
            {
                rightNode.LeftPaths.Add(pathEntity);
            }

            return(pathEntity);
        }
コード例 #8
0
 public PathEntity(NodeEntity LeftNode, NodeEntity RightNode)
 {
     this.LeftNode  = LeftNode;
     this.RightNode = RightNode;
 }
コード例 #9
0
 public virtual void HandleCollision(NodeEntity node)
 {
 }
コード例 #10
0
        public void DetermineDestination()
        {
            // If we already have a Destination, do nothing
            if (this.Destination != null)
            {
                return;
            }

            // If Enemy Owned, get next node in path
            if (this.Owner == Owners.ENEMY &&
                ToVisitedIndex < this.ToVisitPath.Count)
            {
                Destination = this.ToVisitPath[ToVisitedIndex];
                ToVisitedIndex++;
                return;
            }

            // Check for Preferred Path Entity
            if (Location.PreferredPathEntity != null &&
                this.Owner != Owners.ENEMY &&
                !IsIgnoringPreferredPath)
            {
                switch (Direction)
                {
                case Directions.LEFT:
                    if (Location.LeftPaths != null)
                    {
                        if (Destination == Location.PreferredPathEntity.LeftNode)
                        {
                            Direction   = Directions.RIGHT;
                            Destination = Location.PreferredPathEntity.RightNode;
                            if (Location == Destination)
                            {
                                Direction   = Directions.LEFT;
                                Destination = Location.PreferredPathEntity.LeftNode;
                            }
                        }
                        else
                        {
                            Direction   = Directions.LEFT;
                            Destination = Location.PreferredPathEntity.LeftNode;
                            if (Location == Destination)
                            {
                                Direction   = Directions.RIGHT;
                                Destination = Location.PreferredPathEntity.RightNode;
                            }
                        }
                    }
                    else
                    {
                        Direction   = Directions.RIGHT;
                        Destination = Location.PreferredPathEntity.RightNode;
                    }
                    return;

                case Directions.RIGHT:
                    if (Location.RightPaths != null)
                    {
                        if (Destination == Location.PreferredPathEntity.RightNode)
                        {
                            Direction   = Directions.LEFT;
                            Destination = Location.PreferredPathEntity.LeftNode;
                            if (Location == Destination)
                            {
                                Direction   = Directions.RIGHT;
                                Destination = Location.PreferredPathEntity.RightNode;
                            }
                        }
                        else
                        {
                            Direction   = Directions.RIGHT;
                            Destination = Location.PreferredPathEntity.RightNode;
                            if (Location == Destination)
                            {
                                Direction   = Directions.LEFT;
                                Destination = Location.PreferredPathEntity.LeftNode;
                            }
                        }
                    }
                    else
                    {
                        Direction   = Directions.LEFT;
                        Destination = Location.PreferredPathEntity.LeftNode;
                    }
                    return;

                default:
                    break;
                }
            }

            // Get Random Path
            switch (Direction)
            {
            case Directions.LEFT:
                if (Location.LeftPaths != null)
                {
                    Destination = GetPath(Location.LeftPaths).LeftNode;
                }
                else
                {
                    Direction   = Directions.RIGHT;
                    Destination = GetPath(Location.RightPaths).RightNode;
                }
                break;

            case Directions.RIGHT:
                if (Location.RightPaths != null)
                {
                    Destination = GetPath(Location.RightPaths).RightNode;
                }
                else
                {
                    Direction   = Directions.LEFT;
                    Destination = GetPath(Location.LeftPaths).LeftNode;
                }
                break;

            default:
                break;
            }
        }// DetermineDestination
コード例 #11
0
 public IntelligentList(UnitType unitType, NodeEntity node)
 {
     nodeList = new List <NodeEntity>();
     nodeList.Add(node);
     this.unitType = unitType;
 }
コード例 #12
0
 public override void HandleCollision(NodeEntity node)
 {
 }