public static bool PlaceEmptyRectangle(RectangleF rr) { foreach (RoomLayer rl in roomLayers) { if (rl.Visible) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; foreach (GameObject g in ol.Objects) { if (g == currentObject) { continue; } RectangleF r = new Rectangle((int)g.Position.X, (int)g.Position.Y, g.Sprite.ImageRectangle.Width, g.Sprite.ImageRectangle.Height); if (r.Intersects(rr)) { return(false); } } } } } return(true); }
public static GameObject instance_place(Vector2 vec) { roomLayers.Reverse(); foreach (RoomLayer rl in roomLayers) { if (rl.Visible) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; for (int i = ol.Objects.Count - 1; i >= 0; i--) { RectangleF r = new Rectangle((int)ol.Objects[i].Position.X, (int)ol.Objects[i].Position.Y, ol.Objects[i].Sprite.ImageRectangle.Width, ol.Objects[i].Sprite.ImageRectangle.Height); if (r.Contains(vec)) { roomLayers.Reverse(); return(ol.Objects[i]); } } } } } roomLayers.Reverse(); return(null); }
public static List <T> instance_find <T>(Predicate <T> predicate) { List <T> outputList = new List <T>(); foreach (RoomLayer rl in roomLayers) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; outputList.AddRange(ol.Objects.FindAll(x => x.OriginalType == typeof(T)).Cast <T>().ToList().FindAll(predicate)); } } return(outputList); }
public static void instance_destroy(Type type) { foreach (RoomLayer rl in roomLayers) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; foreach (GameObject go in ol.Objects) { if (go.OriginalType == type) { go.Layer.Objects.Remove(go); SceneObjects.Remove(go); } } } } }
public static void instance_destroy(Type type) { foreach (RoomLayer rl in roomLayers) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; foreach (GameObject go in ol.Objects) { if (go.OriginalType == type) { go.Layer.Objects.Remove(go); SceneObjects.Remove(go); if (CollisionsTree.CollisionActiveTypes.Contains(go.GetType())) { SceneColliders.Remove(go); } } } } } }
public static void room_goto(Type room) { // First (again) but I've tackled down later // we // need // to // weed... no! We need to check if current room is persistent // and if that's the case well then boy.. we gonna create a shadow copy of it // saving state of it for later (overwrite if needed // R u persistent madafaka? if (currentRoom != null && currentRoom.Persistent) { // Save teh bitch game_save("temp_" + currentRoom.GetType().ToString().Split('.').Last() + ".sav"); } // Now we check if the next room is persistent // true --> load shadow copy of that room if it exists, otherwise create it from an actual copy // false --> load common copy // Instantiate that room to see what's inside GameRoom tempRoom = (GameRoom)Activator.CreateInstance(room); string mapContent = Path.Combine(RoomEditor.editorForm.currentProject.RootPath, @"\Maps\" + tempRoom.GetType().ToString().Split('.').Last()); // Store persistent objects List <GameObject> persistentObjects = SceneObjects.Where(x => x.Persistent).ToList(); if (tempRoom.Persistent) { // TODO } else { Form1.activeRoom = RoomEditor.roomsControl.dtv.Nodes[0].Nodes.FirstOrDefault(x => x.Text == tempRoom.GetType().ToString().Split('.').Last()); RoomEditor.editorForm.setStatusBottom("Editing " + Form1.activeRoom.Text); game_load(mapContent); // Also we need to assign them all to appropriate layers foreach (GameObject go in persistentObjects) { if (go.PersistentLayer == "") { // Try to find first ObjectLayer ObjectLayer ol = (ObjectLayer)RoomEditor.currentRoom.Layers.FirstOrDefault(x => x is ObjectLayer); if (ol != null) { go.Layer = ol; go.LayerName = go.Layer.Name; go.Layer.Objects.Add(go); sh.RegisterObject(go); } } } SceneObjects.AddRange(persistentObjects); } }
public static void __loadGameObjects(List <GameObject> objects, bool execCreateEvt = true, bool execLoadEvt = true, bool execSetupEvt = true, bool reset = true) { SceneObjects.Clear(); foreach (RoomLayer rl in currentRoom.Layers) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; ol.Objects.Clear(); } } foreach (GameObject g in objects) { if (reset) { g.Reset(); } Spritesheet s = Sprites.FirstOrDefault(x => x.Name == g.Sprite.TextureSource); g.Position = g.__DefaultPosition; g.ImageAngle = g.__DefaultImageAngle; g.Direction = g.__DefaultDirection; g.ImageScale = g.__DefaultImageScale; g.ImageIndex = g.__DefaultImageIndex; g.Sprite.Texture = s.Texture; g.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight); g.Sprite.TextureRows = s.Rows; g.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth; g.Sprite.ImageSize = new Vector2(s.CellWidth, s.CellHeight); g.Sprite.FramesCount = (s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1; g.FramesCount = g.Sprite.FramesCount - 1; g.Sprite.cellW = s.CellHeight; g.Sprite.cellH = s.CellWidth; RoomLayer rt = currentRoom.Layers.FirstOrDefault(x => x.Name == g.LayerName); g.Layer = (ObjectLayer)rt; g.Sprite.UpdateImageRectangle(); g.UpdateState(); g.UpdateColliders(); // Need to give object OriginalType !!! g.OriginalType = Type.GetType(g.TypeString); currentObject = g; if (execCreateEvt) { g.EvtCreate(); } if (execLoadEvt) { g.EvtLoad(); } if (execSetupEvt) { g.EvtSetup(); } SceneObjects.Add(g); g.Layer.Objects.Add(g); sh.RegisterObject(g); if (g.Colliders.Count > 0) { SceneColliders.Add(g); } } foreach (GameObject g in SceneObjects) { g.EvtCreateEnd(); } }