// Performs a deep copy the selected GameEntity private void clone_btn_Click(object sender, EventArgs e) { GameEntity ge = selectedObject_pg.SelectedObject as GameEntity; EntityType entity = ge.Type; Rectangle bb = ge.GetBoundingBox(); GameEntity geCopy = null; // Create new GameEntity if (entity == EntityType.RECT) { geCopy = GameEntity.CreateRectangle(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height); } if (entity == EntityType.CIRCLE) { geCopy = GameEntity.CreateCircle(bb.Width, bb.Location); } if (entity == EntityType.SPRITE) { geCopy = GameEntity.CreateSprite(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height); } if (entity == EntityType.LINETRACK) { geCopy = GameEntity.CreateLineTrack(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height); } if (entity == EntityType.CONVEYBELT) { geCopy = GameEntity.CreateConveyBelt(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height); } if (entity == EntityType.LINESIN) { geCopy = GameEntity.CreateLineSin(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height); } geCopy.SetBoundingBox(bb); // Sets bounding box geCopy.Props = ge.Props; // Deep copy of properties // Adds the gameentity to the list of entities if not null if (geCopy != null) { gameEntities_lb.Items.Add(geCopy); gameEntities_lb.SelectedIndex = gameEntities_lb.Items.Count - 1; selectedObject_pg.SelectedObject = geCopy; RefreshAll(); } }
private void TabPanel_MouseDoubleClick(object sender, MouseEventArgs me) { //Create a rectangle. GameEntity ge = null; if (toolsRect_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateRectangle(me.X, me.Y, 100, 100); } //create sprite if (toolsSprite_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateSprite(me.X, me.Y, 100, 100); } // Create a circle. if (toolsCircle_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateCircle(50, me.Location); } //create line track if (toolsLineTrack_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateLineTrack(me.X, me.Y, 100, 20); } //create convey belt if (toolsConveyBelt_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateConveyBelt(me.X, me.Y, 100, 20); } //create sinline if (toolsLineSin_rb.Checked && me.Button == MouseButtons.Left) { ge = GameEntity.CreateLineSin(me.X, me.Y, 100, 20); } if (ge != null) { gameEntities_lb.Items.Add(ge); gameEntities_lb.SelectedIndex = gameEntities_lb.Items.Count - 1; selectedObject_pg.SelectedObject = ge; RefreshAll(); } }
// Parse XML for each object type; creates new GameEntity object if possible and returns it GameEntity loadFromXml(XmlNode entity) { GameEntity ge = null; string type = entity.Attributes["TypeStr"].Value; if (type == "RECT") { XmlNode properties = entity.FirstChild; string[] outlineColour = properties.InnerText.Split(' '); properties = properties.NextSibling; string[] fillcolour = properties.InnerText.Split(' '); properties = properties.NextSibling; string[] dimension = properties.InnerText.Split(' '); ge = GameEntity.CreateRectangle(Int32.Parse(dimension[0]), Int32.Parse(dimension[1]), Int32.Parse(dimension[2]), Int32.Parse(dimension[3])); ge.Props["OutlineColor"] = Color.FromArgb(Int32.Parse(outlineColour[3]), Int32.Parse(outlineColour[0]), Int32.Parse(outlineColour[1]), Int32.Parse(outlineColour[2])); ge.Props["FillColor"] = Color.FromArgb(Int32.Parse(fillcolour[3]), Int32.Parse(fillcolour[0]), Int32.Parse(fillcolour[1]), Int32.Parse(fillcolour[2])); } else if (type == "CIRCLE") { XmlNode properties = entity.FirstChild; string[] outlineColour = properties.InnerText.Split(' '); properties = properties.NextSibling; string[] fillcolour = properties.InnerText.Split(' '); properties = properties.NextSibling; string[] radius = properties.InnerText.Split(' '); properties = properties.NextSibling; string[] position = properties.InnerText.Split(','); position[0] = position[0].Substring(3); position[1] = position[1].Substring(2, position[1].Length - 3); Point pt = new Point(Int32.Parse(position[0]), Int32.Parse(position[1])); ge = GameEntity.CreateCircle(Int32.Parse(radius[0]), pt); ge.Props["OutlineColor"] = Color.FromArgb(Int32.Parse(outlineColour[3]), Int32.Parse(outlineColour[0]), Int32.Parse(outlineColour[1]), Int32.Parse(outlineColour[2])); ge.Props["FillColor"] = Color.FromArgb(Int32.Parse(fillcolour[3]), Int32.Parse(fillcolour[0]), Int32.Parse(fillcolour[1]), Int32.Parse(fillcolour[2])); } else if (type == "SPRITE") { XmlNode properties = entity.FirstChild; string[] outlineColour = properties.InnerText.Split(' '); properties = properties.NextSibling; bool flipped = Boolean.Parse(properties.InnerText); properties = properties.NextSibling; string spriteName = properties.InnerText; properties = properties.NextSibling; string[] dimension = properties.InnerText.Split(' '); ge = GameEntity.CreateSprite(Int32.Parse(dimension[0]), Int32.Parse(dimension[1]), Int32.Parse(dimension[2]), Int32.Parse(dimension[3])); ge.Props["OutlineColor"] = Color.FromArgb(Int32.Parse(outlineColour[3]), Int32.Parse(outlineColour[0]), Int32.Parse(outlineColour[1]), Int32.Parse(outlineColour[2])); ge.Props["Flipped"] = flipped; ge.Props["SpriteName"] = spriteName; } else if (type == "LINETRACK") { XmlNode properties = entity.FirstChild; int dispHeight = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picWidth = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picHeight = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int speed = Int32.Parse(properties.InnerText); properties = properties.NextSibling; string spriteName = properties.InnerText; properties = properties.NextSibling; string[] dimension = properties.InnerText.Split(' '); ge = GameEntity.CreateLineTrack(Int32.Parse(dimension[0]), Int32.Parse(dimension[1]), Int32.Parse(dimension[2]), Int32.Parse(dimension[3])); ge.Props["DispHeight"] = dispHeight; ge.Props["PicWidth"] = picWidth; ge.Props["PicHeight"] = picHeight; ge.Props["Speed"] = speed; ge.Props["SpriteName"] = spriteName; } else if (type == "CONVEYBELT") { XmlNode properties = entity.FirstChild; int dispHeight = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picWidth = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picHeight = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int speed = Int32.Parse(properties.InnerText); properties = properties.NextSibling; bool clockwise = Boolean.Parse(properties.InnerText); properties = properties.NextSibling; string spriteName = properties.InnerText; properties = properties.NextSibling; string[] dimension = properties.InnerText.Split(' '); ge = GameEntity.CreateConveyBelt(Int32.Parse(dimension[0]), Int32.Parse(dimension[1]), Int32.Parse(dimension[2]), Int32.Parse(dimension[3])); ge.Props["DispHeight"] = dispHeight; ge.Props["PicWidth"] = picWidth; ge.Props["PicHeight"] = picHeight; ge.Props["Speed"] = speed; ge.Props["Clockwise"] = clockwise; ge.Props["SpriteName"] = spriteName; } else if (type == "LINESIN") { XmlNode properties = entity.FirstChild; int a = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int b = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int c = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picWidth = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int picHeight = Int32.Parse(properties.InnerText); properties = properties.NextSibling; int speed = Int32.Parse(properties.InnerText); properties = properties.NextSibling; bool staticBool = Boolean.Parse(properties.InnerText); properties = properties.NextSibling; string spriteName = properties.InnerText; properties = properties.NextSibling; string[] dimension = properties.InnerText.Split(' '); ge = GameEntity.CreateLineSin(Int32.Parse(dimension[0]), Int32.Parse(dimension[1]), Int32.Parse(dimension[2]), Int32.Parse(dimension[3])); ge.Props["a"] = a; ge.Props["b"] = b; ge.Props["c"] = c; ge.Props["PicWidth"] = picWidth; ge.Props["PicHeight"] = picHeight; ge.Props["Speed"] = speed; ge.Props["Static"] = staticBool; ge.Props["SpriteName"] = spriteName; } return(ge); }