예제 #1
0
 /// <summary>
 /// Draw the battle (draws tiles)
 /// </summary>
 /// <param name="spriteBatch"></param>
 public void Draw(SpriteBatch spriteBatch, InfoBar infoBar, UpdateBox updateBox, Camera2D camera)
 {
     /*for(int i = 0; i < _mapSize * _mapSize; i++)
             _tiles[i].Draw(spriteBatch);*/
     for (int i = 0; i < mapSize; i++)
     {
         for (int j = 0; j < mapSize; j++)
         {
             tiles[i, j].Draw(spriteBatch);
         }
     }
     if (players[turn] is Human)
     {
         (players[turn] as Human).Draw(spriteBatch);
     }
 }
예제 #2
0
 public virtual bool Update(Camera2D camera)
 {
     return true;
 }
예제 #3
0
        public Tile Update(ref Rectangle pos, ref int X, ref int Y, ref Camera2D camera, int range, Rectangle endTurnButton)
        {
            currentMouseVector = Vector2.Transform(new Vector2(InputManager.CurrentMouseState.X, InputManager.CurrentMouseState.Y), Matrix.Invert(camera.Transform));
            if (currentMouseVector.X > 0 && currentMouseVector.Y > 0 &&
               currentMouseVector.X < tiles.GetLength(0) * GV.TileSize - 1 && currentMouseVector.Y < tiles.GetLength(1) * GV.TileSize - 1)
            {
                prevMousePos = curMousePos;

                curMousePos.X = (int)MathHelper.Clamp(currentMouseVector.X, 0f, ((float)Math.Sqrt(tiles.Length - 1) * GV.TileSize));
                curMousePos.Y = (int)MathHelper.Clamp(currentMouseVector.Y, 0f, ((float)Math.Sqrt(tiles.Length - 1) * GV.TileSize));

                if (!tiles[prevMousePos.X / GV.TileSize, prevMousePos.Y / GV.TileSize].Location.Intersects(curMousePos))
                {
                    controlCursorHighlight(prevMousePos.X / GV.TileSize, prevMousePos.Y / GV.TileSize, range, false);

                }
                PreviousTile = tiles[curMousePos.X / GV.TileSize, curMousePos.Y / GV.TileSize];
                if (currentMouseVector.X > 0 && currentMouseVector.Y > 0 &&
                    currentMouseVector.X < tiles.GetLength(0) * GV.TileSize - 1 && currentMouseVector.Y < tiles.GetLength(1) * GV.TileSize - 1)
                {
                    controlCursorHighlight(curMousePos.X / GV.TileSize, curMousePos.Y / GV.TileSize, range, true);
                    unitSelected = tiles[curMousePos.X / GV.TileSize, curMousePos.Y / GV.TileSize].Unit;
                }
            }
            else
            {
                controlCursorHighlight(curMousePos.X / GV.TileSize, curMousePos.Y / GV.TileSize, range, false);
            }

            if (InputManager.MouseClicked() &&
                currentMouseVector.X > 0 && currentMouseVector.Y > 0 &&
                currentMouseVector.X < tiles.GetLength(0) * GV.TileSize - 1 && currentMouseVector.Y < tiles.GetLength(1) * GV.TileSize - 1 &&
                !endTurnButton.Contains(new Rectangle(InputManager.CurrentMouseState.X,InputManager.CurrentMouseState.Y,1,1)))
            {
                if (currentGridX == curMousePos.X / GV.TileSize && currentGridY == curMousePos.Y / GV.TileSize)
                {
                    //Mouse.SetPosition(InputManager.CurrentMouseState.X - (int)(camera.Origin.X - camera.Position.X), InputManager.CurrentMouseState.Y - (int)(camera.Origin.Y - camera.Position.Y));
                    controlCursorHighlight(prevMousePos.X / GV.TileSize, prevMousePos.Y / GV.TileSize, range, false);
                    tiles[currentGridX, currentGridY].HighlightCursor = false;
                    return tiles[currentGridX, currentGridY];

                }
                /*
                                    if (new Rectangle(tiles[i, j].Location.X + (int)(camera.Origin.X - camera.Position.X), tiles[i, j].Location.Y + (int)(camera.Origin.Y - camera.Position.Y),
                                        tiles[i, j].Location.Width, tiles[i, j].Location.Height).Contains(mousePos))
                                    {
                                        PreviousTile = tiles[i, j];
                                        tiles[i, j].HighlightCursor = true;
                                        if (InputManager.MouseClicked())
                                        {
                                            if (currentGridX == i && currentGridY == j)
                                            {
                                                return tiles[currentGridX, currentGridY];
                                            }
                */
                currentGridX = curMousePos.X / GV.TileSize;
                currentGridY = curMousePos.Y / GV.TileSize;

            }
            if (InputManager.KeyReady(Keys.W))
            {
                if (currentGridY > 0)
                    currentGridY--;
            }

            if (InputManager.KeyReady(Keys.S))
            {
                // -1 is there because sqrt(400) is 20, and array goes 0 - 19
                if (currentGridY < Math.Sqrt(tiles.Length) - 1)
                    currentGridY++;
            }

            if (InputManager.KeyReady(Keys.A))
            {
                if (currentGridX > 0)
                    currentGridX--;
            }
            if (InputManager.KeyReady(Keys.D))
            {
                // -1 is there because sqrt(400) is 20, and array goes 0 - 19
                if (currentGridX < Math.Sqrt(tiles.Length) - 1)
                    currentGridX++;
            }
            if (InputManager.KeyReady(Keys.Enter))
            {
                return tiles[currentGridX, currentGridY];
                //unit.UnitBox.Offset(tiles[currentGridX, currentGridY].Location.X - unit.UnitBox.X, tiles[currentGridX, currentGridY].Location.Y - unit.UnitBox.Y);
            }
            X = currentGridX;
            Y = currentGridY;
            currentTile = tiles[currentGridX, currentGridY];
            pos.X = tiles[currentGridX, currentGridY].Location.X;
            pos.Y = tiles[currentGridX, currentGridY].Location.Y;
            return null;
        }
예제 #4
0
        /// <summary>
        /// Info Bar constructor
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="g">game1 object</param>
        public InfoBar(Camera2D camera)
        {
            visible = false;
            white = Game1.GameContent.Load<Texture2D>("infobar_bg");
            infobarFont = Game1.GameContent.Load<SpriteFont>("InfoBarFont");

            bgUnitBarY = Game1.GameHeight - 110;
            yMod = 110;
            bgUnitBar = new Rectangle(0, bgUnitBarY + yMod, 800, 110);
            Reposition();

            mousePos = new Rectangle(InputManager.CurrentMouseState.X, InputManager.CurrentMouseState.Y, 1, 1);

            moveButtonColor = Color.BlueViolet;

            // Create the rectangles for the special move
            specialMoveBox = new Rectangle(10, 10, boxWidth, boxHeight);
            specialMoveBoxBorder = new Rectangle(specialMoveBox.X - 10, specialMoveBox.Y - 10, boxWidth + 20, boxHeight + 20);

            selectedAction = Action.None; // no action is selected by default
        }
예제 #5
0
        public Game1()
        {
            gameContent = Content; // *refer to the "static ContentManager gameContent" *
            graphics = new GraphicsDeviceManager(this);

            //graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            //graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            graphics.PreferredBackBufferWidth = 854;
            graphics.PreferredBackBufferHeight = 480;

            Content.RootDirectory = "Content";
            camera = new Camera2D(this);
            //InputManager = new InputManager(this);

            // It's player one's turn on each startup of the game

            //Components.Add(camera); // Add camera to the components to be updated when base.update is called
            //Components.Add(InputManager); // Add input manager to the list of of components to be updated when base.update is called

            //graphics.IsFullScreen = true;

            exiting = false;
        }
예제 #6
0
        public override bool Update(Camera2D camera)
        {
            if (mapControl) //Are we moving amongst the map (1st step)
            {
                updateBox.TargetUnit = mainSelector.UnitSelected;
                if (highlightGone == false) //Make sure we no longer are highlighting tiles
                {
                    secondarySelector.HighlightDelete();
                    highlightGone = true;
                }
                currentTile = mainSelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, 0, endTurnButton);
                if (currentTile != null && currentTile.Unit != null && (Game1.Team == int.Parse(currentTile.Unit.Army.ToString()))) //We have selected a tile and it has a unit to select, invoke the infobar and prepare the secondary selector
                {
                    currentUnit = currentTile.Unit;
                    infoBar.Visible = true;
                    mapControl = false;
                    secondarySelector.UnitSelected = currentUnit;
                    mainSelector.PreviousTile.HighlightCursor = false;

                    secondarySelector.CurrentTile = currentTile;
                    secondarySelector.CurrentGridX = currentGridX;
                    secondarySelector.CurrentGridY = currentGridY;
                    mainSelector.CurrentTile = currentTile;
                    mainSelector.CurrentGridX = currentGridX;
                    mainSelector.CurrentGridY = currentGridY;
                    mainSelector.Tiles[currentGridX, currentGridY].HighlightCursor = true;
                }
            }
            else
            {

                if (infoBar.Visible)
                {
                    updateBox.TargetUnit = currentUnit;
                    if (infoBar.SelectedAction > 0)
                    {
                        selectedAction = infoBar.SelectedAction;
                        infoBar.Visible = false;
                        previousGridX = currentGridX;
                        previousGridY = currentGridY;
                        previousTile = currentTile;
                        previousRectPos = actualPos;
                    }
                    if (InputManager.KeyReady(Keys.Q))
                    {
                        infoBar.Visible = false;
                        infoBar.SpecialMoveBoxVisible = false;
                        mapControl = true;
                        // The code below may or may not be called based on the option of
                        // whether the player wants cancelling the move to bring them back to
                        // the previous unit selected or if they just want it to keep them
                        // on the current tile.
                        /*
                        mainSelector.CurrentTile = currentTile;
                        mainSelector.CurrentGridX = currentGridX;
                        mainSelector.CurrentGridY = currentGridY;
                        */
                    }
                }
                else
                {
                    updateBox.TargetUnit = secondarySelector.UnitSelected;
                    if (InputManager.KeyReady(Keys.Q) && !highlightGone)
                    {
                        infoBar.Visible = true;
                        secondarySelector.HighlightDelete();
                        selectedAction = InfoBar.Action.None;
                        highlightGone = true;
                        mapControl = false;
                        currentTile = previousTile;
                        currentGridX = previousGridX;
                        currentGridY = previousGridY;
                        actualPos = previousRectPos;
                        secondarySelector.CurrentTile = currentTile;
                        secondarySelector.CurrentGridX = currentGridX;
                        secondarySelector.CurrentGridY = currentGridY;
                        mainSelector.CurrentTile = currentTile;
                        mainSelector.CurrentGridX = currentGridX;
                        mainSelector.CurrentGridY = currentGridY;
                        mainSelector.PreviousTile.HighlightCursor = false;
                        foreach (Tile tile in secondarySelector.Tiles)
                        {
                            tile.HighlightCursor = false;
                        }
                        mainSelector.Tiles[currentGridX, currentGridY].HighlightCursor = true;
                    }
                    switch (selectedAction)
                    {
                        case InfoBar.Action.Move:
                            {
                                if (!currentTile.Unit.Bunkered)
                                {
                                    if (highlightGone) //Prevent ourselves from highlighting continuously
                                    {
                                        secondarySelector.HighlightTiles(currentUnit.Movement);
                                        highlightGone = false;
                                    }
                                    selectedTile = secondarySelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, 0, endTurnButton);
                                    if (selectedTile != null && selectedTile.Unit == null && selectedTile.HighlightSpace == true)
                                    {
                                        //infoBar.SelectedAction = (int)PlayerStatus.None;
            /*
                                    secondarySelector.HighlightTiles(currentUnit.Movement);
                                    highlightGone = false;
                                }
                                selectedTile = secondarySelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, 0/*, endTurnButton);
                                if (selectedTile != null && selectedTile.Unit == null && selectedTile.HighlightSpace == true)
                                {*/
                                    //infoBar.SelectedAction = (int)PlayerStatus.None;

                                        //currentUnit.UnitBox.Offset((selectedTile.Location.X - currentUnit.UnitBox.X), (selectedTile.Location.Y - currentUnit.UnitBox.Y));
                                        //currentUnit.UnitPoint = selectedTile.Location.Location;

                                        selectedAction = InfoBar.Action.Animate;
                                    }
                                }
                                else
                                {
                                    Game1.UpdateBox.AddMessage("Unit cannot move \nuntil you \ndeactivate bunker.");
                                    highlightGone = false; //Used so we can still q out of method
                                }
                            }
                            break;
                        /*default:
                            mapControl = true;
                            infoBar.Visible = false;

                            break;*/
                        case InfoBar.Action.Attack:
                            {
                                if (highlightGone) //Prevent ourselves from highlighting continuously
                                {
                                    secondarySelector.HighlightEnemies(currentUnit.Range);
                                    highlightGone = false;
                                }
                                selectedTile = secondarySelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, 0, endTurnButton);
                                if (selectedTile != null && selectedTile.Unit != null && selectedTile.Unit.Army != currentTile.Unit.Army && selectedTile.HighlightEnemy)
                                {
                                    int dealt, received;
                                    Unit attacker = currentTile.Unit;
                                    Unit defender = selectedTile.Unit;
                                    bool isCounterAttack = false;

                                    // MAIN ATTACK
                                    int damageDealt = DamageCalculator.doDamage(attacker, defender, isCounterAttack);
                                    defender.Health -= damageDealt;
                                    dealt = damageDealt;
                                    //updateBox.Update(attacker, defender, damageDealt, isCounterAttack);
                                    //use isCounterAttack as a parameter in updateBox.Update(...)
                                    //if isCounterattack is true, print "attacker did this much damage to defender"
                                    //otherwise, print "defender counterattacked attacker with this much damage"

                                    // COUNTER ATTACK
                                    isCounterAttack = true;
                                    damageDealt = DamageCalculator.doDamage(defender, attacker, isCounterAttack);
                                    attacker.Health -= damageDealt;
                                    received = damageDealt;
                                    //updateBox.Update(defender, attacker, damageDealt, isCounterAttack);

                                    // Game1.UpdateBox.ReportAttack(dealt, received);
                                    Game1.UpdateBox.AddMessage("Player unit attacks, \ndealing " + dealt + " damage!\n\n" + "Enemy unit \ncounterattacks, \ndealing " + received + " damage!");
                                    mapControl = true;
                                    infoBar.Visible = false;
                                    mainSelector.CurrentTile = currentTile;
                                    mainSelector.CurrentGridX = currentGridX;
                                    mainSelector.CurrentGridY = currentGridY;
                                    //Attacker now knows it has attacked this turn
                                    attacker.HasAttacked = true;
                                }
                            }
                            break;
                        case InfoBar.Action.Special:
                            {
                                if (currentTile.Unit.CoolDown == 0) //blocks the use of specials
                                {
                                    if (highlightGone) //Prevent ourselves from highlighting continuously
                                    {
                                        if (infoBar.SelectedSpecialMove.Name == "Frag Grenade")
                                        {
                                            secondarySelector.HighlightSpecial(infoBar.SelectedSpecialMove.Range, true);
                                            highlightGone = false;
                                        }
                                        else
                                        {
                                            secondarySelector.HighlightSpecial(infoBar.SelectedSpecialMove.Range, false);
                                            highlightGone = false;
                                        }
                                    }
                                    int specialDRange = infoBar.SelectedSpecialMove.AreaOfEffect;
                                    selectedTile = secondarySelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, specialDRange, endTurnButton);
                                    if (infoBar.SelectedSpecialMove.NeedsTarget == false || (selectedTile != null && selectedTile.HighlightEnemy))
                                    {
                                        Unit attacker = currentTile.Unit;
                                        bool isCounterAttack = false;
            /*
                                        secondarySelector.HighlightSpecial(infoBar.SelectedSpecialMove.Range, false);
                                        highlightGone = false;
                                    }
                                }
                                int specialDRange = infoBar.SelectedSpecialMove.AreaOfEffect;
                                selectedTile = secondarySelector.Update(ref actualPos, ref currentGridX, ref currentGridY, ref camera, specialDRange/*, endTurnButton);
                                if (infoBar.SelectedSpecialMove.NeedsTarget == false || (selectedTile != null && selectedTile.HighlightEnemy))
                                {
                                    Unit attacker = currentTile.Unit;
                                    bool isCounterAttack = false;
            */
                                        /*
                                         * TODO: Make a special attack happen here:
                                         * get user input for type of attack
                                         * string type = user input
                                         * SpecialMove s1 = new SpecialMove(type);
                                         * Call damage calculator
                                         * Use conditional statements based on s1's properties.
                                         *
                                         * IN THIS CLASS:
                                         * "Bunker Down" - Boost defense to unit
                                         * "Web Grenade" - Lower enemy move value by 2
                                         * "Frag Grenade" - Secondary selector is on all units, don't allow movement of selector
                                         * "Missile" - Doubles the range of helicoptors, but deals 85% damage
                                         * "Cripple" - Lowers enemy move value by 2 and deals ~80% damage
                                         * "Repair" - Tank attempts to fix some of its parts, returning some lost health
                                         * */

                                        if (infoBar.SelectedSpecialMove != null)
                                        {
                                            SpecialMove s1 = infoBar.SelectedSpecialMove;
                                            Random random = new Random();
                                            //Acts upon what type of special is used
                                            switch (s1.Name)
                                            {
                                                case "Bunker Down":
                                                    if (!attacker.HasAttacked && attacker.Movement == attacker.MaxMovement)
                                                    {
                                                        //Going into bunker
                                                        if (attacker.Bunkered == false)
                                                        {
                                                            Game1.UpdateBox.AddMessage("Used Bunker\nDown! Unit's defense \nincreased!");
                                                            attacker.Defense += 5; // add 5 defense to unit currently using the move
                                                            attacker.Attack /= 2;
                                                            attacker.Movement = 0; // moves all lost! to 0
                                                            attacker.HasAttacked = true; // attacked is true, lose a turn
                                                            attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                        }
                                                        //Leaving bunker
                                                        else
                                                        {
                                                            Game1.UpdateBox.AddMessage("Unit is no \nlonger Bunkered.");
                                                            attacker.Attack = attacker.OriAttack;
                                                            attacker.Defense = attacker.OriDefense;
                                                            attacker.CoolDown = s1.CoolDown;
                                                            attacker.HasAttacked = true;
                                                        }
                                                    }
                                                    //If conditions aren't met for going or leaving bunker
                                                    else
                                                    {
                                                        Game1.UpdateBox.AddMessage("Can't bunker down\n after moving\n or attacking.");
                                                    }
                                                    break;
                                                case "Web Grenade":
                                                    //If we aren't bunkered
                                                    if (!attacker.Bunkered)
                                                    {
                                                        Unit defender = selectedTile.Unit;
                                                        defender.Movement -= 2;
                                                        Game1.UpdateBox.AddMessage("Used A Web \nGrenade! Enemy \nunit's move\ndecreased by 2!");
                                                        attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                    }
                                                    //If we are bunkered
                                                    else
                                                    {
                                                        Game1.UpdateBox.AddMessage("Must unbunker unit \nto use this special.");
                                                    }
                                                    break;
                                                case "Frag Grenade":
                                                    //If we aren't bunkered
                                                    if (!attacker.Bunkered)
                                                    {
                                                        Game1.UpdateBox.AddMessage("Used a Frag\ngrenade!\n...Units took\nsome damage!");
                                                        //Each of the five selectable tiles will check if they are not null and if there is a unit present.
                                                        if (tiles[currentGridX, currentGridY].Unit != null)
                                                        {
                                                            // Using Frag Grenade can deal anywhere from 10 to 20 damage.
                                                            tiles[currentGridX, currentGridY].Unit.Health -= random.Next(10, 20);
                                                        }
                                                        if (currentGridX > 0)
                                                        {
                                                            if (tiles[currentGridX - 1, currentGridY].Unit != null)
                                                            {
                                                                // Using Frag Grenade can deal anywhere from 10 to 20 damage.
                                                                tiles[currentGridX - 1, currentGridY].Unit.Health -= random.Next(10, 20);
                                                            }
                                                        }
                                                        if (currentGridY > 0)
                                                        {
                                                            if (tiles[currentGridX, currentGridY - 1].Unit != null)
                                                            {
                                                                // Using Frag Grenade can deal anywhere from 10 to 20 damage.
                                                                tiles[currentGridX, currentGridY - 1].Unit.Health -= random.Next(10, 20);
                                                            }
                                                        }
                                                        if (currentGridX < Math.Sqrt(tiles.Length - 1))
                                                        {
                                                            if (tiles[currentGridX + 1, currentGridY].Unit != null)
                                                            {
                                                                // Using Frag Grenade can deal anywhere from 10 to 20 damage.
                                                                tiles[currentGridX + 1, currentGridY].Unit.Health -= random.Next(10, 20);
                                                            }
                                                        }
                                                        if (currentGridY < Math.Sqrt(tiles.Length - 1))
                                                        {
                                                            if (tiles[currentGridX, currentGridY + 1].Unit != null)
                                                            {
                                                                // Using Frag Grenade can deal anywhere from 10 to 20 damage.
                                                                tiles[currentGridX, currentGridY + 1].Unit.Health -= random.Next(10, 20);
                                                            }
                                                        }
                                                        attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                    }
                                                    //If we are bunkered
                                                    else
                                                    {
                                                        Game1.UpdateBox.AddMessage("Must unbunker unit \nto use this special.");
                                                    }
                                                    break;
                                                case "Missile":
                                                    Unit defending = selectedTile.Unit;
                                                    defending.Health -= (int).85 * DamageCalculator.doDamage(attacker, defending, false);
                                                    Game1.UpdateBox.AddMessage("Used A Missile \n...Target Unit \n takes damage");
                                                    attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                    break;
                                                case "Cripple":
                                                    Unit defend = selectedTile.Unit;
                                                    defend.Movement -= 2;
                                                    defend.Health -= (int).806 * DamageCalculator.doDamage(attacker, defend, false);
                                                    Game1.UpdateBox.AddMessage("Used Cripple \n...Target Unit takes \nsome damage \n and unit's move \ndecreased by 2!");
                                                    attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                    break;
                                                case "Repair":
                                                    int repair = random.Next(0, 10); //How much we heal for
                                                    attacker.Health += repair;
                                                    Game1.UpdateBox.AddMessage("Used Repair \n...Unit healed itself for \n" + repair +" Health.");
                                                    attacker.CoolDown = s1.CoolDown; //Sets cooldown for specials
                                                    break;
                                                default:
                                                    break;
                                            }
                                            infoBar.SelectedSpecialMove = null;
                                        }

                                        //// MAIN ATTACK
                                        //int damageDealt = DamageCalculator.doDamage(attacker, defender, isCounterAttack);
                                        //defender.Health -= damageDealt;
                                        //dealt = damageDealt;
                                        ////updateBox.Update(attacker, defender, damageDealt, isCounterAttack);
                                        ////use isCounterAttack as a parameter in updateBox.Update(...)
                                        ////if isCounterattack is true, print "attacker did this much damage to defender"
                                        ////otherwise, print "defender counterattacked attacker with this much damage"

                                        //// COUNTER ATTACK
                                        //isCounterAttack = true;
                                        //damageDealt = DamageCalculator.doDamage(defender, attacker, isCounterAttack);
                                        //attacker.Health -= damageDealt;
                                        //received = damageDealt;
                                        ////updateBox.Update(defender, attacker, damageDealt, isCounterAttack);

                                        //Game1.UpdateBox.ReportAttack(dealt, received);
                                        mapControl = true;
                                        infoBar.Visible = false;
                                        mainSelector.CurrentTile = currentTile;
                                        mainSelector.CurrentGridX = currentGridX;
                                        mainSelector.CurrentGridY = currentGridY;
                                        //Attacker now knows it has attacked this turn
                                        attacker.HasAttacked = true;
                                    }
                                }
                                else highlightGone = false; //exists so we can q out of a special while we are cooling down.
                            }
                            break;
                        case InfoBar.Action.Animate:
                            //This is where we animate a unit moving
                            AnimateMovement();
                            break;
                    }
                }
                /*
                if (infoBar.YMod > 105)
                {
                    currentUnit = null;
                    mapControl = true;
                    infoBar.ItemSelected = (int)PlayerStatus.None;
                }
                 * */

            }

            if (actualPos.X > ((GV.TileSize * 4) + rectPos.X))
            {
                rectPos.X += GV.TileSize;
            }
            else if (actualPos.X < rectPos.X - (GV.TileSize * 4))
            {
                rectPos.X -= GV.TileSize;
            }
            if (actualPos.Y > ((GV.TileSize * 4) + rectPos.Y))
            {
                rectPos.Y += GV.TileSize;
            }
            else if (actualPos.Y < rectPos.Y - (GV.TileSize * 4))
            {
                rectPos.Y -= GV.TileSize;
            }

            //rectPos = tiles[currentGridX, currentGridY].Location
            //infoBar.SelectedAction = InfoBar.Action.None;
            if (changeTurn)
            {
                foreach (Unit u in ownArmy.Units)
                    u.CoolDown -= 1;
                changeTurn = false;
                return true;
            }
            return false;
        }
예제 #7
0
파일: AI.cs 프로젝트: Ckeds/PortfolioWorks
        public override bool Update(Camera2D camera)
        {
            if (ownArmy.Units.Count > 0)
            {
                if (currentUnitIndex == 0 && turnStart)
                {

                    currentUnit = ownArmy.Units[currentUnitIndex];
                    MoveCalculation();
                    turnStart = false;
                    if (selectedTile != null)
                    {
                        animating = true;
                    }
                    hasAttacked = false;
                    turnStart = false;
                }

                if (!animating && hasAttacked)
                {
                    currentUnitIndex++;
                    if (currentUnitIndex >= ownArmy.Units.Count)
                    {

                        currentUnitIndex = 0;
                        currentTile = ownArmy.Units[0].Tile;
                        selectedTile = null;
                        animating = false;
                        turnStart = true;
                        hasAttacked = false;
                        turnStart = true;
                        ownArmy.Reset();
                        return true;
                    }
                    else
                    {
                        currentUnit = ownArmy.Units[currentUnitIndex];
                        hasAttacked = false;
                        MoveCalculation();
                        if (selectedTile != null)
                        {
                            animating = true;
                        }
                    }
                }
                else if (animating)
                {
                    if (!currentTile.HasUnit())
                    {
                        currentUnit.Tile.Unit = currentUnit;
                        currentTile = currentUnit.Tile;
                    }
                    AnimateMovement();
                }
                else if (!hasAttacked)//added &&!animating -zack
                {
                    Unit enemy = pickEnemy();
                    if (enemy != null)
                    {
                        int damageDealt = DamageCalculator.doDamage(currentUnit, enemy, false);
                        enemy.Health -= damageDealt;
                        //dealt = damageDealt;
                        damageDealt = DamageCalculator.doDamage(currentUnit, enemy, true);
                        currentUnit.Health -= damageDealt;
                        //received = damageDealt;
                        if (enemy.Health <= 0)
                        {
                            enemyUnits.Remove(enemy);
                        }
                    }

                    hasAttacked = true;

                }
                return false;

            }
                return true;
        }