Exemple #1
0
 public Entity(Entity e)
 {
     texture = e.texture;
     textureName = e.textureName;
     rect = e.rect;
     rotation = e.rotation;
     name = "new " + e.Name;
     foreach (CollisionList c in e.cVolumes)
     {
         CollisionList col = new CollisionList();
         col.Clone(c, e);
         cVolumes.Add(col);
     }
     Translate(rect.Width, 0);
 }
        private void button12_Click(object sender, EventArgs e)
        {
            if (currFrame < current.frames.Count - 1)
            {
                if (current.collision[currFrame + 1].Count < colIndex)
                { current.collision[currFrame + 1].Add(null); }

                CollisionList cl = new CollisionList();
                cl.Clone(current.collision[currFrame][colIndex]);
                current.collision[currFrame + 1][colIndex] = cl;
            }
        }
Exemple #3
0
        public void SaveBlueprint()
        {
            //FileStream fs = File.Open(Environment.GetFolderPath(
            //    Environment.SpecialFolder.LocalApplicationData) + name + ".json", FileMode.Create);
            FileStream fs = File.Open("blueprints\\" + name + ".json", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            JsonTextWriter jw = new JsonTextWriter(sw);
            jw.Formatting = Formatting.Indented;

            jw.WriteStartObject();
            jw.WritePropertyName("name");
            jw.WriteValue(name);
            jw.WritePropertyName("rotation");
            jw.WriteValue(rotation);
            jw.WritePropertyName("x");
            Vector2 center = new Vector2(rect.Center.X, rect.Center.Y);
            jw.WriteValue(center.X);
            jw.WritePropertyName("y");
            jw.WriteValue(center.Y);
            jw.WritePropertyName("width");
            jw.WriteValue(rect.Width);
            jw.WritePropertyName("height");
            jw.WriteValue(rect.Height);
            jw.WritePropertyName("collisionVolumes");
            jw.WriteStartArray();
            foreach (CollisionList cl in cVolumes)
            {
                jw.WriteStartObject();
                jw.WritePropertyName("physical");
                jw.WriteValue(cl.Physical);
                jw.WritePropertyName("xpoints");
                jw.WriteStartArray();
                CollisionList copyList = new CollisionList();
                copyList.Clone(cl, this);
                copyList.Rotate(-rotation * 2, rect.Center.X, rect.Center.Y);
                foreach (CollisionPoint p in copyList.Nodes)
                {
                    jw.WriteValue(p.X - center.X);
                }
                jw.WriteEnd();
                jw.WritePropertyName("ypoints");
                jw.WriteStartArray();
                foreach (CollisionPoint p in copyList.Nodes)
                {
                    jw.WriteValue(p.Y - center.Y);
                }
                jw.WriteEnd();
            }

            jw.WriteEnd();
            jw.WriteEnd();
            jw.WritePropertyName("texture");
            jw.WriteValue(textureName);
            jw.WritePropertyName("dynamic");
            jw.WriteValue(dynamic);
            jw.WritePropertyName("tags");
            jw.WriteStartArray();
            foreach (string s in tags)
            {
                jw.WriteValue(s);
            }
            jw.WriteEnd();

            jw.WriteEnd();
            jw.Close();

            fs = File.Open("blueprints\\" + name + ".json", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string json = sr.ReadToEnd();

            Editor.AddBlueprint(name, json);

            fs.Close();
        }