Esempio n. 1
0
        internal IEntity GetTile(int v, Vector2 Position)
        {
            IEntity tile     = null;
            float   distance = 0;

            for (int y = 0; y < mapSize.Y; y++)
            {
                for (int x = 0; x < mapSize.X; x++)
                {
                    ModifiableTile modTile = null;
                    if (map[x, y, 1] != null)
                    {
                        modTile = (ModifiableTile)map[x, y, 1];
                    }
                    else if (GetUnits(new Vector2(x, y)) != null)
                    {
                        modTile = (ModifiableTile)GetUnits(new Vector2(x, y));
                    }
                    if (modTile != null)
                    {
                        if (modTile.TeamAssociation.Equals(v))
                        {
                            if (Vector2.Distance(modTile.Position, Position) < distance || distance == 0)
                            {
                                tile     = modTile;
                                distance = Vector2.Distance(modTile.Position, Position);
                            }
                        }
                    }
                }
            }
            return(tile);
        }
Esempio n. 2
0
 /// <summary>
 /// places a building at a certain point
 /// </summary>
 /// <param name="building"></param>
 /// <param name="position"></param>
 internal void PlaceBlock(ModifiableTile building, Vector2 position)
 {
     for (int y = 0; y < building.Size.Y; y++)
     {
         for (int x = 0; x < building.Size.X; x++)
         {
             try
             {
                 if (y == 0 && x == 0)
                 {
                     building.Subscribe(this);
                     map[(int)position.X + x, (int)position.Y + y, 1] = building;
                 }
                 else
                 {
                     map[(int)position.X + x, (int)position.Y + y, 1] = new ReferenceTile((ModifiableTile)map[(int)position.X, (int)position.Y, 1]);
                     ((ModifiableTile)map[(int)position.X + x, (int)position.Y + y, 1]).Subscribe(this);
                     ((ModifiableTile)map[(int)position.X, (int)position.Y, 1]).Subscribe((ReferenceTile)map[(int)position.X + x, (int)position.Y + y, 1]);
                 }
             }
             catch (IndexOutOfRangeException ex)
             {
                 //If the player tries to place a building off the map
                 string error = $"{ex}";
             }
         }
     }
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 private void DrawHealth(SpriteBatch sb, ModifiableTile tileWithHealth)
 {
     //If a tile has a health bar draw it.
     if (tileWithHealth.healthBar != null)
     {
         if (tileWithHealth.healthBar.Health != null)
         {
             tileWithHealth.healthBar.UpdateHealth(tileWithHealth, GraphicsDevice);
             sb.Draw(tileWithHealth.healthBar.Health, (tileWithHealth.healthBar.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Vector2.Zero, Tile.Zoom, SpriteEffects.None, 0);
         }
     }
 }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// if a modifiable tile dies it updates the map and removes it from either the list of mobs or the map array
 /// </summary>
 /// <param name="observer"></param>
 public void Update(ModifiableTile observer)
 {
     if (observer.Position.X >= 0 && observer.Position.X < mapSize.X && observer.Position.Y >= 0 && observer.Position.Y < mapSize.Y)
     {
         if (observer.State == tileState.dead)
         {
             if (observer is IUnit)
             {
                 int index = mobs.FindIndex(l => l.Position.ToPoint() == observer.Position.ToPoint());
                 if (index >= 0)
                 {
                     mobs.RemoveAt(index);
                 }
             }
             else
             {
                 map[(int)observer.Position.X, (int)observer.Position.Y, 1] = null;
             }
         }
     }
 }
Esempio n. 7
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);
        }
Esempio n. 8
0
        private void SelectedUnitDisplay(ModifiableTile tile)
        {
            if (EntityDetails != null)
            {
                overlay.RemoveComponent(EntityDetails);
            }
            EntityDetails = new UpdatePanel(tile, Game, new Rectangle(new Point(217, 359), new Point(336, 121)), this);//TODO this will need to be more automatic if I add different resolutions/screen sizes
            EntityDetails.Initialize();
            Component com = new ImageBox(tile.block.texture, new Vector2(227, 359), (tile.Size * 16).ToPoint(), Color.White);

            com.Scale = 2 / (tile.Size.X);
            if (tile is Building)
            {
                com       = new ImageBox(((Building)tile).Icon, new Vector2(227, 359), (tile.Size * 16).ToPoint(), Color.White);
                com.Scale = 0.25f;
            }
            EntityDetails.AddComponent(com);
            float y = 359;

            for (int i = 0; i < tile.stats.Count; i++)
            {
                if (tile.stats[i] is Health)
                {
                    com       = new ImageBoxHealth(tile.healthBar.Health, new Vector2(227, 359 + 32), new Point((int)com.Scale, 1), Color.White, tile);
                    com.Scale = 2;
                    EntityDetails.AddComponent(com);
                    if (tile.TeamStats != null)
                    {
                        com = new StatComponent(new Label(new Vector2(224, 359 + 46), $"{tile.CurrentHealth}/{tile.TotalHealth}", Color.White), tile.stats[typeof(Health)].GetType(), tile.stats[typeof(Health)].Value + tile.stats[typeof(Health)].Value);
                    }
                    else
                    {
                        com = new StatComponent(new Label(new Vector2(224, 359 + 46), $"{tile.CurrentHealth}/{tile.TotalHealth}", Color.White), tile.stats[typeof(Health)].GetType(), tile.stats[typeof(Health)].Value);
                    }
                }
                else
                {
                    com       = new ImageBox(tile.stats[i].Texture, new Vector2(300, y - 8), new Point(16), Color.White);
                    com.Scale = 0.25f;
                    EntityDetails.AddComponent(com);
                    string display = tile.stats[i].Value.ToString();
                    if (tile is BasicUnit)
                    {
                        Stat stat = null;
                        if (((BasicUnit)tile).teamStats != null)
                        {
                            stat = ((BasicUnit)tile).teamStats[tile.stats[i].GetType()];
                        }
                        if (stat != null)
                        {
                            display += $" ({stat.Value.ToString()})";
                        }
                    }
                    if (tile.TeamStats != null)
                    {
                        com = new StatComponent(new Label(new Vector2(330, y - 8), display, Color.White), tile.stats[i].GetType(), tile.stats[i].Value + tile.TeamStats[i].Value);
                    }
                    else
                    {
                        com = new StatComponent(new Label(new Vector2(330, y - 8), display, Color.White), tile.stats[i].GetType(), tile.stats[i].Value);
                    }
                    com.Scale = 1;
                }
                com.drawComponent = true;
                EntityDetails.AddComponent(com);
                y += 12 + 5;
            }
            overlay.AddComponent(EntityDetails);
        }
 public UpdatePanel(ModifiableTile tile, Game game, Rectangle bounds, CommandProccesor cp) : base(game, bounds, cp)
 {
     this.tile      = tile;
     prevHealth     = tile.CurrentHealth;
     QueueableUnits = new List <IComponent>();
 }
Esempio n. 10
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();
 }