Esempio n. 1
0
        private Texture2D white; // White bg for the unit info bar itself (Just a placeholder for now. Replace as you like with your own bg image sometime.)

        #endregion Fields

        #region Constructors

        public UpdateBox()
        {
            targetUnit = null;
            white = Game1.GameContent.Load<Texture2D>("infobar_bg");
            updateBoxFont = Game1.GameContent.Load<SpriteFont>("InfoBarFont");

            updateBoxFrame = new Rectangle(Game1.GameWidth - 150, 0, 150, 130);
            updateBox = new Rectangle(updateBoxFrame.X + 10, updateBoxFrame.Y + 10, updateBoxFrame.Width - 20, updateBoxFrame.Height - 20);
            endTurnButton = new Rectangle(updateBoxFrame.X + 10, updateBox.Y + 120, updateBoxFrame.Width - 20, 20);
            endTurnButtonColor = Color.BlueViolet;

            messageQueue = new Collections.Queue<string>();
        }
Esempio n. 2
0
        /* Initial equation for damage (will be tweaked upon testing)
         * THE EQUATION:
         * Damage = ((((2 * Level*10 / 5 + 2) * AttackStat * AttackPower / DefenseStat) / 50) + 2) * CriticalHit * Weakness/Resistance * RandomNumber / 100
         * RESTRICTIONS FOR VALUES:
         * 1<Level<3 (ex. 3 = veteran)
         * AttackStat = attack attribute of the units you want to attack with
         * AttackPower = power of the attack the unit uses
         * DefenseStat = defense attribute of the units you want to attack
         * 85 <= RandomNumber <= 100
         * CriticalHit = 1.5 if a RandomNumber from 0 to 9 equals 9
         * Weakness/Resistance = .8 if soldiers attack tanks (more resistant)
         * Weakness/Resistance = 1.2 if tanks attack soldiers (less resistant)
         * Weakness/Resistance may not be in the final equation as more unit types are added
         * The equation is derived from the Pokemon damage calculation.
         * */
        public static int doDamage(Unit attacker, Unit defender, bool isCounter)
        {
            // new Random object
            Random rgen = new Random();

            // This will check attacker's levelN (currently, it just checks exp)
            int level = attacker.Exp / 10 + 1;

            int attackStat = attacker.Attack;

            // This will check attacker.attackTypePower (may not be in final equation)
            int attackPower = 1;

            int defenseStat = defender.Defense;

            // This is the critical hit (type is double)
            double criticalHit;
            if (rgen.Next(0, 10) == 9)
            {
                criticalHit = 1.5;
            }
            else criticalHit = 1;

            // A random number to give the equation a little variability
            int rand = rgen.Next(85, 101);

            // the final damage calculation
            int damage = (int)(((((level * 25 + 2) * attackStat * attackPower / defenseStat) / 2) + 2) * criticalHit * rand / 100);

            // a modifier for the damage based on number of members left
            damage = (int)Math.Round((double)(damage * attacker.Members / attacker.FullMembers));

            // a modifier for the damage if it is a counter attack
            if (isCounter)
            {
                rand = rgen.Next(1, 101);
                damage = (int)(damage * (.4 + .002 * rand));
            }

            // damage is returned
            return damage;
        }
Esempio n. 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;
        }
Esempio n. 4
0
 public void Draw(SpriteBatch spriteBatch)
 {
     if (highlightCursor)
         spriteBatch.Draw(texture, location, textureLocation, Color.Black, 0f, Vector2.Zero, SpriteEffects.None, 1f);
     else
     {
         if (highlightSpace)
             spriteBatch.Draw(texture, location, textureLocation, Color.CornflowerBlue, 0f, Vector2.Zero, SpriteEffects.None, 1f);
         else if (highlightEnemy)
             spriteBatch.Draw(texture, location, textureLocation, Color.DarkGreen, 0f, Vector2.Zero, SpriteEffects.None, 1f);
         else
             spriteBatch.Draw(texture, location, textureLocation, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1f);
     }
     if (unit != null)
     {
         unit.Draw(spriteBatch);
         if (unit.Health == 0)
             unit = null;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Draw method for InfoBar.
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="u">You can store any picture in this one variable (u). So each unit can have its own kind of picture.
        /// Each unit has its own picture so whenever you want to draw a unit, pass in a unit into the Draw method, and Draw the picture that way.</param>             
        public void Draw(SpriteBatch spriteBatch, Unit u)
        {
            if (yMod < 105)
            {
                // Currently, spriteBatch.Begin() and spriteBatch.End() are called in here.
                // If anything else uses the same spriteBatch.Begin() and spriteBatch.End(), they will be moved to the Game1.Draw() method before and after the call of this method.

                // This is the main bar (the big bar that has everything inside it)
                spriteBatch.Draw(white, bgUnitBar, Color.White);

                // This will be the background rectangle that is behind the unit pic.
                spriteBatch.Draw(white, unitPicBackRect, Color.Black);

                // This will draw unit pictures that are a part of the Unit class.
                spriteBatch.Draw(u.UnitPic, unitPicRect,u.DisplaySource, Color.White);

                // This is the black border rectangle (which contains the smaller white one with the buttons + descriptions)
                spriteBatch.Draw(white, ctrOutRect, Color.Black);

                // This is the smaller white rectangle (that contains the black rectangle that has buttons + description of abilities)
                spriteBatch.Draw(white, ctrInRect, Color.White);

                // This is the black rectangle inside the white rectangle (that contains special button + description text)
                spriteBatch.Draw(white, ctrInBlackRect, Color.Black);

                // This is the black rectangle (which contains the stats rectangle) - it serves as the border of the stats rect
                spriteBatch.Draw(white, statRectBorder, Color.Black);

                // The stats rectangle itself on the far right
                spriteBatch.Draw(white, statRect, Color.White);

                // THE BUTTONS
                spriteBatch.Draw(white, moveButton, moveButtonColor);
                spriteBatch.Draw(white, atkButton, atkButtonColor);
                spriteBatch.Draw(white, specialButton, specialButtonColor);

                // Drawing info bar text
                spriteBatch.DrawString(
                    infobarFont,
                    u.Name,
                    new Vector2(bgUnitBar.X + 20, bgUnitBar.Y + 10),
                    Color.Silver);
                spriteBatch.DrawString(
                    infobarFont,
                    "Level: " + u.Level,
                    new Vector2(bgUnitBar.X + 20, bgUnitBar.Y + 20),
                    Color.Silver);
                // Draw health/maxHealth
                spriteBatch.DrawString(
                    infobarFont,
                    "Health " + u.Health + "/" + u.MaxHealth,
                    new Vector2(statRect.X + 10, statRect.Y + 5),
                    Color.Black);
                // Draw move/maxMove
                spriteBatch.DrawString(
                    infobarFont,
                    "Movement " + u.Movement + "/" + u.MaxMovement,
                    new Vector2(statRect.X + 10, statRect.Y + 20),
                    Color.Black);
                // Draw Attack
                spriteBatch.DrawString(
                    infobarFont,
                    "Attack " + u.Attack,
                    new Vector2(statRect.X + 10, statRect.Y + 35),
                    Color.Black);
                // Draw Defense
                spriteBatch.DrawString(
                    infobarFont,
                    "Defense " + u.Defense,
                    new Vector2(statRect.X + 10, statRect.Y + 50),
                    Color.Black);
                // Draw members/fullMembers
                spriteBatch.DrawString(
                    infobarFont,
                    "Members " + u.Members + "/" + u.FullMembers,
                    new Vector2(statRect.X + 10, statRect.Y + 65),
                    Color.Black);
                // Draw Move Button Text
                spriteBatch.DrawString(
                    infobarFont,
                    "Move",
                    new Vector2(moveButton.X + 35, moveButton.Y + 5),
                    Color.GhostWhite);
                // Draw Attack Button Text
                spriteBatch.DrawString(
                    infobarFont,
                    "Attack",
                    new Vector2(atkButton.X + 33, atkButton.Y + 5),
                    Color.GhostWhite);
                // Draw Special Button Text
                spriteBatch.DrawString(
                    infobarFont,
                    "Special",
                    new Vector2(specialButton.X + 29, specialButton.Y + 5),
                    Color.GhostWhite);
                // Displays info about whether the unit has attacked this turn
                if (mousePos.Intersects(atkButton))
                {
                    // The string to be drawn
                    //itemSelected = (int)PlayerStatus.Special;
                    if (!u.HasAttacked)
                        spriteBatch.DrawString(
                            infobarFont,
                            "This unit has not attacked\n yet this turn.",
                            new Vector2(ctrInBlackRect.X + 135, ctrInBlackRect.Y + 10),
                            Color.Silver);
                    else
                        spriteBatch.DrawString(
                        infobarFont,
                        "This unit has already attacked\n this turn.",
                        new Vector2(ctrInBlackRect.X + 135, ctrInBlackRect.Y + 10),
                        Color.Silver);
                }
                // Displays info of Special button effect when mouse hovers over the special button
                else if (mousePos.Intersects(specialButton))
                {
                    // The string to be drawn
                    //itemSelected = (int)PlayerStatus.Special;
                    if(u.CoolDown == 0)
                        spriteBatch.DrawString(
                            infobarFont,
                            "Unit can use a special attack \nthis turn.",
                            new Vector2(ctrInBlackRect.X + 135, ctrInBlackRect.Y + 10),
                            Color.GhostWhite);
                    else
                        spriteBatch.DrawString(
                            infobarFont,
                            "Unit cannot use a special attack \nfor " + u.CoolDown + " turn(s).",
                            new Vector2(ctrInBlackRect.X + 135, ctrInBlackRect.Y + 10),
                            Color.GhostWhite);
                }

                if (specialMoveBoxVisible)
                {
                    selectedSpecialMoveIndex = -1;
                    selectedSpecialMove = null;

                    spriteBatch.Draw(white, specialMoveBoxBorder, Color.Black);
                    spriteBatch.Draw(white, specialMoveBox, Color.White);

                    spriteBatch.DrawString(infobarFont, "Special Moves", new Vector2(specialMoveBox.X + 35, specialMoveBox.Y + 5), Color.DarkCyan);

                    List<Rectangle> moveRects = new List<Rectangle>();
                    int offset = 0;
                    foreach (SpecialMove sm in u.SpecialMoves)
                    {
                        moveRects.Add(new Rectangle(specialMoveBox.X + 5, specialMoveBox.Y + 25 + offset, specialMoveBox.Width - 10, 20));
                        offset += 55;
                    }

                    for (int i = 0; i < moveRects.Count; i++)
                    {
                        if (moveRects[i].Contains(mousePos))
                        {
                            if (InputManager.MouseClicked())
                            {
                                selectedSpecialMove = u.SpecialMoves[i];
                            }
                            selectedSpecialMoveIndex = i;
                            break;
                        }
                    }

                    for (int i = 0; i < u.SpecialMoves.Count; i++)
                    {
                        if (i == selectedSpecialMoveIndex)
                        {
                            spriteBatch.Draw(white, moveRects[i], Color.DarkSlateBlue);
                            spriteBatch.DrawString(infobarFont, u.SpecialMoves[i].Name, new Vector2(moveRects[i].X + 5, moveRects[i].Y + 2), Color.GhostWhite);
                            spriteBatch.DrawString(
                                infobarFont,
                                u.SpecialMoves[i].Description,
                                new Vector2(ctrInBlackRect.X + 135, ctrInBlackRect.Y + 10),
                                Color.Silver);
                        }
                        else
                        {
                            spriteBatch.Draw(white, moveRects[i], Color.BlueViolet);
                            spriteBatch.DrawString(infobarFont, u.SpecialMoves[i].Name, new Vector2(moveRects[i].X + 5, moveRects[i].Y + 2), Color.GhostWhite);
                        }
                    }

                    if (selectedSpecialMove != null)
                    {
                        selectedAction = Action.Special;
                        specialMoveBoxVisible = false;
                    }
                }
            }
        }
Esempio n. 6
0
 private int InvalidTile(Tile movetile, Unit movingUnit)
 {
     if (movetile.HasUnit())
     {
         return -10000;
     }
     if (movetile.Collision > movingUnit.Collision)
     {
         return -10000;
     }
     return 0;
 }