예제 #1
0
 public TestBase(Tile tile)
     : base(ScreenManager.Game.Content.Load<Model>("Model\\pyramids"))
 {
     this.scale = 5;
     this.position = tile.Position;
     this.tile = tile;
 }
예제 #2
0
 public AStar(Tile startTile, Tile goalTile)
 {
     openNodes = new List<Node>();
     closedNodes = new List<Node>();
     openDict = new Dictionary<int, Tile>();
     closedDict = new Dictionary<int, Tile>();
     this.startTile = startTile;
     this.goalTile = goalTile;
 }
예제 #3
0
 public Tower(Model model, Tile tile)
     : base(model)
 {
     attackTime = new TimeSpan(0, 0, 0,0,500);
     elapsedTime = new TimeSpan(0,0,1);
     unitToAttack = null;
     attackPower = 10;
     this.tile = tile;
     this.position = tile.Position;
 }
예제 #4
0
 public Unit(Model model, Base.Base goalBase)
     : base(model)
 {
     previousTile = new Tile();
     currentTile = new Tile();
     focalPoint = new Vector3();
     focalTile = new Tile();
     goalTile = goalBase.Tile;
     isStuck = false;
     health = 100;
 }
예제 #5
0
        public Base(int playerNum, int teamNum, BaseType baseType, Tile tile)
        {
            PlayerNum = playerNum;
            TeamNum = teamNum;
            this.Scale = 2.75f;
            this.Tile = tile;
            this.Position = tile.Position;

            this.model = ScreenManager.Game.Content.Load<Model>("Objects\\Base\\oilRig");
            SetupModel(Position);
            SetupCamera();
        }
예제 #6
0
        public PlayScreen()
            : base("PlayScreen")
        {
            units = new List<Unit>();
            towers = new List<Tower>();

            Vector2 numTiles = new Vector2(20, 10);

            TileMap.InitializeTileMap(Vector3.Zero, numTiles, new Vector2(100, 100));

            startBase = new TestBase(TileMap.Tiles[0]);
            goalBase = new TestBase(TileMap.Tiles[TileMap.Tiles.Count - 1]);

            startBase.SetGoalBase(goalBase);
            goalBase.SetGoalBase(startBase);

            bases = new List<Base>();
            bases.Add(startBase);
            bases.Add(goalBase);

            TileMap.SetBase(goalBase);
            TileMap.SetBase(startBase);

            TileMap.UpdateTilePaths();

            //towers = new Dictionary<int, Tower>();
            //for (int i = 0; i < numTiles.X * numTiles.Y; i++)
            //   towers.Add(i, new TowerAGood(TileMap.Tiles[i].Position));

            background = ScreenManager.Game.Content.Load<Texture2D>("water_tiled");

            cameraManager = (CameraManager)ScreenManager.Game.Services.GetService(typeof(CameraManager));

            myModel = new AnimatedModel(ScreenManager.Game.Content.Load<Model>("AnimatedModel\\dude"));
            myModel.Scale = 2.0f;
            myModel.PlayClip("Take 001");

            currentTile = TileMap.GetTileFromPos(Vector3.Zero);
            myModel.SetPosition(currentTile.Position);

            if (numTiles.X == 10 && numTiles.Y == 10)
            {
                cameraManager.SetPosition(new Vector3(0.0f, 1400.0f, 500.0f));
                cameraManager.SetLookAtPoint(new Vector3(0.0f, 0.0f, 50.0f));
            }
            else if (numTiles.X == 20 && numTiles.Y == 10)
            {
                cameraManager.SetPosition(new Vector3(0.0f, 1700.0f, 500.0f));
                cameraManager.SetLookAtPoint(new Vector3(0.0f, 0.0f, 100.0f));
            }
        }
        public TileTestScreen()
            : base("TileTestScreen")
        {
            units = new List<Unit>();
            towers = new List<Tower>();
            rand = new Random();

            TileMap.InitializeTileMap(Vector3.Zero, new Vector2(10, 10), new Vector2(50, 50));

            startBase = new TestBase(TileMap.Tiles[0]);
            goalBase = new TestBase(TileMap.Tiles[TileMap.Tiles.Count - 1]);

            for (int i = 0; i < TileMap.Tiles.Count; i++)
            {
                TileMap.Tiles[i].UpdatePathTo(goalBase.GetTile());
            }

            background = ScreenManager.Game.Content.Load<Texture2D>("Model\\background");
            myModel = new AnimatedModel(ScreenManager.Game.Content.Load<Model>("AnimatedModel\\dude"));
            myModel.Scale = 5.0f;
            myModel.PlayClip("Take 001");

            currentTile = TileMap.GetTileFromPos(Vector3.Zero);
            myModel.SetPosition(currentTile.Position);
            cameraManager = (CameraManager)ScreenManager.Game.Services.GetService(typeof(CameraManager));
            cameraManager.SetPosition(new Vector3(0.0f, 500.0f, 5000.0f));

            ground = new StaticModel(ScreenManager.Game.Content.Load<Model>("Model\\pyramids"));
            ground.Scale = 1000.0f;
            ground.SetPosition(new Vector3(0.0f, -0.1f, 0.0f));

            #region Setup Text
            font = ScreenManager.Game.Content.Load<SpriteFont>("DummyText\\Font");

            center = new Vector2((ScreenManager.GraphicsDeviceManager.PreferredBackBufferWidth / 2),
                                 (ScreenManager.GraphicsDeviceManager.PreferredBackBufferHeight / 2));
            //Setup Text
            text = "Hello World! Hello World! Hellllllooooo World!";

            //Find out how long the text is using this font
            Vector2 textLength = font.MeasureString(text);

            textPosition = new Vector2(center.X - (textLength.X / 2), center.Y - (textLength.Y / 2));
            #endregion
        }
예제 #8
0
 public static void SetObject(Base gameObject, Tile Tile2)
 {
     SetBase(gameObject, Tile2);
 }
예제 #9
0
 public static void SetObject(Tower gameObject, Tile Tile2)
 {
     SetTower(ref gameObject, ref Tile2);
 }
예제 #10
0
 public static void SetBase(Base setBase, Tile tile)
 {
     bases.Add(setBase);
     tile.TileType = TileType.Base;
 }
예제 #11
0
        public static void RemoveTower(ref Tile Tile2)
        {
            for (int i = 0; i < Tile2.tileNeighbors.Count; i++)
            {
                Tile2.tileNeighbors[i].UnregisterTowerListenerForTower(ref Tile2.Tower);
                Tile2.tileNeighbors[i].UnregisterTowerListenerForUnit(ref Tile2.Tower);
            }
            Tile2.RemoveBlockableObject();

            //AStar2.UpdateWalkableNeighborsForTileID(Tile2.ID);
            AStar2.UpdateNeeded = true;
            //UpdateTilePaths();
        }
예제 #12
0
        public void UpdateTargetPlayer(ref Tile newGoalTile, int newTargetPlayer)
        {
            goalTileID = newGoalTile.ID;
            PlayerToAttack = newTargetPlayer;

            SetFocalPointAndVelocity(TileMap.Tiles[CurrentTileID].PathsInts[newGoalTile.ID][1]);//currentTile.Paths[goalTile.ID][1]);

            Status = UnitStatus.Deployed;

            UpdatePath();
            UpdateTransforms();
        }
예제 #13
0
        private Node TransformToNode(Tile tile, Node parentNode)
        {
            Node node = new Node();
            if (tile == null)
            {
                tile = new Tile();
            }
            node.tile = tile;
            node.parentTile = parentNode.tile;
            node.currentCost = GetDistanceBetweenTiles(tile, parentNode.tile) + parentNode.currentCost;
            node.goalCost = GetDistanceToGoal(tile);
            node.overallCost = node.currentCost + node.goalCost;

            return node;
        }
예제 #14
0
 private float GetDistanceBetweenTiles(Tile tile1, Tile tile2)
 {
     double first = (double)(tile1.Position.X - tile2.Position.X);
     double second = (double)(tile1.Position.Z - tile2.Position.Z);
     // return Math.Abs(tile1.Position.X - tile1.Position.Y) + Math.Abs(tile2.Position.X - tile2.Position.Y);
     return (float)Math.Sqrt((first * first) + (second * second));
 }
예제 #15
0
 public void UpdatePathTo(Tile baseTile)
 {
     AStar aStar = new AStar(this, baseTile);
     paths[baseTile.ID] = new List<Tile>(aStar.FindPath());
 }
예제 #16
0
 public List<Tile> GetPathTo(Tile baseTile)
 {
     UpdatePathTo(baseTile);
     return paths[baseTile.ID];
 }
예제 #17
0
 public Base(Model model)
     : base(model)
 {
     this.tile = GetTile();
 }
예제 #18
0
 public TowerTest(Tile tile)
     : base(ScreenManager.Game.Content.Load<Model>("Model\\pyramids"), tile)
 {
     this.position = position;
     this.Scale = 5;
 }
 public void BuildTower(Tile tile)
 {
     List<Tile> path;
     Tower tower = new TowerTest(tile);
     tile.SetTower(tower);
     bool canBuildTower = true;
     for (int i = 0; i < TileMap.Tiles.Count; i++)
     {
         path = TileMap.Tiles[i].GetPathTo(goalBase.GetTile());
         if (path.Count == 0 && TileMap.Tiles[i] != goalBase.GetTile())
         {
             canBuildTower = false;
         }
     }
     if (canBuildTower)
     {
         towers.Add(tower);
     }
     else
     {
         tile.RemoveTower();
     }
 }
        public override void HandleInput(InputManager input)
        {
            base.HandleInput(input);
            bool moveModel = false;
            Tile newTile = new Tile();
            if (input.CheckNewAction(InputAction.TileMoveUp))
            {
                moveModel = true;
                newTile = TileMap.GetTileNeighbor(currentTile, NeighborTile.Up);
            }
            if (input.CheckNewAction(InputAction.TileMoveDown))
            {
                moveModel = true;
                newTile = TileMap.GetTileNeighbor(currentTile, NeighborTile.Down);
            }
            if (input.CheckNewAction(InputAction.TileMoveLeft))
            {
                moveModel = true;
                newTile = TileMap.GetTileNeighbor(currentTile, NeighborTile.Left);
            }
            if (input.CheckNewAction(InputAction.TileMoveRight))
            {
                moveModel = true;
                newTile = TileMap.GetTileNeighbor(currentTile, NeighborTile.Right);
            }
            if (!newTile.IsNull())
                currentTile = newTile;

            if(input.CheckNewAction(InputAction.Selection))
            {
                //units.Add(new TestUnit(startBase.GetTile().Position));
            }

            //if (input.CheckNewAction(InputAction.Selection))
            //{
            //    for (int i = 0; i < units.Count; i++)
            //    {
            //        units[i].SetPosition(new Vector3(rand.Next(-99, 99), 0, rand.Next(-99, 99)));
            //        units[i].GetTile();
            //    }
            //    //ScreenManager.Game.Exit();
            //}
            if (input.CheckAction(InputAction.RotateLeft))
            {
                cameraManager.RotateX(-0.03f);
            }
            if (input.CheckAction(InputAction.RotateRight))
            {
                cameraManager.RotateX(0.03f);
            }
            if (input.CheckAction(InputAction.RotateUp))
            {
                cameraManager.RotateY(0.01f);
            }
            if (input.CheckAction(InputAction.RotateDown))
            {
                cameraManager.RotateY(-0.01f);
            }
            if (input.CheckAction(InputAction.StrafeLeft))
            {
                cameraManager.StrafeX(-10.0f);
            }
            if (input.CheckAction(InputAction.StrafeRight))
            {
                cameraManager.StrafeX(10.0f);
            }
            if (input.CheckAction(InputAction.StrafeUp))
            {
                cameraManager.StrafeY(10.0f);
            }
            if (input.CheckAction(InputAction.StrafeDown))
            {
                cameraManager.StrafeY(-10.0f);
            }

            if (moveModel)
                myModel.SetPosition(currentTile.Position);

            if (input.CheckNewAction(InputAction.TowerBuild))
            {
                BuildTower(currentTile);
            }
        }
예제 #21
0
        public static bool SetTower(ref Tower tower, ref Tile Tile2)
        {
            //Tile2.SetBlockableObject(tower);
            //AStar2.UpdateWalkableNeighborsForTileID(Tile2.ID);
            if (IsTilePathsValidFor(Tile2.ID))
            {
                Tile2.SetBlockableObject(tower);
                //AStar2.UpdateWalkableNeighborsForTileID(Tile2.ID);
                AStar2.UpdateNeeded = true;
                ////UpdateTilePaths();

                //walkableNeighbors = GetWalkableNeighbors(Tile2);

                //IDEA: WHAT ABOUT OFFSETTING THIS TO THE THREAD?
                //Maintain a list of towers to update on the next update pass after walkableNeighbors is relevant?
                for (int i = 0; i < Tile2.tileNeighbors.Count; i++)
                {
                    Tile2.tileNeighbors[i].RegisterTowerListenerForUnit(ref tower);
                }
                for (int i = 0; i < Tile2.tileNeighbors.Count; i++)
                {
                    Tile2.tileNeighbors[i].RegisterTowerListenerForTower(ref tower);
                }
                tower.tile = Tile2;
                OnTowerCreated();

                return true;
            }

               // RemoveTower(ref Tile2);

            //Tile2.RemoveBlockableObject();
            //for (int i = 0; i < Tile2.tileNeighbors.Count; i++)
            //{
            //    Tile2.tileNeighbors[i].UnregisterTowerListenerForTower(ref tower);
            //    Tile2.tileNeighbors[i].UnregisterTowerListenerForUnit(ref tower);
            //}
            //AStar2.UpdateWalkableNeighborsForTileID(Tile2.ID);
            //for (int j = 0; j < bases.Count; j++)
            //{
            //    for (int i = 0; i < bases.Count; i++)
            //    {
            //        if (i != j)
            //        {
            //            bases[i].Tile.UpdatePathTo(bases[j].Tile);
            //        }
            //    }
            //}
            return false;
        }
예제 #22
0
 public Node(Tile parentTile, Tile tile, float overallCost, float initialCost, float goalCost)
 {
     this.parentTile = parentTile;
     this.tile = tile;
     this.overallCost = overallCost;
     this.currentCost = initialCost;
     this.goalCost = goalCost;
 }
예제 #23
0
        public static void SetTowerForLevelMap(Tower tower, Tile tile)
        {
            tile.SetBlockableObject(tower);
            //tile2.SetBlockableObject(tower);

            //UpdateTilePaths();

            //List<Tile> walkableNeighbors = GetWalkableNeighbors(tile);

            for (int i = 0; i < tile.tileNeighbors.Count; i++)
            {
                tile.tileNeighbors[i].RegisterTowerListenerForUnit(ref tower);
            }

            for (int i = 0; i < tile.tileNeighbors.Count; i++)
            {
                tile.tileNeighbors[i].RegisterTowerListenerForTower(ref tower);
            }
            //OnTowerCreated();
        }
예제 #24
0
        public static bool SetTower(Tower tower, Tile tile)
        {
            tile.SetTower(tower);
            if (IsTilePathsValid())
            {
                UpdateTilePaths();

                List<Tile> walkableNeighbors = GetWalkableNeighbors(tile);

                for (int i = 0; i < walkableNeighbors.Count; i++)
                {
                   walkableNeighbors[i].RegisterTowerListener(tower);
                }
                OnTowerCreated();
                return true;
            }

            RemoveTower(tile);
            return false;
        }
예제 #25
0
 private float GetDistanceToGoal(Tile tile)
 {
     return GetDistanceBetweenTiles(tile, goalTile);
 }
예제 #26
0
        public static List<int> GetWalkableNeighborsInts(Tile Tile2)
        {
            //REFACTOR with static neighbor list
            //List<Tile2> neighbors = new List<Tile2>();
            intNeighbors[Tile2.ID].Clear();
            //Tile currentNeighbor;

            //for(int i =0; i< allNeighbors.Count; i++)
            //    tileNeighbors[i] = Tile2.tileNeighbors[(int)allNeighbors[i]];// GetTileNeighbor(ref Tile2, allNeighbors[i]);

            for (int i = 0; i < allNeighbors.Count; i++)
            {
                //currentNeighbor = GetTileNeighbor(ref Tile2, allNeighbors[i]);

                if (Tile2.tileNeighbors[i].IsWalkable())
                {
                    if (i == 6)//allNeighbors[i] == NeighborTile.DownLeft)
                    {
                        if (Tile2.tileNeighbors[5].IsWalkable() &&
                            Tile2.tileNeighbors[7].IsWalkable())
                            intNeighbors[Tile2.ID].Add(Tile2.tileNeighbors[i].ID);
                    }
                    else if (i == 4)//allNeighbors[i] == NeighborTile.DownRight)
                    {
                        if (Tile2.tileNeighbors[5].IsWalkable() &&
                            Tile2.tileNeighbors[3].IsWalkable())
                            intNeighbors[Tile2.ID].Add(Tile2.tileNeighbors[i].ID);
                    }
                    else if (i == 0)//allNeighbors[i] == NeighborTile.UpLeft)
                    {
                        if (Tile2.tileNeighbors[1].IsWalkable() &&
                            Tile2.tileNeighbors[7].IsWalkable())
                            intNeighbors[Tile2.ID].Add(Tile2.tileNeighbors[i].ID);
                    }
                    else if (i == 2)//allNeighbors[i] == NeighborTile.UpRight)
                    {
                        if (Tile2.tileNeighbors[1].IsWalkable() &&
                            Tile2.tileNeighbors[3].IsWalkable())
                            intNeighbors[Tile2.ID].Add(Tile2.tileNeighbors[i].ID);
                    }
                    else
                        intNeighbors[Tile2.ID].Add(Tile2.tileNeighbors[i].ID);
                }

            }
            return intNeighbors[Tile2.ID];
        }
예제 #27
0
 public Node(Tile tile)
     : this(null, tile, 0f, 0f, 0f)
 {
 }
예제 #28
0
        public void Deploy(Tile baseTile, Tile goalTile, int playerToAttack)
        {
            previousTileID = baseTile.ID;
            CurrentTileID = baseTile.ID;
            goalTileID = goalTile.ID;
            PlayerToAttack = playerToAttack;
               // this.previousTile = baseTile;
            //this.currentTile = baseTile;
            //this.goalTile = goalTile;
            this.Position = baseTile.Position;
            int count = 0;
            //lock (AStar2.tileInformationLock)
            lock(AStar2.locks[CurrentTileID][goalTile.ID])
            {
                while (count < 60)
                {
                    if (TileMap.Tiles[CurrentTileID].PathsInts[goalTile.ID].Count > 0)
                    {
                        SetFocalPointAndVelocity(TileMap.Tiles[CurrentTileID].PathsInts[goalTile.ID][1]);//currentTile.Paths[goalTile.ID][1]);
                        break;
                    }
                    count++;

                    if (count >= 60)
                    {
                        return;
                    }
                }

            }
            Status = UnitStatus.Deployed;
            UpdatePath();
            UpdateTransforms();
        }
예제 #29
0
 public void UpdatePathTo(Tile baseTile)
 {
     // List<Tile> newList = new List<Tile>();
     AStar2.InitAstar(this.ID, baseTile.ID);
     // List<Tile> tempPath = Paths[baseTile.ID];
     List<int> tempIntPath = UnSafePaths[baseTile.ID];
     AStar2.FindPath(ref tempIntPath);//new List<Tile>(AStar2.FindPath());
     //Paths[baseTile.ID] = tempPath;
 }
예제 #30
0
        /// <summary>
        /// Gets a neigbhoring Tile2's position
        /// </summary>
        /// <param name="Tile2">The start Tile2</param>
        /// <param name="neighborTile">The neighbor to examine</param>
        /// <returns>Returns the Tile2 neighbor or a null Tile2 if neighbor is not found</returns>
        public static Tile GetTileNeighbor(Tile Tile2, NeighborTile neighborTile)
        {
            //return Tile2.tileNeighbors[(int)neighborTile];
            int newIndex = 0;// Tile2.ID;
            int min, max, tileId;
            tileId = Tile2.ID;
            min = mins[tileId];// (Tile2.ID / numTilesX) * numTilesX;
            max = maxs[tileId];// min + numTilesX - 1;
            switch (neighborTile)
            {
                case NeighborTile.Up: newIndex = tileId - (int)numTiles.X;
                    break;
                case NeighborTile.Down: newIndex = tileId + (int)numTiles.X;
                    break;
                case NeighborTile.Left: newIndex = tileId - 1;
                    if (newIndex < min)
                        newIndex = tileId;
                    break;
                case NeighborTile.Right: newIndex = tileId + 1;
                    if (newIndex > max)
                        newIndex = tileId;
                    break;
                case NeighborTile.UpLeft: newIndex = tileId - numTilesX - 1;
                    if (newIndex < min - (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.UpRight: newIndex = tileId - numTilesX + 1;
                    if (newIndex > max - (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.DownLeft: newIndex = tileId + numTilesX - 1;
                    if (newIndex < min + (int)numTiles.X)
                        newIndex = tileId;
                    break;
                case NeighborTile.DownRight: newIndex = tileId + numTilesX + 1;
                    if (newIndex > max + (int)numTiles.X)
                        newIndex = tileId;
                    break;
            }

            if (newIndex < 0 || newIndex >= totalTiles)
            {
                newIndex = tileId;
            }
            if (newIndex == tileId)
            {
                return Tile.NullTile;
            }

            return tiles[newIndex];
        }