Exemple #1
0
        /// <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();
        }
Exemple #2
0
        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
                }
            }
        }
Exemple #3
0
        /// <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();
        }
Exemple #4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released)
            {
                world.Insert(ShapePrimitives.BezelRectangle(new Vector2(mouse.X, mouse.Y), new Vector2(mouse.X + 20, mouse.Y + 20), 5));
            }
            lastMouse = mouse;

            float         deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            KeyboardState ks        = Keyboard.GetState();
            Vector2       velocity  = Vector2.Zero;
            float         speed     = 90; // a link to the past link moves at 90 pixels per second!

            if (ks.IsKeyDown(Keys.W))
            {
                velocity += new Vector2(0, -speed * deltaTime);
            }
            if (ks.IsKeyDown(Keys.S))
            {
                velocity += new Vector2(0, speed * deltaTime);
            }
            if (ks.IsKeyDown(Keys.A))
            {
                velocity += new Vector2(-speed * deltaTime, 0);
            }
            if (ks.IsKeyDown(Keys.D))
            {
                velocity += new Vector2(speed * deltaTime, 0);
            }

            world.ClearDebugTag();
            List <Polygon> polys = world.Retrieve(new RectangleF(poly1.Origin.X + poly1.BoundingBox.Left, poly1.Origin.Y + poly1.BoundingBox.Top, poly1.BoundingBox.Width, poly1.BoundingBox.Height));

            foreach (IPolygon poly in polys)
            {
                poly.AddTag("debug");
            }

            Window.Title = polys.Count.ToString();
            poly1.Move(polys, velocity);


            base.Update(gameTime);
        }