Ejemplo n.º 1
0
 public static void WriteMap(string mapname, Tile[,] tileArray, Entity[,] entityArray, string zoneName)
 {
     using (StreamWriter sw = File.CreateText(mapname))
     {
         sw.WriteLine("zone;" + zoneName);
         for (int i = 0; i < tileArray.GetLength(0); i++)
         {
             for (int j = 0; j < tileArray.GetLength(1); j++)
             {
                 var textureArchiveName = Archive.textureDictionary.FirstOrDefault(x => x.Value == tileArray[i, j].texture).Key;
                 sw.WriteLine("tile;" + textureArchiveName + ";" + tileArray[i, j].position.X + ";" + tileArray[i, j].position.Y + ";" + tileArray[i, j].Wall);
             }
         }
         for (int i = 0; i < entityArray.GetLength(0); i++)
         {
             for (int j = 0; j < entityArray.GetLength(1); j++)
             {
                 if (entityArray[i, j] != null)
                 {
                     var textureArchiveName = Archive.textureDictionary.FirstOrDefault(x => x.Value == entityArray[i, j].texture).Key;
                     if (entityArray[i, j] is Player)
                     {
                         sw.WriteLine("player;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y);
                     }
                     else if (entityArray[i, j] is Enemy)
                     {
                         Enemy enemy    = (Enemy)entityArray[i, j];
                         var   teamName = CombatTeamDatabase.teamDictionary.FirstOrDefault(x => x.Value.ID == enemy.team.ID).Key;
                         sw.WriteLine("enemy;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + teamName);
                     }
                     else if (entityArray[i, j] is FriendlyEntity)
                     {
                         FriendlyEntity npc        = (FriendlyEntity)entityArray[i, j];
                         var            dialogName = DialogDictionary.dialogDictionary.FirstOrDefault(x => x.Value == npc.dialog).Key;
                         sw.WriteLine("friendly;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + dialogName);
                     }
                     else if (entityArray[i, j] is ItemEntity)
                     {
                         ItemEntity item     = (ItemEntity)entityArray[i, j];
                         var        itemName = ItemDatabase.items.FirstOrDefault(x => x.Value == item.containedItem).Key;
                         sw.WriteLine("item;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" + itemName);
                     }
                     else if (entityArray[i, j] is PortalEntity)
                     {
                         PortalEntity portal = (PortalEntity)entityArray[i, j];
                         sw.WriteLine("portal;" + textureArchiveName + ";" + entityArray[i, j].position.X + ";" + entityArray[i, j].position.Y + ";" +
                                      portal.zoneName + ";" + portal.spawnPosition.X + ";" + portal.spawnPosition.Y);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public PortalEntity ZoneSwitch()
        {
            foreach (Entity e in entityList)
            {
                if (e is PortalEntity)
                {
                    PortalEntity portal = (PortalEntity)e;
                    if (portal.position == player.position)
                    {
                        return(portal);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void LoadMap(string path)
        {
            Map loadedMap = FileReader.ReadMap(path);

            tileArray   = loadedMap.tiles;
            entityArray = new Entity[46, 26];
            zoneName    = loadedMap.zoneName;

            foreach (Entity e in loadedMap.entityList)
            {
                int XValue = (int)(e.position.X / tileSize);
                int YValue = (int)(e.position.Y / tileSize);

                if (e is Enemy)
                {
                    entityArray[XValue, YValue]         = new Enemy(e.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y));
                    entityArray[XValue, YValue].team.ID = e.team.ID;
                }
                else if (e is FriendlyEntity)
                {
                    FriendlyEntity f = (FriendlyEntity)e;
                    entityArray[XValue, YValue] = new FriendlyEntity(e.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                     f.dialog);
                }
                else if (e is ItemEntity)
                {
                    ItemEntity i = (ItemEntity)e;
                    entityArray[XValue, YValue] = new ItemEntity(e.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                 i.containedItem);
                }
                else if (e is PortalEntity)
                {
                    PortalEntity i = (PortalEntity)e;
                    entityArray[XValue, YValue] = new PortalEntity(e.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y),
                                                                   i.zoneName, i.spawnPosition);
                }
            }

            if (loadedMap.player != null)
            {
                int XValue = (int)(loadedMap.player.position.X / tileSize);
                int YValue = (int)(loadedMap.player.position.Y / tileSize);
                entityArray[XValue, YValue] = new Player(loadedMap.player.animation.texture, new Vector2(XValue * tileSize + tileGridOffset.X, YValue * tileSize + tileGridOffset.Y), new List <Item>());
            }
        }
Ejemplo n.º 4
0
        protected override void Update(GameTime gameTime)
        {
            KeyMouseReader.Update();

            if (KeyMouseReader.KeyPressed(Keybinds.binds["toggleFullscreen"]))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges();
            }

            switch (currentGameState)
            {
            case (GameState.Menus):
                startMenu.Update();

                if (KeyMouseReader.KeyPressed(Keybinds.binds["back"]))
                {
                    this.Exit();
                }
                break;

            case (GameState.World):
                map.Update(gameTime);

                string       previousZoneName = map.zoneName;
                PortalEntity temporaryPortal  = map.ZoneSwitch();
                if (temporaryPortal != null)
                {
                    fileName = temporaryPortal.zoneName;
                    Player     tempPlayer = map.player;
                    TabManager tab        = map.tabManager;
                    map                 = FileReader.ReadMap(fileName);
                    map.player          = tempPlayer;
                    map.player.position = temporaryPortal.spawnPosition;
                    map.player.map      = map;
                    map.tabManager      = tab;

                    if (map.zoneName != previousZoneName)
                    {
                        MediaPlayer.Play(Archive.songDictionary[map.zoneName]);
                    }
                }

                if (map.EngageCombatBool(ref combat) == true)
                {
                    currentGameState = GameState.Combat;
                }

                if (KeyMouseReader.KeyPressed(Keys.Escape))
                {
                    currentGameState = GameState.Menus;
                    MediaPlayer.Stop();
                }
                break;

            case (GameState.Combat):
                combat.Update(gameTime);
                if (!combat.active && !combat.fadingOut)
                {
                    MediaPlayer.Play(Archive.songDictionary[map.zoneName]);
                    currentGameState = GameState.World;
                    foreach (Quest q in map.tabManager.questTab.questSystem.quests)
                    {
                        foreach (Objective o in q.objectives)
                        {
                            if (o is KillObjective)
                            {
                                KillObjective oKill = (KillObjective)o;
                                oKill.CompareTeam(combat.enemyID);
                            }
                        }
                    }

                    if (combat.winnerTeam == 2)
                    {
                        Initialize();
                    }
                    else
                    {
                        map.player.team.characters[0].Heal((int)(map.player.team.characters[0].maxHealth * 0.2f));
                    }
                }

                if (KeyMouseReader.KeyPressed(Keybinds.binds["back"]))
                {
                    this.Exit();
                }
                break;

            case (GameState.WorldEditor):
                mapEditor.Update();

                if (KeyMouseReader.KeyPressed(Keybinds.binds["back"]))
                {
                    currentGameState = GameState.Menus;
                }
                break;
            }

            base.Update(gameTime);
        }
Ejemplo n.º 5
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;
                    }
                }
            }
        }
Ejemplo n.º 6
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);
        }