Exemple #1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(Globals.GraphicsDevice);

            ScreenUtility.InitGraphicsMode(800, 480, false);

            var vertices = new List <Vector2>();

            vertices.Add(new Vector2(100, 100));
            vertices.Add(new Vector2(200, 100));
            vertices.Add(new Vector2(150, 150));

            _polygons[0] = new PolygonExtent();
            _polygons[0].Reset(vertices);
            _polygons[0].ReAnchor(_polygons[0].Center);

            vertices.Clear();
            vertices.Add(new Vector2(300, 300));
            vertices.Add(new Vector2(400, 300));
            vertices.Add(new Vector2(400, 400));
            vertices.Add(new Vector2(300, 400));

            _polygons[1] = new PolygonExtent();
            _polygons[1].Reset(vertices);
            _polygons[1].ReAnchor(_polygons[1].Center);

            vertices.Clear();
            vertices.Add(new Vector2(300, 300));
            vertices.Add(new Vector2(400, 300));
            vertices.Add(new Vector2(420, 400));
            vertices.Add(new Vector2(350, 450));
            vertices.Add(new Vector2(280, 400));

            _polygons[2] = new PolygonExtent();
            _polygons[2].Reset(vertices);
            _polygons[2].ReAnchor(_polygons[2].Center);

            vertices.Clear();
            Vector2 offset = new Vector2(300, 100);

            vertices.Add(offset + new Vector2(0, 0));
            vertices.Add(offset + new Vector2(50, 0));
            vertices.Add(offset + new Vector2(50, -50));
            vertices.Add(offset + new Vector2(100, -50));
            vertices.Add(offset + new Vector2(100, 0));
            vertices.Add(offset + new Vector2(150, 0));
            vertices.Add(offset + new Vector2(150, 50));
            vertices.Add(offset + new Vector2(100, 50));
            vertices.Add(offset + new Vector2(100, 100));
            vertices.Add(offset + new Vector2(50, 100));
            vertices.Add(offset + new Vector2(50, 50));
            vertices.Add(offset + new Vector2(0, 50));

            _polygons[3] = new PolygonExtent();
            _polygons[3].Reset(vertices);
            _polygons[3].ReAnchor(_polygons[3].Center);

            _contentLoaded = true;
        }
Exemple #2
0
        protected override void Update(GameTime gameTime)
        {
            // For Mobile devices, this logic will close the Game when the Back button is pressed
            // Exit() is obsolete on iOS
#if !__IOS__ && !__TVOS__
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
#endif
            base.Update(gameTime);
            KeyboardState ks = Keyboard.GetState();

            #region Move Polygon
            PolygonExtent polygonToMove = null;

            if (ks.IsKeyDown(Keys.D1))
            {
                polygonToMove = _polygons[0];
            }
            if (ks.IsKeyDown(Keys.D2))
            {
                polygonToMove = _polygons[1];
            }
            if (ks.IsKeyDown(Keys.D3))
            {
                polygonToMove = _polygons[2];
            }
            if (ks.IsKeyDown(Keys.D4))
            {
                polygonToMove = _polygons[3];
            }

            if (null != polygonToMove)
            {
                if (ks.IsKeyDown(Keys.A))
                {
                    polygonToMove.Anchor -= new Vector2(5, 0);
                }
                if (ks.IsKeyDown(Keys.D))
                {
                    polygonToMove.Anchor += new Vector2(5, 0);
                }
                if (ks.IsKeyDown(Keys.W))
                {
                    polygonToMove.Anchor -= new Vector2(0, 5);
                }
                if (ks.IsKeyDown(Keys.S))
                {
                    polygonToMove.Anchor += new Vector2(0, 5);
                }
                if (ks.IsKeyDown(Keys.Q))
                {
                    polygonToMove.Angle -= 0.04f;
                }
                if (ks.IsKeyDown(Keys.E))
                {
                    polygonToMove.Angle += 0.04f;
                }
                if (ks.IsKeyDown(Keys.Z))
                {
                    polygonToMove.Scale *= 1.04f;
                }
                if (ks.IsKeyDown(Keys.C))
                {
                    polygonToMove.Scale /= 1.04f;
                }
            }
            #endregion

            #region Check for Collisions
            for (int i = 0; i < 4; i++)
            {
                _inCollision[i] = false;
            }

            for (int i = 0; i < 4; i++)
            {
                if (i == 3)
                {
                    break;
                }

                for (int j = i + 1; j < 4; j++)
                {
                    if (_polygons[i].Intersects(_polygons[j]))
                    {
                        _inCollision[i] = true;
                        _inCollision[j] = true;
                    }
                }
            }
            #endregion
        }
Exemple #3
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(Globals.GraphicsDevice);

            ScreenUtility.InitGraphicsMode(800, 480, false);

            var circle = new CircularExtent();

            circle.Reset(new Vector2(100, 100), 50);
            circle.ReAnchor(circle.Center);
            _extents[0] = circle;

            circle = new CircularExtent();
            circle.Reset(new Vector2(300, 300), 75);
            circle.ReAnchor(circle.Center);
            _extents[1] = circle;

            var vertices = new List <Vector2>();

            vertices.Add(new Vector2(300, 300));
            vertices.Add(new Vector2(400, 300));
            vertices.Add(new Vector2(420, 400));
            vertices.Add(new Vector2(350, 450));
            vertices.Add(new Vector2(280, 400));

            var poly = new PolygonExtent();

            poly.Reset(vertices);
            poly.ReAnchor(poly.Center);
            _extents[2] = poly;

            vertices.Clear();
            Vector2 offset = new Vector2(300, 100);

            vertices.Add(offset + new Vector2(0, 0));
            vertices.Add(offset + new Vector2(50, 0));
            vertices.Add(offset + new Vector2(50, -50));
            vertices.Add(offset + new Vector2(100, -50));
            vertices.Add(offset + new Vector2(100, 0));
            vertices.Add(offset + new Vector2(150, 0));
            vertices.Add(offset + new Vector2(150, 50));
            vertices.Add(offset + new Vector2(100, 50));
            vertices.Add(offset + new Vector2(100, 100));
            vertices.Add(offset + new Vector2(50, 100));
            vertices.Add(offset + new Vector2(50, 50));
            vertices.Add(offset + new Vector2(0, 50));

            poly = new PolygonExtent();
            poly.Reset(vertices);
            poly.ReAnchor(poly.Center);
            _extents[3] = poly;

            var composite = new CompositeExtent();

            var child1 = new CircularExtent();

            child1.Reset(new Vector2(50, 50), 50);
            child1.ReAnchor(circle.Center);

            vertices = new List <Vector2>();

            vertices.Add(new Vector2(100, 100));
            vertices.Add(new Vector2(200, 100));
            vertices.Add(new Vector2(200, 200));
            vertices.Add(new Vector2(100, 200));

            var child2 = new PolygonExtent();

            child2.Reset(vertices);
            child2.ReAnchor(poly.Center);

            composite.Add(child1);
            composite.Add(child2);

            _extents[4]    = composite;
            _contentLoaded = true;
        }