Ejemplo n.º 1
0
        //Constructor for Cannon object
        public Cannon(int x, int y) : base(x, y)
        {
            //Setting image and type of cannon
            img       = cannonImg;
            towerType = "Cannon";

            //Setting tower price
            priceGold  = GOLD_PRICE;
            priceWood  = WOOD_PRICE;
            priceSteel = STEEL_PRICE;

            //Setting damage, range, and shoot time of tower
            propertyValue[0] = DEFAULT_DAMAGE;
            propertyValue[1] = DEFAULT_RANGE;
            shootFrameMax    = SHOOT_TIME;

            //Setting up defense tower range circles
            currentRangeCircle = new GUI.Circle(center, (int)propertyValue[1], Color.White * 0.25f);
            futureRangeCircle  = new GUI.Circle(center, (int)Math.Round(propertyValue[1] * 1.25), Color.Green * 0.25f);

            //Setting up animation components
            sourceRect = new Rectangle(rect.X + 25, rect.Y + 25, 50, 50);
            origin     = new Vector2(50, 50);
            rotation   = (float)(Math.PI / 2.0);

            //Setting up shop item variables for possible upgrades
            upgradeItems[0] = new GameData.ShopItem("Damage +", GOLD_PRICE / 2, WOOD_PRICE / 2, STEEL_PRICE / 2, "Damage", (int)Math.Round(propertyValue[0] * 0.25), upgradeButtonImg, upgradeButtonRect[0]);
            upgradeItems[1] = new GameData.ShopItem("Range +", GOLD_PRICE / 2, WOOD_PRICE / 2, STEEL_PRICE / 2, "Range", (int)Math.Round(propertyValue[1] * 0.25), upgradeButtonImg, upgradeButtonRect[1]);
        }
        //Pre: 'newCircle', the circle to check for collision, 'newPoint', the point to check for collision
        //Post: Returns true or false, depending on whether the point is inside circle
        //Description: Subprogram to check if an enemy is inside a tower's range
        public static bool PointToCircle(GUI.Circle newCircle, Vector2 newPoint)
        {
            //If enemy is inside circle, return true
            if (Math.Pow((newCircle.center.X - newPoint.X), 2) + Math.Pow((newCircle.center.Y - newPoint.Y), 2) <= newCircle.radius * newCircle.radius)
            {
                return(true);
            }

            //Otherwise, return false
            return(false);
        }
Ejemplo n.º 3
0
        //Constructor for giant bomb object
        public GiantBomb(int x, int y) : base(x, y)
        {
            //Setting up item image, rectangle, and circle
            animationImg = ItemResources.explosionImg;
            rect         = new Rectangle(x * 50, y * 50, 50, 50);
            rangeCircle  = new GUI.Circle(new Vector2(x * 50 + 25, y * 50 + 25), RANGE, Color.White);

            //Setting value of damage
            damageValue = DAMAGE;

            //Setting up and playing bomb soundeffect
            sndInstance        = Projectiles.ProjectileResources.bomberSnd.CreateInstance();
            sndInstance.Volume = Driver.Main.actualVolume[1];
            sndInstance.Play();
        }
Ejemplo n.º 4
0
        //Constructor for arrow drop object
        public ArrowDrop(int x, int y) : base(x, y)
        {
            //Setting up item image, rectangle, and circle
            img         = animationImg;
            rect        = new Rectangle((int)((x - 1.5) * 50), (int)((y - 1.5) * 50), 200, 200);
            rangeCircle = new GUI.Circle(new Vector2(x * 50 + 25, y * 50 + 25), RANGE, Color.White);

            //Setting damange of item
            damageValue = DAMAGE;

            //Setting up and playing bomb soundeffect
            sndInstance        = Projectiles.ProjectileResources.archerSnd.CreateInstance();
            sndInstance.Volume = Driver.Main.actualVolume[1];
            sndInstance.Play();
        }
Ejemplo n.º 5
0
        //Overloaded constructor for defense tower class
        public Cannon(int x, int y, int propLevel1, int propLevel2, int total) : base(x, y, propLevel1, propLevel2, total)
        {
            //Setting image and type of archer
            img       = cannonImg;
            towerType = "Cannon";

            //Setting tower price
            priceGold  = GOLD_PRICE;
            priceWood  = WOOD_PRICE;
            priceSteel = STEEL_PRICE;

            //Setting damage, range, shoot time, and kills
            propertyValue[0] = (int)(DEFAULT_DAMAGE * Math.Pow(1.25, propLevel1));
            propertyValue[1] = (int)(DEFAULT_RANGE * Math.Pow(1.25, propLevel2));
            shootFrameMax    = SHOOT_TIME;
            totalKills       = total;

            //Setting up defense tower range circles
            currentRangeCircle = new GUI.Circle(center, propertyValue[1], Color.White * 0.25f);
            futureRangeCircle  = new GUI.Circle(center, (int)Math.Round(propertyValue[1] * 1.25), Color.Green * 0.25f);

            //Setting up animation components
            sourceRect = new Rectangle(rect.X + 25, rect.Y + 25, 50, 50);
            origin     = new Vector2(50, 50);
            rotation   = (float)(Math.PI / 2.0);

            //Selection to either update 1st shop item or clear shop item, depending on level
            if (propertyLevel[0] < 4)
            {
                upgradeItems[0] = new GameData.ShopItem("Damage +", propertyLevel[0] * (priceGold) / 2, propertyLevel[0] * (priceWood) / 2, propertyLevel[0] * (priceSteel) / 2, "Damage", (int)(propertyValue[0] * 0.25), upgradeButtonImg, upgradeButtonRect[0]);
            }
            else
            {
                upgradeItems[0] = new GameData.ShopItem(0);
                upgradeItems[0].Clear();
            }

            //Selection to either update 2nd shop item or clear shop item, depending on level
            if (propertyLevel[1] < 4)
            {
                upgradeItems[1] = new GameData.ShopItem("Range +", propertyLevel[1] * (priceGold) / 2, propertyLevel[1] * (priceWood) / 2, propertyLevel[1] * (priceSteel) / 2, "Range", (int)(propertyValue[1] * 0.25), upgradeButtonImg, upgradeButtonRect[1]);
            }
            else
            {
                upgradeItems[1] = new GameData.ShopItem(1);
                upgradeItems[1].Clear();
            }
        }
Ejemplo n.º 6
0
        //Constructor for Bomber object
        public Bomber(int x, int y) : base(x, y)
        {
            //Setting image and type of bomber
            img       = bomberImg;
            towerType = "Bomber";

            //Setting tower price
            priceGold  = GOLD_PRICE;
            priceWood  = WOOD_PRICE;
            priceSteel = STEEL_PRICE;

            //Setting damage, range, and shoot time of tower
            propertyValue[0] = DEFAULT_DAMAGE;
            propertyValue[1] = DEFAULT_RANGE;
            shootFrameMax    = SHOOT_TIME;

            //Setting up defense tower range circles
            currentRangeCircle = new GUI.Circle(center, (int)propertyValue[1], Color.White * 0.25f);
            futureRangeCircle  = new GUI.Circle(center, (int)Math.Round(propertyValue[1] * 1.25), Color.Green * 0.25f);

            //Setting up shop item variables for possible upgrades
            upgradeItems[0] = new GameData.ShopItem("Damage +", GOLD_PRICE / 2, WOOD_PRICE / 2, STEEL_PRICE / 2, "Damage", (int)Math.Round(propertyValue[0] * 0.25), upgradeButtonImg, upgradeButtonRect[0]);
            upgradeItems[1] = new GameData.ShopItem("Range +", GOLD_PRICE / 2, WOOD_PRICE / 2, STEEL_PRICE / 2, "Range", (int)Math.Round(propertyValue[1] * 0.25), upgradeButtonImg, upgradeButtonRect[1]);
        }
        //Pre: 'newCircle', the search circle, 'newEnemyList', the list of enemies to check for collision,
        //Post: Returns a list of enemies within the range
        //Description: Subprogram to determine all enemies within the range of a circle
        public static List <Enemies.Enemy> QuadTree(GUI.Circle newCircle, List <Enemies.Enemy> newEnemyList)
        {
            //List of enemies to return and quadrant of enemies
            List <Enemies.Enemy> enemyReturnList = new List <Enemies.Enemy>();
            int circleQuadrant;

            //Initial min, max and midpoint coordinates of x and y
            int xMin = 650;
            int xMax = 0;
            int xMid;
            int yMin = 550;
            int yMax = 0;
            int yMid;

            //Determining max, min, and mid of enemy x and y coordinates
            for (int i = 0; i < newEnemyList.Count; i++)
            {
                //If newEnemy center x is less than current x min, set new x min
                if (newEnemyList[i].centerLoc.X < xMin)
                {
                    xMin = (int)newEnemyList[i].centerLoc.X;
                }

                //If newEnemy center x is greater than current x max, set new x max
                if (newEnemyList[i].centerLoc.X > xMax)
                {
                    xMax = (int)newEnemyList[i].centerLoc.X;
                }

                //If newEnemy center y is less than current y min, set new y min
                if (newEnemyList[i].centerLoc.Y < yMin)
                {
                    yMin = (int)newEnemyList[i].centerLoc.Y;
                }

                //If newEnemy center y is greater than current y max, set new y max
                if (newEnemyList[i].centerLoc.Y > yMax)
                {
                    yMax = (int)newEnemyList[i].centerLoc.Y;
                }
            }
            xMid = (int)((xMax + xMin) / 2.0);
            yMid = (int)((yMax + yMin) / 2.0);

            //Determining quadrant of quadtree circle
            if (newCircle.center.X > xMid)
            {
                if (newCircle.center.Y > yMid)
                {
                    circleQuadrant = 3;
                }
                else
                {
                    circleQuadrant = 2;
                }
            }
            else
            {
                if (newCircle.center.Y > yMid)
                {
                    circleQuadrant = 4;
                }
                else
                {
                    circleQuadrant = 1;
                }
            }

            //If center of quadtree is inside of circle
            if (Math.Abs(newCircle.center.X - xMid) >= newCircle.radius &&
                Math.Abs(newCircle.center.Y - yMid) >= newCircle.radius)
            {
                //If enemy is inside circle's quadrant, add enemy
                for (int i = 0; i < newEnemyList.Count; i++)
                {
                    if (circleQuadrant == 1 && newEnemyList[i].centerLoc.X <= xMid && newEnemyList[i].centerLoc.Y <= yMid)
                    {
                        enemyReturnList.Add(newEnemyList[i]);
                    }
                    else if (circleQuadrant == 2 && newEnemyList[i].centerLoc.X >= xMid && newEnemyList[i].centerLoc.Y <= yMid)
                    {
                        enemyReturnList.Add(newEnemyList[i]);
                    }
                    else if (circleQuadrant == 3 && newEnemyList[i].centerLoc.X >= xMid && newEnemyList[i].centerLoc.Y >= yMid)
                    {
                        enemyReturnList.Add(newEnemyList[i]);
                    }
                    else if (circleQuadrant == 4 && newEnemyList[i].centerLoc.X <= xMid && newEnemyList[i].centerLoc.Y >= yMid)
                    {
                        enemyReturnList.Add(newEnemyList[i]);
                    }
                }

                //Performing appropriate return, depending on how many enemies are left
                if (enemyReturnList.Count == 0)
                {
                    //If list is empty, return empty list
                    return(enemyReturnList);
                }
                else if (enemyReturnList.Count == 1)
                {
                    //If list has one enemy, return appropriate list depending on if enemy is within range
                    if (PointToCircle(newCircle, enemyReturnList[0].centerLoc))
                    {
                        return(enemyReturnList);
                    }
                    else
                    {
                        return(new List <Enemies.Enemy>());
                    }
                }
                else if (enemyReturnList.Count == 2)
                {
                    //If list has two enemies, check of they are within range
                    for (int i = 0; i < 2; i++)
                    {
                        if (PointToCircle(newCircle, enemyReturnList[i].centerLoc))
                        {
                            enemyReturnList.Add(enemyReturnList[i]);
                        }
                    }
                    enemyReturnList.RemoveRange(0, 2);

                    //Returning enemy list
                    return(enemyReturnList);
                }
                else
                {
                    //Calling recursive case
                    return(QuadTree(newCircle, new List <Enemies.Enemy>(enemyReturnList)));
                }
            }
            else
            {
                //Checking to see if enemy is inside circle
                for (int i = 0; i < newEnemyList.Count; i++)
                {
                    if (PointToCircle(newCircle, newEnemyList[i].centerLoc))
                    {
                        enemyReturnList.Add(newEnemyList[i]);
                    }
                }

                //Returning enemy list
                return(enemyReturnList);
            }
        }