Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            time = (float)gameTime.ElapsedGameTime.TotalSeconds;

            currentCoord = new Coordinates((int)TroopVect.X, (int)TroopVect.Y);

            moving = PathMove(GameManager.grid.gridSquares, GameManager.HEIGHT, GameManager.WIDTH, ref TroopVect, ref ScreenPos, speed, time, Direction);

            if (moving)
                ScreenPos = new Vector2((int)GameManager.grid.gridBorder.X + (TroopVect.X * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2, (int)GameManager.grid.gridBorder.Y + (TroopVect.Y * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2);

            else
            {
                TroopVect.X = (float)Math.Round(TroopVect.X);
                TroopVect.Y = (float)Math.Round(TroopVect.Y);
            }

            Vector2 NextScreenPos = new Vector2((int)GameManager.grid.gridBorder.X + (nextCoord.x * GameManager.SQUARESIZE + 0.1f), (int)GameManager.grid.gridBorder.Y + (nextCoord.y * GameManager.SQUARESIZE));
            Direction = Movement;

            if (usingSpriteSheet)
            {
                EffectManager.spriteSheetUpdate(ref spriteSheetNo, ref animElasped, targetElasped, sheetFrameTotal, gameTime);
                SourceRect = new Rectangle(0, spriteSheetNo * Art.FriendlySoldier.Height / (sheetFrameTotal + 1), Art.FriendlySoldier.Width, Art.FriendlySoldier.Height / (sheetFrameTotal + 1));
                
            }
        }
Exemplo n.º 2
0
        public Squares(int SquareSize, Vector2 Location, int x, int y, int defDist)
        {
            sqrLoc = Location;
            
            typeOfSquare = SqrFlags.Unoccupied;
            Building = BuildingType.None;
            TowerHere = null;

            rect = new Rectangle((int)Location.X, (int)Location.Y, SquareSize, SquareSize);

            sqrCoord = new Coordinates(x, y, defDist);

            PixelScreenPos = new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
        }
Exemplo n.º 3
0
        public Tower(string towerID, Type type, Vector2 position, Coordinates coords, int level = 1, int range = 200, int health = 100, int damage = 500, float fireRate = 2f)
        {
            TowerID = towerID;
            TowerListener.Add(this);

            TypeofTower = type;
            TowerProjectiles = new List<Projectile>();
            Rotation = 0;
            Position = position;
            Level = level;
            Range = range;
            Health = health;
            Damage = damage;
            FireRate = fireRate;
            shootTimer = fireRate;

            switch (type)
            {
                case Type.Gun:
                    Sprite = Art.TowerGun[level - 1];
                    Damage = 500;
                    TowerType = "Gun";
                    break;
                case Type.Rocket:
                    Sprite = Art.TowerRocket[level - 1];
                    Damage = 1700;
                    FireRate = 0.5f;
                    TowerType = "Rocket";
                    break;
                case Type.SAM:
                    Sprite = Art.TowerSAM[level - 1];
                    Damage = 250;
                    TowerType = "SAM";
                    break;
                case Type.Tesla:
                    Sprite = Art.TowerTesla[level - 1];
                    Damage = 40;
                    FireRate = 100;
                    TowerType = "Tesla";
                    break;
            }

            towerCoords = new Coordinates(coords.x, coords.y);
            healthBar = new UiStatusBars(health, new Vector2(32, 12), Position - new Vector2(Art.TowerGun[0].Width / 2, 20), Art.HpBar[0], Art.HpBar[1]);
        }
Exemplo n.º 4
0
        public static void SpawnTower(string TypeID, Vector2 towerVector, Coordinates squareCoords)
        {
            if (TypeID == "Gun")
                Towers.Add(new Tower(CreateID(TypeID), Tower.Type.Gun, towerVector, squareCoords));
            else if (TypeID == "Rocket")
                Towers.Add(new Tower(CreateID(TypeID), Tower.Type.Rocket, towerVector, squareCoords));
            else if (TypeID == "SAM")
                Towers.Add(new Tower(CreateID(TypeID), Tower.Type.SAM, towerVector, squareCoords));
            else if (TypeID == "Tesla")
                Towers.Add(new Tower(CreateID(TypeID), Tower.Type.Tesla, towerVector, squareCoords));

            GameManager.TowerWasBuilt(TypeID);

            GameManager.grid.gridSquares[(int)squareCoords.x, (int)squareCoords.y].typeOfSquare = Squares.SqrFlags.Occupied;
            GameManager.grid.gridSquares[(int)squareCoords.x, (int)squareCoords.y].typeOfSquare |= Squares.SqrFlags.Wall;
            GameManager.grid.gridSquares[(int)squareCoords.x, (int)squareCoords.y].typeOfSquare |= Squares.SqrFlags.Concrete;
            GameManager.grid.gridSquares[(int)squareCoords.x, (int)squareCoords.y].Building = Squares.BuildingType.Tower;
        }
Exemplo n.º 5
0
 public Ai()
 {
     defDist = GameManager.DEFAULYDIST;
     tempInt = GameManager.DEFAULYDIST;
     nextCoord = new Coordinates(0, 0);
 }
Exemplo n.º 6
0
 public FriendlyAi()
 {
     tempInt = GameManager.DEFAULYDIST;
     nextCoord = new Coordinates(0, 0);
 }
Exemplo n.º 7
0
 public void PathMoveReset()
 {
     tempInt = defDist;
     nextCoord = new Coordinates(0, 0);
 }
Exemplo n.º 8
0
        public static bool InaccessibleSquareCheck(Squares[,] Grid, Coordinates SquareCoords)
        {
            Squares[,] TempGrid;
            TempGrid = Grid;

            TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].typeOfSquare = Squares.SqrFlags.Wall;
            TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].Building = Squares.BuildingType.Trench;

            if (GridPaths(TempGrid))
            {
                TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].typeOfSquare = Squares.SqrFlags.Unoccupied;
                TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].Building = Squares.BuildingType.None;
                return true;
            }

            else
            {
                TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].typeOfSquare = Squares.SqrFlags.Unoccupied;
                TempGrid[(int)SquareCoords.x, (int)SquareCoords.y].Building = Squares.BuildingType.None;
                return false;
            }
        } 
Exemplo n.º 9
0
 public bool CoordEqual(Coordinates Coord)
 {
     if (Coord.x == x && Coord.y == y)
         return true;
     else return false;
 
 }
Exemplo n.º 10
0
 public void PathMoveReset()
 {
     tempInt = defDist;
     nextCoord = new Coordinates(0, 0);
 }
Exemplo n.º 11
0
 public static bool HasNeighbour(Squares.BuildingType typeOfBuilding, Coordinates coord)
 {
     // Check North
     if (coord.y > 0)
         if (GameManager.grid.gridSquares[(int)coord.x, (int)coord.y - 1].Building == typeOfBuilding)
             return true;
     // Check East
     if (coord.x < GameManager.WIDTH - 1)
         if (GameManager.grid.gridSquares[(int)coord.x + 1, (int)coord.y].Building == typeOfBuilding)
             return true;
     // Check South
     if (coord.y < GameManager.HEIGHT - 1)
         if (GameManager.grid.gridSquares[(int)coord.x, (int)coord.y + 1].Building == typeOfBuilding)
             return true;
     // Check West
     if (coord.x > 0)
         if (GameManager.grid.gridSquares[(int)coord.x - 1, (int)coord.y].Building == typeOfBuilding)
             return true;
     return false;
 }
Exemplo n.º 12
0
        public static bool GridPaths(Squares[,] Grid)
        {
            GridReset(Grid);

            bool loopStop = true;
            bool done = false;
            int count = 0;

            List<Coordinates> coords;
            List<Coordinates> tempCoords;
            Coordinates currentElement;

            coords = new List<Coordinates>();
            tempCoords = new List<Coordinates>();
            currentElement = new Coordinates(0,0);

            if (!done)
            {
                coords.Add(GameManager.ENDPOINT);
                currentElement = coords[count];
                Grid[(int)GameManager.ENDPOINT.x, (int)GameManager.ENDPOINT.y].sqrCoord.counter = GameManager.ENDPOINT.counter;
                done = true;
            }

            while (loopStop)
            {

                //Check right square
                if (currentElement.x + 1 < GameManager.WIDTH)
                    if (!Grid[(int)currentElement.x + 1, (int)currentElement.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall))
                        tempCoords.Add(new Coordinates(currentElement.x + 1, currentElement.y, currentElement.counter + 1));

                //check left square
                if (currentElement.x - 1 >= 0)
                    if (!Grid[(int)currentElement.x - 1, (int)currentElement.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall))
                        tempCoords.Add(new Coordinates(currentElement.x - 1, currentElement.y, currentElement.counter + 1));

                //check lower square
                if (currentElement.y + 1 < GameManager.HEIGHT)
                    if (!Grid[(int)currentElement.x, (int)currentElement.y + 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall))
                        tempCoords.Add(new Coordinates(currentElement.x, currentElement.y + 1, currentElement.counter + 1));

                //check upper square
                if (currentElement.y - 1 >= 0)
                    if (!Grid[(int)currentElement.x, (int)currentElement.y - 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall))
                        tempCoords.Add(new Coordinates(currentElement.x, currentElement.y - 1, currentElement.counter + 1));

                duplicateCheck(ref count, tempCoords, coords);

                squaresCounter(currentElement.counter + 1, Grid, tempCoords);

                for (int i = 0; i < tempCoords.Count; i++)
                    coords.Add(tempCoords[i]);

                count++;

                if (count < coords.Count())
                    currentElement = coords[count];

                tempCoords.Clear();

                if (count == (GameManager.WIDTH * GameManager.HEIGHT) -  GetTrenchCount(Grid))
                    loopStop = false;

            }

            Grid[(int)GameManager.ENDPOINT.x, (int)GameManager.ENDPOINT.y].sqrCoord.counter = GameManager.ENDPOINT.counter;

            if (!CheckSquareCounters(Grid))
                return false;

            return true;
        }
Exemplo n.º 13
0
        public bool PathMove(Squares[,] squares, int height, int width, ref Vector2 EnemyVect, ref Vector2 ScreenPos, float speed, float time, Vector2 Direction, string EnemyType)
        {
            if (!Moving)
            {
                ScreenPos = new Vector2(Node.X, Node.Y);

                if (EnemyType != "Helicopter")
                {
                    if (currentCoord.x + 1 < width) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x + 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x + 1, (int)currentCoord.y].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x + 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x + 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }


                    if (currentCoord.x - 1 >= 0) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x - 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x - 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x - 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }

                    if (currentCoord.y + 1 < height) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x, (int)currentCoord.y + 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y + 1, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y + 1, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }

                    if (currentCoord.y - 1 >= 0) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x, (int)currentCoord.y - 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y - 1, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y - 1, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }
                }

                else if (EnemyType == "Helicopter")
                    nextCoord = GameManager.ENDPOINT;

                Node = new Vector2((nextCoord.x * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2, (int)GameManager.grid.gridBorder.Y + (nextCoord.y * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2);

                distance = Vector2.Distance(new Vector2(currentCoord.x, currentCoord.y), new Vector2(nextCoord.x, nextCoord.y));

                Direction = new Vector2(nextCoord.x - currentCoord.x, nextCoord.y - currentCoord.y);
                Movement = Direction;
                Direction.Normalize();

                previousVect = new Vector2(currentCoord.x, currentCoord.y);

                Moving = true;

            }


            if (Moving)
            {
                EnemyVect += Direction * speed * time;
                if (Vector2.Distance(previousVect, EnemyVect) >= distance)
                {
                    if(Direction.Y >= 0 && Direction.X >= 0)
                        ScreenPos = new Vector2(Node.X, Node.Y);

                    Moving = false;

                    return false;
                }

                return true;
            }

            else return false;
            
        }
Exemplo n.º 14
0
 public Ai()
 {
     defDist = GameManager.DEFAULYDIST;
     tempInt = GameManager.DEFAULYDIST;
     nextCoord = new Coordinates(0, 0);
 }
Exemplo n.º 15
0
        public bool PathMove(Squares[,] squares, int height, int width, ref Vector2 EnemyVect, ref Vector2 ScreenPos, float speed, float time, Vector2 Direction)
        {
            bool wallfound = false;

            if (!Moving)
            {
                ScreenPos = new Vector2(Node.X, Node.Y);

                    if (currentCoord.x + 1 < width) // check array wont go out of bounds 
                    {
                        if (squares[(int)currentCoord.x + 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            tempInt = squares[(int)currentCoord.x + 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                            nextCoord = new Coordinates((int)currentCoord.x + 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            wallfound = true;
                        }
                    }


                    if (currentCoord.x - 1 >= 0) // check array wont go out of bounds 
                    {
                        if (squares[(int)currentCoord.x - 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if ((wallfound == true && GameManager.rnd.Next(0, 5) == 1) || !wallfound)
                            {
                                tempInt = squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x - 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                                wallfound = true;
                            }
                        }
                    }

                    if (currentCoord.y + 1 < height) // check array wont go out of bounds 
                    {
                        if (squares[(int)currentCoord.x, (int)currentCoord.y + 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if ((wallfound == true && GameManager.rnd.Next(0, 5) == 1) || !wallfound)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y + 1, tempInt); // set temp coord to the aipos + direction.
                                wallfound = true;
                            }
                        }
                    }

                    if (currentCoord.y - 1 >= 0 && currentCoord.x < 20) // check array wont go out of bounds 
                    {
                        if (squares[(int)currentCoord.x, (int)currentCoord.y - 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if ((wallfound == true && GameManager.rnd.Next(0, 5) == 1) || !wallfound)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y - 1, tempInt); // set temp coord to the aipos + direction.
                                wallfound = true;
                            }
                        }
                    }
               

                Node = new Vector2((nextCoord.x * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2, (int)GameManager.grid.gridBorder.Y + (nextCoord.y * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2);

                distance = Vector2.Distance(new Vector2(currentCoord.x, currentCoord.y), new Vector2(nextCoord.x, nextCoord.y));

                Direction = new Vector2(nextCoord.x - currentCoord.x, nextCoord.y - currentCoord.y);
                Movement = Direction;
                Direction.Normalize();

                previousVect = new Vector2(currentCoord.x, currentCoord.y);

                Moving = true;

            }

            if (Moving)
            {
                EnemyVect += Direction * speed * time;
                if (Vector2.Distance(previousVect, EnemyVect) >= distance)
                {
                    if (Direction.Y >= 0 && Direction.X >= 0)
                        ScreenPos = new Vector2(Node.X, Node.Y);

                    Moving = false;

                    return false;
                }

                return true;
            }

            else return false;
        }
Exemplo n.º 16
0
 public bool Equals(Coordinates Coords)
 { 
     if(Coords.x == x && Coords.y == y && Coords.counter == counter)
         return true;
     else return false;
 }
Exemplo n.º 17
0
        public bool PathMove(Squares[,] squares, int height, int width, ref Vector2 EnemyVect, ref Vector2 ScreenPos, float speed, float time, Vector2 Direction, string EnemyType)
        {
            if (!Moving)
            {
                ScreenPos = new Vector2(Node.X, Node.Y);

                if (EnemyType != "Helicopter")
                {
                    if (currentCoord.x + 1 < width) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x + 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x + 1, (int)currentCoord.y].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x + 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x + 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }


                    if (currentCoord.x - 1 >= 0) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x - 1, (int)currentCoord.y].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x - 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x - 1, (int)currentCoord.y].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x - 1, (int)currentCoord.y, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }

                    if (currentCoord.y + 1 < height) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x, (int)currentCoord.y + 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y + 1, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y + 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y + 1, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }

                    if (currentCoord.y - 1 >= 0) // check array wont go out of bounds 
                    {
                        if (!squares[(int)currentCoord.x, (int)currentCoord.y - 1].typeOfSquare.HasFlag(Squares.SqrFlags.Wall)) //check next square is not a wall
                        {
                            if (squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter < tempInt) // check the square distance from endpoint is less than the current pos. 
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y - 1, tempInt); // set temp coord to the aipos + direction.
                            }

                            if (squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter == tempInt && GameManager.rnd.Next(0, 2) == 1)
                            {
                                tempInt = squares[(int)currentCoord.x, (int)currentCoord.y - 1].sqrCoord.counter; // set the tempint to new distance value
                                nextCoord = new Coordinates((int)currentCoord.x, (int)currentCoord.y - 1, tempInt); // set temp coord to the aipos + direction.
                            }
                        }
                    }
                }

                else if (EnemyType == "Helicopter")
                {
                    List<Coordinates> availableCoord = new List<Coordinates>();

                    foreach (Squares square in squares)
                    {
                        if (square.sqrCoord.counter != GameManager.DEFAULYDIST)
                            availableCoord.Add(square.sqrCoord);
                    }

                    int indexNext = GameManager.rnd.Next(0, availableCoord.Count);

                    nextCoord = availableCoord[indexNext];

                    if (GameManager.rnd.Next(0, 100) == 1)
                        nextCoord = GameManager.ENDPOINT;

                }

                Node = new Vector2((nextCoord.x * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2, (int)GameManager.grid.gridBorder.Y + (nextCoord.y * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2);

                distance = Vector2.Distance(new Vector2(currentCoord.x, currentCoord.y), new Vector2(nextCoord.x, nextCoord.y));

                Direction = new Vector2(nextCoord.x - currentCoord.x, nextCoord.y - currentCoord.y);
                Movement = Direction;
                Direction.Normalize();

                previousVect = new Vector2(currentCoord.x, currentCoord.y);

                Moving = true;

            }


            if (Moving)
            {
                EnemyVect += Direction * speed / GameManager.FPS ;
                if (Vector2.Distance(previousVect, EnemyVect) >= distance)
                {
                    if(Direction.Y >= 0 && Direction.X >= 0)
                        ScreenPos = new Vector2(Node.X, Node.Y);

                    Moving = false;

                    if (EnemyType == "Helicopter")
                    {

                        for (int i = 0; i < 3; i++)
                        {
                            EnemyManager.SpawnEnemy(EnemyManager.SpawnSoldierString, EnemyVect - new Vector2(2 * i / 4, 0));
                        }

                    }

                    return false;
                }

                return true;
            }

            else return false;
            
        }
Exemplo n.º 18
0
        public void Update(Grid.gridFlags endPoint, GameTime gameTime)
        {
            time = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //check for out of bounds, only really occurs when they are spawned from a destroyed vehicle as the vehicle is turning
            if (enemyVect.X >= 20)
                enemyVect.X = 19;
            if (enemyVect.Y >= 15)
                enemyVect.Y = 14;
            if (enemyVect.X < 0)
                enemyVect.X = 0;
            if (enemyVect.Y < 0)
                enemyVect.Y = 0;

            currentCoord = new Coordinates((int)enemyVect.X, (int)enemyVect.Y);

            if(enemyVect != null)
                moving = PathMove(GameManager.grid.gridSquares, GameManager.HEIGHT, GameManager.WIDTH, ref enemyVect, ref ScreenPos, speed, time, Direction, EnemyType);

            if (GameManager.ENDPOINT != null)
            {
                if (currentCoord.CoordEqual(GameManager.ENDPOINT))
                {
                    IsDestroyed = true;
                    GameManager.BaseHealth -= damage;
                }
            }

            if (hitPoints <= 0)
            {
                IsDestroyed = true;
            }

            // Get screen pixel position from Grid Coordinates (enemyVect).
            if (moving)
                ScreenPos = new Vector2((int)GameManager.grid.gridBorder.X + (enemyVect.X * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2, (int)GameManager.grid.gridBorder.Y + (enemyVect.Y * GameManager.SQUARESIZE) + GameManager.SQUARESIZE / 2);

            else
            {
                enemyVect.X = (float)Math.Round(enemyVect.X);
                enemyVect.Y = (float)Math.Round(enemyVect.Y);
            }


            if (EnemyType == "Tank" || EnemyType == "Jeep")
            {
                TurretDirection = TankTurret.Update(this);
            }

            Vector2 NextScreenPos = new Vector2((int)GameManager.grid.gridBorder.X + (nextCoord.x * GameManager.SQUARESIZE + 0.1f), (int)GameManager.grid.gridBorder.Y + (nextCoord.y * GameManager.SQUARESIZE));
            Direction = Movement;

            if (!towerInRange)
            {
                TurretDirection = Direction;
                //float nextTurretDirection = Direction.ToAngle();
                //// LERPING HERE
                //turretRotation = Extensions.CurveAngle(turretRotation, nextTurretDirection, 0.3f);
                //TurretDirection = turretRotation.ToVector();
            }

            if (usingSpriteSheet)
            {
                EffectManager.spriteSheetUpdate(ref spriteSheetNo, ref animElasped, targetElasped, sheetFrameTotal, gameTime);

                if(EnemyType == "Soldier")
                    SourceRect = new Rectangle(0, spriteSheetNo * Art.Soldier.Height / (sheetFrameTotal + 1), Art.Soldier.Width, Art.Soldier.Height / (sheetFrameTotal + 1));
                else if (EnemyType == "Helicopter")
                    SourceRect = new Rectangle(spriteSheetNo * Art.Helicopter.Width / (sheetFrameTotal + 1) , 0, Art.Helicopter.Width / (sheetFrameTotal + 1), Art.Helicopter.Height); 
            }

        }