コード例 #1
0
 public void SetAIDestinations(List <GameObject> aiUnits)
 {
     if (myMap.isDrawn == true)
     {
         foreach (GameObject unit in aiUnits)
         {
             List <Tile> newList = new List <Tile>();
             if (unit.GetType().BaseType == typeof(Mobile) && ((Mobile)unit).isMoving == false)
             {
                 //System.Console.WriteLine("Test");
                 Random random  = new Random();
                 int    randomX = random.Next(10, 700);
                 int    randomY = random.Next(10, 350);
                 MovementManager.changeDestination(aiUnits, new Vector2(randomX, randomY));
                 //((Mobile)unit).setDestination(new Vector2(randomX, randomY));
                 //((Mobile)unit).pathList.Clear();
                 //((Mobile)unit).pathList.AddRange(myMap.GetPath(unit.position, ((Mobile)unit).destination, newList));
                 //((Mobile)unit).isMoving = true;
             }
         }
     }
     else
     {
         return;
     }
 }
コード例 #2
0
ファイル: Commander.cs プロジェクト: zws3mb/retribution
 public void rally()
 {
     if (!rallyTimer.Enabled)
     {
         rallyTimer.Start();
         specialAttack = true;
         List <GameObject> rallied = new List <GameObject>();
         if (ModelManager.player.Contains(this))
         {
             foreach (GameObject unit in ModelManager.player)
             {
                 if (unit.GetType().BaseType == typeof(Mobile))
                 {
                     if (!((Mobile)unit).isMoving)
                     {
                         rallied.Add(unit);
                         unit.selected = true;
                         if (unit.basehealth - unit.health >= 3)
                         {
                             unit.health += 3;
                         }
                     }
                 }
             }
             MovementManager.changeDestination(rallied, this.position);
         }
         if (ModelManager.artificial.Contains(this))
         {
             foreach (GameObject unit in ModelManager.artificial)
             {
                 if (unit.GetType().BaseType == typeof(Mobile))
                 {
                     if (!((Mobile)unit).isMoving)
                     {
                         rallied.Add(unit);
                         unit.selected = true;
                         if (unit.basehealth - unit.health >= 3)
                         {
                             unit.health += 3;
                         }
                     }
                 }
             }
             MovementManager.changeDestination(rallied, this.position);
         }
     }
 }
コード例 #3
0
        public void pursue(GameObject unit)
        {
            //Unit is the AI unit set to pursue
            List <GameObject> attackParty = new List <GameObject>();

            unit.selected = true;
            attackParty.Add(unit);
            int size = random.Next(1, aiUnits.Count);

            if (String.Compare(unit.type, "COMMANDER", true) == 0)
            {
                size = aiUnits.Count;
            }
            special(unit);
            for (int x = 0; x < size; x++) // "Count/3" was breaking the game once a user got the enemy units to less than 3
            {
                GameObject gunit = aiUnits[x];
                if (gunit.aiTarget == null && gunit.GetType().BaseType == typeof(Mobile))//if doesn't have target already and can move
                {
                    special(gunit);
                    gunit.aiTarget = unit.aiTarget;
                    gunit.selected = true;
                    attackParty.Add(gunit);//band with this guy
                }
            }
            MovementManager.changeDestination(attackParty, unit.aiTarget.position);
            //foreach (GameObject cunit in attackParty)
            //{
            //    if (cunit.GetType().BaseType == typeof(Mobile))
            //    {
            //        ((Mobile)cunit).setDestination( unit.aiTarget.position);
            //        List<Tile> newList = new List<Tile>();

            //        ((Mobile)cunit).pathList.Clear();
            //        ((Mobile)cunit).pathList.AddRange(myMap.GetPath(unit.position, ((Mobile)cunit).destination, newList));
            //        ((Mobile)cunit).isMoving = true;
            //        ((Mobile)cunit).isPaused=false;
            //    }
            //}
        }
コード例 #4
0
        public void explore(GameObject unit)
        {
            //if (random.NextDouble()*100<=4)
            //{
            List <GameObject> searchParty = new List <GameObject>();

            unit.selected = true;
            searchParty.Add(unit);
            int randpull = random.Next(0, aiUnits.Count);

            for (int x = 0; x < randpull; x++)
            {
                GameObject gunit = aiUnits[x];

                if (gunit.aiTarget == null && gunit.GetType().BaseType == typeof(Mobile))
                {
                    searchParty.Add(gunit);
                    gunit.selected = true;
                }
            }
            Vector2 explore = new Vector2(random.Next(0, 704), random.Next(600, 1024));

            MovementManager.changeDestination(searchParty, explore);
            //foreach (GameObject cunit in searchParty)
            //{

            //((Mobile)cunit).setDestination(MovementManager.getNormalizedVector(cunit.position,explore), explore);
            //((Mobile)cunit).setDestination(explore);
            //List<Tile> newList = new List<Tile>();

            //((Mobile)cunit).pathList.Clear();
            //((Mobile)cunit).pathList.AddRange(myMap.GetPath(cunit.position, ((Mobile)cunit).destination, newList));
            //((Mobile)cunit).isMoving = true;

            // }
            //}
        }
コード例 #5
0
ファイル: BossUnit.cs プロジェクト: zws3mb/retribution
 public void pound()
 {
     if (!poundTimer.Enabled && !poundCD.Enabled)
     {
         poundTimer.Start();
         specialAttack = true;
         foreach (GameObject unit in ModelManager.player)
         {
             if (unit.GetType().BaseType == typeof(Mobile))
             {
                 if (this.IsInRange(unit) && unit != this)
                 {
                     List <GameObject> filler = new List <GameObject>();
                     filler.Add(unit);
                     Vector2 debug  = Vector2.Normalize(Vector2.Subtract(unit.position, this.position));
                     Vector2 debug2 = Vector2.Multiply(debug, this.attackRange);
                     Vector2 pvec   = Vector2.Add(this.position, debug2);
                     int     temp   = ((Mobile)unit).moveSpeed;
                     ((Mobile)unit).moveSpeed = 900;
                     bool mov  = ((Mobile)unit).isMoving;
                     bool paus = ((Mobile)unit).isPaused;
                     ((Mobile)unit).isMoving = true;
                     ((Mobile)unit).isPaused = false;
                     bool sel = unit.selected;
                     unit.selected = true;
                     MovementManager.changeDestination(filler, pvec);
                     unit.selected            = sel;
                     ((Mobile)unit).isMoving  = mov;
                     ((Mobile)unit).moveSpeed = temp;
                     ((Mobile)unit).isPaused  = paus;
                     unit.health--;
                 }
             }
         }
     }
 }
コード例 #6
0
        public void Update(MouseState newcurrent, MouseState newprevious, ref double ClickTimer, KeyboardState keyPress,
                           ref Dictionary <Keys, List <GameObject> > groupedUnits, ref List <GameObject> units, ref List <GameObject> aunits,
                           ref LoadManager loadManager, ref ProjectileManager projMan, ContentManager theContent, ref int playerResources, bool dbuildPhase)

        {
            Rectangle holder = mouseRec;

            mouseRec = new Rectangle(newcurrent.X, newcurrent.Y, 2, 2);
            if (!loaded)
            {
                loadMouseOvers(theContent);
                loaded = true;
            }
            mouseOver();
            mouseRec = holder;
            bool singleClick = false;

            current    = newcurrent;
            previous   = newprevious;
            buildPhase = dbuildPhase;
            if (keyPress.IsKeyDown(Keys.S) && current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released)
            {
                int      x             = Convert.ToInt32(current.X);
                int      y             = Convert.ToInt32(current.Y);
                Vector2  mousePosition = new Vector2(x, y);
                ClickBox temp          = new ClickBox(mousePosition);
                //temp.LoadContent(theContent);
                foreach (GameObject unit in units)
                {
                    if (unit.selected && unit.GetType() == typeof(Tower))
                    {
                        if (!((Tower)unit).placed)
                        {
                            ((Tower)unit).placed = true;
                            unit.position        = mousePosition;
                        }
                    }
                }
            }
            // Select units after releasing mouse and clear rectangle:
            if (current.LeftButton == ButtonState.Released &&
                previous.LeftButton == ButtonState.Pressed
                )
            {
                for (int i = 0; i < units.Count; i++)
                {
                    if (!selectSimilar)
                    {
                        units[i].selected = false;
                    }
                    if (units[i].Bounds.Intersects(mouseRec))
                    {
                        units[i].selected = true;
                    }
                }

                mouseRec = Rectangle.Empty;
            }

            if (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Released && prevclick)
            {
                if (ClickTimer < TimerDelay)
                {
                    selectSimilar = true;
                }
                else
                {
                    ClickTimer    = 0;
                    selectSimilar = false;
                }
            }

            // Select with a single mouse click:
            if (current.LeftButton == ButtonState.Pressed &&
                previous.LeftButton == ButtonState.Released
                )
            {
                mouseRec       = new Rectangle((int)current.X, (int)current.Y, 0, 0);
                mouseRecOrigin = new Vector2(current.X, current.Y);
                GameObject selectedUnit = null;

                for (int i = 0; i < units.Count; i++)
                {
                    units[i].selected = false;
                    if (units[i].isSelectable(current) == true)
                    {
                        units[i].selected = true;
                        selectedUnit      = units[i];
                        InfoCard.info(units[i]);
                        break;
                    }
                }

                if (selectSimilar && selectedUnit != null)
                {
                    for (int i = 0; i < units.Count; i++)
                    {
                        if (units[i].GetType() == selectedUnit.GetType())
                        {
                            units[i].selected = true;
                        }
                    }
                }

                singleClick = true;
                prevclick   = true;
            }


            // Move selected units or attack:
            if (current.RightButton == ButtonState.Pressed &&
                previous.RightButton == ButtonState.Released
                )
            {
                Vector2    testvec        = new Vector2(current.X, current.Y);
                GameObject selectedTarget = null;

                for (int i = 0; i < aunits.Count; i++)
                {
                    if (aunits[i].isLoaded)
                    {
                        if (aunits[i].isSelectable(current))
                        {
                            selectedTarget = aunits[i];
                            break;
                        }
                    }
                }

                for (int i = 0; i < units.Count; i++)
                {
                    if (units[i].selected == true)
                    {
                        units[i].aiTarget = selectedTarget;
                    }
                }
                MovementManager.changeDestination(units, testvec);
            }

            if (keyPress.GetPressedKeys().Length > 0 && IsKeyADigit(keyPress.GetPressedKeys()[0]))
            {
                Keys pressedKey = keyPress.GetPressedKeys()[0];
                if (previousKeyboard.IsKeyDown(Keys.LeftControl) && keyPress.IsKeyDown(pressedKey))
                {
                    List <GameObject> groupList = new List <GameObject>();

                    foreach (GameObject gobj in units)
                    {
                        if (gobj.selected)
                        {
                            groupList.Add(gobj);
                        }
                    }

                    if (groupList.Count > 0)
                    {
                        if (!groupedUnits.ContainsKey(pressedKey))
                        {
                            groupedUnits.Add(pressedKey, groupList);
                        }
                        else
                        {
                            groupedUnits[pressedKey] = groupList;
                        }
                    }
                }


                if (!previousKeyboard.IsKeyDown(pressedKey) && keyPress.IsKeyDown(pressedKey))
                {
                    if (groupedUnits.ContainsKey(pressedKey))
                    {
                        deselect(ref groupedUnits, pressedKey);
                        List <GameObject> groupList = groupedUnits[pressedKey];
                        foreach (GameObject gobj in groupList)
                        {
                            gobj.selected = true;
                        }
                    }
                }
            }

            if (!previousKeyboard.IsKeyDown(Keys.Delete) && keyPress.IsKeyDown(Keys.Delete) && units.Count > 0)
            {
                if (dbuildPhase) // complete refund
                {
                    int refund = getCost(units[units.Count - 1]);
                    playerResources += refund;
                }
                if (units.Count == 1)
                {
                    if (units[0].GetType() == typeof(Warrior))
                    {
                        if (((Warrior)(units[0])).moveSpeed == 7)
                        {
                            return;
                        }
                    }
                }
                units.RemoveAt(units.Count - 1);
                offset -= 50;
                if (offset < 0 && default_player_y > 608)
                {
                    offset            = 300;
                    default_player_y -= 32;
                }

                // what to do when not in build phase? partial refund? currently can't undo build in play phase
            }

            if (!previousKeyboard.IsKeyDown(Keys.Back) && keyPress.IsKeyDown(Keys.Back))
            {
                foreach (GameObject gobj in units)
                {
                    if (gobj.selected)
                    {
                        if (gobj.GetType() == typeof(Warrior))
                        {
                            if (((Warrior)(gobj)).moveSpeed == 7)
                            {
                                return;
                            }
                        }
                        int refund = getCost(gobj);
                        playerResources += refund;
                    }
                }
                units.RemoveAll(gobj => gobj.selected);
            }


            Rectangle rect;

            //  Purchase Archer
            gui.buttonCols.TryGetValue("ARCHER", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.Z) && keyPress.IsKeyDown(Keys.Z) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Archer.cost)
                {
                    modelManager.addUnit("PLAYER", "ARCHER", placementUtil());
                    playerResources -= Archer.cost;
                }
            }

            //  Purchase tower
            gui.buttonCols.TryGetValue("TOWER", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.X) && keyPress.IsKeyDown(Keys.X) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Tower.cost)
                {
                    modelManager.addUnit("PLAYER", "TOWER", placementUtil());
                    playerResources -= Tower.cost;
                }
            }

            //  Purchase warrior
            gui.buttonCols.TryGetValue("WARRIOR", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.C) && keyPress.IsKeyDown(Keys.C) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Warrior.cost)
                {
                    modelManager.addUnit("PLAYER", "WARRIOR", placementUtil());
                    playerResources -= Warrior.cost;
                }
            }

            //  Spawn Pawn For Free!!!! Yay
            gui.buttonCols.TryGetValue("PAWN", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.V) && keyPress.IsKeyDown(Keys.V) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Pawn.cost)
                {
                    modelManager.addUnit("PLAYER", "PAWN", placementUtil());
                    playerResources -= Pawn.cost;
                }
            }

            //  Spawn Apprentice For Free!!!! Yay
            gui.buttonCols.TryGetValue("APPRENTICE", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.B) && keyPress.IsKeyDown(Keys.B) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Apprentice.cost)
                {
                    modelManager.addUnit("PLAYER", "APPRENTICE", placementUtil());
                    playerResources -= Apprentice.cost;
                }
            }

            //  Spawn Commander For Free!!!! Yay
            gui.buttonCols.TryGetValue("COMMANDER", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.N) && keyPress.IsKeyDown(Keys.N) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Commander.cost)
                {
                    modelManager.addUnit("PLAYER", "COMMANDER", placementUtil());
                    playerResources -= Commander.cost;
                }
            }

            //  Spawn Catapult For Free!!!! Yay
            gui.buttonCols.TryGetValue("CATAPULT", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.M) && keyPress.IsKeyDown(Keys.M) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Catapult.cost)
                {
                    modelManager.addUnit("PLAYER", "CATAPULT", placementUtil());
                    playerResources -= Catapult.cost;
                }
            }

            //  Spawn Catapult For Free!!!! Yay
            gui.buttonCols.TryGetValue("ROGUE", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.J) && keyPress.IsKeyDown(Keys.J) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Rogue.cost)
                {
                    modelManager.addUnit("PLAYER", "ROGUE", placementUtil());
                    playerResources -= Rogue.cost;
                }
            }
            gui.buttonCols.TryGetValue("CLERIC", out rect);
            if (!previousKeyboard.IsKeyDown(Keys.K) && keyPress.IsKeyDown(Keys.K) || (buttonClick(rect) && singleClick))
            {
                if (playerResources >= Cleric.cost)
                {
                    modelManager.addUnit("PLAYER", "CLERIC", placementUtil());
                    playerResources -= Cleric.cost;
                }
            }

            //  Skill - When F is pressed, units selected will perform skill
            foreach (GameObject unit in units)
            {
                //  Skill - Apprentice Fireball
                if (unit.selected && unit.GetType() == typeof(Apprentice) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Apprentice)unit).fireball(projMan, theContent, unit, new Vector2(current.X, current.Y));
                }
                if (unit.selected && unit.GetType() == typeof(Archer) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Archer)unit).rapidFire();
                }
                if (unit.selected && unit.GetType() == typeof(Warrior) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Warrior)unit).juggernaut();
                }
                if (unit.selected && unit.GetType() == typeof(Rogue) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Rogue)unit).stealth();
                }
                if (unit.selected && unit.GetType() == typeof(Commander) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Commander)unit).rally();
                }
                if (unit.selected && unit.GetType() == typeof(Tower) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((Tower)unit).entrench();
                }
                if (unit.selected && unit.GetType() == typeof(BossUnit) &&
                    !previousKeyboard.IsKeyDown(Keys.F) && keyPress.IsKeyDown(Keys.F))
                {
                    ((BossUnit)unit).pound();
                }
                //  Skill - Rogue stealth

                //  SKill - etc.
            }



            //  Update mouse rectangle:
            if (current.LeftButton == ButtonState.Pressed &&
                previous.LeftButton == ButtonState.Pressed
                )
            {
                if (current.X > mouseRecOrigin.X)
                {
                    mouseRec.Width = current.X - mouseRec.X;
                }
                else
                {
                    mouseRec.Width = (int)mouseRecOrigin.X - current.X;
                    mouseRec.X     = current.X;
                }

                if (current.Y > mouseRecOrigin.Y)
                {
                    mouseRec.Height = current.Y - mouseRec.Y;
                }
                else
                {
                    mouseRec.Height = (int)mouseRecOrigin.Y - current.Y;
                    mouseRec.Y      = current.Y;
                }
            }


            previousKeyboard = keyPress;
            //MoraleBar.resourceVal(playerResources);
        }