コード例 #1
0
        public LevelEditorState(Surface _sfcGameWindow, string _name = "untitled") : base(_sfcGameWindow)
        {
            camera     = new Camera();
            name       = _name;
            map        = new Map();
            map.editor = true;
            vecPlayer  = new Vector(new Point(2, 3));
            player     = new EditorSprite(vecPlayer, new Player(0, 0));
            enemies    = new List <EditorSprite> ();
            if (name.EndsWith(".xml"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(Constants.Constants.GetResourcePath(name));
                map.FromXML(doc);
                XmlNode p = doc.SelectSingleNode("//player");
                player.gridPos.X = Convert.ToInt16(p.Attributes ["x"].InnerText);
                player.gridPos.Y = Convert.ToInt16(p.Attributes ["y"].InnerText);
                name             = name.Replace(".xml", "");
                foreach (XmlNode node in doc.SelectNodes("//enemy"))
                {
                    EnemyType    typ   = (EnemyType)Enum.Parse(typeof(EnemyType), node.Attributes ["type"].InnerText);
                    int          x     = Convert.ToInt16(node.Attributes ["x"].InnerText);
                    int          y     = Convert.ToInt16(node.Attributes ["y"].InnerText);
                    Enemy        enemy = Enemy.GetEnemy(typ, x, y);
                    EditorSprite s     = new EditorSprite(new Vector(new Point(x, y)), enemy);
                    Vector       vec   = map.GetTilePos(x, y);
                    s.x    = vec.X;
                    s.y    = vec.Y;
                    s.data = (object)typ;
                    enemies.Add(s);
                }
            }
            else
            {
                map.EmptyMap();
            }

            Vector v = map.GetTilePos((int)player.gridPos.X, (int)player.gridPos.Y);

            player.x = v.X;
            player.y = v.Y;

            grid = new EditorGrid();

            List <MenuObject> menuObjs = new List <MenuObject> ();

            foreach (TileType typ in Enum.GetValues(typeof(TileType)))
            {
                MenuText t = new MenuText(typ.ToString(), Color.Gold, Color.Black, TEXT_SIZE);
                menuObjs.Add(t);
            }
            foreach (EnemyType typ in Enum.GetValues(typeof(EnemyType)))
            {
                MenuText t = new MenuText(typ.ToString(), Color.Gold, Color.Gray, TEXT_SIZE);
                menuObjs.Add(t);
            }
            MenuText menuNoEnemy = new MenuText("NoEnemy", Color.Gold, Color.Gray, TEXT_SIZE);

            menuObjs.Add(menuNoEnemy);
            MenuText menuPlayer = new MenuText("Player", Color.Gold, Color.Blue, TEXT_SIZE);

            menuObjs.Add(menuPlayer);
            MenuText menuSave = new MenuText("Save", Color.Gold, Color.Red, TEXT_SIZE);

            menuSave.selectedHandler += EventSave;
            menuObjs.Add(menuSave);
            MenuText menuDelete = new MenuText("Delete", Color.Gold, Color.Red, TEXT_SIZE);

            menuDelete.selectedHandler += EventDelete;
            menuObjs.Add(menuDelete);
            MenuText menuQuit = new MenuText("Exit", Color.Gold, Color.Red, TEXT_SIZE);

            menuQuit.selectedHandler += delegate(MenuObject obj) {
                backToMenuHandler(obj);
            };
            menuObjs.Add(menuQuit);
            MenuText menuName = new MenuText(name, Color.Green, Color.Green, TEXT_SIZE);

            menuObjs.Add(menuName);
            menu = new Menu(menuObjs, MenuLayout.Horizontal, 5, 700);
            GenerateMenuBackground();
        }
コード例 #2
0
 void HandleMouse()
 {
     if (Mouse.IsButtonPressed (MouseButton.PrimaryButton)) {
         MenuText mT = (MenuText)menu.objects [menu.objects.Count - 1];
         if (mT.colourSelected != Color.Red) {
             mT.colourSelected = Color.Red;
             mT.colourNotSelected = Color.Red;
             mT.RenderText ();
         }
         int tileX, tileY;
         tileX = tileY = 0;
         bool tileXA = false;
         bool tileYA = false;
         for (int x=0; x < Constants.Constants.MAP_WIDTH; x++) {
             if (Mouse.MousePosition.X + map.overallCamera.x < x * Tile.WIDTH + x * 2 + 1) {
                 tileX = x - 1;
                 tileXA = true;
                 break;
             }
         }
         for (int y=0; y < Constants.Constants.MAP_HEIGHT; y++) {
             if (Mouse.MousePosition.Y + map.overallCamera.y < y * Tile.WIDTH + y * 2 + 1) {
                 tileY = y - 1;
                 tileYA = true;
                 break;
             }
         }
         if (tileXA && tileYA) {
             MenuText menuText = (MenuText)menu.objects [menu.selected];
             Vector v = map.GetTilePos (tileX, tileY);
             if (menuText.text == "Player") {
                 player.gridPos = new Vector (new Point (tileX, tileY));
                 player.x = v.X;
                 player.y = v.Y;
             } else if (menuText.text == "NoEnemy") {
                 EditorSprite removeSprite = null;
                 foreach (EditorSprite s in enemies) {
                     if (s.gridPos.X == tileX && s.gridPos.Y == tileY) {
                         removeSprite = s;
                     }
                 }
                 if (removeSprite != null) {
                     enemies.Remove (removeSprite);
                 }
             } else if (menuText.text.EndsWith ("Enemy")) {
                 EnemyType typ = (EnemyType)Enum.Parse (typeof(EnemyType), menuText.text);
                 Enemy e = Enemy.GetEnemy (typ, 0, 0);
                 EditorSprite s = new EditorSprite (new Vector (new Point (tileX, tileY)), e);
                 s.data = (object)typ;
                 for (int i=0; i < enemies.Count; i++) {
                     EditorSprite sprite = enemies [i];
                     if (sprite.gridPos.X == s.gridPos.X && sprite.gridPos.Y == s.gridPos.Y) {
                         enemies.Remove (sprite);
                         i--;
                     }
                 }
                 s.x = v.X;
                 s.y = v.Y;
                 enemies.Add (s);
             } else if (menuText.text != "Exit" && menuText.text != "Save" && menuText.text != name) {
                 TileType typ = (TileType)Enum.Parse (typeof(TileType), menuText.text, true);
                 Graphic t = map.lookup [typ].Clone ();
                 if (typ == TileType.Fire) {
                     t.colour = Color.Orange;
                 }
                 map.map [tileY] [tileX].tileType = typ;
                 map.map [tileY] [tileX].tileGraphic = t;
             }
         }
     }
 }
コード例 #3
0
 void HandleMouse()
 {
     if (Mouse.IsButtonPressed(MouseButton.PrimaryButton))
     {
         MenuText mT = (MenuText)menu.objects [menu.objects.Count - 1];
         if (mT.colourSelected != Color.Red)
         {
             mT.colourSelected    = Color.Red;
             mT.colourNotSelected = Color.Red;
             mT.RenderText();
         }
         int tileX, tileY;
         tileX = tileY = 0;
         bool tileXA = false;
         bool tileYA = false;
         for (int x = 0; x < Constants.Constants.MAP_WIDTH; x++)
         {
             if (Mouse.MousePosition.X + map.overallCamera.x < x * Tile.WIDTH + x * 2 + 1)
             {
                 tileX  = x - 1;
                 tileXA = true;
                 break;
             }
         }
         for (int y = 0; y < Constants.Constants.MAP_HEIGHT; y++)
         {
             if (Mouse.MousePosition.Y + map.overallCamera.y < y * Tile.WIDTH + y * 2 + 1)
             {
                 tileY  = y - 1;
                 tileYA = true;
                 break;
             }
         }
         if (tileXA && tileYA)
         {
             MenuText menuText = (MenuText)menu.objects [menu.selected];
             Vector   v        = map.GetTilePos(tileX, tileY);
             if (menuText.text == "Player")
             {
                 player.gridPos = new Vector(new Point(tileX, tileY));
                 player.x       = v.X;
                 player.y       = v.Y;
             }
             else if (menuText.text == "NoEnemy")
             {
                 EditorSprite removeSprite = null;
                 foreach (EditorSprite s in enemies)
                 {
                     if (s.gridPos.X == tileX && s.gridPos.Y == tileY)
                     {
                         removeSprite = s;
                     }
                 }
                 if (removeSprite != null)
                 {
                     enemies.Remove(removeSprite);
                 }
             }
             else if (menuText.text.EndsWith("Enemy"))
             {
                 EnemyType    typ = (EnemyType)Enum.Parse(typeof(EnemyType), menuText.text);
                 Enemy        e   = Enemy.GetEnemy(typ, 0, 0);
                 EditorSprite s   = new EditorSprite(new Vector(new Point(tileX, tileY)), e);
                 s.data = (object)typ;
                 for (int i = 0; i < enemies.Count; i++)
                 {
                     EditorSprite sprite = enemies [i];
                     if (sprite.gridPos.X == s.gridPos.X && sprite.gridPos.Y == s.gridPos.Y)
                     {
                         enemies.Remove(sprite);
                         i--;
                     }
                 }
                 s.x = v.X;
                 s.y = v.Y;
                 enemies.Add(s);
             }
             else if (menuText.text != "Exit" && menuText.text != "Save" && menuText.text != name)
             {
                 TileType typ = (TileType)Enum.Parse(typeof(TileType), menuText.text, true);
                 Graphic  t   = map.lookup [typ].Clone();
                 if (typ == TileType.Fire)
                 {
                     t.colour = Color.Orange;
                 }
                 map.map [tileY] [tileX].tileType    = typ;
                 map.map [tileY] [tileX].tileGraphic = t;
             }
         }
     }
 }
コード例 #4
0
        public LevelEditorState(Surface _sfcGameWindow, string _name="untitled")
            : base(_sfcGameWindow)
        {
            camera = new Camera ();
            name = _name;
            map = new Map ();
            map.editor = true;
            vecPlayer = new Vector (new Point (2, 3));
            player = new EditorSprite (vecPlayer, new Player (0, 0));
            enemies = new List<EditorSprite> ();
            if (name.EndsWith (".xml")) {
                XmlDocument doc = new XmlDocument ();
                doc.Load (Constants.Constants.GetResourcePath (name));
                map.FromXML (doc);
                XmlNode p = doc.SelectSingleNode ("//player");
                player.gridPos.X = Convert.ToInt16 (p.Attributes ["x"].InnerText);
                player.gridPos.Y = Convert.ToInt16 (p.Attributes ["y"].InnerText);
                name = name.Replace (".xml", "");
                foreach (XmlNode node in doc.SelectNodes("//enemy")) {
                    EnemyType typ = (EnemyType)Enum.Parse (typeof(EnemyType), node.Attributes ["type"].InnerText);
                    int x = Convert.ToInt16 (node.Attributes ["x"].InnerText);
                    int y = Convert.ToInt16 (node.Attributes ["y"].InnerText);
                    Enemy enemy = Enemy.GetEnemy (typ, x, y);
                    EditorSprite s = new EditorSprite (new Vector (new Point (x, y)), enemy);
                    Vector vec = map.GetTilePos (x, y);
                    s.x = vec.X;
                    s.y = vec.Y;
                    s.data = (object)typ;
                    enemies.Add (s);
                }
            } else {
                map.EmptyMap ();
            }

            Vector v = map.GetTilePos ((int)player.gridPos.X, (int)player.gridPos.Y);
            player.x = v.X;
            player.y = v.Y;

            grid = new EditorGrid ();

            List<MenuObject > menuObjs = new List<MenuObject> ();
            foreach (TileType typ in Enum.GetValues(typeof(TileType))) {
                MenuText t = new MenuText (typ.ToString (), Color.Gold, Color.Black, TEXT_SIZE);
                menuObjs.Add (t);
            }
            foreach (EnemyType typ in Enum.GetValues(typeof(EnemyType))) {
                MenuText t = new MenuText (typ.ToString (), Color.Gold, Color.Gray, TEXT_SIZE);
                menuObjs.Add (t);
            }
            MenuText menuNoEnemy = new MenuText ("NoEnemy", Color.Gold, Color.Gray, TEXT_SIZE);
            menuObjs.Add (menuNoEnemy);
            MenuText menuPlayer = new MenuText ("Player", Color.Gold, Color.Blue, TEXT_SIZE);
            menuObjs.Add (menuPlayer);
            MenuText menuSave = new MenuText ("Save", Color.Gold, Color.Red, TEXT_SIZE);
            menuSave.selectedHandler += EventSave;
            menuObjs.Add (menuSave);
            MenuText menuDelete = new MenuText ("Delete", Color.Gold, Color.Red, TEXT_SIZE);
            menuDelete.selectedHandler += EventDelete;
            menuObjs.Add (menuDelete);
            MenuText menuQuit = new MenuText ("Exit", Color.Gold, Color.Red, TEXT_SIZE);
            menuQuit.selectedHandler += delegate(MenuObject obj) {
                backToMenuHandler (obj);
            };
            menuObjs.Add (menuQuit);
            MenuText menuName = new MenuText (name, Color.Green, Color.Green, TEXT_SIZE);
            menuObjs.Add (menuName);
            menu = new Menu (menuObjs, MenuLayout.Horizontal, 5, 700);
            GenerateMenuBackground ();
        }