public AtomicSquad(ref GameEntity ent)
 {
     m_geSquadEntity = ent;
 }
Esempio n. 2
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            Content.RootDirectory = "Content";

            MapHandler.GetInstance().SetDebug(false);

            m_TreeList = new List<TreeEntity>();
            //m_TreeList.Add(new TreeEntity(new Vector2(2 * 64, 4 * 64/4 )));
            //m_TreeList.Add(new TreeEntity(new Vector2(9 * 64 + 32, 7 * 64 / 4)));
            //m_TreeList.Add(new TreeEntity(new Vector2(0 * 64, 0 * 64 / 4)));
            //m_TreeList.Add(new TreeEntity(new Vector2(1 * 64, 10 * 64 / 4)));

            m_LumberMills = new List<LumberMill>();
            //m_LumberMills.Add(new LumberMill(new Vector2(8 * 64, 8 * 64/4)));

            m_mouseSource = new Rectangle(0, 0, 19, 19);

            m_TestLayer = new MapLayer(new Vector2(m_LayerWidth, m_LayerHeight), new Vector2(64, 64));
            m_WaterLayer = new MapLayer(new Vector2(m_LayerWidth, m_LayerHeight), new Vector2(64, 64));

            GenerateRandomMap();

            //for (int i = 4; i < 6; i++)
            //{
            //    for (int j = 0; j < 22; j++)
            //        m_TestLayer.SetTileToSolid(i, j, m_bSetTilesToSolid);
            //}
            //m_TestLayer.SetTileToSolid(5, 21, false);
            //m_TestLayer.SetTileToSolid(4, 0, false);

            MapHandler.GetInstance().SetActiveLayer(m_TestLayer);
            SetTilesToSolid();

            m_TestTile = new MapTile(new Vector2(0, 0), 0, new Vector2(64,64));

            m_GoblinList = new List<GoblinLumberjack>();
            m_Goblin = new GoblinLumberjack(ENTITY_COLOR.RED, new Vector2(5 * 64, 12 * 64/4), DIRECTION.DOWN);

            m_GoblinList.Add((GoblinLumberjack)m_Goblin);

            m_GoblinList.Add(new GoblinLumberjack(ENTITY_COLOR.ORANGE,
                                MapHandler.GetInstance().GetTilePosition(new Vector2(0,0)), DIRECTION.DOWN));

            m_GoblinList.Add(new GoblinLumberjack(ENTITY_COLOR.ORANGE,
                                MapHandler.GetInstance().GetTilePosition(new Vector2(0, 0)), DIRECTION.DOWN));

            m_GoblinList.Add(new GoblinLumberjack(ENTITY_COLOR.ORANGE,
                                MapHandler.GetInstance().GetTilePosition(new Vector2(0, 0)), DIRECTION.DOWN));

            m_GoblinList.Add(new GoblinLumberjack(ENTITY_COLOR.ORANGE,
                                MapHandler.GetInstance().GetTilePosition(new Vector2(0, 0)), DIRECTION.DOWN));

            GameEntity tempGobling;
            m_goblinSquad = new CompositeSquad(m_Goblin);
            tempGobling = m_GoblinList[1];
            m_goblinSquad.AddSquad(new AtomicSquad(ref tempGobling));
            tempGobling = m_GoblinList[2];
            m_goblinSquad.AddSquad(new AtomicSquad(ref tempGobling));
            tempGobling = m_GoblinList[3];
            m_goblinSquad.AddSquad(new AtomicSquad(ref tempGobling));
            tempGobling = m_GoblinList[4];
            m_goblinSquad.AddSquad(new AtomicSquad(ref tempGobling));

            m_FormationList = new List<Formation>();
            m_FormationList.Add(FormationFactory.GetInstance().GetBoxFormation());
            m_FormationList.Add(FormationFactory.GetInstance().GetDiamondFormation());
            m_FormationList.Add(FormationFactory.GetInstance().GetFightingVFormation());
            m_FormationList.Add(FormationFactory.GetInstance().GetLineFormation());
            m_FormationList.Add(FormationFactory.GetInstance().GetShieldFormation());
            //((GoblinLumberjack)m_Goblin).SetTargetLumberMill(m_LumberMills[0]);
            m_goblinSquad.SetFormation(m_FormationList[m_currFormationIndex]);

            m_Goblin.SetEntitySpeed(new Vector2(1, 1));
            m_mapList = new List<List<int>>();
            m_mapList.Add(new List<int>() { });

            //List<Vector2> adjacents = MapHandler.GetInstance().GetAdjacentsToTile(new Vector2(5, 5));

            //for (int i = 0; i < adjacents.Count; i++)
            //{
            //    Console.WriteLine(adjacents[i]);
            //}

            //AStarPathFinder finder = new AStarPathFinder();
            //PathNode m_path = finder.FindPath(new Vector2(0, 0), new Vector2(3, 2));
            //AStarNode node = null;
            //if(m_path != null)
            //node = (AStarNode) m_path;

            //int counter = 0;
            //while (node != null)
            //{
            //    Console.WriteLine("" + counter + ": " + node.GetNodePosition());
            //    counter++;
            //    node = (AStarNode)node.GetNextNode();
            //}
        }
        /// <summary>
        /// If the entity to go to is a tree then we set it as our target tree.
        /// If the rntity to go to is a lumber mill then we set it as our target
        /// mill.
        /// 
        /// Otherwise it delegates to the parent's implementation.
        /// </summary>
        /// <param name="toEntity"></param>
        /// <param name="distance"></param>
        public override void MoveDistanceInFrontOfEntity(GameEntity toEntity, int distance)
        {
            // If the target is a tree then save it
            // as a target.
            if (toEntity is TreeEntity)
            {
                m_TargetTree = (TreeEntity)toEntity;
                if(!m_MyStateMachine.IsInState(GLumberjack_TreeTravel.GetInstance()))
                    m_MyStateMachine.ChangeState(GLumberjack_TreeTravel.GetInstance());
            }
            // If it is a lumbermill then save it
            // as a target.
            else if (toEntity is LumberMill)
            {
                m_TargetLumberMill = (LumberMill)toEntity;
                if(!m_MyStateMachine.IsInState(GLumberjack_MillTravel.GetInstance()))
                    m_MyStateMachine.ChangeState(GLumberjack_MillTravel.GetInstance());
            }

            // Perform the normal logic.
            base.MoveDistanceInFrontOfEntity(toEntity, distance);
            Vector2 tempOut;
            if (FindPathToDestination(m_WorldPosition, m_DestinationPosition, out tempOut))
            {
                m_DestinationPosition = tempOut;
            }
            //Vector2 startIndex = Map.MapHandler.GetInstance().GetTileIndex(m_WorldPosition);
            //Vector2 endIndex = Map.MapHandler.GetInstance().GetTileIndex(m_DestinationPosition);
            //// Call path finder to find path from the startIndex to the endIndex.
            //m_pnCurrPath = m_pfMyPathFinder.FindPath(startIndex, endIndex);
            //// If a pass was found then set the first node in the path
            //// as the first destination.
            //if (m_pnCurrPath != null)
            //{
            //    m_DestinationPosition = Map.MapHandler.GetInstance().GetTilePosition(m_pnCurrPath.GetNodePosition());
            //}
        }
Esempio n. 4
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            Content.RootDirectory = "Content";

            m_TreeList = new List<TreeEntity>();
            m_TreeList.Add(new TreeEntity(new Vector2(2 * 64, 4 * 64/4 )));
            m_TreeList.Add(new TreeEntity(new Vector2(9 * 64 + 32, 7 * 64 / 4)));
            m_TreeList.Add(new TreeEntity(new Vector2(0 * 64, 0 * 64 / 4)));
            m_TreeList.Add(new TreeEntity(new Vector2(1 * 64, 10 * 64 / 4)));

            m_LumberMills = new List<LumberMill>();
            m_LumberMills.Add(new LumberMill(new Vector2(8 * 64, 8 * 64/4)));

            m_mouseSource = new Rectangle(0, 0, 19, 19);

            m_TestLayer = new MapLayer(new Vector2(m_LayerWidth, m_LayerHeight), new Vector2(64, 64));
            m_WaterLayer = new MapLayer(new Vector2(m_LayerWidth, m_LayerHeight), new Vector2(64, 64));

            GenerateRandomMap();

            //for (int i = 4; i < 6; i++)
            //{
            //    for (int j = 0; j < 22; j++)
            //        m_TestLayer.SetTileToSolid(i, j, m_bSetTilesToSolid);
            //}
            //m_TestLayer.SetTileToSolid(5, 21, false);
            //m_TestLayer.SetTileToSolid(4, 0, false);

            MapHandler.GetInstance().SetActiveLayer(m_TestLayer);
            SetTilesToSolid();

            m_TestTile = new MapTile(new Vector2(0, 0), 0, new Vector2(64,64));

            m_Gobling = new GoblinLumberjack(ENTITY_COLOR.RED, new Vector2(64 * 8, 0), DIRECTION.DOWN);

            ((GoblinLumberjack)m_Gobling).SetTargetLumberMill(m_LumberMills[0]);

            m_Gobling.SetEntitySpeed(new Vector2(1, 1));
            m_mapList = new List<List<int>>();
            m_mapList.Add(new List<int>() { });

            //List<Vector2> adjacents = MapHandler.GetInstance().GetAdjacentsToTile(new Vector2(5, 5));

            //for (int i = 0; i < adjacents.Count; i++)
            //{
            //    Console.WriteLine(adjacents[i]);
            //}

            //AStarPathFinder finder = new AStarPathFinder();
            //PathNode m_path = finder.FindPath(new Vector2(0, 0), new Vector2(3, 2));
            //AStarNode node = null;
            //if(m_path != null)
            //node = (AStarNode) m_path;

            //int counter = 0;
            //while (node != null)
            //{
            //    Console.WriteLine("" + counter + ": " + node.GetNodePosition());
            //    counter++;
            //    node = (AStarNode)node.GetNextNode();
            //}
        }
 public CompositeSquad(GameEntity squadLeader)
 {
     m_geSquadLeader = squadLeader;
     m_lstSquad = new List<BaseSquad>();
 }