예제 #1
0
파일: Camera.cs 프로젝트: ericamccowan/ILS
        public static Camera getInstance()
        {
            if ( _instance == null )
            {
                _instance = new Camera();
            }

            return _instance;
        }
예제 #2
0
파일: LoadMap.cs 프로젝트: ericamccowan/ILS
        // Loading map with two player references:
        public void loadNewMap( ref AssistManager assistManager, ref AnimationManager animationManager, ref ArtManager artManager, ref DoorManager doorManager, ref Map currentMap, ref World world, ref Camera camera, ref Collision collision, ref TimerManager timerManager, ref NPCManager npcManager, ref Player player1, ref Player player2 )
        {
            // Start loadNewMap.

            // Getting the nextRoom/Map data then wiping it:
            string mapToLoad = world.nextMap;
            Vector2 nextRoomSize = world.nextRoomSize;
            Vector2 nextRoomStart = world.nextRoomStart;
            Vector2 exitPosition = world.nextExitPosition;
            bool localMultiplayer = Game1.Instance.LocalMultiplayer;
            world.resetNextMapData();

            // Resetting major classes:
            camera = new Camera();
            currentMap = new Map( );
            camera.resetSingletonData();
            collision = new Collision();

            player1.spriteAnimation.resetSingletonReferences(); // Reseting the draw variables (IE camera) for the player.
            if ( localMultiplayer )
            {
                player2.spriteAnimation.resetSingletonReferences();
            }

            animationManager = new AnimationManager( );
            artManager.tilesetList = new TilesetList();
            doorManager = new DoorManager();

            // Checking if we should initalize the asset manager with more than one player.
            if ( localMultiplayer )
            {
                assistManager = new AssistManager( ref player1, ref player2 );
            }
            else
            {
                assistManager = new AssistManager( ref player1 );
            }

            assistManager.initalizeSingletonData();
            npcManager = new NPCManager();

            // Reloading data:
            tmxLoading( ref mapToLoad, ref nextRoomSize, ref nextRoomStart, ref currentMap, ref camera, ref collision, ref assistManager, ref animationManager, ref doorManager, ref timerManager, ref npcManager, ref player1, ref player2 );
            artManager.tilesetList.loadAll( );

            // Reseting the starting position if need be:
            if ( exitPosition != Vector2.Zero )
            { // Start Exit Position if.

                // Adding the screenoffset to the position since it was not calculated when the exit position was read in.
                //player1.spriteAnimation.position = exitPosition + camera.screenOffset;
                player1.spriteAnimation.position = exitPosition;

                if ( localMultiplayer )
                {
                    //player2.spriteAnimation.position = exitPosition + camera.screenOffset;
                    player2.spriteAnimation.position = exitPosition;
                }

            } // Start Exit Position if.
            else
            { // Start exitPosition is zero else.

                player1.spriteAnimation.position = currentMap.playerOneStart;

                if ( localMultiplayer )
                {
                    player2.spriteAnimation.position = currentMap.playerTwoStart;
                }

            } // End exitPosition is zero else.
        }
예제 #3
0
파일: Game1.cs 프로젝트: ericamccowan/ILS
        protected override void Initialize()
        {
            // Start Initialize.

            // Initializing local variables:
            _currentID = 0; // Initialize ID to 0 so that the "world" is 0.

            // Initializing Draw variables:
            _viewPortColor = GameGlobals.viewPortColor;
            _spriteSortMode = GameGlobals.spriteSortMode;
            _samplerState = GameGlobals.samplerState;

            // Calling my custom object setup routines:
            GameData.getInstance().setUp();
            InputManager.getInstance().setUp();
            Physics.getInstance ();

            // Setting up any input as needed:
            InputManager.getInstance().addInputToMonitor( Buttons.B, GameGlobals.allPlayers, true );

            // setting up references to game systems and objects:
            _camera = Camera.getInstance ();

            // Setting the game state:
            _gameState = GameState.running;

            base.Initialize();
        }
예제 #4
0
파일: LoadMap.cs 프로젝트: ericamccowan/ILS
        public void tmxLoading( ref string mapName, ref Vector2 nextRoomSize, ref Vector2 nextRoomStart, ref Map currentMap, ref Camera camera, ref Collision collision, ref AssistManager assistManager, ref AnimationManager animationManager, ref DoorManager doorManager, ref TimerManager timerManager, ref NPCManager npcManager, ref Player player1, ref Player player2 )
        {
            // Start tmxloading Class.

            #region Setting up variables, ect.

            // Temp Map variables:
            byte row;
            byte column;
            int layerHeight;
            currentMap.layerNumber = -1; // Setting this to -1 so that the case statement will start at 0 without the need for a if statement.
            int tempLayerNumber;
            int tempTileGID;
            int tempMapWidth = 0;

            // Temp data to reduce function calls:
            int currentMapTileHeight;
            Vector2 screenOffset;

            // Temp values for Tileset and Image data:
            int tilesetOffset;
            string tilesetName;
            int tilesetWidth;
            int tilesetHeight;
            int tileWidth;
            int tileHeight;
            ulong trans;

            // Initializing object variables:

            // Basic object data:
            string tempName;
            string tempType;
            Vector2 tempPosition;
            int tempWidth;
            int tempHeight;
            bool tempHighlightAble;
            bool tempGlow;
            bool tempDraw;
            int tempLayer;
            bool tempCollidable;

            // Tileset & tileID data:
            string tempTileset;
            int tempTileID;
            int tempDestroyedTileID;
            int tempOpenTileID;
            int tempEmptyTileID;

            // Transition & Door specific data:
            string tempNextMap;
            Vector2 tempExitPosition;
            string tempExitDirection;
            Vector2 tempNextRoomSize;
            Vector2 tempNextRoomStart;
            string tempKey;
            bool tempAutoOpen;

            // Container specific data:
            bool tempIsFull;
            bool tempIsOpen;

            // Readable specific data:
            string tempConvoIndex;

            // Destroyable specific data:
            bool tempIsDestroyed;
            float tempHP;

            // Movable specific data:
            bool tempMovable;
            bool tempThrowable;

            // Switch specific data:
            string tempActivatable;

            // Actavatable specific data:
            Vector2 tempSlideEnd;
            float tempSlideTime;

            // Animation specific data:
            bool tempRunning;
            bool tempContinuous;
            int tempPlayCountMax;
            bool tempReverse;

            // NPC Specific data:
            int tempAge;
            bool tempMale;
            float tempWalkSpeed;
            float tempRunSpeed;

            #endregion

            currentMap.mapName = mapName; // Setting the map name.
            camera.currentRoomSize = nextRoomSize;
            camera.currentRoomStart = nextRoomStart;
            currentMap.currentRoomStart = nextRoomStart;

            // Default information that must be set because I am using a switch to load information:
            currentMapTileHeight = Globals.tileSize;
            screenOffset = Vector2.Zero;

            // Opening the map then reading it:
            using ( XmlReader reader = XmlReader.Create( content.RootDirectory + @"\Maps\" + mapName + ".tmx" ))

                while ( reader.Read() )
                { // Start read file while.

                    // Only detect start elements.
                    if ( reader.IsStartElement() )
                    { // Start IsStartElement if.

                        // Get element name and switch on it.
                        switch( reader.Name )
                        { // Start reader.Name switch.

                            #region Map Case.
                            case "map":

                                // Map Data attributes:
                                currentMap.mapVersion = Convert.ToSingle( reader["version"] );
                                currentMap.mapOrientation = reader["orientation"];
                                currentMap.mapWidth =  Convert.ToUInt16( reader["width"] );
                                currentMap.mapHeight = Convert.ToUInt16( reader["height"] );
                                currentMap.mapTileWidth = Convert.ToUInt16(reader["tilewidth"]);
                                currentMap.mapTileHeight = Convert.ToUInt16(reader["tileheight"]);
                                if ( currentMap.Rows.Count == 0 ) // Making sure the cell list has not been initialized yet;
                                {
                                    currentMap.initalizeCellList(); // Setting the map list to the correct size.
                                }

                                camera.resetCamera( ref nextRoomSize );

                                // Temp data to reduce function calls:
                                currentMapTileHeight = currentMap.mapTileHeight;

                                tempMapWidth = currentMap.mapWidth - 1;

                                screenOffset = camera.screenOffset;

                                collision.screenOffset = screenOffset;

                                break; // End Map Data case.
                            #endregion

                            #region Tileset Case
                            case "tileset":

                                #region Initalizing variables

                                // Initializing variables:
                                //tOffset = 0;
                                //tName = "";
                                //tWidth = 0;
                                //tHeight = 0;
                                //tsWidth = 0;
                                //tsHeight = 0;
                                //trans = 0;

                                #endregion

                                // Reading the "tileset" attributes:
                                tilesetOffset = Convert.ToUInt16(reader["firstgid"]);
                                tilesetName = reader["name"];

                                // Breaking if a tileset should not be loaded:
                                if ( tilesetName == "Animation" )
                                {
                                    break;
                                }

                                tileWidth = Convert.ToUInt16(reader["tilewidth"]);
                                tileHeight = Convert.ToUInt16(reader["tileheight"]);

                                // Moving to the "image" element:
                                reader.ReadToFollowing("image");

                                // REading the "image" attributes:
                                trans = Convert.ToUInt64(reader["trans"], 16);
                                tilesetWidth = Convert.ToUInt16(reader["width"]);
                                tilesetHeight = Convert.ToUInt16(reader["height"]);

                                // Adding the tileset and image information to the dictionary:
                                artManager.tilesetList.addTilesetToLoad( ref tilesetName, ref tilesetOffset, ref tileWidth, ref tileHeight, ref tilesetWidth, ref tilesetHeight, ref trans );

                                break; // End tileset case.
                            #endregion

                            #region Layer Case
                            case "layer":

                                #region Initalizing variables

                                // Initializing variables:
                                currentMap.layerNumber += 1;
                                tempLayerNumber = currentMap.layerNumber;
                                column = 0;
                                row = 0;
                                tileWidth = Globals.tileSize;

                                #endregion

                                switch( reader["name"] )
                                { // Start Layer validation switch.

                                    #region case List for layers (1 case per map layer)
                                    case "Ground Layer 1":
                                    case "Ground Layer 2":
                                    case "Impassable Layer":
                                    case "Upper Layer":
                                    case "Roof Layer":
                                    case "Sky Layer 1":
                                    case "Sky Layer 2":
                                    #endregion

                                    // Getting the height of this layer:
                                    layerHeight = Convert.ToUInt16( reader["height"] );

                                    while ( row < layerHeight - 0 )
                                    { // Start layer while.

                                        reader.ReadToFollowing("tile");
                                        tempTileGID = Convert.ToInt32( reader["gid"] );

                                        #region Start Layer 2 ( Collision Layer ) If.
                                        if (tempLayerNumber == 2)
                                        { // Start layer 2 if.

                                            switch (tempTileGID)
                                            { // Start tempTileGID switch.

                                                #region Do nothing (0)
                                                case 0:

                                                    break;
                                                #endregion

                                                #region Grass ( 264 )
                                                case 264:

                                                    assistManager.addGrass(new Vector2(column * tileWidth, row * tileWidth));
                                                    currentMap.Rows[row].Columns[column].layerList[tempLayerNumber] = tempTileGID;

                                                    break;
                                                #endregion

                                                #region Cut Grass ( 265 )
                                                case 265:

                                                    assistManager.addCutGrass(new Vector2(column * tileWidth, row * tileWidth));
                                                    currentMap.Rows[row].Columns[column].layerList[tempLayerNumber] = tempTileGID;

                                                    break;
                                                #endregion

                                                #region Water Cases

                                                #region Water - ShoreTop1 ( 942 )
                                                case 942:

                                                    animationManager.addWaterToRunning( "ShoreTop1", "ShoreTop1", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreTop2 ( 943 )
                                                case 943:

                                                    animationManager.addWaterToRunning( "ShoreTop2", "ShoreTop2", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShallowLeft ( 944 )
                                                case 944:

                                                    animationManager.addWaterToRunning( "ShallowLeft", "ShallowLeft", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShallowTop ( 945 )
                                                case 945:

                                                    animationManager.addWaterToRunning( "ShallowTop", "ShallowTop", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShallowRight ( 946 )
                                                case 946:

                                                    animationManager.addWaterToRunning( "ShallowRight", "ShallowRight", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreAngleLeft1 ( 975 )
                                                case 975:

                                                    animationManager.addWaterToRunning( "ShoreAngleLeft1", "ShoreAngleLeft1", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreAngleLeft2 ( 976 )
                                                case 976:

                                                    animationManager.addWaterToRunning( "ShoreAngleLeft2", "ShoreAngleLeft2", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreAngleAngleRight1 ( 974 )
                                                case 974:

                                                    animationManager.addWaterToRunning( "ShoreAngleAngleRight1", "ShoreAngleAngleRight1", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreAngleAngleRight2 ( 977 )
                                                case 977:

                                                    animationManager.addWaterToRunning( "ShoreAngleAngleRight2", "ShoreAngleAngleRight2", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreRight ( 978 )
                                                case 978:

                                                    animationManager.addWaterToRunning( "ShoreRight", "ShoreRight", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - ShoreLeft ( 1016 )
                                                case 1016:

                                                    animationManager.addWaterToRunning( "ShoreLeft", "ShoreLeft", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - Deep1 ( 1017 )
                                                case 1017:

                                                    animationManager.addWaterToRunning( "Deep1", "Deep1", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - Deep2 ( 1018 )
                                                case 1018:

                                                    animationManager.addWaterToRunning( "Deep2", "Deep2", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - Deep3 ( 1019 )
                                                case 1019:

                                                    animationManager.addWaterToRunning( "Deep3", "Deep3", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - Deepst1 ( 1020 )
                                                case 1020:

                                                    animationManager.addWaterToRunning( "Deepst1", "Deepst1", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #region Water - Deepst2 ( 1021 )
                                                case 1021:

                                                    animationManager.addWaterToRunning( "Deepst2", "Deepst2", false, false, false, new Vector2( column * tileWidth, row * tileWidth ), true, true, 0, true, 1, false );
                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = 266;

                                                    break;
                                                #endregion

                                                #endregion

                                                #region Evrything else
                                                default:

                                                    currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = tempTileGID;

                                                    break;
                                                #endregion

                                            } // End tempTileGID switch.
                                        } // End layer 2 if.
                                        #endregion
                                        else
                                        { // Start not layer 2 else.

                                            currentMap.Rows[ row ].Columns[ column ].layerList[ tempLayerNumber ] = tempTileGID;

                                        } // End not layer 2 else.

                                        column++; // Increasing the column position.

                                        if ( column > tempMapWidth ) // Checking to see if we have exceeded the total number of columns.
                                        {
                                            column = 0; // Reseting column count.
                                            row++; // Moving to the next row.
                                        }
                                    } // End layer while.

                                    break; // End of layer case's.

                                } // End Layer validation switch.

                                break; // End layer case.
                            #endregion

                            #region Object Case
                            case "object":

                                switch( reader[ "type" ] )
                                { // Start reader type case.

                                    #region Object Loading

                                    #region Object Type case List (1 case for each object):
                                    case "Object":
                                    case "Readable":
                                    case "Destroyable":
                                    case "Switch":
                                    case "Container":
                                    case "Grass":
                                    case "Decoration":
                                    #endregion

                                        #region Initalizing variables:

                                        // Basic object data:
                                            tempName = "";
                                            tempType = "";
                                            tempPosition = Vector2.Zero;
                                            tempWidth = 0;
                                            tempHeight = 0;

                                        // Other Object Data:
                                            tempActivatable = "";
                                            tempConvoIndex = "";
                                            tempDestroyedTileID = 0;
                                            tempDraw = true;
                                            tempEmptyTileID = 0;
                                            tempGlow = false;
                                            tempHighlightAble = true;
                                            tempCollidable = true;
                                            tempHP = 1.0f;
                                            tempIsDestroyed = false;
                                            tempIsFull = false;
                                            tempIsOpen = false;
                                            tempLayer = 0;
                                            tempMovable = false;
                                            tempOpenTileID = 0;
                                            tempThrowable = false;
                                            tempTileID = 0;
                                            tempTileset = "";

                                        #endregion

                                        // Reading generic object information:
                                        tempName = reader[ "name" ];
                                        tempType = reader[ "type" ];
                                        tempPosition.X = float.Parse( reader[ "x" ]);
                                        tempPosition.Y = float.Parse( reader[ "y" ]);
                                        tempWidth = Convert.ToUInt16( reader[ "width" ]);
                                        tempHeight = Convert.ToUInt16( reader[ "height" ]);

                                        // Reading the "activatable" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempActivatable = reader["value"];
                                        }

                                        // Reading the collidable element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute( "collidable" );
                                        if ( reader["value"] == "False" || reader["value"] == "false")
                                        {
                                            tempCollidable = false;
                                        }

                                        // Reading the "convoIndex" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempConvoIndex = reader["value"];
                                        }

                                        // Reading the "destroyedTileID"
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempDestroyedTileID = Convert.ToUInt16( reader[ "value" ]);
                                        }

                                        // Reading the draw element:
                                        reader.ReadToFollowing( "property" );
                                        reader.MoveToAttribute( "draw" );
                                        if ( reader[ "value" ] == "False" || reader[ "value" ] == "false" )
                                        {
                                            tempDraw = false;
                                        }

                                        // Reading the "emptyTileID"
                                        reader.ReadToFollowing( "property" );
                                        if (reader["value"] != "")
                                        {
                                            tempEmptyTileID = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the Glow element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("glow");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempGlow = true;
                                        }

                                        // Reading the HighlightAble element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("highlightAble");
                                        if ( reader["value"] == "False" || reader["value"] == "false" )
                                        {
                                            tempHighlightAble = false;
                                        }

                                        // Reading the "hp" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempHP = float.Parse(reader["value"]);
                                        }

                                        // Reading the isDestroyed" element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("isDestroyed");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempIsDestroyed = true;
                                        }

                                        // Reading the isFull element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("isFull");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempIsFull = true;
                                        }

                                        // Reading the isOpen element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("isOpen");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempIsOpen = true;
                                        }

                                        // Reading the "layer" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempLayer = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the Movable element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("movable");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempMovable = true;
                                        }

                                        // Reading the "openTileID" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempOpenTileID = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the throwable element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("throwable");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempThrowable = true;
                                        }

                                        // Reading the "tileID" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileID = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "tileset" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileset = reader["value"];
                                        }

                                        //Adding the Destructible to the list:
                                        if (player2 == null)
                                        {
                                           assistManager.addObject( ref tempName, ref tempType, ref tempPosition, ref tempWidth, ref tempHeight, ref tempConvoIndex, ref tempDestroyedTileID, ref tempEmptyTileID, ref tempGlow, ref tempHighlightAble, ref tempCollidable, ref tempHP, ref tempIsDestroyed, ref tempIsFull, ref tempIsOpen, ref tempMovable, ref tempOpenTileID, ref tempThrowable, ref tempTileID, ref tempTileset, ref tempActivatable, ref tempDraw, ref tempLayer, ref player1);
                                        }
                                        else
                                        {
                                            assistManager.addObject( ref tempName, ref tempType, ref tempPosition, ref tempWidth, ref tempHeight, ref tempConvoIndex, ref tempDestroyedTileID, ref tempEmptyTileID, ref tempGlow, ref tempHighlightAble, ref tempCollidable, ref tempHP, ref tempIsDestroyed, ref tempIsFull, ref tempIsOpen, ref tempMovable, ref tempOpenTileID, ref tempThrowable, ref tempTileID, ref tempTileset, ref tempActivatable, ref tempDraw, ref tempLayer, ref player1, ref player2);

                                        }

                                        break;
                                    #endregion

                                    #region Starting Point
                                        case "Starting Point":

                                            #region Initalizing variables:

                                            // Temp data to reduce function calls:
                                            screenOffset = camera.screenOffset;

                                            #endregion

                                            // Reading the players starting points:
                                            if( reader[ "name" ] == "P1" )
                                            { // Start P1 starting point if.

                                                //currentMap.playerOneStart = new Vector2( float.Parse( reader["x"] ) + screenOffset.X, float.Parse( reader[ "y" ]) + screenOffset.Y );
                                                currentMap.playerOneStart = new Vector2( float.Parse( reader["x"] ), float.Parse( reader[ "y" ] ) );

                                            } // End P1 starting point if.
                                            else if( player2 != null && reader[ "name" ] == "P2" )
                                            { // Start P2 starting point else if.

                                                //currentMap.playerTwoStart = new Vector2( float.Parse( reader["x"] ) + screenOffset.X, float.Parse( reader[ "y" ] ) + screenOffset.Y );
                                                currentMap.playerTwoStart = new Vector2( float.Parse( reader["x"] ), float.Parse( reader[ "y" ] ) );

                                            } // End P2 starting point else if.

                                            break;
                                    #endregion

                                    #region Activatable

                                    case "Activatable":

                                        #region Initalizing variables:

                                        // Basic object data:
                                        tempName = "";
                                        tempType = "";
                                        tempPosition = Vector2.Zero;
                                        tempWidth = 0;
                                        tempHeight = 0;

                                        // Other Object Data:
                                        tempDraw = true;
                                        tempGlow = false;
                                        tempHighlightAble = false;
                                        tempTileID = 0;
                                        tempTileset = "";

                                        // Actavatable specific data:
                                        tempSlideEnd = Vector2.Zero;
                                        tempSlideTime = 0.0f;

                                        // Temp data to reduce function calls:
                                        currentMapTileHeight = currentMap.mapTileHeight;
                                        screenOffset = camera.screenOffset;

                                        #endregion

                                        // Reading generic object information:
                                        tempName = reader["name"];
                                        tempPosition.X = float.Parse(reader["x"]);
                                        tempPosition.Y = float.Parse(reader["y"]);
                                        tempWidth = Convert.ToUInt16(reader["width"]);
                                        tempHeight = Convert.ToUInt16(reader["height"]);

                                        // Reading the "tempType" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempType = reader["value"];
                                        }

                                        // Reading the draw element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("draw");
                                        if ( reader["value"] == "False" || reader["value"] == "false" )
                                        {
                                            tempDraw = false;
                                        }

                                        // Reading the Glow element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("glow");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempGlow = true;
                                        }
                                        else
                                        {
                                            tempGlow = false;
                                        }

                                        // Reading the HighlightAble element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("highlightAble");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempHighlightAble = true;
                                        }

                                        // Reading the "Slide End X" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            //tempSlideEnd.X = ( ( float.Parse(reader["value"]) * currentMapTileHeight ) + screenOffset.X );
                                            tempSlideEnd.X = ( (float.Parse(reader["value"]) * currentMapTileHeight) );
                                        }

                                        // Reading the "Slide End Y" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            //tempSlideEnd.Y = ( ( float.Parse(reader["value"]) * currentMapTileHeight ) + screenOffset.Y );
                                            tempSlideEnd.Y = (( float.Parse( reader["value"] ) * currentMapTileHeight) );
                                        }

                                        // Reading the "Slide Time" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempSlideTime = (float.Parse(reader["value"]) );
                                        }

                                        // Reading the "tileID" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileID = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "tileset" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileset = reader["value"];
                                        }

                                        // Adding the Actavatable to the list:
                                        if ( player2 == null )
                                        {
                                            assistManager.addActivatable( ref tempName, ref tempType, ref tempPosition, ref tempWidth,
                                                ref tempHeight, ref tempHighlightAble, ref tempGlow, ref tempSlideTime,
                                                ref tempSlideEnd, ref tempTileset, ref tempTileID,
                                                player1 );

                                        }
                                        else
                                        {
                                            assistManager.addActivatable( ref tempName, ref tempType, ref tempPosition, ref tempWidth,
                                                ref tempHeight, ref tempHighlightAble, ref tempGlow, ref tempSlideTime,
                                                ref tempSlideEnd, ref tempTileset, ref tempTileID, player1, player2 );

                                        }

                                        break;
                                    #endregion Activatable

                                    #region Animation

                                    case "Animation":

                                        #region Initalizing variables:

                                        // Basic object data:
                                        tempName = "";
                                        tempType = "";
                                        tempPosition = Vector2.Zero;

                                        // Other Object Data:
                                        tempDraw = true;
                                        tempGlow = false;
                                        tempHighlightAble = false;
                                        tempCollidable = true;
                                        tempLayer = 0;
                                        tempTileset = "";

                                        // Animation specific data:
                                        tempReverse = false;
                                        tempRunning = false;
                                        tempContinuous = false;
                                        tempPlayCountMax = 0;

                                        // Temp data to reduce function calls:
                                        screenOffset = camera.screenOffset;

                                        #endregion

                                        // Reading generic object information:
                                        tempName = reader["name"];
                                        tempPosition.X = float.Parse( reader["x"] );
                                        tempPosition.Y = float.Parse( reader["y"] );

                                        // Reading the "Type" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempType = reader["value"];
                                        }

                                        // Reading the collidable element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("collidable");
                                        if (reader["value"] == "False" || reader["value"] == "false")
                                        {
                                            tempCollidable = false;
                                        }

                                        // Reading the continuous element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("continuous");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempContinuous = true;
                                        }

                                        // Reading the draw element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("draw");
                                        if ( reader["value"] == "False" || reader["value"] == "false" )
                                        {
                                            tempDraw = false;
                                        }

                                        // Reading the Glow element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("glow");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempGlow = true;
                                        }

                                        // Reading the HighlightAble element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("highlightAble");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempHighlightAble = true;
                                        }

                                        // Reading the "layer" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempLayer = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "playCountMax" element:
                                        reader.ReadToFollowing("property");
                                        if ( reader["value"] != "" )
                                        {
                                            tempPlayCountMax = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the reverse element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("continuous");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempReverse = true;
                                        }

                                        // Reading the running element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("running");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempRunning = true;
                                        }

                                        // Reading the "tileset" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileset = reader["value"];
                                        }

                                        // Adding the new animation:
                                        animationManager.addAnimationToRunning( ref tempType, ref tempName, ref tempGlow, ref tempHighlightAble, tempCollidable, ref tempPosition, ref tempRunning, ref tempContinuous, ref tempPlayCountMax, ref tempLayer, ref tempDraw, ref tempReverse );

                                        break;
                                    #endregion Animation

                                    #region Doors

                                    case "Door":

                                        #region Initalizing variables:

                                        // Basic object data:
                                        tempName = "";
                                        tempType = "";
                                        tempPosition = Vector2.Zero;

                                        // Other Object Data:
                                        tempDraw = true;
                                        tempExitPosition = Vector2.Zero;
                                        tempExitDirection = "";
                                        tempNextRoomSize = Vector2.Zero;
                                        tempNextRoomStart = Vector2.Zero;
                                        tempGlow = false;
                                        tempHighlightAble = false;
                                        tempHP = 1.0f;
                                        tempIsOpen = false;
                                        tempLayer = 0;
                                        tempNextMap = "";
                                        tempTileset = "";
                                        tempTileID = 0;
                                        tempReverse = false;
                                        tempAutoOpen = false;

                                        // Temp data to reduce function calls:
                                        screenOffset = camera.screenOffset;

                                        // Door Specific data:
                                        tempKey = "";

                                        #endregion

                                        // Reading generic object information:
                                        tempName = reader["name"];
                                        tempPosition.X = float.Parse(reader["x"]);
                                        tempPosition.Y = float.Parse(reader["y"]);

                                        // Reading the "Type" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempType = reader["value"];
                                        }

                                        // Reading the draw element:
                                        reader.ReadToFollowing( "property" );
                                        reader.MoveToAttribute( "draw" );
                                        if ( reader[ "value" ] == "True" || reader[ "value" ] == "true" )
                                        {
                                            tempAutoOpen = true;
                                        }

                                        // Reading the draw element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("draw");
                                        if ( reader["value"] == "False" || reader["value"] == "false" )
                                        {
                                            tempDraw = false;
                                        }

                                        // Reading the "exitDirection" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempExitDirection = reader["value"];
                                        }

                                        // Reading the "Exit X" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempExitPosition.X = ( float.Parse(reader["value"]) * currentMapTileHeight );
                                        }

                                        // Reading the "Exit Y" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempExitPosition.Y = ( float.Parse(reader["value"]) * currentMapTileHeight );
                                        }

                                        // Reading the Glow element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("glow");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempGlow = true;
                                        }

                                        // Reading the HighlightAble element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("highlightAble");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempHighlightAble = true;
                                        }

                                        // Reading the "hp" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempHP = float.Parse(reader["value"]);
                                        }

                                        // Reading the isOpen element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("isOpen");
                                        if ( reader["value"] == "True" || reader["value"] == "true" )
                                        {
                                            tempIsOpen = true;
                                        }

                                        // Reading the "key" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempKey = reader["value"];
                                        }

                                        // Reading the "layer" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempLayer = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "nextMap" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempNextMap = reader["value"];
                                        }

                                        // Reading the "roomSizeX" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempNextRoomSize.X = ( float.Parse(reader["value"]) * currentMapTileHeight );
                                        }

                                        // Reading the "roomSizeY" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempNextRoomSize.Y = ( float.Parse(reader["value"]) * currentMapTileHeight );
                                        }

                                        // Reading the "roomStartX" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempNextRoomStart.X = (float.Parse(reader["value"]) * currentMapTileHeight);
                                        }

                                        // Reading the "roomStartY" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempNextRoomStart.Y = (float.Parse(reader["value"]) * currentMapTileHeight);
                                        }

                                        // Reading the "tileID" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileID = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "tileset" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempTileset = reader["value"];
                                        }

                                        doorManager.addDoor( ref collision, ref tempName, ref tempType, ref tempAutoOpen, ref tempTileID, ref tempPosition, ref tempIsOpen, ref tempKey, ref tempGlow, ref tempHighlightAble, ref tempHP, ref tempTileset, ref tempDraw, ref tempLayer, ref tempNextMap, ref tempExitPosition, ref tempExitDirection, ref tempNextRoomStart, ref tempNextRoomSize, ref player1 );

                                        break;

                                    #endregion

                                    #region NPC

                                    case "NPC":

                                        #region Initalizing variables:

                                        // Basic object data:
                                        tempName = "";
                                        tempType = "";
                                        tempPosition = Vector2.Zero;

                                        // Other Object Data:
                                        tempConvoIndex = "";
                                        tempHP = 1.0f;

                                        // NPC specific data:
                                        tempAge = 0;
                                        tempMale = true;
                                        tempWalkSpeed = 200.0f;
                                        tempRunSpeed = 350.0f;

                                        // Temp data to reduce function calls:
                                        screenOffset = camera.screenOffset;

                                        #endregion

                                        // Reading generic object information:
                                        tempName = reader["name"];
                                        tempPosition.X = float.Parse(reader["x"]);
                                        tempPosition.Y = float.Parse(reader["y"]);

                                        // Reading the "Type" element:
                                        reader.ReadToFollowing( "property" );
                                        if (reader[ "value" ] != "" )
                                        {
                                            tempType = reader[ "value" ];
                                        }

                                        // Reading the "age" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempAge = Convert.ToUInt16(reader["value"]);
                                        }

                                        // Reading the "convoIndex" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempConvoIndex = reader["value"];
                                        }

                                        // Reading the "hp" element:
                                        reader.ReadToFollowing("property");
                                        if (reader["value"] != "")
                                        {
                                            tempHP = float.Parse(reader["value"]);
                                        }

                                        // Reading the male element:
                                        reader.ReadToFollowing("property");
                                        reader.MoveToAttribute("male");
                                        if ( reader["value"] == "False" || reader["value"] == "false" )
                                        {
                                            tempMale = false;
                                        }

                                        // Reading the "runSpeed" element:
                                        reader.ReadToFollowing("property");
                                        if ( reader["value"] != "" )
                                        {
                                            tempRunSpeed = float.Parse(reader["value"]);
                                        }

                                        // Reading the "walkSpeed" element:
                                        reader.ReadToFollowing("property");
                                        if ( reader["value"] != "" )
                                        {
                                            tempWalkSpeed = float.Parse(reader["value"]);
                                        }

                                        // Adding the new NPC:
                                        npcManager.addNPC( tempType, tempName, tempAge, tempMale, tempHP, tempConvoIndex, tempWalkSpeed, tempRunSpeed, tempPosition );

                                        break;

                                    #endregion

                                    #region Collision Object

                                    case "CollisionObject":

                                        #region Initalizing variables:

                                        // Basic object data:
                                        tempName = "";
                                        tempPosition = Vector2.Zero;
                                        tempWidth = 0;
                                        tempHeight = 0;

                                        // Temp data to reduce function calls:
                                        screenOffset = camera.screenOffset;

                                        #endregion

                                        // Reading generic collision object information:
                                        tempName = reader["name"];
                                        tempPosition.X = float.Parse(reader["x"]);
                                        tempPosition.Y = float.Parse(reader["y"]);
                                        tempWidth = Convert.ToUInt16(reader["width"]);
                                        tempHeight = Convert.ToUInt16(reader["height"]);

                                        // Adding the new NPC:
                                        assistManager.addCollisionObject( ref tempName, ref tempPosition, ref tempWidth, ref tempHeight, ref player1 );

                                        break;

                                    #endregion

                                } // End reader type case.

                                break; // End object group

                            #endregion

                        } // End reader.name switch.
                    } // End IsStartElement if.
                } // End read file while.
        }
예제 #5
0
파일: Map.cs 프로젝트: ericamccowan/ILS
        } // End constructor.
        #endregion


        public void setUp( string mapName, float mapVersion, string mapOrientation, int mapWidth, int mapHeight, int mapTileWidth, int mapTileHeight, int numberOfLayers, List<MapRow> rowList )
        { // Start Setup.

            // Singleton reference cache:
            _camera = Camera.getInstance();
            _gameData = GameData.getInstance();
            _spriteBatch = Game1.Instance.SpriteBatch;

            // Information loaded from the map:
            _mapName = mapName;
            _mapVersion = mapVersion;
            _mapOrientation = mapOrientation;
            _mapWidth = mapWidth;
            _mapHeight = mapHeight;
            _mapTileWidth = mapTileWidth;
            _mapTileHeight = mapTileHeight;
            _numberOfLayers = numberOfLayers;
            _rowList = rowList;

            // Getting the texture:
            if ( _gameData.ArtManager.ContainsKey ( mapName ) )
                _texture = _gameData.ArtManager.getObject ( _mapName );
            else
                _texture = _gameData.ArtManager.getObject ( GameGlobals.defaultGraphicFiles[1] );

            _textureWidth = _texture.Width;
            _textureHeight = _texture.Height;

            // Setting basic draw data based on defaults:
            _sourceRect = Rectangle.Empty;
            _sourceRect.Width = _mapTileWidth;
            _sourceRect.Height = _mapTileHeight;
            _tint = MapGlobals.defaultTint;
            _rotation = MapGlobals.defaultRotation;
            _origin = MapGlobals.defaultOrigin;
            _scale = MapGlobals.defaultScale;
            _spriteEffect = MapGlobals.defaultSpriteEffect;
            _layer = 1.0f;
            _tilesToViewAcross = (int) ( _gameData.ViewportWidth / _mapTileWidth );
            _tilesToViewDown = (int) ( _gameData.ViewportHeight / _mapTileHeight );
            //_rotationCompensatorMultiplier = MapGlobals.tileViewMultiplier;

        } // End Setup.