Пример #1
0
 void Draw(TemplateButton button)
 {
     if (button.Visable)
     {
         Draw((Button)button);
         for (int j = 0; j < 15; j++)
         {
             for (int k = 0; k < 10; k++)
             {
                 if (button.Template.Tiles[j, k].Solid)
                 {
                     Draw(MiniSolid, button.Position + new Vector2(4 + MiniSolid.Width * j, 4 + MiniSolid.Height * k), button.Origin);
                 }
                 else
                 {
                     if (button.Template.Tiles[j, k].Door)
                     {
                         Draw(MiniDoor, button.Position + new Vector2(4 + MiniDoor.Width * j, 4 + MiniDoor.Height * k), button.Origin);
                     }
                     else
                     {
                         Draw(MiniEmpty, button.Position + new Vector2(4 + MiniEmpty.Width * j, 4 + MiniEmpty.Height * k), button.Origin);
                     }
                 }
             }
         }
         if (button.Template.Difficulty != 0 && button.Template.Payout != null)
         {
             Draw(MiniPrize, button.Position + new Vector2(4 + MiniEmpty.Width * button.Template.Payout.X, 4 + MiniEmpty.Height * button.Template.Payout.Y), button.Origin);
         }
         foreach (Entity entity in button.Template.Entities)
         {
             if (entity is Item)
             {
                 Draw(MiniItem, button.Position + new Vector2(4 + MiniItem.Width * entity.Position.X, 4 + MiniItem.Height * entity.Position.Y), button.Origin);
             }
             else if (entity is Enemy)
             {
                 Draw(MiniEnemy, button.Position + new Vector2(4 + MiniEnemy.Width * entity.Position.X, 4 + MiniEnemy.Height * entity.Position.Y), button.Origin);
             }
         }
         SpriteBatch.DrawString(Calibri, "Difficulty: " + button.Template.Difficulty.ToString(), OffsetVector + button.Position + new Vector2(-35, -22), Color.White);
         SpriteBatch.DrawString(Calibri, button.Template.Name, OffsetVector + button.Position + new Vector2(60, -22), Color.White);
     }
 }
Пример #2
0
        void LoadEditorTemplates()
        {
            //Foreach .lvl files add it to the list
            string[] fileNames = Directory.GetFiles(Directory.GetCurrentDirectory() + @"\roomtemplates\");
            try
            {
                foreach (string file in fileNames)
                {
                    StreamReader streamreader  = new StreamReader(file);
                    string       importedlevel = streamreader.ReadToEnd();
                    streamreader.Close();

                    string[] contents = importedlevel.Replace("\r\n", "").Replace("\n", "").Replace("\r", "").Split('-');

                    CurrentTemplateName = Strip(file);
                    TemplateButton result = new TemplateButton(UnselectedSummary, CurrentTemplateName, DoorTiles, 0);

                    string[] solids = contents[0].Split(':')[1].Split(',');
                    foreach (string s in solids)
                    {
                        if (s != "")
                        {
                            string[] pair = s.Split('/');
                            result.Template.Tiles[Convert.ToInt32(pair[0]), Convert.ToInt32(pair[1])] = SolidTile.Copy();
                        }
                    }

                    string[] doors = contents[1].Split(':')[1].Split(',');
                    foreach (string d in doors)
                    {
                        if (d != "")
                        {
                            string[] pair = d.Split('/');
                            result.Template.Tiles[Convert.ToInt32(pair[0]), Convert.ToInt32(pair[1])] = DoorTile.Copy();
                        }
                    }

                    string[] payout = contents[2].Split(':')[1].Split('/');
                    result.Template.Payout = new Vector2I(Convert.ToInt32(payout[0]), Convert.ToInt32(payout[1]));

                    string[] creatures = contents[3].Split(':')[1].Split(',');
                    foreach (string c in creatures)
                    {
                        if (c != "")
                        {
                            string[] pair  = c.Split('=');
                            int      hash  = Convert.ToInt32(pair[0]);
                            Enemy    enemy = EnemyButtons.Single(x => x.Enemy.Hash == hash).Enemy;
                            Enemy    guy   = enemy.Copy(new Vector2I(Convert.ToInt32(pair[1].Split('/')[0]), Convert.ToInt32(pair[1].Split('/')[1])), enemy.Hash);
                            result.Template.Entities.Add(guy);
                        }
                    }

                    result.Template.Difficulty = Convert.ToInt32(contents[4].Split(':')[1]);
                    TemplateButtons.Add(result);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            TemplateButtons.Sort();
            ReallignTemplates();
        }
Пример #3
0
        void SaveContent()
        {
            for (int i = 0; i < EnemyButtons.Count(); i++)
            {
                EnemyButton E         = EnemyButtons.ElementAt(i);
                string      directory = Directory.GetCurrentDirectory() + @"\enemytemplates\" + i.ToString() + ".nme";
                string      content   = "";
                content += "Hash = ";
                content += E.Enemy.Hash.ToString();
                content += "\n";
                content += "Brains = ";
                if (E.Enemy.Brains == Nature.SMART)
                {
                    content += "Smart";
                }
                else
                {
                    content += "Dumb";
                }
                content += "\n";
                content += "MaxHP = ";
                content += E.Enemy.MaxHP.ToString();
                content += "\n";
                content += ",";
                content += "\n";
                content += "Texture = ";
                content += Array.IndexOf(EnemySprites, E.Enemy.Sprite).ToString();
                content += ",";
                content += "\n";
                content += "Damage = ";
                content += E.Enemy.Damage.ToString();
                content += "\n";
                content += "-";
                content += "\n";
                for (int j = 0; j < E.Enemy.Effects.Count(); j++)
                {
                    int e = (int)E.Enemy.Effects.ElementAt(j);
                    content += e.ToString();
                    if (j != E.Enemy.Effects.Count() - 1)
                    {
                        content += ", ";
                    }
                }
                content += "\n";
                File.WriteAllText(@directory, content);
            }

            for (int i = 0; i < TemplateButtons.Count(); i++)
            {
                TemplateButton T         = TemplateButtons.ElementAt(i);
                string         directory = Directory.GetCurrentDirectory() + @"\roomtemplates\" + i.ToString() + ".lvl";
                string         content   = "SOLIDS:";
                content += "\n";
                bool doit = false;
                for (int j = 0; j < 15; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        if (T.Template.Tiles[j, k].Solid)
                        {
                            content += j.ToString();
                            content += "/";
                            content += k.ToString();
                            content += ",";
                            content += "\n";
                            doit     = true;
                        }
                    }
                }
                if (doit)
                {
                    content = content.Substring(0, content.Length - 2) + "\n";
                }
                content += "-";
                content += "\n";
                content += "DOORS:";
                content += "\n";
                doit     = false;
                for (int j = 0; j < 15; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        if (T.Template.Tiles[j, k].Door)
                        {
                            content += j.ToString();
                            content += "/";
                            content += k.ToString();
                            content += ",";
                            content += "\n";
                            doit     = true;
                        }
                    }
                }
                if (doit)
                {
                    content = content.Substring(0, content.Length - 2) + "\n";
                }
                content += "-";
                content += "\n";
                content += "PAYOUT:";
                content += "\n";
                if (T.Template.Payout == null)
                {
                    content += "0";
                    content += "/";
                    content += "0";
                }
                else
                {
                    content += T.Template.Payout.X.ToString();
                    content += "/";
                    content += T.Template.Payout.Y.ToString();
                }
                content += "\n";
                content += "-";
                content += "\n";
                content += "ENEMIES:";
                content += "\n";
                for (int j = 0; j < T.Template.Entities.Count(); j++)
                {
                    Entity E = T.Template.Entities.ElementAt(j);
                    if (E.GetClass() == "Enemy")
                    {
                        content += E.Hash.ToString();
                        content += "=";
                        content += E.Position.X.ToString();
                        content += "/";
                        content += E.Position.Y.ToString();
                        if (j != T.Template.Entities.Count() - 1)
                        {
                            content += ",";
                        }
                        content += "\n";
                    }
                }
                content += "-";
                content += "\n";
                content += "DIFFICULTY: ";
                content += T.Template.Difficulty.ToString();
                content += "\n";
                File.WriteAllText(@directory, content);
            }
            Saved = true;
        }
Пример #4
0
        void HandleEditorInput(Button button, bool LeftClick)
        {
            if (LeftClick)
            {
                switch (button.Action)
                {
                case "quit":
                    Quit();
                    break;

                case "templatestab":
                    CurrentTab    = Tab.TEMPLATES;
                    button.Sprite = SelectedTab;
                    foreach (Button b in EditorButtons)
                    {
                        if (b.Action == "enemy")
                        {
                            ((EnemyButton)b).Visable = false;
                        }
                        else if (b.Action == "enemiestab")
                        {
                            b.Sprite = UnselectedTab;
                        }
                    }
                    ReallignTemplates();
                    break;

                case "enemiestab":
                    CurrentTab    = Tab.ENEMIES;
                    button.Sprite = SelectedTab;
                    foreach (Button b in EditorButtons)
                    {
                        if (b.Action == "room")
                        {
                            ((TemplateButton)b).Visable = false;
                        }
                        else if (b.Action == "templatestab")
                        {
                            b.Sprite = UnselectedTab;
                        }
                    }
                    ReallignEnemies();
                    break;

                case "up":
                    if (CurrentTab == Tab.TEMPLATES)
                    {
                        CurrentTemplateIndex--;
                        if (CurrentTemplateIndex < 0)
                        {
                            CurrentTemplateIndex = 0;
                        }
                        else
                        {
                            foreach (TemplateButton B in TemplateButtons)
                            {
                                B.Position.Y += 51;
                            }
                        }
                        ReallignTemplates();
                    }
                    else
                    {
                        CurrentEnemyIndex--;
                        if (CurrentEnemyIndex < 0)
                        {
                            CurrentEnemyIndex = 0;
                        }
                        else
                        {
                            foreach (EnemyButton E in EnemyButtons)
                            {
                                E.Position.Y += 51;
                            }
                        }
                        ReallignEnemies();
                    }
                    break;

                case "down":
                    if (CurrentTab == Tab.TEMPLATES)
                    {
                        CurrentTemplateIndex++;
                        if (CurrentTemplateIndex > TemplateButtons.Count() - 7)
                        {
                            CurrentTemplateIndex = TemplateButtons.Count() - 7;
                        }
                        else
                        {
                            foreach (TemplateButton B in TemplateButtons)
                            {
                                B.Position.Y -= 51;
                            }
                        }
                        ReallignTemplates();
                    }
                    else
                    {
                        CurrentEnemyIndex++;
                        if (CurrentEnemyIndex > EnemyButtons.Count() - 7)
                        {
                            CurrentEnemyIndex = EnemyButtons.Count() - 7;
                        }
                        else
                        {
                            foreach (EnemyButton E in EnemyButtons)
                            {
                                E.Position.Y -= 51;
                            }
                        }
                        ReallignEnemies();
                    }
                    break;

                case "sprite":
                    if (CurrentEnemy.Sprite == Enemy1)
                    {
                        CurrentEnemy.Sprite = Enemy2;
                    }
                    else if (CurrentEnemy.Sprite == Enemy2)
                    {
                        CurrentEnemy.Sprite = Enemy3;
                    }
                    else if (CurrentEnemy.Sprite == Enemy3)
                    {
                        CurrentEnemy.Sprite = Enemy4;
                    }
                    else if (CurrentEnemy.Sprite == Enemy4)
                    {
                        CurrentEnemy.Sprite = Enemy1;
                    }
                    break;

                case "hp":
                    CurrentEnemy.HP++;
                    CurrentEnemy.MaxHP++;
                    break;

                case "damage":
                    CurrentEnemy.Damage++;
                    break;

                case "break":
                    //Pause to debug
                    break;

                case "room":
                    if (((TemplateButton)button).Visable && CurrentTab == Tab.TEMPLATES)
                    {
                        foreach (TemplateButton c in TemplateButtons)
                        {
                            c.Sprite = UnselectedSummary;
                        }
                        button.Sprite   = SelectedSummary;
                        CurrentTemplate = ((TemplateButton)button).Template;
                    }
                    break;

                case "enemy":
                    if (((EnemyButton)button).Visable && CurrentTab == Tab.ENEMIES)
                    {
                        foreach (EnemyButton e in EnemyButtons)
                        {
                            e.Sprite = UnselectedSummary;
                        }
                        button.Sprite = SelectedSummary;
                        CurrentEnemy  = ((EnemyButton)button).Enemy;
                    }
                    break;

                case "save":
                    SaveContent();
                    break;

                case "new":
                    if (CurrentTab == Tab.TEMPLATES)
                    {
                        CurrentTemplateName = Convert.ToString(Convert.ToInt32(CurrentTemplateName.Split('.')[0]) + 1);
                        TemplateButton result = new TemplateButton(UnselectedSummary, CurrentTemplateName + ".lvl", DoorTiles, 0);
                        TemplateButtons.Add(result);
                        TemplateButtons.Sort();
                        ReallignTemplates();
                    }
                    else if (CurrentTab == Tab.ENEMIES)
                    {
                        CurrentCreatureName = Convert.ToString(Convert.ToInt32(CurrentCreatureName.Split('.')[0]) + 1) + ".nme";
                        EnemyButton result = new EnemyButton(UnselectedSummary, Enemy1, CurrentCreatureName);
                        EnemyButtons.Add(result);
                        EnemyButtons.Sort();
                        ReallignEnemies();
                    }
                    break;

                case "door":
                    for (int i = 0; i < 15; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            if (MouseOver(i, j))
                            {
                                CurrentTemplate.Tiles[i, j] = DoorTile.Copy();
                            }
                        }
                    }
                    break;

                case "item":
                    for (int i = 0; i < 15; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            if (MouseOver(i, j))
                            {
                                HealthPotion newthing = GenericItem.Copy(new Vector2I(i, j), GenericItem.Hash);
                                if (CurrentTemplate.Entities.Contains(newthing))
                                {
                                    CurrentTemplate.Entities.Remove(newthing);
                                }
                                else
                                {
                                    CurrentTemplate.Entities.Add(newthing);
                                }
                            }
                        }
                    }
                    break;

                case "prize":
                    for (int i = 0; i < 15; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            if (MouseOver(i, j))
                            {
                                CurrentTemplate.Payout = new Vector2I(i, j);
                            }
                        }
                    }
                    break;

                case "difficulty":
                    CurrentTemplate.Difficulty++;
                    break;
                }
            }
            else
            {
                switch (button.Action)
                {
                case "hp":
                    CurrentEnemy.HP--;
                    CurrentEnemy.MaxHP--;
                    break;

                case "sprite":
                    if (CurrentEnemy.Sprite == Enemy1)
                    {
                        CurrentEnemy.Sprite = Enemy4;
                    }
                    else if (CurrentEnemy.Sprite == Enemy2)
                    {
                        CurrentEnemy.Sprite = Enemy3;
                    }
                    else if (CurrentEnemy.Sprite == Enemy3)
                    {
                        CurrentEnemy.Sprite = Enemy2;
                    }
                    else if (CurrentEnemy.Sprite == Enemy4)
                    {
                        CurrentEnemy.Sprite = Enemy1;
                    }
                    break;

                case "damage":
                    CurrentEnemy.Damage--;
                    break;

                case "difficulty":
                    CurrentTemplate.Difficulty--;
                    break;
                }
            }
        }