예제 #1
0
        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
파일: Map.cs 프로젝트: bschwind/AI-Example
        //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;
 }
예제 #4
0
 public AttackEnemyBehavior(Unit u, Random r)
 {
     rand = r;
     unit = u;
 }
예제 #5
0
 public HelpTeammateBehavior(Unit u)
 {
     unit = u;
 }
예제 #6
0
 public TakeResourceBehavior(Unit u)
 {
     unit = u;
 }
예제 #7
0
파일: Unit.cs 프로젝트: bschwind/AI-Example
 public bool Intersects(Unit other)
 {
     return bounds.Intersects(other.bounds);
 }
예제 #8
0
 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);
 }