Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 public GoToTowerBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 4
0
 public AttackEnemyBehavior(Unit u, Random r)
 {
     rand = r;
     unit = u;
 }
Ejemplo n.º 5
0
 public HelpTeammateBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 6
0
 public TakeResourceBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 7
0
 public bool Intersects(Unit other)
 {
     return bounds.Intersects(other.bounds);
 }
Ejemplo n.º 8
0
 public GoToResourceBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 10
0
 public GoToHQBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 11
0
 public DepositResourcesBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 12
0
 public RestoreTowerBehavior(Unit u)
 {
     unit = u;
 }
Ejemplo n.º 13
0
 public void AddUnit(Unit u)
 {
     units.Add(u);
 }
Ejemplo n.º 14
0
        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;
            }
        }
Ejemplo n.º 15
0
 public void RemoveUnit(Unit u)
 {
     units.Remove(u);
 }