Beispiel #1
0
        private void checkDoors(MapTile mapTile, int x, int y)
        {
            //If the next tile is a closed door then check if we have the key
            if (mapTile.Tile.Category == "door" && mapTile.Tile.IsBlock)
            {
                //For each key if it matches then open the door by switching the sprite & sprite to its matching open version
                if (mapTile.Tile.Color == "brown" && _gameState.HasBrownKey)
                {
                    //Open the door
                    mapTile.Tile = _tiles["E"];
                    mapTile.SetSprite(x, y);
                }

                if (mapTile.Tile.Color == "red" && _gameState.HasRedKey)
                {
                    //Open the door
                    mapTile.Tile = _tiles["I"];
                    mapTile.SetSprite(x, y);
                }

                if (mapTile.Tile.Color == "green" && _gameState.HasGreenKey)
                {
                    //Open the door
                    mapTile.Tile = _tiles["G"];
                    mapTile.SetSprite(x, y);
                }
            }
        }
Beispiel #2
0
        public Area(StreamReader stream, Dictionary <string, Tile> tiles)
        {
            string line;

            //1st line is the name
            Name = stream.ReadLine().ToLower();

            //next 4 lines are which areas you go for N,E,S,W
            NorthArea = stream.ReadLine().ToLower();
            EastArea  = stream.ReadLine().ToLower();
            SouthArea = stream.ReadLine().ToLower();
            WestArea  = stream.ReadLine().ToLower();

            //Read in 8 lines of 8 characters each. Look up the tile and make the
            //matching sprite
            for (int j = 0; j < MapSizeY; j++)
            {
                //Get a line of map characters
                line = stream.ReadLine();

                for (int i = 0; i < MapSizeX; i++)
                {
                    MapTile mapTile = new MapTile();
                    Map[i, j]    = mapTile;
                    mapTile.Tile = tiles[line[i].ToString()];
                    mapTile.SetSprite(i, j);
                }
            }

            //Read game objects until the blank line
            while (!stream.EndOfStream && (line = stream.ReadLine().Trim()) != "")
            {
                //Each line is an x,y coordinate and a tile shortcut
                //Look up the tile and construct the sprite
                string[] elements = line.Split(',');
                int      x        = Convert.ToInt32(elements[0]);
                int      y        = Convert.ToInt32(elements[1]);
                MapTile  mapTile  = Map[x, y];
                mapTile.ObjectTile = tiles[elements[2]];
                mapTile.SetObjectSprite(x, y);

                if (mapTile.ObjectTile.IsTransparent)
                {
                    mapTile.ObjectSprite.ColorKey = Color.FromArgb(75, 75, 75);
                }
            }
        }