public static Level ReadFile(BinaryReader Reader) { Level NewLevel = new Level(ReadRectangle(Reader), new Camera(ReadVector4(Reader))); NewLevel.MyCamera.EditorOffset = ReadVector2(Reader); int ObjectCount = Reader.ReadInt32(); NewLevel.ObjectList = new List <BasicObject>(ObjectCount); for (int i = 0; i < ObjectCount; i++) { BasicObject NewObject = Instancer.CreateInstanceOf(Reader.ReadString(), NewLevel); NewObject.Create(Vector2.Zero, Vector2.Zero); // if (NewObject != null) { NewObject.PreRead(Reader); NewObject.Read(Reader); } } try { NewLevel.MyBackground = BackgroundBasic.ReturnBackground(Reader.ReadInt32()); } catch (Exception e) { } return(NewLevel); }
public override void Update() { MousePos = Vector2.Transform(new Vector2(WindowManager.mouseState.X, WindowManager.mouseState.Y), Matrix.Invert(GameManager.MyLevel.MyCamera.ReturnMatrix())); MousePoint = new Point((int)MousePos.X, (int)MousePos.Y); if (WindowManager.KeyState.IsKeyDown(Keys.Delete)) { List <Object> DeleteList = new List <object>(); foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.Selected) { DeleteList.Add(Object); } } foreach (BasicObject Object in DeleteList) { Object.Delete(); } } if (WindowManager.mouseState.LeftButton == ButtonState.Released) { if (DraggingMove) { GameManager.MyLevel.HasChanged = true; foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.Selected) { int x = (int)(Math.Floor(Object.Position.X / MasterEditor.GridSize.X) * (float)MasterEditor.GridSize.X); int y = (int)(Math.Floor(Object.Position.Y / MasterEditor.GridSize.Y) * (float)MasterEditor.GridSize.Y); Object.ChangePosition(new Vector2(x, y)); } } } if (DraggingSelect) { if (MasterEditor.mouseMode == MouseMode.Select) { foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { Object.ChangeSelect(false); } foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.MyRectangle.Intersects(DragRectangle)) { Object.ChangeSelect(true); } } } else { Rectangle LvlRect = GameManager.MyLevel.MyRectangle; for (int x = (int)(Math.Floor(LvlRect.X / MasterEditor.GridSize.X) * (float)MasterEditor.GridSize.X); x < LvlRect.X + LvlRect.Width; x += (int)MasterEditor.GridSize.X) { for (int y = (int)(Math.Floor(LvlRect.Y / MasterEditor.GridSize.X) * (float)MasterEditor.GridSize.X); y < LvlRect.Y + LvlRect.Height; y += (int)MasterEditor.GridSize.Y) { Rectangle CheckRect = new Rectangle(x, y, (int)MasterEditor.GridSize.X, (int)MasterEditor.GridSize.Y); if (CheckRect.Intersects(DragRectangle)) { bool PlaceFree = false; if (GameManager.MyLevel.MyRectangle.Contains(CheckRect)) { PlaceFree = true; foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.MyRectangle.Intersects(CheckRect)) { PlaceFree = false; } } } if (PlaceFree) { BasicObject Object = (BasicObject)Instancer.CreateInstanceOf(MasterEditor.SelectedObjectCreater, GameManager.MyLevel); Object.Create(MasterEditor.GridSize, new Vector2(x, y)); } } } } } } DraggingMove = false; DraggingSelect = false; Dragging = false; } if (WindowManager.mouseState.RightButton == ButtonState.Released) { DraggingCamera = false; } if (Dragging) { Rectangle PreviousRect = EditorStatic.CloneRectangle(GameManager.MyLevel.MyRectangle); Rectangle LevelRect = GameManager.MyLevel.MyRectangle; LevelRect.Width += (int)(MousePos.X - DragPos.X) * DraggingX; LevelRect.Height += (int)(MousePos.Y - DragPos.Y) * DraggingY; LevelRect.X += (int)(MousePos.X - DragPos.X) * Math.Abs(Math.Min(0, DraggingX)); LevelRect.Y += (int)(MousePos.Y - DragPos.Y) * Math.Abs(Math.Min(0, DraggingY)); LevelRect.Width = Math.Max(100, LevelRect.Width); LevelRect.Height = Math.Max(100, LevelRect.Height); GameManager.MyLevel.MyRectangle = LevelRect; GameManager.MyLevel.HasResized = true; GameManager.MyLevel.MyCamera.EditorOffset += new Vector2(LevelRect.Width - PreviousRect.Width, LevelRect.Height - PreviousRect.Height) / 2 * new Vector2(Math.Abs(DraggingX), Math.Abs(DraggingY)); DragPos = MousePos; } if (DraggingSelect) { DragRectangle.Width = MousePoint.X - DragRectangle.X; DragRectangle.Height = MousePoint.Y - DragRectangle.Y; } if (DraggingMove) { Vector2 Change = MousePos - MoveDragPos; foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.Selected) { Object.ChangePosition(Object.Position + Change); } } MoveDragPos = MousePos; } if (DraggingCamera) { GameManager.MyLevel.MyCamera.EditorOffset += (MousePos - CameraDragPos) / 2; CameraDragPos = MousePos; } if (GameManager.MyLevel != null) { GameManager.MyLevel.MyCamera.MyRectangle = new Vector4( GameManager.MyLevel.MyCamera.EditorOffset.X + (Game1.self.Window.ClientBounds.Width - GameManager.MyLevel.MyRectangle.Width) / 2, GameManager.MyLevel.MyCamera.EditorOffset.Y + (Game1.self.Window.ClientBounds.Height - GameManager.MyLevel.MyRectangle.Height) / 2, //200,200, Game1.self.Window.ClientBounds.Width, Game1.self.Window.ClientBounds.Height ); } base.Update(); }
public override void ContainsMouse() { if (!Dragging && !DraggingCamera) { if (WindowManager.JustRightClicked && WindowManager.KeyState.IsKeyDown(Keys.LeftShift)) { DraggingCamera = true; CameraDragPos = MousePos; } if (WindowManager.JustLeftClicked) { LeftClick(); } if (GameManager.MyLevel.MyRectangle.Contains(MousePoint)) { if (WindowManager.mouseState.LeftButton.Equals(ButtonState.Pressed)) { if (MasterEditor.mouseMode == MouseMode.Place) { int x = (int)(Math.Floor(MousePos.X / MasterEditor.GridSize.X) * (float)MasterEditor.GridSize.X); int y = (int)(Math.Floor(MousePos.Y / MasterEditor.GridSize.Y) * (float)MasterEditor.GridSize.Y); Rectangle CheckRect = new Rectangle(x, y, (int)MasterEditor.GridSize.X, (int)MasterEditor.GridSize.Y); bool PlaceFree = false; if (GameManager.MyLevel.MyRectangle.Contains(CheckRect)) { PlaceFree = true; foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.MyRectangle.Intersects(CheckRect)) { PlaceFree = false; } } } if (PlaceFree) { BasicObject NewObject = (BasicObject)Instancer.CreateInstanceOf(MasterEditor.SelectedObjectCreater, GameManager.MyLevel); NewObject.Create(MasterEditor.GridSize, new Vector2(x, y)); } } } } if (WindowManager.mouseState.RightButton.Equals(ButtonState.Pressed) && WindowManager.KeyState.IsKeyUp(Keys.LeftShift)) { List <BasicObject> DeleteObjects = new List <BasicObject>(GameManager.MyLevel.ObjectList.Count); int x = (int)(Math.Floor(MousePos.X / MasterEditor.GridSize.X) * (float)MasterEditor.GridSize.X); int y = (int)(Math.Floor(MousePos.Y / MasterEditor.GridSize.Y) * (float)MasterEditor.GridSize.Y); Rectangle CheckRect = new Rectangle(x, y, (int)MasterEditor.GridSize.X, (int)MasterEditor.GridSize.Y); foreach (BasicObject Object in GameManager.MyLevel.ObjectList) { if (Object.MyRectangle.Intersects(CheckRect)) { DeleteObjects.Add(Object); } } foreach (BasicObject Object in DeleteObjects) { Object.Delete(); } } } base.ContainsMouse(); }