public override void OnInitialization() { int z = 0; foreach (LayerSource layer in this.Source.Layers) { foreach (EntityInstance i in layer.Entities) { Type t = this.Parent.EntityTypes.First(item => item.Name == i.Type); Entity e = (Entity)t.GetConstructor(new Type[0]).Invoke(new object[0]); foreach (KeyValuePair <string, string> property in i.Properties) { FieldInfo f = t.GetField(property.Key); f.SetValue(e, property.Value.To(f.FieldType)); } e.Position = new Vector(i.X, i.Y); e.Z = z + 0.3 + Meth.InfToOne(i.Z) * 0.1 - this.Source._MainLayerZ; if (this._SavedEntities != null) { Bunch <SavedEntity> ss = this._SavedEntities.Where(item => item.Identifier == e.Identifier); if (ss.Count > 0) { ss[0].Apply(e); } } this.Children.Add(e); if (e is LevelConnection) { this._Entrances[e.Identifier] = e; } } z++; } for (int i = 0; i < this.Source.LayerImages.Count; i++) { Image img = new Image(this.Source.LayerImages[i]) { Z = i * 0.5 - this.Source._MainLayerZ }; this.Graphics.Add(img); this.Layers.Add(img); } this.Static = true; }
public override void Update() { this.Z = this.StartedDragging ? 10 : (3.5 + Meth.InfToOne(this.EntityZ) / 2); if (TileEditor.Editor.TabListRight.CurName == "Entities") { this.Area.Enabled = true; this.Icon.Color = this.IsInsideLevel ? Color.White : Color.White ^ 170; this.Icon.Shader["Selected"] = (this.Selected && !this.StartedDragging) ? 1 : 0; this.Icon.Shader["Color0"] = Meth.Down(this.Runtime / 20.0) % 2 == 0 ? Color.Black : Color.White; this.Icon.Shader["Color1"] = Meth.Down(this.Runtime / 20.0) % 2 == 1 ? Color.Black : Color.White; this.IconOverlay.Color = Color.White ^ 85; this.IconOverlay.Shader["Selected"] = (this.Selected && !this.StartedDragging) ? 1 : 0; this.IconOverlay.Shader["Color0"] = Meth.Down(this.Runtime / 20.0) % 2 == 0 ? Color.Black : Color.White; this.IconOverlay.Shader["Color1"] = Meth.Down(this.Runtime / 20.0) % 2 == 1 ? Color.Black : Color.White; if (this.Type.Entrance) { this.TestArea.Enabled = true; this.TestButton.Visible = true; this.TestButton.Color = Color.Green * (this.TestArea.IsHovered ? 1 : 0.7); } } else { this.Area.Enabled = false; this.Icon.Color = Color.Transparent; this.Icon.Shader["Selected"] = 0; this.IconOverlay.Color = Color.White ^ 85; this.IconOverlay.Shader["Selected"] = 0; if (this.Type.Entrance) { this.TestArea.Enabled = false; this.TestButton.Visible = false; } } }
public override void OnInitialization() { //this.Entities = this.Parent.EntityTypes; //for (int i = 0; i < this.Source.Layers.Count; i++) //{ // LayerSource l = this.Source.Layers[i]; // for (int n = 0; n <= 1; n++) // { // Renderer r = new Renderer(this.Size * this.Source._Game.Tilesize); // for (int x = 0; x < this.Size.X; x++) // { // for (int y = 0; y < this.Size.Y; y++) // { // if (this.Source._Game.Areasets[l.Tiles[x, y].Item1].Cols[l.Tiles[x, y].Item2].Any(item => item) == (n == 1)) // r.Draw(new Image(this.Source._Game.Areasets[l.Tiles[x, y].Item1].Tiles[l.Tiles[x, y].Item2]) { BlendMode = BlendMode.None, Position = new Vector(x, y) * this.Source._Game.Tilesize }); // } // } // Image img = new Image(r.ImageSource) { Z = i + n * 0.6 }; // this.Layers.Add(img); // this.Graphics.Add(img); // } //} int z = 0; foreach (LayerSource layer in this.Source.Layers) { foreach (EntityInstance i in layer.Entities) { Type t = this.Parent.EntityTypes.First(item => item.Name == i.Type); Entity e = (Entity)t.GetConstructor(new Type[0]).Invoke(new object[0]); foreach (KeyValuePair <string, string> property in i.Properties) { FieldInfo f = t.GetField(property.Key); f.SetValue(e, property.Value.To(f.FieldType)); } e.Position = new Vector(i.X, i.Y); e.Z = z + 0.3 + Meth.InfToOne(i.Z) * 0.1 - this.Source._MainLayerZ; //if (this._SavedEntities != null) //{ // Bunch<SavedEntity> ss = this._SavedEntities.Where(item => item.Identifier == e.Identifier); // if (ss.Count > 0) // ss[0].Apply(e); //} this.Children.Add(e); } z++; } Bunch <ImageSource> layers = new Bunch <ImageSource>(); foreach (LayerSource l in this.Source.Layers) { //if (l.Main) // this.MainLayer = l; //this.Layers.Add(l); for (int n = 0; n <= 1; n++) { Renderer r = new Renderer(this.Size * this.Parent.Tilesize); Bunch <Graphic> gs = new Bunch <Graphic>(); for (int x = 0; x < this.Size.X; x++) { for (int y = 0; y < this.Size.Y; y++) { if (this.Parent.Areasets[l.Tiles[x, y].Item1].Cols[l.Tiles[x, y].Item2].Any(item => item) == (n == 1)) { gs.Add(new Image(this.Parent.Areasets[l.Tiles[x, y].Item1].Tiles[l.Tiles[x, y].Item2]) { BlendMode = BlendMode.None, Position = new Vector(x, y) * this.Parent.Tilesize }); } } } r.Draw(gs); layers.Add(r.ImageSource); } } for (int i = 0; i < layers.Count; i++) { Image img = new Image(layers[i]) { Z = i * 0.5 - this.Source._MainLayerZ }; this.Graphics.Add(img); this.Layers.Add(img); } //this.Liquid = new Liquid(this.Source.Collisions) { Z = 1000 }; //this.Liquid.Liquids[5, 8] = 32; //this.Liquid.Liquids[6, 8] = 32; //this.Liquid.Liquids[7, 8] = 32; //this.Liquid.Liquids[8, 8] = 32; //this.Liquid.Liquids[9, 8] = 32; //this.Liquid.Liquids[10, 8] = 32; //this.Liquid.Liquids[11, 8] = 32; //this.Liquid.Liquids[12, 8] = 32; //this.Children.Add(this.Liquid); this.Static = true; foreach (Collider c in this.Source.Colliders) { this.AddCollider(c); //this.Graphics.Add(c.Shape); } this.Friction = this.LevelFriction; }