示例#1
0
 /// <summary>
 /// Generates waypoints using A*
 /// </summary>
 /// <param name="Position"></param>
 public override void Move(Vector2 Position, WorldHandler world)
 {
     if (world.GetUnit(Position) == null && world.GetTile(Position) == null)
     {
         ResetUnit();
         Target = null;
     }
     base.Move(Position, world);
 }
示例#2
0
 public Overlay(Game game, InputDefinitions input, WorldHandler world, CommandProccesor command) : base(game)
 {
     cp                   = command;
     this.world           = world;
     this.input           = input;
     cp.overlay           = this;
     ZeroVector           = Vector2.Zero;
     currentCursorTexture = TextureValue.Cursor;
     tile                 = world.GetTile(input.InputPos);
     ClickTime            = 0;
 }
示例#3
0
        private void DrawScreen(SpriteBatch sb, int x, int y, int i)
        {
            Tile tile = null;

            if (x >= 0 && x < bounds.Width && y >= 0 && y < bounds.Height)
            {
                TilePos = new Vector2(x, y);
                //Background tiles are drawn first
                if (i == 0)
                {
                    tile = world.GetBackgroundTile(TilePos);
                    sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                }
                //Units are drawn second
                else if (i == 1)
                {
                    tile = (ModifiableTile)world.GetUnit(TilePos);
                    if (tile != null && tile.block.texture != TextureValue.None)
                    {
                        Texture2D texture = ContentHandler.DrawnTexture(tile.block.texture);
                        ((BasicUnit)tile).UpdatePosition(Game.GraphicsDevice, tile.Position);
                        sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                        DrawHealth(sb, (ModifiableTile)tile);
                    }
                }
                //Draw buildings third
                else
                {
                    tile = world.GetTile(TilePos);
                    if (tile != null && tile.block.texture != TextureValue.None)
                    {
                        Texture2D texture = ContentHandler.DrawnTexture(tile.block.texture);
                        tile.UpdatePosition(Game.GraphicsDevice, tile.Position);
                        sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                        if (!(tile is IHarvestable))
                        {
                            DrawHealth(sb, (ModifiableTile)tile);
                        }
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// set a spawn point if the spawnmarker isn't null otherwise set the spawn marker
        /// </summary>
        /// <param name="position"></param>
        /// <param name="building"></param>
        internal void SetSpawnPoint(Vector2 position, Building building)
        {
            if (SpawnMarker != null)
            {
                spawnMarkerBuilding.SetSpawn(position);
                SpawnMarker         = null;
                spawnMarkerBuilding = null;
            }
            else
            {
                SpawnMarker = ContentHandler.DrawnTexture(TextureValue.SpawnPoint);

                ModifiableTile tile = world.GetTile(position);
                if (tile is ReferenceTile)
                {
                    tile = ((ReferenceTile)tile).tile;
                }
                spawnMarkerBuilding = (Building)tile;
            }
        }
示例#5
0
        /// <summary>
        /// Generates waypoints using A*
        /// </summary>
        /// <param name="Position"></param>
        public virtual void Move(Vector2 Position, WorldHandler world)
        {
            Vector2 newPosition      = new Vector2();
            Vector2 selectedPosition = Position;
            float   closestDistance  = 0;

            if (Target != null && Target is IEntity)
            {
                for (int y = -1; y <= Target.Size.Y; y++)
                {
                    for (int x = -1; x <= Target.Size.X; x++)
                    {
                        if (x == -1 || y == -1 || x == Target.Size.X || y == Target.Size.Y)
                        {
                            newPosition = Position + new Vector2(x, y);
                            float currentDistance = Vector2.Distance(newPosition, this.Position);
                            if (world.GetUnit(newPosition) == null && world.GetTile(newPosition) == null && (closestDistance == 0 || closestDistance > currentDistance))
                            {
                                closestDistance      = currentDistance;
                                selectedPosition     = newPosition;
                                DistanceFromPosition = new Vector2(x, y);
                            }
                        }
                    }
                }
            }
            waypoints.Clear();
            waypoints = aStar.FindPath(this.Position, selectedPosition, world, waypoints);
            if (waypoints.Count > 0)
            {
                nextPoint = waypoints[0];
            }
            else
            {
                nextPoint = Position;
            }
            TargetPosition = Position;
        }
示例#6
0
        private Command OnMapAction(Vector2 currentPos)
        {
            if (input.CheckInput(Controls.Select))
            {
                clicked = true;
                if (cc.SelectedBuild != null)
                {
                    return(new BuildCommand(cc.SelectedBuild, wh, (CurrentPos).ToPoint().ToVector2()));
                }
                else if (cc.SpawnMarker != null)
                {
                    return(new SetSpawnPointCommand(currentPos));
                }
                else
                {
                    ModifiableTile tile = null;

                    if (tile == null)
                    {
                        tile = wh.GetTile(CurrentPos);
                    }
                    if (tile is ReferenceTile)
                    {
                        tile = ((ReferenceTile)tile).tile;
                    }
                    if (tile == null)
                    {
                        try
                        {
                            tile = (ModifiableTile)wh.GetUnit(CurrentPos);
                        }
                        catch (ArgumentOutOfRangeException) { }//Prevents a crash if there aren't any units at this point
                    }
                    if (tile != null)
                    {
                        if (tile is IEntity)
                        {
                            SelectedUnitDisplay(tile);
                        }
                        if (tile is BasicUnit && tile.TeamAssociation == cc.Team)
                        {
                            AddQueueables(tile);
                            return(new SelectCommand((IUnit)tile));
                        }
                        else if (tile is Building)
                        {
                            AddQueueables(tile);
                        }
                        SelectedUnitDisplay(tile);
                    }
                }
            }
            else if (input.CheckInput(Controls.Interact))
            {
                clicked = true;
                Tile tile = wh.GetTile(CurrentPos);
                if (tile is ReferenceTile)
                {
                    tile = ((ReferenceTile)tile).tile;
                }
                if (tile is IHarvestable)
                {
                    return(new AttackCommand((IEntity)tile));
                }
                else if (tile is Building)
                {
                    if (((ModifiableTile)tile).TeamAssociation == cc.Team)
                    {
                        if (((Building)tile).CurrentHealth >= ((Building)tile).TotalHealth)
                        {
                            return(new GarrisonCommand((Building)tile));
                        }
                        else
                        {
                            return(new RepairCommand((Building)tile)); //Should be a repair command Garrison at the moment will cause the buildings to be repaired....needs to be updated later
                        }
                    }
                    else
                    {
                        return(new AttackCommand((IEntity)tile));
                    }
                }
                else
                {
                    IUnit unit = wh.GetUnit(CurrentPos);
                    if (unit != null)
                    {
                        return(new AttackCommand(unit));
                    }
                    else
                    {
                        return(new Movecommand((CurrentPos).ToPoint().ToVector2()));
                    }
                }
            }
            else if (input.CheckRelease(Controls.Select))
            {
                Vector2      startPoint    = camera.ConvertToWorldSpace(input.StartPosition);
                Vector2      endPoint      = camera.ConvertToWorldSpace(input.EndPosition);
                List <IUnit> unitSelection = new List <IUnit>();
                Vector2      tempStart     = startPoint;
                Vector2      tempEnd       = endPoint;
                bool         UnitsTheSame  = true;
                #region Fix Start/End points
                int startY = (int)startPoint.Y > endPoint.Y ? (int)endPoint.Y : (int)startPoint.Y; //If the endpoint is above the start point flip it
                int startX = (int)startPoint.X > endPoint.X ? (int)endPoint.X : (int)startPoint.X; //if the end point is left of the start point flip it
                int endY   = (int)startPoint.Y == startY ? (int)endPoint.Y : (int)startPoint.Y;    //if the start point is the start point stay the same if not flip
                int endX   = (int)startPoint.X == startX ? (int)endPoint.X : (int)startPoint.X;    //^
                #endregion

                for (int y = (int)startY; y < endY; y++)
                {
                    for (int x = (int)startX; x < endX; x++)
                    {
                        IUnit unit = wh.GetUnit(new Vector2(x, y));
                        if (unit != null)
                        {
                            unitSelection.Add(unit);
                        }
                    }
                }
                if (unitSelection.Count > 0)
                {
                    if (unitSelection.Where(l => l.GetType() != unitSelection[0].GetType()).Count() > 0) // if there are any units not like the first unit in the list they aren't the same otherwise they are
                    {
                        UnitsTheSame = false;
                    }
                }
                if (UnitsTheSame && unitSelection.Count > 0)
                {
                    AddQueueables((Tile)unitSelection[0]);
                    if (unitSelection.Count == 1)
                    {
                        SelectedUnitDisplay((ModifiableTile)unitSelection[0]);
                    }
                    else
                    {
                        displaySelectedUnits(unitSelection);
                    }
                }
                if (unitSelection.Count > 0)
                {
                    return(new SelectCommand(unitSelection));
                }
            }
            return(null);
        }
示例#7
0
 public override void Draw(SpriteBatch spriteBatch)
 {
     tile = world.GetTile(cp.camera.ConvertToWorldSpace(input.InputPos));
     if (tile == null)
     {
         tile = (ModifiableTile)world.GetUnit(input.InputPos);
     }
     if (tile != null)
     {
         if (tile is ReferenceTile)
         {
             tile = ((ReferenceTile)tile).tile;
         }
         if (tile != null && tile.TeamAssociation != CommandComponent.ID) //HACK if I add multiple players this might change but ID's at the moment this will work
         {
             if (tile is IHarvestable)
             {
                 currentCursorTexture = TextureValue.HarvestPower;
             }
             else
             {
                 currentCursorTexture = TextureValue.Damage;
             }
         }
         else
         {
             if (tile is Building)
             {
                 currentCursorTexture = TextureValue.BuildPower;
             }
             else
             {
                 currentCursorTexture = TextureValue.Cursor;
             }
         }
     }
     else
     {
         currentCursorTexture = TextureValue.Cursor;
     }
     spriteBatch.Begin();
     ComponentOverlay(spriteBatch);
     spriteBatch.Draw(ContentHandler.DrawnTexture(TextureValue.Overlay), Vector2.Zero, Color.White);
     DrawMap(spriteBatch);
     DrawText(spriteBatch);
     foreach (CommandButton button in components.Where(l => l is CommandButton))//For all queueable objects if you can afford it, it shows up normally if not it shows up red
     {
         if (button.command is BuildSelectCommand)
         {
             if (!cp.cc.CheckCost(((BuildSelectCommand)button.command).build))
             {
                 button.Color = Color.Red;
             }
             else
             {
                 button.Color = Color.White;
             }
         }
     }
     base.Draw(spriteBatch);
     if (description.drawComponent)
     {
         spriteBatch.Draw(description.picture, description.Position, description.Color);
         spriteBatch.DrawString(ContentHandler.Font, description.Text, description.Position, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
     }
     if (currentCursorTexture == TextureValue.Cursor)
     {
         if (cp.clicked)
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Yellow, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
         else
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Red, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
     }
     else
     {
         if (cp.clicked)
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Green, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
         else
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.White, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }