Example #1
0
        protected override void Initialize()
        {
            this.aBlock = new ABlock(new Vector2(800, 200));

            // TODO: Add your initialization logic here
            bullets = new List<Bullet>();
            blocks = new List<ABlock>();
            //set up the viewport to match screen resolution and set to full screen
            graphics.PreferredBackBufferWidth = 1920;
            graphics.PreferredBackBufferHeight = 1080;
            graphics.IsFullScreen = true;
            graphics.ApplyChanges();

            this.IsMouseVisible = true;

            aColor = Color.Black;

            anotherColor = Color.White;

            base.Initialize();
        }
Example #2
0
        protected override void Initialize()
        {
            this.aBlock = new ABlock(new Vector2(800, 200));

            // TODO: Add your initialization logic here
            bullets = new List <Bullet>();
            blocks  = new List <ABlock>();
            //set up the viewport to match screen resolution and set to full screen
            graphics.PreferredBackBufferWidth  = 1920;
            graphics.PreferredBackBufferHeight = 1080;
            graphics.IsFullScreen = true;
            graphics.ApplyChanges();

            this.IsMouseVisible = true;

            aColor = Color.Black;

            anotherColor = Color.White;

            base.Initialize();
        }
Example #3
0
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true)
            {
                this.Exit();
            }

            mouseState = Mouse.GetState();

            //left mouse button click
            if (mouseState.LeftButton == ButtonState.Pressed && mouseState.RightButton == ButtonState.Released)
            {
                //add a bullet
                Bullet abullet = new Bullet(new Vector2(mouseState.X, mouseState.Y));
                bullets.Add(abullet);
            }
            //right mouse button click
            if (mouseState.LeftButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed)
            {
                //add a block
                ABlock anBlock = new ABlock(new Vector2(mouseState.X, mouseState.Y));
                blocks.Add(anBlock);
            }

            for (int i = bullets.Count - 1; i >= 0; i--)
            {
                bullets[i].UpdateBullet();
                if (bullets[i].active == false)
                {
                    bullets.RemoveAt(i);
                }
            }

            for (int i = bullets.Count - 1; i >= 0; i--)
            {
                for (int j = blocks.Count - 1; j >= 0; j--)
                {
                    Rectangle theBlock = new Rectangle(Convert.ToInt32(blocks[j].aPosition.X), Convert.ToInt32(blocks[j].aPosition.Y), blocks[j].blockWidth, blocks[j].blockHeight);

                    Rectangle theBullet = new Rectangle(Convert.ToInt32(bullets[i].position.X), Convert.ToInt32(bullets[i].position.Y), 1, 1);

                    if (theBlock.Intersects(theBullet))
                    {
                        //if the distance is less than 2pixels, check collision between the bullet and the pixel, checking for distance between them
                        for (int k = 0; k <= blocks[j].blockWidth; k++)
                        {
                            for (int l = 0; l <= blocks[j].blockHeight; l++)
                            {
                                if (blocks[j].aBlock[k, l].active == true)
                                {
                                    if (Vector2.Distance(blocks[j].aBlock[k, l].pixelPosition, bullets[i].position) < 15.0f)
                                    {
                                        bullets[i].active             = false;
                                        blocks[j].aBlock[k, l].active = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            UpdateBlocks();

            base.Update(gameTime);
        }
Example #4
0
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true)
            {
                this.Exit();
            }

            mouseState = Mouse.GetState();

            //left mouse button click
            if (mouseState.LeftButton == ButtonState.Pressed && mouseState.RightButton == ButtonState.Released)
            {
                //add a bullet
                Bullet abullet = new Bullet(new Vector2(mouseState.X,mouseState.Y));
                bullets.Add(abullet);
            }
            //right mouse button click
            if (mouseState.LeftButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed)
            {
                //add a block
                ABlock anBlock = new ABlock(new Vector2(mouseState.X, mouseState.Y));
                blocks.Add(anBlock);
            }

            for (int i = bullets.Count - 1; i >= 0; i--)
            {
                bullets[i].UpdateBullet();
                if (bullets[i].active == false)
                {

                    bullets.RemoveAt(i);
                }

            }

            for (int i = bullets.Count - 1; i >= 0; i--)
            {
                for (int j = blocks.Count - 1; j >= 0; j--)
                {
                    Rectangle theBlock = new Rectangle(Convert.ToInt32(blocks[j].aPosition.X), Convert.ToInt32(blocks[j].aPosition.Y), blocks[j].blockWidth, blocks[j].blockHeight);

                    Rectangle theBullet = new Rectangle(Convert.ToInt32(bullets[i].position.X), Convert.ToInt32(bullets[i].position.Y), 1, 1);

                    if (theBlock.Intersects(theBullet))
                    {

                        //if the distance is less than 2pixels, check collision between the bullet and the pixel, checking for distance between them
                        for (int k = 0; k <= blocks[j].blockWidth; k++)
                        {
                            for (int l = 0; l <= blocks[j].blockHeight; l++)
                            {
                                if (blocks[j].aBlock[k, l].active == true)
                                {
                                    if (Vector2.Distance(blocks[j].aBlock[k, l].pixelPosition, bullets[i].position) < 15.0f)
                                    {
                                        bullets[i].active = false;
                                        blocks[j].aBlock[k, l].active = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            UpdateBlocks();

            base.Update(gameTime);
        }