Пример #1
0
        public void LoadContent()
        {
            background = content.Load<Texture2D>("Background/BG01");
            damageStringFont = content.Load<SpriteFont>("Font");

            int fPositionX = (Level.windowWidth / 4);
            int fPositionY = (Level.windowHeight / 12);
            fPos = new Vector2((float)fPositionX, (float)fPositionY);

            playButton = new Button(content, "Button/buttona", new Vector2((windowWidth / 2) - 20,(windowHeight / 3) + (windowHeight / 2)));
            attackButton = new Button(content, "Button/buttonb", new Vector2((windowWidth / 2) - 24, (windowHeight / 3) + (windowHeight / 2)));

            hero.LoadContent();
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            mouseState = Mouse.GetState();
            mouseX = mouseState.X;
            mouseY = mouseState.Y;
            Trace.Write(mouseX + "," + mouseY + ",");
            prev_mpressed = mpressed;
            mpressed = mouseState.LeftButton == ButtonState.Pressed;

            mpos = new ((float)mouseX, (float)mouseY);

            attackButton = new Button(content, "Button/buttonb", new Vector2((float)mouseX, (float)mouseY));
            hero.Update(gameTime);

            oldMouseState = mouseState;

            timer++;

            if (attackButton.Update(gameTime, mouseX, mouseY, mpressed, prev_mpressed) && damageNumber!=0)
            {
                damageNumber -= 1;
            }

            else if (damageNumber == 0 && timer >= 15)
            {
                damageNumber = 10;
            }

            bool tappedPlayButton = playButton.Update(gameTime, mouseX, mouseY, mpressed, prev_mpressed);

            if (tappedPlayButton)
            {
                hero.PlayAttackAnimation();
                isTappedPlayButton = true;
            }

            if (isTappedPlayButton)
            {
                afterAttackTime = afterAttackTime.Subtract(gameTime.ElapsedGameTime);
            }

            if (afterAttackTime.TotalMilliseconds <= 0)
            {
                hero.PlayIdleAnimation();
                afterAttackTime = TimeSpan.FromSeconds(2);
            }
        }