예제 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //gui.AddWidget(panel1);

            // load all needed textures here

            #region textures
            shipTexture         = Content.Load <Texture2D>("ship01");
            enemyShipTexture1   = Content.Load <Texture2D>("ship02Flipped");
            enemyShipTexture2   = Content.Load <Texture2D>("ship03Flipped");
            energyBar           = Content.Load <Texture2D>("energyBar");
            healthBarFull       = Content.Load <Texture2D>("healthBarFull");
            healthBarMed        = Content.Load <Texture2D>("healthBarMed");
            healthBarLow        = Content.Load <Texture2D>("healthBarLow");
            shieldBubble        = Content.Load <Texture2D>("shieldBubble");
            gridSprite          = Content.Load <Texture2D>("Grid");
            gridHighlightSprite = Content.Load <Texture2D>("GridNotWalkable");
            energyBarSprite     = Content.Load <Texture2D>("energyBar");
            roomSprite          = Content.Load <Texture2D>("Room2x2");
            roomHighlightSprite = Content.Load <Texture2D>("Room2x2");
            pixel = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            pixel.SetData(new[] { Color.Green });
            crewNoAnimate          = Content.Load <Texture2D>("crewNoAnimate");
            starTexture            = Content.Load <Texture2D>("starNode");
            overworldCursorTexture = Content.Load <Texture2D>("overworldCursor");
            starGreyedTexture      = Content.Load <Texture2D>("starNodeGreyed");


            #endregion


            #region player ship construction

            //Vector2 playerShipStartPosition = new Vector2(50,50);

            gridWidth  = shipTexture.Bounds.Width / 32;
            gridHeight = shipTexture.Bounds.Height / 32;
            shipGrid   = new int[gridWidth, gridHeight];
            // initialize the player's ship

            // TODO: initialize all objects for a ship outside of the ship itself
            // pass in the UIDs of the grids, rooms, and weapons attributed with this ship

            // grid creation for the player ship
            for (int i = 0; i < shipTexture.Bounds.Width / 32; i++)
            {
                // in each column, iterate over the ship sprite's height
                for (int j = 0; j < shipTexture.Bounds.Height / 32; j++)
                {
                    // create a new grid object for i,j
                    //shipGrid[i, j] = new Grid(gridTexture, highlightTexture, new Vector2(i * 32 + position.X, j * 32 + position.Y), new Vector2(i, j));
                    Grid toAdd = new Grid(gridSprite, gridHighlightSprite,
                                          new Vector2(i * 32 + playerShipStartPosition.X, j * 32 + playerShipStartPosition.Y),
                                          new Vector2(i, j));

                    int UID = GridManager.AddEntity(toAdd);
                    gridUIDs.Add(UID);
                    shipGrid[i, j] = UID;
                }
            }

            // create rooms, add them to the manager, pass their UIDs to the ship
            int roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 1, 1, playerShipStartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
            roomUIDs.Add(roomUID);
            roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 3, 2, playerShipStartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
            roomUIDs.Add(roomUID);

            bool[] roomTypes = new bool[11];

            for (int i = 0; i < 11; i++)
            {
                roomTypes[i] = false;
            }



            int weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
            weaponUIDs.Add(weaponUID);


            weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
            weaponUIDs.Add(weaponUID);

            weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
            weaponUIDs.Add(weaponUID);

            weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
            weaponUIDs.Add(weaponUID);


            weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
            weaponUIDs.Add(weaponUID);

            System.Diagnostics.Debug.WriteLine(weaponUIDs.Count);


            playerShipUID = ShipManager.AddEntity(new Ship(shipTexture, gridSprite, gridHighlightSprite, playerShipStartPosition, roomUIDs, gridUIDs, weaponUIDs, roomTypes, shipGrid, 0));


            foreach (var item in weaponUIDs)
            {
                WeaponToShip[item] = playerShipUID;
            }


            setRoomGridDictionary(playerShipUID);
            setRoomToShipDictionary(playerShipUID, roomUIDs);
            setUnwalkableGrids(playerShipUID);
            filledRoomUIDs = setCrewDictionary(playerShipUID);
            setFilledDict(playerShipUID, filledRoomUIDs);


            //playerShip = new Ship(shipTexture, gridSprite, gridHighlightSprite, new Vector2(50, 50), roomUIDs, gridUIDs, weaponUIDs, roomTypes);



            #endregion



            #region enemy ship construction 1

            /*
             * //Vector2 enemyShipStartPosition = new Vector2(400,50);
             *
             * Vector2 enemyShipStartPosition;
             * enemyShipStartPosition = new Vector2(400, 50);
             *
             * gridUIDs = new List<int>();
             * roomUIDs = new List<int>();
             * weaponUIDs = new List<int>();
             * gridWidth = shipTexture.Bounds.Width / 32;
             * gridHeight = shipTexture.Bounds.Height / 32;
             * shipGrid = new int[gridWidth, gridHeight];
             * // grid creation for the player ship
             * for (int i = 0; i < shipTexture.Bounds.Width / 32; i++)
             * {
             *  // in each column, iterate over the ship sprite's height
             *  for (int j = 0; j < shipTexture.Bounds.Height / 32; j++)
             *  {
             *      // create a new grid object for i,j
             *      //shipGrid[i, j] = new Grid(gridTexture, highlightTexture, new Vector2(i * 32 + position.X, j * 32 + position.Y), new Vector2(i, j));
             *      Grid toAdd = new Grid(gridSprite, gridHighlightSprite,
             *                 new Vector2(i * 32 + enemyShip1StartPosition.X, j * 32 + enemyShip1StartPosition.Y),
             *                 new Vector2(i, j));
             *
             *      int UID = GridManager.AddEntity(toAdd);
             *      gridUIDs.Add(UID);
             *      shipGrid[i, j] = UID;
             *  }
             * }
             *
             * roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 3, 1, enemyShip1StartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
             * roomUIDs.Add(roomUID);
             * roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 3, 4, enemyShip1StartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
             * roomUIDs.Add(roomUID);
             *
             * roomTypes = new bool[11];
             *
             * for (int i = 0; i < 11; i++)
             * {
             *  roomTypes[i] = false;
             * }
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * System.Diagnostics.Debug.WriteLine(weaponUIDs.Count);
             *
             *
             * enemyShipUID1 = ShipManager.AddEntity(new Ship(shipTexture, gridSprite, gridHighlightSprite, playerShipStartPosition, roomUIDs, gridUIDs, weaponUIDs, roomTypes, shipGrid, 0));
             *
             *
             * foreach (var item in weaponUIDs)
             * {
             *  WeaponToShip[item] = enemyShipUID1;
             * }
             *
             *
             * WeaponToShip[weaponUID] = enemyShipUID1;
             * setRoomGridDictionary(enemyShipUID1);
             * setUnwalkableGrids(enemyShipUID1);
             */
            #endregion

            #region enemy ship construction 2

            /*
             * //enemyShipStartPosition = new Vector2(400, 50);
             * gridUIDs = new List<int>();
             * roomUIDs = new List<int>();
             * weaponUIDs = new List<int>();
             * gridWidth = shipTexture.Bounds.Width / 32;
             * gridHeight = shipTexture.Bounds.Height / 32;
             * shipGrid = new int[gridWidth, gridHeight];
             * // grid creation for the player ship
             * for (int i = 0; i < shipTexture.Bounds.Width / 32; i++)
             * {
             *  // in each column, iterate over the ship sprite's height
             *  for (int j = 0; j < shipTexture.Bounds.Height / 32; j++)
             *  {
             *      // create a new grid object for i,j
             *      //shipGrid[i, j] = new Grid(gridTexture, highlightTexture, new Vector2(i * 32 + position.X, j * 32 + position.Y), new Vector2(i, j));
             *      Grid toAdd = new Grid(gridSprite, gridHighlightSprite,
             *                 new Vector2(i * 32 + enemyShip2StartPosition.X, j * 32 + enemyShip2StartPosition.Y),
             *                 new Vector2(i, j));
             *
             *      int UID = GridManager.AddEntity(toAdd);
             *      gridUIDs.Add(UID);
             *      shipGrid[i, j] = UID;
             *  }
             * }
             *
             * roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 3, 1, enemyShip2StartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
             * roomUIDs.Add(roomUID);
             * roomUID = RoomManager.AddEntity(new Room(roomHighlightSprite, roomHighlightSprite, 3, 4, enemyShip2StartPosition, Globals.roomShape.TwoXTwo, Globals.roomType.EMPTY_ROOM, 2, 2));
             * roomUIDs.Add(roomUID);
             *
             * roomTypes = new bool[11];
             *
             * for (int i = 0; i < 11; i++)
             * {
             *  roomTypes[i] = false;
             * }
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * weaponUID = WeaponManager.AddEntity(new Weapon(gridSprite, 0, 0, 10, 500, 3));
             * weaponUIDs.Add(weaponUID);
             *
             * System.Diagnostics.Debug.WriteLine(weaponUIDs.Count);
             *
             *
             * enemyShipUID2 = ShipManager.AddEntity(new Ship(shipTexture, gridSprite, gridHighlightSprite, playerShipStartPosition, roomUIDs, gridUIDs, weaponUIDs, roomTypes, shipGrid, 0));
             *
             *
             * foreach (var item in weaponUIDs)
             * {
             *  WeaponToShip[item] = enemyShipUID2;
             * }
             *
             *
             * WeaponToShip[weaponUID] = enemyShipUID2;
             * setRoomGridDictionary(enemyShipUID2);
             * setUnwalkableGrids(enemyShipUID2);
             */
            #endregion
            // load fonts

            font = Content.Load <SpriteFont>("Calibri");

            // load gui elements

            skin = new Skin(Content.Load <Texture2D>("uiskin"), System.IO.File.ReadAllText("Content/uiskinmap.txt"));

            gui = new Gui(this, skin, new Ruminate.GUI.Framework.Text(font, Color.White));

            // add all text the GUI we may be using here

            gui.AddText("error", new Ruminate.GUI.Framework.Text(font, Color.Red));
            gui.AddText("password", new Ruminate.GUI.Framework.Text(font, Color.TransparentBlack));
            gui.AddText("empty", new Ruminate.GUI.Framework.Text(font, Color.LightSlateGray));


            #region stuff from initialize

            // initialize the state of all input managers
            currentKeyState    = Keyboard.GetState();
            currentMouseState  = Mouse.GetState();
            previousKeyState   = Keyboard.GetState();
            previousMouseState = Mouse.GetState();

            // initialize the game state machine and states

            #region state machine setup
            stateMachine = new StateMachine();

            startMenu = new State {
                Name = "startMenu"
            };
            battle = new State {
                Name = "battle"
            };
            pauseState = new State {
                Name = "pauseState"
            };
            overworld = new State {
                Name = "overworld"
            };
            narrative = new State {
                Name = "narrative"
            };
            introState = new State {
                Name = "introState"
            };


            startMenu.Transitions.Add(battle.Name, battle);
            startMenu.Transitions.Add(overworld.Name, overworld);
            startMenu.Transitions.Add(pauseState.Name, pauseState);
            startMenu.Transitions.Add(introState.Name, introState);


            battle.Transitions.Add(startMenu.Name, startMenu);
            battle.Transitions.Add(overworld.Name, overworld);
            battle.Transitions.Add(pauseState.Name, pauseState);

            pauseState.Transitions.Add(startMenu.Name, startMenu);
            pauseState.Transitions.Add(battle.Name, battle);

            overworld.Transitions.Add(battle.Name, battle);
            overworld.Transitions.Add(narrative.Name, narrative);
            overworld.Transitions.Add(pauseState.Name, pauseState);

            narrative.Transitions.Add(overworld.Name, overworld);
            narrative.Transitions.Add(pauseState.Name, pauseState);

            introState.Transitions.Add(overworld.Name, overworld);

            stateMachine.Start(battle);
            #endregion

            // set up any UI elements here

            #region ui setup


            #endregion

            // set up game objects

            crewMembers = new List <Crew>();

            // set up each game state
            setupStartMenu();
            setupBattle(playerShipUID);
            setupPauseState();
            setupOverworld();

            #endregion
        }
예제 #2
0
        public List <int> setCrewDictionary(int shipUID)
        {
            Ship thisShip = (Ship)ShipManager.RetrieveEntity(shipUID);



            // roomShipKeys: current room UIDs in current ship
            List <int> roomShipKeys = new List <int>();

            // gridRoomKeys: current grid UIDs in rooms on current ship
            List <int> gridRoomKeys = new List <int>();


            // This is looping over every room that exists.
            //System.Diagnostics.Debug.WriteLine("RoomToShip: " + RoomToShip.Keys.Count.ToString());
            foreach (int i in RoomToShip.Keys)
            {
                if (RoomToShip[i] == shipUID)
                {
                    //System.Diagnostics.Debug.WriteLine("This is getting the rooms: "+i.ToString());
                    roomShipKeys.Add(i);
                }
            }

            // This is looping over Grids in every room that exists.
            foreach (int i in GridToRoom.Keys)
            {
                if (roomShipKeys.Contains(GridToRoom[i]))
                {
                    //System.Diagnostics.Debug.WriteLine("This is getting the grids: " + i.ToString());
                    gridRoomKeys.Add(i);
                }
            }


            int mans = 0;

            List <int> filledRoomUIDs = new List <int>();

            foreach (int i in gridRoomKeys)
            {
                if (mans == 3)
                {
                    break;
                }

                Grid thisGrid = (Grid)GridManager.RetrieveEntity(i);

                Crew newguy = new Crew(thisGrid.Sprite.Position2D, thisGrid.GridPosition, crewNoAnimate, crewNoAnimate);

                int crewUID = CrewManager.AddEntity(newguy);

                CrewToShip[crewUID] = shipUID;
                CrewToRoom[crewUID] = GridToRoom[i];

                filledRoomUIDs.Add(i);


                mans++;
            }



            return(filledRoomUIDs);
        }