예제 #1
0
    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.

        IniLoader gIni = new IniLoader("Content\\WIZZ.ini");
        string    firstLevel;

        gIni.GetString("startOnLevel", out firstLevel, "MAIN");
        gIni.GetBool("drawNormals", out drawNormals, false);
        string levelPath;

        gIni.GetString("levelPath", out levelPath, Constants.LEVEL_PATH);

        spriteBatch = new SpriteBatch(GraphicsDevice);
        testLevel   = GLEED2D.Level.FromFile(levelPath + firstLevel + ".xml", Content);
        Utilities.Init(Content);

        SuperHackyLevelParsing();

        m_player = (Player)EntityManager.get().Create(EntityManager.ENT_TYPE.PLAYER);
        m_player.Init(Content);
        m_player.Spawn();
        // TODO: use this.Content to load your game content here
    }
예제 #2
0
 //MENU
 public void newLevel()
 {
     Application.DoEvents();
     Level newlevel = new Level();
     newlevel.EditorRelated.Version = Editor.Instance.Version;
     Editor.Instance.loadLevel(newlevel);
     levelfilename = "untitled";
     DirtyFlag = false;
 }
예제 #3
0
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            if (type == typeof(Level))
            {
                // Create the instance to deserialize into.
                Level level = new Level();

                level.CanvasColor = new Color(
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[1],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[2],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[3],
                    (byte)(int)(dictionary["CanvasColor"] as ArrayList)[0]);
                Constants.Instance.ColorBackground = level.CanvasColor;
                level.Scale = (int)dictionary["Scale"];

                ArrayList spawnList = dictionary["PlayerSpawn"] as ArrayList;
                float spawnX = 0.0f;
                if (spawnList[0] is decimal)
                    spawnX = (float)(decimal)spawnList[0];
                if (spawnList[0] is int)
                    spawnX = (float)(int)spawnList[0];

                float spawnY = 0.0f;
                if (spawnList[1] is decimal)
                    spawnY = (float)(decimal)spawnList[1];
                if (spawnList[1] is int)
                    spawnY = (float)(int)spawnList[1];
                level.PlayerSpawn = new Vector2(spawnX, spawnY);

                level.Music = dictionary["Music"] as String;
                level.ContentRootFolder = dictionary["ContentRootFolder"] as String;

                // Deserialize the ListItemCollection's items.
                Dictionary<int, object> layersDict = new Dictionary<int, object>();
                ArrayList itemsList = (ArrayList)dictionary["Layers"];
                foreach (Dictionary<string, object> layerDict in itemsList)
                {

                    Layer layer = new Layer(layerDict["ID"] as String);
                    float scale = 1.0f;
                    if (layerDict["Scale"] is decimal)
                        scale = (float)(decimal)layerDict["Scale"];
                    if (layerDict["Scale"] is int)
                        scale = (float)(int)layerDict["Scale"];
                    layer.ScrollSpeed = new Microsoft.Xna.Framework.Vector2(1.0f/scale, 1.0f/scale);
                    layer.ZPos = (int)layerDict["Layer"];

                    level.Layers.Add(layer);

                    layersDict.Add((int)layerDict["Layer"], layer);
                //    level.Add(serializer.ConvertToType<ListItem>(itemsList[i]));
                }

                ArrayList objList = (ArrayList)dictionary["Objects"];
                foreach (Dictionary<string, object> groupDict in objList)
                {

                    ArrayList childList = (ArrayList)groupDict["Children"];
                    foreach (Dictionary<string, object> childDict in childList)
                    {

                        Vector2 position = new Vector2( 0.0f, 0.0f);
                        float rotation = 0.0f;

                        if (childDict.ContainsKey("Transform"))
                        {
                            Dictionary<string, object> transDict = childDict["Transform"] as Dictionary<string, object>;
                            ArrayList posList = transDict["Position"] as ArrayList;
                            float posX = 0.0f;
                            if (posList[0] is decimal)
                                posX = (float)(decimal)posList[0];
                            if (posList[0] is int)
                                posX = (float)(int)posList[0];

                            float posY = 0.0f;
                            if (posList[1] is decimal)
                                posY = (float)(decimal)posList[1];
                            if (posList[1] is int)
                                posY = (float)(int)posList[1];

                            position = new Vector2(posX * level.Scale, posY * level.Scale);
                            if (transDict["Rotation"] is decimal)
                                rotation = (float)(decimal)transDict["Rotation"];
                            if (transDict["Rotation"] is int)
                                rotation = (float)(int)transDict["Rotation"];
                        }

                        if (childDict.ContainsKey("Renderable"))
                        {
                            Dictionary<string, object> rendDict = childDict["Renderable"] as Dictionary<string, object>;
                            TextureItem item = new TextureItem(level.ContentRootFolder + '/' + rendDict["Image"] as String, position);
                            item.texture_filename = rendDict["Image"] as String;
                            item.Name = childDict["Name"] as String;
                            item.Rotation = rotation * MathHelper.Pi/180.0f;
                            item.TintColor = new Color(
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[3],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[0],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[1],
                                (float)(int)(rendDict["ColorMod"] as ArrayList)[2]);

                            float xscale = 1.0f;
                            if (rendDict["xScale"] is decimal)
                                xscale = (float)(decimal)rendDict["xScale"];
                            if (rendDict["xScale"] is int)
                                xscale = (float)(int)rendDict["xScale"];

                            float yscale = 1.0f;
                            if (rendDict["yScale"] is decimal)
                                yscale = (float)(decimal)rendDict["yScale"];
                            if (rendDict["yScale"] is int)
                                yscale = (float)(int)rendDict["yScale"];

                            item.setScale(new Vector2(xscale, yscale));

                            //Game Specific components
                            if (childDict.ContainsKey("Planet"))
                            {
                                Dictionary<string, object> gravDict = childDict["Planet"] as Dictionary<string, object>;
                                double gravity = 0.0f;
                                if (gravDict["Gravity"] is decimal)
                                    gravity = (double)(decimal)gravDict["Gravity"];
                                if (gravDict["Gravity"] is int)
                                    gravity = (double)(int)gravDict["Gravity"];
                                item.CustomProperties.Add("Gravity", new CustomProperty("Gravity", gravity, typeof(double), ""));
                            }

                            (layersDict[(int)rendDict["Layer"]] as Layer).Items.Add( item );
                        }

                    }
                }

                //Engine draws things in reverse
                foreach (Layer layer in level.Layers)
                {
                    layer.Items.Reverse();
                }

                return level;
            }
            return null;
        }
예제 #4
0
        public void loadLevel(Level l)
        {
            AdesExtensions.dummyReference();
            /* DISABLED LEVEL-SPECIFIC CONTENT ROOT.
            if (l.ContentRootFolder == null)
            {
                l.ContentRootFolder = Constants.Instance.DefaultContentRootFolder;
                if (!Directory.Exists(l.ContentRootFolder))
                {
                    Forms.DialogResult dr = Forms.MessageBox.Show(
                        "The DefaultContentRootFolder \"" + l.ContentRootFolder + "\" (as set in the Settings Dialog) doesn't exist!\n"
                        + "The ContentRootFolder of the new level will be set to the Editor's work directory (" + Forms.Application.StartupPath + ").\n"
                        + "Please adjust the DefaultContentRootFolder in the Settings Dialog.\n"
                        + "Do you want to open the Settings Dialog now?", "Error",
                        Forms.MessageBoxButtons.YesNo, Forms.MessageBoxIcon.Exclamation);
                    if (dr == Forms.DialogResult.Yes) new SettingsForm().ShowDialog();
                    l.ContentRootFolder = Forms.Application.StartupPath;
                }
            }
            else
            {
                if (!Directory.Exists(l.ContentRootFolder))
                {
                    Forms.MessageBox.Show("The directory \"" + l.ContentRootFolder + "\" doesn't exist! "
                        + "Please adjust the XML file before trying again.");
                    return;
                }
            }
             */

            AdesExtensions.loadContentRoot(Constants.Instance.DefaultContentRootFolder);
            l.ContentRootFolder = Constants.Instance.DefaultContentRootFolder;

            AdesExtensions.addCustomPropertiesToLevel(l);

            TextureLoader.Instance.Clear();

            foreach (Layer layer in l.Layers)
            {
                layer.level = l;
                foreach (Item item in layer.Items)
                {
                    item.layer = layer;
                    if (!item.loadIntoEditor()) return;
                }
            }

            level = l;

            AdesExtensions.dummyReference();  //MainForm.Instance.loadfolder(level.ContentRootFolder);
            MainForm.Instance.loadfolder(Constants.Instance.DefaultContentRootFolder);

            if (level.Name == null) level.Name = "Level_01";

            SelectedLayer = null;
            if (level.Layers.Count > 0) SelectedLayer = level.Layers[0];
            SelectedItems.Clear();

            camera = new Camera(MainForm.Instance.pictureBox1.Width, MainForm.Instance.pictureBox1.Height);
            camera.Position = level.EditorRelated.CameraPosition;
            MainForm.Instance.zoomcombo.Text = "100%";
            undoBuffer.Clear();
            redoBuffer.Clear();
            MainForm.Instance.undoButton.DropDownItems.Clear();
            MainForm.Instance.redoButton.DropDownItems.Clear();
            MainForm.Instance.undoButton.Enabled = MainForm.Instance.undoMenuItem.Enabled = undoBuffer.Count > 0;
            MainForm.Instance.redoButton.Enabled = MainForm.Instance.redoMenuItem.Enabled = redoBuffer.Count > 0;
            commandInProgress = false;

            updatetreeview();
        }
예제 #5
0
 //MENU
 public void newLevel()
 {
     Application.DoEvents();
     Level newlevel = new Level();
     newlevel.EditorRelated.Version = Editor.Instance.Version;
     Editor.Instance.loadLevel(newlevel);
     levelfilename = "untitled";
     DirtyFlag = false;
     AdesExtensions.addCustomPropertiesToLevel(Editor.Instance.level);
 }
예제 #6
0
파일: Game1.cs 프로젝트: MattDBell/GCubed
    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.

            IniLoader gIni = new IniLoader("Content\\WIZZ.ini");
            string firstLevel;

            gIni.GetString("startOnLevel", out firstLevel,"MAIN");
            gIni.GetBool("drawNormals", out drawNormals, false);
            string levelPath;
            gIni.GetString("levelPath", out levelPath, Constants.LEVEL_PATH);

            spriteBatch = new SpriteBatch(GraphicsDevice);
            testLevel = GLEED2D.Level.FromFile(levelPath + firstLevel + ".xml", Content);
            Utilities.Init(Content);

            SuperHackyLevelParsing();

            m_player = (Player)EntityManager.get().Create(EntityManager.ENT_TYPE.PLAYER);
            m_player.Init(Content);
            m_player.Spawn();
            // TODO: use this.Content to load your game content here
    }
예제 #7
0
파일: MainForm.cs 프로젝트: rostok/gleed2d
 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (Editor.Instance.SelectedItems.Count == 0)
     {
         MessageBox.Show("select some items first");
         return;
     }
     Level l = new Level();
     l.ContentRootFolder = Editor.Instance.level.ContentRootFolder;
     l.Name = "exportLevel";
     Layer la = new Layer("exportLayer");
     l.Layers.Add(la);
     foreach (Item selitem in Editor.Instance.SelectedItems)
         la.Items.Add(selitem.clone());
     
     System.Windows.Forms.Clipboard.SetText(l.exportToString());
 }