Example #1
0
 protected override void LoadContent()
 {
     Archive.Initialize(Content);
     ItemDatabase.Initialize();
     DialogDictionary.Initialize();
     CombatTeamDatabase.Initialize();
     spriteBatch = new SpriteBatch(GraphicsDevice);
 }
Example #2
0
        protected void PlaceTile()
        {
            int XValue = (int)((KeyMouseReader.mousePosition.X - tileGridOffset.X) / tileSize);
            int YValue = (int)((KeyMouseReader.mousePosition.Y - tileGridOffset.Y) / tileSize);

            if (KeyMouseReader.mouseState.LeftButton == ButtonState.Pressed)
            {
                if (selectedTileType == 0 || selectedTileType == 1)
                {
                    if ((XValue >= 0 && XValue < entityArray.GetLength(0)) &&
                        (YValue >= 0 && YValue < entityArray.GetLength(1)))
                    {
                        if (selectedTileType == 0)
                        {
                            tileArray[XValue, YValue] = new Tile(selectedTile.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y), false);
                        }
                        if (selectedTileType == 1)
                        {
                            tileArray[XValue, YValue] = new Tile(selectedTile.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y), true);
                        }
                    }
                }
                else if (selectedTileType == 2 || selectedTileType == 3 || selectedTileType == 4)
                {
                    if ((XValue >= 0 && XValue < entityArray.GetLength(0)) &&
                        (YValue >= 0 && YValue < entityArray.GetLength(1)))
                    {
                        if (selectedEntity is Player)
                        {
                            entityArray[XValue, YValue] = new Player(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y), new List <Item>());
                        }
                        else if (selectedEntity is Enemy)
                        {
                            string indexName = Prompt.ShowEnemySelector();
                            if (indexName != "")
                            {
                                entityArray[XValue, YValue]      = new Enemy(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y));
                                entityArray[XValue, YValue].team = CombatTeamDatabase.GetTeam(indexName);
                            }
                        }
                        else if (selectedEntity is FriendlyEntity)
                        {
                            string indexName = Prompt.ShowDialogSelector();
                            if (indexName != "")
                            {
                                entityArray[XValue, YValue] = new FriendlyEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                                 DialogDictionary.dialogDictionary[indexName]);
                            }
                        }
                        else if (selectedEntity is ItemEntity)
                        {
                            string indexName = Prompt.ShowItemSelector();
                            if (indexName != "")
                            {
                                entityArray[XValue, YValue] = new ItemEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                             ItemDatabase.items[indexName]);
                            }
                        }
                        else if (selectedEntity is PortalEntity)
                        {
                            if (XValue == 0)
                            {
                                entityArray[XValue, YValue] = new PortalEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                               selectedPortalLocation, new Vector2((entityArray.GetLength(0) - 2) * tileSize, YValue * tileSize));
                            }
                            else if (XValue == (entityArray.GetLength(0) - 1))
                            {
                                entityArray[XValue, YValue] = new PortalEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                               selectedPortalLocation, new Vector2(tileSize, YValue * tileSize));
                            }
                            else if (YValue == 0)
                            {
                                entityArray[XValue, YValue] = new PortalEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                               selectedPortalLocation, new Vector2(XValue * tileSize, (entityArray.GetLength(1) - 2) * tileSize));
                            }
                            else if (YValue == (entityArray.GetLength(1) - 1))
                            {
                                entityArray[XValue, YValue] = new PortalEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                               selectedPortalLocation, new Vector2(XValue * tileSize, tileSize));
                            }
                            else
                            {
                                string tempString = Interaction.InputBox("Input coordinate X", "Data text", "0");
                                if (tempString != "")
                                {
                                    int xCoordinate = Int32.Parse(tempString);
                                    tempString = "";
                                    tempString = Interaction.InputBox("Input coordinate Y", "Data text", "0");
                                    if (tempString != "")
                                    {
                                        int yCoordinate = Int32.Parse(tempString);
                                        entityArray[XValue, YValue] = new PortalEntity(selectedEntity.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                                       selectedPortalLocation, new Vector2((float)xCoordinate * tileSize, (float)yCoordinate * tileSize));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (KeyMouseReader.mouseState.RightButton == ButtonState.Pressed)
            {
                if (selectedTileType == 2 || selectedTileType == 3 || selectedTileType == 4)
                {
                    if ((XValue >= 0 && XValue < entityArray.GetLength(0)) &&
                        (YValue >= 0 && YValue < entityArray.GetLength(1)))
                    {
                        entityArray[XValue, YValue] = null;
                    }
                }
            }
        }
Example #3
0
        public static Map ReadMap(string mapname)
        {
            List <string> strings      = new List <string>();
            StreamReader  streamReader = new StreamReader(mapname);
            Map           map          = new Map();

            Tile[,] mapGrid = new Tile[46, 26];

            while (!streamReader.EndOfStream)
            {
                string   mapValue    = streamReader.ReadLine();
                string[] stringArray = mapValue.Split(';');

                if (stringArray[0] != "zone")
                {
                    int       xPosition = Int32.Parse(stringArray[2]);
                    int       yPosition = Int32.Parse(stringArray[3]);
                    Vector2   position  = new Vector2(Int32.Parse(stringArray[2]), Int32.Parse(stringArray[3]));
                    Texture2D texture   = Archive.textureDictionary[stringArray[1]];

                    switch (stringArray[0])
                    {
                    case "tile":
                        bool isWallTile = bool.Parse(stringArray[4]);
                        mapGrid[xPosition / 32, yPosition / 32] = new Tile(texture, position, isWallTile);
                        break;

                    case "item":
                        string     itemName = stringArray[4];
                        ItemEntity item     = new ItemEntity(texture, position, ItemDatabase.items[itemName]);
                        map.entityList.Add(item);
                        break;

                    case "player":
                        map.player = new Player(texture, new Vector2(xPosition, yPosition), new List <Item>());
                        map.player.team.characters.Add(new Character(Archive.textureDictionary["warriorCombat"], Archive.textureDictionary["warriorCombatOutline"],
                                                                     Vector2.Zero, true, "Warrior", 100, 10, 5, 6, 15, 10, 100, 5, 70));
                        map.player.map = map;
                        break;

                    case "enemy":
                        string teamName = stringArray[4];
                        Enemy  enemy    = new Enemy(texture, new Vector2(xPosition, yPosition));
                        enemy.team = CombatTeamDatabase.GetTeam(teamName);
                        map.entityList.Add(enemy);
                        break;

                    case "friendly":
                        string         questName = stringArray[4];
                        FriendlyEntity friendly  = new FriendlyEntity(texture, new Vector2(xPosition, yPosition), DialogDictionary.dialogDictionary[questName]);
                        map.entityList.Add(friendly);
                        break;

                    case "portal":
                        string       zoneName = stringArray[4];
                        int          spawnX   = Int32.Parse(stringArray[5]);
                        int          spawnY   = Int32.Parse(stringArray[6]);
                        PortalEntity portal   = new PortalEntity(texture, new Vector2(xPosition, yPosition), zoneName, new Vector2(spawnX, spawnY));
                        map.entityList.Add(portal);
                        break;
                    }
                }
                else
                {
                    map.zoneName = stringArray[1];
                }
            }
            streamReader.Close();
            map.SetTiles(mapGrid);
            return(map);
        }