示例#1
1
        /// <summary>
        /// Player constructor.
        /// </summary>
        /// <param name="color"></param>
        public Player(Alliance alliance, Color color, Point startLocation)
        {
            Game1.GetInstance().players.AddLast(this);
            this.device = Game1.GetInstance().GraphicsDevice;
            this.alliance = alliance;
            this.startLocation = startLocation;
            if (!this.alliance.members.Contains(this)) this.alliance.members.AddLast(this);
            this.color = color;

            selectionTex = Game1.GetInstance().Content.Load<Texture2D>("Selection");
            selectedTex = Game1.GetInstance().Content.Load<Texture2D>("Selected");

            units = new CustomArrayList<Unit>();
            buildings = new CustomArrayList<Building>();
            hud = new HUD(this, color);
            resources = 100000;

            meleeStore = new MeleeStore(this);
            rangedStore = new RangedStore(this);
            fastStore = new FastStore(this);

            arrowManager = new ArrowManager();

            lightTexture = Game1.GetInstance().Content.Load<Texture2D>("Fog/Light");

            MouseManager.GetInstance().mouseClickedListeners += ((MouseClickListener)this).OnMouseClick;
            MouseManager.GetInstance().mouseReleasedListeners += ((MouseClickListener)this).OnMouseRelease;
            MouseManager.GetInstance().mouseMotionListeners += ((MouseMotionListener)this).OnMouseMotion;
            MouseManager.GetInstance().mouseDragListeners += ((MouseMotionListener)this).OnMouseDrag;
        }
示例#2
0
        public void Reverse()
        {
            CollisionChangedEvent e = new CollisionChangedEvent();
            e.collisionMap = collision;
            e.collisionAdded = false;
            e.changedRect = this.rect;

            foreach (CollisionChangedEvent.QuadPart part in e.changedQuads)
            {
                part.quad.collisionTexture.UpdateCollision(part.rectangle, false);
            }

            CustomArrayList<Node> processedNodes = new CustomArrayList<Node>();
            foreach (Node node in createdNodes)
            {
                CustomArrayList<PathfindingNode> connectedNodes = node.GetConnectedNodes();
                for( int i = 0; i < connectedNodes.Count(); i++ ){
                    Node connectedNode = (Node)connectedNodes.ElementAt(i);
                    if (!processedNodes.Contains(connectedNode))
                    {
                        SmartPathfindingNodeProcessor.GetInstance().Push(connectedNode);
                        processedNodes.AddLast(connectedNode);
                    }
                }
                node.Destroy();
            }
            for( int i = 0; i < this.removedNodes.Count(); i++ ){
                Point p = this.removedNodes.ElementAt(i);
                // Console.Out.WriteLine("Restoring node " + p);
                new Node(collision, p.X, p.Y);
            }

            collision.FireCollisionChangedEvent(e);
        }
示例#3
0
文件: HUD.cs 项目: Wotuu/RTS_XNA_v2
        /// <summary>
        /// Sets the textures to use for the HUD.
        /// Creates new instances of needed components.
        /// Sets variables to their default values.
        /// </summary>
        /// <param name="p">The player this HUD belongs to</param>
        /// <param name="c">The desired color for this HUD</param>
        public HUD(Player p, Color c)
        {
            this.player = p;
            this.color = c;

            hudTex = Game1.GetInstance().Content.Load<Texture2D>("HUD/HUD");
            miniMapTex = Game1.GetInstance().Content.Load<Texture2D>("HUD/HUDMiniMap");
            sf = Game1.GetInstance().Content.Load<SpriteFont>("Fonts/SpriteFont1");

            loadForEngineer = false;
            loadForUnit = false;
            loadForResources = false;
            loadForSentry = false;
            loadForBarracks = false;
            loadForFactory = false;
            loadForFortress = false;
            draw = false;

            objects = new CustomArrayList<HUDObject>();

            LoadCommands();

            MouseManager.GetInstance().mouseClickedListeners += ((MouseClickListener)this).OnMouseClick;
            MouseManager.GetInstance().mouseReleasedListeners += ((MouseClickListener)this).OnMouseRelease;
        }
示例#4
0
        public override CustomArrayList<Point> ApplyPattern()
        {
            CustomArrayList<Point> list = new CustomArrayList<Point>();
            if (selection.units.Count() == 1)
            {
                list.AddLast(location);
                return list;
            }

            int rows = (int)Math.Ceiling((selection.units.Count() / (double)width));

            int offset_x = 0 - (((width - 1) * spacing) / 2);
            int offset_y = 0 - (((rows - 1) * spacing) / 2);

            int count = 0;
            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; (x < width) && (count < selection.units.Count()); x++)
                {
                    // Create the rectangle pattern
                    Point newPoint = new Point(location.X + offset_x + x * spacing,
                        location.Y + offset_y + y * spacing);
                    // Rotate the pattern around
                    newPoint = Util.GetPointOnCircle(location, Util.GetHypoteneuseLength(newPoint, this.location),
                        orientation - (Util.GetHypoteneuseAngleRad(newPoint, this.location) * (180 / Math.PI)));
                    // If it collided with a wall, adjust the pattern to fit
                    CollisionMap c = Game1.GetInstance().map.collisionMap;
                    // If this point is in the middle of collision
                    if (c.CollisionAt(newPoint))
                    {
                        // Get all points between the point and the centre
                        Point[] points = c.PixelsBetweenPoints(newPoint, this.location, 1);
                        foreach (Point point in points)
                        {
                            // Get the point that doesn't have collision, and is farthest away from the centre
                            if (!c.CollisionAt(point))
                            {
                                newPoint = point;
                                break;
                            }
                        }
                    }
                    list.AddLast(newPoint);
                    count++;
                }
            }
            return list;
        }
示例#5
0
        static void Main(string[] args)
        {
            // difference between Array and ArrayList --> Arrays are fixed sized so adding elements is troublesome...

            CustomArrayList <string> shoppingList = new CustomArrayList <string>();

            // this list is a joke and not reflective of my drinking habits
            shoppingList.Add("Milk");
            shoppingList.Add("Beer");
            shoppingList.Add("Whiskey");
            shoppingList.Add("Vodka");
            shoppingList.Add("Bread");
            shoppingList.Add("Rice");
            shoppingList.Add("Pork Belly");

            Console.WriteLine("I drink too much {0}", shoppingList[3]);

            Console.WriteLine("Here's the shopping list: ");
            for (int i = 0; i < shoppingList.Count; i++)
            {
                Console.WriteLine(" - " + shoppingList[i]);
            }
        }
示例#6
0
        /// <summary>
        /// Applies color to the map!
        /// </summary>
        /// <param name="location">The location to add color to.</param>
        /// <param name="radius">The radius to color.</param>
        public void ApplyColor(Vector2 location, int radius)
        {
            Rectangle rect = new Rectangle(
                (int)(location.X - radius), (int)(location.Y - radius),
                (int)(radius * 2), (int)(radius * 2));

            CustomArrayList<Quad> quadList = new CustomArrayList<Quad>();
            double checkInterval = 3.0;

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Top)));
            // top line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left + (i * (int)(rect.Width / checkInterval)), rect.Top)));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Top)));

            // right line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Top + (int)(i * (rect.Height / checkInterval)))));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Bottom)));

            // bottom line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left + (int)(i * (rect.Width / checkInterval)), rect.Bottom)));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Bottom)));

            // left line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Top + (int)(i * (rect.Height / checkInterval)))));

            CustomArrayList<Quad> affectedQuads = new CustomArrayList<Quad>();

            for (int i = 0; i < quadList.Count(); i++)
            {
                Quad quad = quadList.ElementAt(i);
                if (quad != null && !affectedQuads.Contains(quad)) affectedQuads.AddLast(quad);
            }

            // Update each of the quads.
            for (int i = 0; i < affectedQuads.Count(); i++)
            {
                Quad q = affectedQuads.ElementAt(i);

                Rectangle updatedRect = Rectangle.Intersect(q.rectangle, rect);

                updatedRect.X = updatedRect.X - q.rectangle.X;
                updatedRect.Y = updatedRect.Y - q.rectangle.Y;
                q.colorTexture.ColorTexture(updatedRect);
            }
            // this.tree.
        }
示例#7
0
 public BuildingMesh(RTSCollisionMap collision)
 {
     this.collision = collision;
     createdNodes = new Node[4];
     removedNodes = new CustomArrayList<Point>();
 }
示例#8
0
        /// <summary>
        /// Merges the loaded layers!
        /// </summary>
        public void MergeLayers()
        {
            if (this.layers.Count() == 0)
            {
                throw new Exception("Perform LoadLayers() first.");
            }

            mapTiles = new Texture2D[this.layers.GetFirst().data.GetLength(0), this.layers.GetFirst().data.GetLength(1)];
            for (int i = 0; i < this.layers.GetFirst().data.GetLength(0); i++)
            {
                for (int j = 0; j < this.layers.GetFirst().data.GetLength(1); j++)
                {
                    CustomArrayList<Texture2D> preBlend = new CustomArrayList<Texture2D>();
                    for (int k = 0; k < this.layers.Count(); k++)
                    {
                        int data = this.layers.ElementAt(k).data[i, j];
                        if (data != -1) preBlend.AddLast(this.individualTiles[data]);
                    }
                    mapTiles[i, j] = this.BlendTextures(preBlend.ToArray(), BlendMode.PriorityBlend);

                    // One step closer to completion
                    Game1.GetInstance().currentLoadProgress += 9;
                }
            }
        }
示例#9
0
 /// <summary>
 /// Merges a linked list of textures.
 /// </summary>
 /// <param name="textures"></param>
 /// <returns></returns>
 public Texture2D MergeTextures(CustomArrayList<Texture2D> textures)
 {
     return this.MergeTextures(textures.ToArray());
 }
示例#10
0
        /// <summary>
        /// Gets the pixels between points.
        /// </summary>
        /// <param name="p1">Point one</param>
        /// <param name="p2">Point two</param>
        /// <param name="spacing">The pixel spacing between the points (default should be 1). Lower than 1 will use 1.</param>
        /// <returns></returns>
        public Point[] PixelsBetweenPoints(Point p1, Point p2, int spacing)
        {
            if (spacing < 1) spacing = 1;
            int xDiff = p2.X - p1.X;
            int yDiff = p2.Y - p1.Y;

            double maxWidth = Math.Max(Math.Abs(xDiff), Math.Abs(yDiff));

            double xDelta = (xDiff / maxWidth) * spacing;
            // Console.Out.WriteLine("xDelta: " + xDelta);
            double yDelta = (yDiff / maxWidth) * spacing;
            // Console.Out.WriteLine("yDelta: " + yDelta);

            CustomArrayList<Point> pointList = new CustomArrayList<Point>();
            Point currentPoint = p1;
            Point previousPoint = new Point(-100, -100);
            double currentX = p1.X, currentY = p1.Y;
            for (int i = 0; i < maxWidth / spacing; i++)
            {
                currentX += xDelta;
                currentY += yDelta;

                currentPoint.X = (int)currentX;
                currentPoint.Y = (int)currentY;

                Point newPoint = new Point(currentPoint.X, currentPoint.Y);
                if (previousPoint != null && !previousPoint.Equals(newPoint))
                {
                    // Console.Out.WriteLine(i + ". Adding point to list: " + newPoint);
                    pointList.AddLast(newPoint);
                }
                previousPoint = newPoint;
            }
            return pointList.ToArray();
        }
示例#11
0
        /// <summary>
        /// Places nodes around all the edges
        /// </summary>
        public CustomArrayList<Point> GetNodeLocationsAroundEdges()
        {
            Boolean previous = CollisionAt(0);
            CustomArrayList<Point> pointList = new CustomArrayList<Point>();
            for (int i = 0; i < dataLength - 1; i++)
            {
                Boolean current = CollisionAt(i);
                if ((int)(i / mapWidth) % VERTICAL_COLLISION_CHECK_SPACING != 0) { continue; }
                // if (i % mapWidth > mapWidth - 15 || i % mapWidth < 15) { continue; }
                if (i % mapWidth == 0) { previous = current; }
                if (current != previous)
                {
                    if (!current && (i + 10 < dataLength) && !CollisionAt(i + 10)) pointList.AddLast(IndexToPoint(i + 10));
                    else if ((i - 10 > -1) && !CollisionAt(i - 10)) pointList.AddLast(IndexToPoint(i - 10));
                }
                previous = current;
            }

            for (int i = 0; i < mapWidth; i += HORIZONTAL_COLLISION_CHECK_SPACING)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    int index = i + j * mapWidth;
                    Boolean current = CollisionAt(index);
                    // if (index % mapWidth % HORIZONTAL_COLLISION_CHECK_SPACING != 0) { continue; }
                    if (j == 0) previous = current;
                    // if (index % screenWidth > screenWidth - 15 || index % screenWidth < 15) continue;
                    if (current != previous)
                    {
                        if (!current && (index + (10 * mapWidth) < dataLength)
                            && !CollisionAt(index + (10 * mapWidth)))
                            pointList.AddLast(IndexToPoint(index + (10 * mapWidth)));
                        else if ((index - (10 * mapWidth) > -1) && !CollisionAt(index - (10 * mapWidth)))
                            pointList.AddLast(IndexToPoint(index - (10 * mapWidth)));
                    }
                    previous = current;
                }
            }

            // Remove nodes that are closer than NODE_REMOVE_DISTANCE of each other
            for (int i = 0; i < pointList.Count(); i++)
            {
                Point p1 = pointList.ElementAt(i);
                for (int j = 0; j < pointList.Count(); j++)
                {
                    Point p2 = pointList.ElementAt(j);
                    if (p1 != p2 && PathfindingUtil.GetHypoteneuseLength(p1, p2) < NODE_REMOVE_DISTANCE)
                    {
                        pointList.Remove(p1);
                        i--;
                        j--;
                        break;
                    }
                }
            }
            return pointList;
        }
示例#12
0
 public UnitSelection(CustomArrayList<Unit> units)
 {
     this.units = units;
 }
示例#13
0
 /// <summary>
 /// Whether the mouse is over a unit or not
 /// if it is, it'll return it. =D
 /// </summary>
 /// <returns>The unit, or null if there was no unit!</returns>
 public Unit GetMouseOverUnit(CustomArrayList<Unit> units)
 {
     MouseState state = Mouse.GetState();
     for (int i = 0; i < this.units.Count(); i++)
     {
         Unit u = this.units.ElementAt(i);
         if (u.GetDrawRectangle().Contains(state.X, state.Y)) return u;
     }
     return null;
 }
示例#14
0
        /*
        /// <summary>
        /// Converts a boolean to a texture.
        /// </summary>
        /// <param name="device">The device to create the texture on</param>
        /// <param name="data">The data</param>
        /// <param name="width">the width</param>
        /// <param name="inversedScale">An invesed scale. 2 means, 2 times as small. 4 times as small, etc. USE IN MULTIPLES OF 2, OR FAIL.</param>
        /// <returns></returns>
        public Texture2D BoolToTexture(GraphicsDevice device, Boolean[] data, int width, int inversedScale)
        {
            if (inversedScale == 1) return BoolToTexture(device, data, width);
            int[] intData = new int[data.Length / ( inversedScale * inversedScale )];
            Texture2D texture = new Texture2D(device, width / inversedScale,
                ( data.Length / width) / inversedScale);

            int newPixelCount = 0;
            int skips = 0;
            for (int i = 0; i < data.Length - 1; i += inversedScale)
            {
                bool skipNext = false;
                if (i % (width * inversedScale) == 0) skipNext = true;
                if (data[i]) intData[newPixelCount] = (int)Color.Black.PackedValue;
                else intData[newPixelCount] = 0;

                newPixelCount++;
                if (skipNext)
                {
                    // Console.Out.Write("Skipping @ " + i + ", " + newPixelCount + ", " + skips);
                    i += width * (inversedScale - 1);
                    // Console.Out.WriteLine(" new: " + i);
                    skips++;
                    continue;
                }
            }
            // Console.Out.WriteLine("Finished, copied " + newPixelCount + " pixels, while the array size is " + intData.Length);
            texture.SetData(intData);
            return texture;
        }*/
        /// <summary>
        /// Updates the collisionmap, without updating or adding pathfinding points. 
        /// DO NOT USE THIS METHOD IN-GAME, ONLY IN THE EDITOR.
        /// </summary>
        /// <param name="rect">The rectangle</param>
        /// <param name="add">Whether to add or to remove the rect.</param>
        public void UpdateCollisionMap(Rectangle rect, Boolean add)
        {
            CollisionChangedEvent e = new CollisionChangedEvent();
            e.collisionMap = this;
            e.changedRect = rect;
            e.collisionAdded = add;

            CustomArrayList<Quad> quadList = new CustomArrayList<Quad>();
            double checkInterval = 3.0;

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Top)));
            // top line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left + (i * (int)(rect.Width / checkInterval)), rect.Top)));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Top)));

            // right line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Top + (int)(i * (rect.Height / checkInterval)))));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Bottom)));

            // bottom line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left + (int)(i * (rect.Width / checkInterval)), rect.Bottom)));

            quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Right, rect.Bottom)));

            // left line
            for (int i = 0; i < checkInterval; i++)
                quadList.AddLast(this.tree.GetQuadByPoint(new Point(rect.Left, rect.Top + (int)(i * (rect.Height / checkInterval)))));

            CustomArrayList<Quad> affectedQuads = new CustomArrayList<Quad>();

            for (int i = 0; i < quadList.Count(); i++)
            {
                Quad quad = quadList.ElementAt(i);
                if (quad != null && !affectedQuads.Contains(quad)) affectedQuads.AddLast(quad);
            }

            // Update each of the quads.
            for( int i = 0; i < affectedQuads.Count(); i++ ){
                Quad q = affectedQuads.ElementAt(i);

                Rectangle updatedRect = Rectangle.Intersect(q.rectangle, rect);
                updatedRect.X = updatedRect.X - q.rectangle.X;
                updatedRect.Y = updatedRect.Y - q.rectangle.Y;
                q.collisionTexture.UpdateCollision(updatedRect, add);
                e.changedQuads.AddLast(new CollisionChangedEvent.QuadPart(q, updatedRect));
            }

            FireCollisionChangedEvent(e);
        }
示例#15
0
 /// <summary>
 /// Gets the point that is closest of a collection from a unit.
 /// </summary>
 /// <param name="unit">The unit.</param>
 /// <param name="points">The list of points to chose from</param>
 /// <returns>The point.</returns>
 private Point GetClosestPoint(Unit unit, CustomArrayList<Point> points)
 {
     Point closestPoint = new Point(0, 0);
     double closestDistance = Double.MaxValue;
     Point unitLocation = new Point((int)unit.x, (int)unit.y);
     for( int i = 0; i < points.Count(); i++){
         Point p = points.ElementAt(i);
         double currentDistance = Util.GetHypoteneuseLength(p, unitLocation);
         if (currentDistance < closestDistance)
         {
             closestPoint = p;
             closestDistance = currentDistance;
         }
     }
     return closestPoint;
 }
示例#16
0
文件: HUD.cs 项目: Wotuu/RTS_XNA_v2
        private void LoadCommands()
        {
            commandObjects = new CustomArrayList<HUDCommandObject>();
            startCommandX = 673;
            startCommandY = 688;

            //No more than 8 seperate Commands!!!
            moveCommand = new HUDCommandObject(TextureManager.GetInstance().GetTexture(HUDCommandObject.Type.Move), HUDCommandObject.Type.Move, startCommandX, startCommandY, new Color(0, 100, 255, 255), this.color);
            commandObjects.AddLast(moveCommand);
            IncrementStartCommandXY(startCommandX);

            attackCommand = new HUDCommandObject(TextureManager.GetInstance().GetTexture(HUDCommandObject.Type.Attack), HUDCommandObject.Type.Attack, startCommandX, startCommandY, new Color(255, 0, 12, 255), this.color);
            commandObjects.AddLast(attackCommand);
            IncrementStartCommandXY(startCommandX);

            defendCommand = new HUDCommandObject(TextureManager.GetInstance().GetTexture(HUDCommandObject.Type.Defend), HUDCommandObject.Type.Defend, startCommandX, startCommandY, new Color(255, 125, 0, 255), this.color);
            commandObjects.AddLast(defendCommand);
            IncrementStartCommandXY(startCommandX);

            stopCommand = new HUDCommandObject(TextureManager.GetInstance().GetTexture(HUDCommandObject.Type.Stop), HUDCommandObject.Type.Stop, startCommandX, startCommandY, new Color(255, 0, 0, 255), this.color);
            commandObjects.AddLast(stopCommand);
            IncrementStartCommandXY(startCommandX);

            repairCommand = new HUDCommandObject(TextureManager.GetInstance().GetTexture(HUDCommandObject.Type.Repair), HUDCommandObject.Type.Repair, startCommandX, startCommandY, new Color(255, 187, 0, 255), this.color);
            commandObjects.AddLast(repairCommand);
            IncrementStartCommandXY(startCommandX);
        }
示例#17
0
文件: HUD.cs 项目: Wotuu/RTS_XNA_v2
        /// <summary>
        /// Checks whether the HUD should be hidden or not. (if the player this HUD belongs to is not the player that is watching)
        /// Loads the objects to display according to selected units/buildings.
        /// </summary>
        /// <param name="ks">Default KeyboardState</param>
        /// <param name="ms">Default MouseState</param>
        public void Update(KeyboardState ks, MouseState ms)
        {
            if (!draw)
            {
                draw = true;
            }
            CountUnits();

            objects = new CustomArrayList<HUDObject>();

            for (int i = 0; i < this.commandObjects.Count(); i++)
            {
                this.commandObjects.ElementAt(i).disabled = true;
            }

            if (loadForEngineer)
            {
                resourceObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Resources), HUDObject.Type.Resources, startObjectX, startObjectY, color);
                objects.AddLast(resourceObject);
                IncrementStartObjectXY(startObjectX);

                barracksObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Barracks), HUDObject.Type.Barracks, startObjectX, startObjectY, color);
                objects.AddLast(barracksObject);
                IncrementStartObjectXY(startObjectX);

                factoryObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Factory), HUDObject.Type.Factory, startObjectX, startObjectY, color);
                objects.AddLast(factoryObject);
                IncrementStartObjectXY(startObjectX);

                sentryObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Sentry), HUDObject.Type.Sentry, startObjectX, startObjectY, color);
                objects.AddLast(sentryObject);
                IncrementStartObjectXY(startObjectX);

                fortressObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Fortress), HUDObject.Type.Fortress, startObjectX, startObjectY, color);
                objects.AddLast(fortressObject);
                IncrementStartObjectXY(startObjectX);

                for (int i = 0; i < this.commandObjects.Count(); i++)
                {
                    HUDCommandObject co = this.commandObjects.ElementAt(i);
                    if (co.type == HUDCommandObject.Type.Repair || co.type == HUDCommandObject.Type.Move || co.type == HUDCommandObject.Type.Stop || co.type == HUDCommandObject.Type.Defend)
                    {
                        co.disabled = false;
                    }
                }
            }
            if (loadForUnit)
            {
                for (int i = 0; i < this.commandObjects.Count(); i++)
                {
                    HUDCommandObject co = this.commandObjects.ElementAt(i);
                    if (co.type == HUDCommandObject.Type.Attack || co.type == HUDCommandObject.Type.Defend || co.type == HUDCommandObject.Type.Move || co.type == HUDCommandObject.Type.Stop)
                    {
                        co.disabled = false;
                    }
                }
            }
            if (loadForBarracks)
            {
                meleeObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Melee), HUDObject.Type.Melee, startObjectX, startObjectY, color);
                objects.AddLast(meleeObject);
                IncrementStartObjectXY(startObjectX);

                rangedObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Ranged), HUDObject.Type.Ranged, startObjectX, startObjectY, color);
                objects.AddLast(rangedObject);
                IncrementStartObjectXY(startObjectX);

                fastObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Fast), HUDObject.Type.Fast, startObjectX, startObjectY, color);
                objects.AddLast(fastObject);
                IncrementStartObjectXY(startObjectX);
            }
            if (loadForFortress)
            {
                engineerObject = new HUDObject(TextureManager.GetInstance().GetTexture(HUDObject.Type.Engineer), HUDObject.Type.Engineer, startObjectX, startObjectY, color);
                objects.AddLast(engineerObject);
                IncrementStartObjectXY(startObjectX);
            }

            startObjectX = 278;
            startObjectY = 688;
        }
示例#18
0
 /// <summary>
 /// Loads the mapnames from disk.
 /// </summary>
 /// <returns>The list of names.</returns>
 public CustomArrayList<String> LoadMapNames()
 {
     DirectoryInfo di = new DirectoryInfo(Game1.MAPS_FOLDER_LOCATION);
     CustomArrayList<String> names = new CustomArrayList<String>();
     foreach (FileInfo fi in di.GetFiles())
     {
         if (fi.Extension == ".xml") names.AddLast(fi.Name.Replace(".xml", ""));
     }
     return names;
 }
示例#19
0
 public Polygon(CustomArrayList<Point> points)
 {
     this.points = points;
     PolygonManager.GetInstance().polygons.AddLast(this);
 }
示例#20
0
        /// <summary>
        /// Inits the draw locations of the polygons
        /// </summary>
        private void InitPathDrawPolygons()
        {
            this.pathDrawPolygons = new Polygon[5];

            CustomArrayList<Vector2> list = new CustomArrayList<Vector2>();
            list.AddLast(new Vector2(0, 0));
            list.AddLast(new Vector2(0, 1080));
            list.AddLast(new Vector2(400, 1080));
            list.AddLast(new Vector2(349, 729));
            list.AddLast(new Vector2(389, 415));
            list.AddLast(new Vector2(273, 0));
            this.pathDrawPolygons[0] = new Polygon(list);

            list = new CustomArrayList<Vector2>();
            list.AddLast(new Vector2(273, 0));
            list.AddLast(new Vector2(389, 415));
            list.AddLast(new Vector2(349, 729));
            list.AddLast(new Vector2(400, 1080));
            list.AddLast(new Vector2(789, 1080));
            list.AddLast(new Vector2(741, 700));
            list.AddLast(new Vector2(743, 241));
            list.AddLast(new Vector2(613, 0));
            this.pathDrawPolygons[1] = new Polygon(list);

            list = new CustomArrayList<Vector2>();
            list.AddLast(new Vector2(613, 0));
            list.AddLast(new Vector2(743, 241));
            list.AddLast(new Vector2(741, 700));
            list.AddLast(new Vector2(789, 1080));
            list.AddLast(new Vector2(1317, 1080));
            list.AddLast(new Vector2(1265, 825));
            list.AddLast(new Vector2(1309, 203));
            list.AddLast(new Vector2(1269, 0));
            this.pathDrawPolygons[2] = new Polygon(list);

            list = new CustomArrayList<Vector2>();
            list.AddLast(new Vector2(1269, 0));
            list.AddLast(new Vector2(1309, 203));
            list.AddLast(new Vector2(1265, 825));
            list.AddLast(new Vector2(1317, 1080));
            list.AddLast(new Vector2(1579, 1080));
            list.AddLast(new Vector2(1575, 795));
            list.AddLast(new Vector2(1523, 0));
            this.pathDrawPolygons[3] = new Polygon(list);

            list = new CustomArrayList<Vector2>();
            list.AddLast(new Vector2(1523, 0));
            list.AddLast(new Vector2(1575, 795));
            list.AddLast(new Vector2(1579, 1080));
            list.AddLast(new Vector2(1920, 1080));
            list.AddLast(new Vector2(1920, 0));

            this.pathDrawPolygons[4] = new Polygon(list);
        }
示例#21
0
文件: Unit.cs 项目: Wotuu/RTS_XNA_v2
        /// <summary>
        /// Calculates a path between the current unit and the point.
        /// </summary>
        /// <param name="p">The point to calculate to.</param>
        /// <returns>The list containing all the points that you should visit.</returns>
        public CustomArrayList<Point> CalculatePath(Point p)
        {
            CustomArrayList<Point> result = new CustomArrayList<Point>();
            long ticks = DateTime.UtcNow.Ticks;
            if (Game1.GetInstance().map.collisionMap.IsCollisionBetween(new Point((int)this.x, (int)this.y), p))
            {
                Game1 game = Game1.GetInstance();
                // Create temp nodes
                Node start = new Node(game.map.collisionMap, (int)this.x, (int)this.y, true);
                Node end = new Node(game.map.collisionMap, p.X, p.Y, true);
                CustomArrayList<PathfindingNode> nodes = new AStar(start, end).FindPath();
                if (nodes != null)
                {
                    // Remove the first node, because that's the node we're currently on ..
                    nodes.RemoveFirst(true);
                    // Clear our current waypoints
                    this.waypoints.Clear();
                    for( int i = 0; i < nodes.Count(); i++ ){
                        result.AddLast(nodes.ElementAt(i).GetLocation());
                    }
                }

                // Nodes can no longer be used
                start.Destroy();
                end.Destroy();
            }
            else
            {
                result.AddLast(p);
            }
            return result;
        }
示例#22
0
文件: Unit.cs 项目: Wotuu/RTS_XNA_v2
 /// <summary>
 /// Updates the enemiesInRange variable, to contain all the enemies within the attack range of this unit.
 /// </summary>
 public void CheckForEnemiesInRange(float rangeToCheck)
 {
     if (enemiesInRange != null)
     {
         enemiesInRange.Clear();
     }
     else
     {
         enemiesInRange = new CustomArrayList<Unit>();
         CheckForEnemiesInRange(rangeToCheck);
     }
     for (int i = 0; i < Game1.GetInstance().players.Count(); i++ )
     {
         Player player = Game1.GetInstance().players.ElementAt(i);
         // Don't check for units on our alliance
         if (player.alliance.members.Contains(this.player)) continue;
         else
         {
             for (int j = 0; j < player.units.Count(); j++)
             {
                 Unit unit = player.units.ElementAt(j);
                 if (Util.GetHypoteneuseLength(unit.GetLocation(), this.GetLocation()) < rangeToCheck)
                 {
                     enemiesInRange.AddLast(unit);
                 }
             }
         }
     }
 }
示例#23
0
 /// <summary>
 /// Gets the point that is furthest away of a collcetion from a unit.
 /// </summary>
 /// <param name="unit">The unit.</param>
 /// <param name="points">The list of points to chose from</param>
 /// <returns>The point.</returns>
 private Point GetFarthestPoint(Unit unit, CustomArrayList<Point> points)
 {
     Point farthestPoint = new Point(0, 0);
     double farthestDistance = 0;
     Point unitLocation = new Point((int)unit.x, (int)unit.y);
     for (int i = 0; i < points.Count(); i++)
     {
         Point p = points.ElementAt(i);
         double currentDistance = Util.GetHypoteneuseLength(p, unitLocation);
         if (currentDistance > farthestDistance)
         {
             farthestPoint = p;
             farthestDistance = currentDistance;
         }
     }
     return farthestPoint;
 }
示例#24
0
 public ArrowManager()
 {
     projectiles = new CustomArrayList<Projectile>();
 }
示例#25
0
 /// <summary>
 /// Whether the mouse is over a unit or not
 /// if it is, it'll return it. =D
 /// </summary>
 /// <returns>The unit, or null if there was no unit!</returns>
 public Building GetMouseOverBuilding(CustomArrayList<Building> buildings)
 {
     MouseState state = Mouse.GetState();
     for (int i = 0; i < this.buildings.Count(); i++)
     {
         Building b = this.buildings.ElementAt(i);
         if (b.DefineDrawRectangle().Contains(state.X, state.Y)) return b;
     }
     return null;
 }
 protected PathfindingNodeProcessor()
 {
     toProcess = new CustomArrayList<PathfindingNode>();
 }
示例#27
0
        public void OnMouseClick(MouseEvent m)
        {
            // Bots dont use the mouse, or shouldn't
            if (Game1.CURRENT_PLAYER != this)
            {
                return;
            }

            if ((m.button == MouseEvent.MOUSE_BUTTON_3))
            {
                if (IsPreviewingBuilding())
                {
                    this.RemovePreviewBuildings();
                }
                else
                {
                    previewPatternClick = GetAddedOffsettedMouseLocation(m);
                }
            }

            if (!hud.DefineRectangle().Contains(m.location) &&
                !hud.DefineMiniMapRectangle().Contains(m.location))
            {
                if (m.button == MouseEvent.MOUSE_BUTTON_1)
                {
                    Unit mouseOverUnit = this.GetMouseOverUnit(this.units);
                    if (mouseOverUnit == null)
                    {
                        if (this.currentSelection != null && this.currentSelection.units.Count() != 0 &&
                            !this.hud.IsMouseOverBuilding() && !this.IsPreviewingBuilding())
                        {
                            this.DeselectAllUnits();
                            this.currentSelection = null;
                        }
                    }
                    else
                    {
                        this.DeselectAllUnits();
                        this.DeselectAllBuildings();
                        // Performed a double click!
                        if (Game1.GetInstance().frames - lastBtn1ClickFrames < 20)
                        {
                            CustomArrayList<Unit> selectionUnits = new CustomArrayList<Unit>();
                            for (int i = 0; i < this.units.Count(); i++)
                            {
                                Unit unit = this.units.ElementAt(i);
                                if (Game1.GetInstance().IsOnScreen(unit.DefineDrawRectangle()) && mouseOverUnit.type == unit.type)
                                    selectionUnits.AddLast(unit);
                            }
                            this.currentSelection = new UnitSelection(selectionUnits);
                        }
                        else if (!mouseOverUnit.selected)
                        {
                            CustomArrayList<Unit> selectionUnits = new CustomArrayList<Unit>();
                            selectionUnits.AddLast(mouseOverUnit);
                            this.currentSelection = new UnitSelection(selectionUnits);
                        }
                    }

                    Building mouseOverBuilding = this.IsMouseOverFriendlyBuilding();
                    if (mouseOverBuilding == null)
                    {
                        if (this.buildingSelection != null && this.buildingSelection.buildings.Count() != 0 &&
                            !this.IsPreviewingBuilding())
                        {
                            this.DeselectAllBuildings();
                            this.buildingSelection = null;
                        }
                    }
                    else
                    {
                        this.DeselectAllUnits();
                        this.DeselectAllBuildings();
                        // Performed a double click!
                        if (Game1.GetInstance().frames - lastBtn1ClickFrames < 20)
                        {
                            CustomArrayList<Building> selectionBuildings = new CustomArrayList<Building>();
                            for (int i = 0; i < this.buildings.Count(); i++)
                            {
                                Building b = this.buildings.ElementAt(i);
                                if (Game1.GetInstance().IsOnScreen(b.DefineDrawRectangle()) && mouseOverBuilding.type == b.type)
                                    selectionBuildings.AddLast(b);
                            }
                            this.buildingSelection = new BuildingSelection(selectionBuildings);
                        }
                        else if (!mouseOverBuilding.selected)
                        {
                            CustomArrayList<Building> selectionBuildings = new CustomArrayList<Building>();
                            selectionBuildings.AddLast(mouseOverBuilding);
                            this.buildingSelection = new BuildingSelection(selectionBuildings);
                            this.buildingSelection.SelectAll();
                        }
                    }
                }
            }

            if (m.button == MouseEvent.MOUSE_BUTTON_1)
            {
                lastBtn1ClickFrames = Game1.GetInstance().frames;
            }
        }
示例#28
0
 public BuildingSelection(CustomArrayList<Building> buildings)
 {
     this.buildings = buildings;
 }
示例#29
0
        /// <summary>
        /// Spawns the starting units of this player.
        /// </summary>
        public void SpawnStartUnits()
        {
            if (Game1.GetInstance().IsMultiplayerGame() &&
                Game1.CURRENT_PLAYER != this) return;

            if (!Game1.GetInstance().IsMultiplayerGame())
            {
                int unitCount = 25;

                CustomArrayList<Unit> temp_units = new CustomArrayList<Unit>();
                // +1 to compensate for the engineer
                for (int i = 0; i < unitCount + 1; i++)
                {
                    // Fill the list with dummy units
                    Unit u = null;
                    temp_units.AddLast(u);
                }

                UnitSelection selection = new UnitSelection(temp_units);
                UnitGroupPattern pattern = new CirclePattern(startLocation, selection, 90, 0);
                CustomArrayList<Point> points = pattern.ApplyPattern();

                for (int i = 0; i < unitCount; i++)
                {

                    Point p = points.ElementAt(i);
                    if (i % 2 == 0)
                    {
                        //temp_units.AddLast(fastStore.getUnit(Unit.Type.Fast, p.X, p.Y));
                    }
                    else
                    {
                        temp_units.AddLast(rangedStore.getUnit(Unit.Type.Ranged, p.X, p.Y));
                    }

                    // Point p = points.ElementAt(i);
                    //temp_units.AddLast(meleeStore.getUnit(Unit.Type.Melee, p.X, p.Y));
                }
            }

            meleeStore.getUnit(Unit.Type.Engineer, startLocation.X, startLocation.Y);
        }
示例#30
0
        /// <summary>
        /// Gets the closest node in line of sight from the given point.
        /// </summary>
        /// <param name="p">The point.</param>
        /// <returns>The node, or null if no node is in range.</returns>
        public PathfindingNode ClosestNodeInLOS(Point p)
        {
            PathfindingNodeManager manager = PathfindingNodeManager.GetInstance();
            CustomArrayList<PathfindingNode> inRangeNodes = new CustomArrayList<PathfindingNode>();
            for( int i = 0; i < manager.GetNodeCount(); i++)
            {
                PathfindingNode node = manager.GetNodeAt(i);
                if (this.IsCollisionBetween(p, node.GetLocation()))
                {
                    inRangeNodes.AddLast(node);
                }
            }
            PathfindingNode closestNode = inRangeNodes.ElementAt(0);
            double closestDistance = Double.MaxValue;
            for( int i = 0; i < inRangeNodes.Count(); i++ ){
                PathfindingNode node = inRangeNodes.ElementAt(i);

                double newDistance = PathfindingUtil.GetHypoteneuseLength(closestNode.GetLocation(), node.GetLocation());
                if (closestDistance > newDistance)
                {
                    closestDistance = newDistance;
                    closestNode = node;
                }
            }
            return closestNode;
        }