public bool ShouldTakeControl()
        {
            //Only attack if we can see an enemy unit
            for (int i = 0; i < unit.GetVisibleObjects().GetCount(); i++)
            {
                Unit u = unit.GetVisibleObjects()[i] as Unit;
                if (u != null)
                {
                    if (!u.GetTeamColor().Equals(unit.GetTeamColor()))
                    {
                        enemy = u;
                        //Send out a message - "Help, I've found an enemy!"
                        unit.AddMessage(new FoundEnemyMessage(unit, enemy));
                        return true;
                    }
                }
            }

            return false;
        }
示例#2
0
        //Returns all the neighbors within a given circle
        public Buffer<GameObject> GetNeighbors(Circle c, Unit u)
        {
            neighborList.Clear();

            int xMin = (int)(c.Center.X - c.Radius);
            int xMax = (int)(c.Center.X + c.Radius);
            int yMin = (int)(c.Center.Y - c.Radius);
            int yMax = (int)(c.Center.Y + c.Radius);

            xMin = (int)Math.Max(xMin, 0f);
            yMin = (int)Math.Max(yMin, 0f);
            xMax = (int)Math.Min(xMax, width - 1);
            yMax = (int)Math.Min(yMax, height - 1);

            for (int i = xMin; i <= xMax; i++)
            {
                for (int j = yMin; j <= yMax; j++)
                {
                    for (int k = 0; k < objectMap[i, j].GetCount(); k++)
                    {
                        GameObject go = objectMap[i, j][k];
                        if (c.Intersects(go.GetBounds()) && !neighborList.Contains(go))
                        {
                            if (u == null)
                            {
                                neighborList.Add(go);
                            }
                            else if (!u.Equals(go))
                            {
                                neighborList.Add(go);
                            }
                        }
                    }
                }
            }

            return neighborList;
        }
示例#3
0
 public GoToTowerBehavior(Unit u)
 {
     unit = u;
 }
 public AttackEnemyBehavior(Unit u, Random r)
 {
     rand = r;
     unit = u;
 }
 public HelpTeammateBehavior(Unit u)
 {
     unit = u;
 }
 public TakeResourceBehavior(Unit u)
 {
     unit = u;
 }
示例#7
0
 public bool Intersects(Unit other)
 {
     return bounds.Intersects(other.bounds);
 }
 public GoToResourceBehavior(Unit u)
 {
     unit = u;
 }
示例#9
0
        private void initializeTeams(int teamCount)
        {
            for (int i = 0; i < teamCount; i++)
            {
                //This code initializes each team member in a circle
                //around their HQ

                float angle = i * MathHelper.TwoPi / teamCount;
                angle += MathHelper.PiOver4;

                Vector2 center = new Vector2(gridLength / 2, gridLength / 2);

                Vector2 teamSpawn = center + new Vector2((float)Math.Cos(angle) * (gridLength/2f) * 0.9f, (float)Math.Sin(angle) * (gridLength/2f) * 0.9f);
                HQ hq = new HQ(new Vector3(teamSpawn, 0), teamColors[i], rand, map);
                hqs.Add(hq);

                for (int j = 0; j < unitsPerTeam; j++)
                {
                    Vector2 spawnPoint = randomPointInCircle(teamSpawn, gridLength/20f);
                    Unit u = new Unit(new Vector3(spawnPoint, 0), rand, hqs[i]);
                    u.Map = map;
                    u.TeamColor = teamColors[i];
                    u.RotateTo(new Vector3(gridLength / 2f, gridLength / 2f, 0f));
                    units.Add(u);
                    hq.AddUnit(u);
                }
            }
        }
示例#10
0
 public GoToHQBehavior(Unit u)
 {
     unit = u;
 }
 public DepositResourcesBehavior(Unit u)
 {
     unit = u;
 }
示例#12
0
 public RestoreTowerBehavior(Unit u)
 {
     unit = u;
 }
示例#13
0
文件: HQ.cs 项目: bschwind/AI-Example
 public void AddUnit(Unit u)
 {
     units.Add(u);
 }
示例#14
0
文件: HQ.cs 项目: bschwind/AI-Example
        public void Update(GameTime g)
        {
            newUnits.Clear();
            while (resources >= resourcesPerUnit && newUnits.GetCount() <= newUnits.GetCapacity())
            {
                resources -= resourcesPerUnit;
                Unit u = new Unit(this.pos, rand, this);
                u.Map = map;
                u.TeamColor = teamColor;
                newUnits.Add(u);
                units.Add(u);
            }

            if (units.Count <= 0)
            {
                lostGame = true;
            }
        }
示例#15
0
文件: HQ.cs 项目: bschwind/AI-Example
 public void RemoveUnit(Unit u)
 {
     units.Remove(u);
 }