/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here poly1 = new Polygon(Vector2.Zero, new List <Vector2>() { new Vector2(100, 0), new Vector2(150, 50), new Vector2(100, 150), new Vector2(0, 100) }); poly2 = new Polygon(new Vector2(80, 80), new List <Vector2>() { new Vector2(50, 50), new Vector2(100, 0), new Vector2(150, 150) }); poly3 = new Polygon(new Vector2(400, 200), new List <Vector2>() { new Vector2(0, 50), new Vector2(50, 0), new Vector2(150, 80), new Vector2(160, 200), new Vector2(-10, 190) }); circle = ShapePrimitives.Circle(new Vector2(400, 200), 60, 16); rect = ShapePrimitives.Rectangle(new Vector2(60, 60), new Vector2(120, 120)); base.Initialize(); }
public void LoadBoundaryData() { foreach (var objectLayer in MapData.ObjectLayers) { foreach (var obj in objectLayer.Objects) { if (objectLayer.Name.Contains("collision") && obj is TiledMapRectangleObject) { if (obj is TiledMapPolygonObject) { Point2[] points = (obj as TiledMapPolygonObject).Points; List <Vector2> newPoints = points.Select(point => new Vector2(point.X, point.Y)).ToList(); World.Insert(new Polygon(obj.Position, newPoints)); } else if (obj is TiledMapRectangleObject) { TiledMapRectangleObject rect = obj as TiledMapRectangleObject; Polygon p = ShapePrimitives.Rectangle(obj.Position, (obj as TiledMapRectangleObject).Size.Width, (obj as TiledMapRectangleObject).Size.Height); World.Insert(p); } else { throw new Exception("uhh something's missing :>"); } } if (objectLayer.Name.Contains("scripts") && obj is TiledMapRectangleObject) { Vector2 pos = (obj as TiledMapRectangleObject).Position; Size2 size = (obj as TiledMapRectangleObject).Size; Rectangle rect = new Rectangle( (int)(pos.X / MapData.TileWidth), (int)(pos.Y / MapData.TileHeight), (int)(size.Width / MapData.TileWidth), (int)(size.Height / MapData.TileHeight)); for (int x = rect.Left; x < rect.Right; x++) { for (int y = rect.Top; y < rect.Bottom; y++) { InteractScripts.Add(new MapObject <ScriptData>() { X = x, Y = y, Data = new ScriptData() { Script = obj.Name } }); } } } // todo: handle scripts, warps, etc etc } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here IsMouseVisible = true; graphics.PreferredBackBufferHeight = 600; graphics.PreferredBackBufferWidth = 800; graphics.ApplyChanges(); world = new Quadtree <Polygon>(new RectangleF(0, 0, 800, 600)); poly1 = new Polygon(Vector2.Zero, new List <Vector2>() { new Vector2(25, 0), new Vector2(38, 12), new Vector2(25, 38), new Vector2(0, 25) }); world.Insert(new Polygon(new Vector2(80, 80), new List <Vector2>() { new Vector2(50, 50), new Vector2(100, 0), new Vector2(150, 150) })); world.Insert(new Polygon(new Vector2(400, 200), new List <Vector2>() { new Vector2(0, 50), new Vector2(50, 0), new Vector2(150, 80), new Vector2(160, 200), new Vector2(-10, 190) })); world.Insert(ShapePrimitives.Circle(new Vector2(600, 200), 60, 10)); world.Insert(ShapePrimitives.BezelRectangle(new Vector2(60, 60), new Vector2(160, 220), 15)); world.Insert(ShapePrimitives.Rectangle(new Vector2(620, 200), new Vector2(660, 230))); world.Insert(ShapePrimitives.Rectangle(new Vector2(0, 400), new Vector2(30, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(30, 400), new Vector2(60, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(60, 400), new Vector2(90, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(90, 400), new Vector2(120, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(120, 400), new Vector2(150, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(150, 400), new Vector2(180, 430))); world.Insert(ShapePrimitives.Rectangle(new Vector2(0, 430), new Vector2(30, 460))); world.Insert(ShapePrimitives.Rectangle(new Vector2(30, 430), new Vector2(60, 460))); world.Insert(ShapePrimitives.Rectangle(new Vector2(60, 430), new Vector2(90, 460))); world.Insert(ShapePrimitives.Rectangle(new Vector2(90, 430), new Vector2(120, 460))); world.Insert(ShapePrimitives.Rectangle(new Vector2(120, 430), new Vector2(150, 460))); world.Insert(ShapePrimitives.Rectangle(new Vector2(150, 430), new Vector2(180, 460))); base.Initialize(); }