Beispiel #1
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            //Gravity
            foreach (Block myblock in BlockList)
            {

                if ((myblock.y + 8) < ScreenHeight - 100)
                {
                    bool touching = false;

                    foreach (Block gblock in BlockList)
                    {
                        for (int i = 1; i < 19; i++)
                        {
                            if ((myblock.y + 10 < (gblock.y + 8)) && ((myblock.y + 10 > (gblock.y))) &&
                                    ((myblock.x + i) >= gblock.x && (myblock.x + i) < (gblock.x + 20)))
                            {
                                touching = true;
                                break;
                            }
                        }
                    }

                    if (!touching)
                        myblock.y++;
                }
            }

              MouseState mouse = Mouse.GetState();
            currentKeyboardState = Keyboard.GetState();

            currentKeyboardState = Keyboard.GetState();

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                //pick up any brick
                if (!BlockPickedUp)
                    PickupBrick(mouse.X, mouse.Y);
            }

            if (mouse.LeftButton == ButtonState.Released)
            {
                //drop up any brick
                BlockPickedUp = false;
                PickedUpBlock = null;
            }

            if (mouse.RightButton == ButtonState.Pressed)
            {
                Block myobj = new Block();
                myobj.blcolor = 4;
                myobj.x = mouse.X;
                myobj.y = mouse.Y;
                myobj.exists = true;
                BlockList.Add(myobj);
            }

            if (IsPressed(Keys.Left, Buttons.A))
            {
            }

            if (BlockPickedUp)
            {
                PickedUpBlock.x = mouse.X - 10;
                PickedUpBlock.y = mouse.Y - 3;
            }

            if (IsPressed(Keys.Right, Buttons.A))
            {
            }

            if (IsPressed(Keys.Up, Buttons.A))
            {
            }

            if (IsPressed(Keys.Down, Buttons.A))
            {
            }

            if (IsPressed(Keys.Escape, Buttons.Back))
            {
                Exit();
            }

            base.Update(gameTime);
        }
Beispiel #2
0
        private void PickupBrick(int xpos, int ypos)
        {
            //// checks if block exists at click position.
            foreach (Block myblock in BlockList)
            {
                if (!myblock.exists)
                    continue;

                if ((ypos < (myblock.y + 8)) && ((ypos > (myblock.y))) && ((xpos + 1) >= myblock.x && (xpos + 1) < (myblock.x + 21)))
                {
                    BlockPickedUp = true;
                    PickedUpBlock = myblock;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("SpriteFont1");
            grayblock = Content.Load<Texture2D>("greyblock");
            pinkblock = Content.Load<Texture2D>("pinkblock");
            goldblock = Content.Load<Texture2D>("goldblock");
            blueblock = Content.Load<Texture2D>("blueblock");
            grenblock = Content.Load<Texture2D>("grenblock");

            // TODO: use this.Content to load your game content here

            //Draw the background

            for (int ii = 690; ii < 700; ii = ii + 10)
            {
                for (int i = 40; i < 700; i = i + 21)
                {
                    Block myobj = new Block();
                    myobj.blcolor = 1;
                    myobj.x = i;
                    myobj.y = ii;
                    myobj.exists = true;
                    BlockList.Add(myobj);
                }
            }

            for (int ii = 10; ii < 700; ii = ii + 10)
            {
                for (int i = 800; i < 810; i = i + 21)
                {
                    Block myobj = new Block();
                    myobj.blcolor = 3;
                    myobj.x = i;
                    myobj.y = ii;
                    myobj.exists = true;
                    BlockList.Add(myobj);
                }
            }
        }