public void Clone(CollisionList list)
        {
            if (list.head != null)
            {
                CollisionPoint c = list.head;

                while (c != null)
                {
                    Add(c.X, c.Y);
                    c = c.Next;
                }
            }
        }
        /// <summary>
        /// Create new nodes to match another collision list
        /// </summary>
        /// <param name="c">The list to clone</param>
        public void Clone(CollisionList list, Entity e)
        {
            if (list.head != null)
            {
                CollisionPoint c = list.head;

                while (c != null)
                {
                    Add(c.X, c.Y);
                    c = c.Next;
                }
            }

            Rotate(e.Rotation, e.Rect.Center.X, e.Rect.Center.Y);
        }
Beispiel #3
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);
 }
Beispiel #4
0
 public Entity(string unparsedJson)
 {
     JObject json = JObject.Parse(unparsedJson);
     name = (string)json["name"];
     string textureName = (string)json["texture"];
     this.textureName = textureName;
      texture = MenuSystem.textureBank.Textures[textureName];
     int x, y, w, h;
     x = (int)((float)json["x"]);
     y = (int)((float)json["y"]);
     w = (int)json["width"];
     h = (int)json["height"];
     rect = new Rectangle(x - (w / 2), y - (h / 2), w, h);
     rotation = (float)json["rotation"];
     JArray volumes = (JArray)json["collisionVolumes"];
     for (int index = 0; index < volumes.Count; index++)
     {
         CollisionList cl = new CollisionList();
         JObject collisionJson = (JObject)(volumes[index]);
         JArray points = (JArray)collisionJson["xpoints"];
         List<float> xpoints = new List<float>();
         for (int i = 0; i < points.Count; i++)
         {
             xpoints.Add((float)points[i] + x);
         }
         points = (JArray)collisionJson["ypoints"];
         List<float> ypoints = new List<float>();
         for (int i = 0; i < points.Count; i++)
         {
             ypoints.Add((float)points[i] + y);
         }
         for (int i = 0; i < xpoints.Count; i++)
         {
             cl.Add(xpoints[i], ypoints[i]);
         }
         cl.Physical = (bool)collisionJson["physical"];
         cVolumes.Add(cl);
     }
     dynamic = (bool)json["dynamic"];
     JArray tags = (JArray)json["tags"];
     for (int index = 0; index < tags.Count; index++)
     {
         this.tags.Add((string)tags[index]);
     }
 }
        public void LoadAnim(string unparsedJson)
        {
            JObject json = JObject.Parse(unparsedJson);
            JArray animations = (JArray)json["animations"];
            for (int i = 0; i < animations.Count; i++)
            {
                anims.Add(new Animation());
                JObject animation = (JObject)(animations[i]);
                anims[i].name = (string)animation["name"];
                anims[i].speed = (float)animation["speed"];
                anims[i].loopback = (int)animation["loop"];
                anims[i].nFrames = (int)animation["frames"];

                JArray collisionArray = (JArray)animation["collisionVolumes"];
                for (int ca = 0; ca < collisionArray.Count; ca++)
                {
                    JObject volumeContainer = (JObject)(collisionArray[ca]);
                    JArray volumes = (JArray)volumeContainer["volumes"];
                    anims[i].collision.Add(new List<CollisionList>());

                    for (int v = 0; v < volumes.Count; v++)
                    {
                        JObject volume = (JObject)(volumes[v]);

                        float centerX = (float)volume["centerX"];
                        float centerY = (float)volume["centerY"];
                        bool physical = (bool)volume["physical"];
                        CollisionList cl = new CollisionList();
                        JArray points = (JArray)volume["xpoints"];
                        List<float> xpoints = new List<float>();
                        for (int p = 0; p < points.Count; p++)
                        {
                            xpoints.Add((float)points[p] + centerX);
                        }
                        points = (JArray)volume["ypoints"];
                        List<float> ypoints = new List<float>();
                        for (int p = 0; p< points.Count; p++)
                        {
                            ypoints.Add((float)points[p] + centerY);
                        }
                        for (int p = 0; p < xpoints.Count; p++)
                        {
                            cl.Add(xpoints[p], ypoints[p]);
                        }

                        anims[i].collision[ca].Add(cl);
                    }
                }
            }
            foreach (Animation anim in anims)
            {
                if (Directory.Exists("images\\anim\\" + entity.Name + "\\" + anim.name))
                {
                    for (int i = 0; i < anim.nFrames; i++)
                    {
                        Stream s = File.OpenRead("images\\anim\\" + entity.Name + "\\" + anim.name + "\\" + i + ".png");
                        Texture2D texture = Texture2D.FromStream(graphics, s);
                        anim.frames.Add(texture);
                    }
                }
            }
        }
        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;
            }
        }
Beispiel #7
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();
        }