Exemple #1
0
        public void Update(GameTime gameTime)
        {
            this.flameTimer += gameTime.ElapsedTotalSeconds;
            if (this.flameTimer >= 0.1f)
            {
                this.sprite.Children[0].Frame++;
                if (this.sprite.Children[0].Frame >= 2)
                    this.sprite.Children[0].Frame = 0;

                this.flameTimer -= 0.1f;
            }

            Vector2 movement = this.gamePad.LeftThumbStick;
            this.sprite.X += 200.0f * movement.X * gameTime.ElapsedTotalSeconds;
            this.sprite.Y += 200.0f * movement.Y * gameTime.ElapsedTotalSeconds;

            //if (this.Keyboard.IsKeyDown(Keys.Left))
            //    this.sprite.X -= 200.0f * gameTime.ElapsedTotalSeconds;
            //else if (this.Keyboard.IsKeyDown(Keys.Right))
            //    this.sprite.X += 200.0f * gameTime.ElapsedTotalSeconds;

            //if (this.Keyboard.IsKeyDown(Keys.Up))
            //    this.sprite.Y -= 100.0f * gameTime.ElapsedTotalSeconds;
            //else if (this.Keyboard.IsKeyDown(Keys.Down))
            //    this.sprite.Y += 100.0f * gameTime.ElapsedTotalSeconds;

            if (this.keyboard.IsKeyPressed(Keys.Space) || this.gamePad.IsButtonPressed(GamePadButtons.X))
                this.blasterSoundEffect.Play();
        }
        protected override void Draw(GameTime gameTime)
        {
            if (this.graphicsDevice.BeginDraw())
            {
                this.graphicsDevice.Clear(Color.CornflowerBlue);

                this.effect.SetValue<float>("StartX", 100.0f);
                this.effect.SetValue<float>("Time", (float)gameTime.TotalTime.TotalSeconds);

                this.graphics.Begin(this.effect, 0, 0);

                int totalChunks = 100;
                int chunkSize = this.texture.Width / totalChunks;
                Rectangle destination = new Rectangle(100, 142, chunkSize, this.texture.Height);
                Rectangle source = new Rectangle(0, 0, chunkSize, this.texture.Height);

                for (int i = 0; i < totalChunks; i++)
                {
                    this.graphics.DrawTexture(this.texture, destination, source, Color.White);

                    destination.X += chunkSize;
                    source.X += chunkSize;
                }

                this.graphics.End();

                this.graphicsDevice.EndDraw();

                this.graphicsDevice.Present();
            }
        }
        protected override void Draw(GameTime gameTime)
        {
            this.graphicsDevice.Clear(new Color(192, 192, 192, 255));

            if (this.graphicsDevice.BeginDraw())
            {
                // Draw the single sprite.
                this.graphics.Begin();
                this.graphics.DrawSprite(this.sprite);
                this.graphics.End();

                this.graphicsDevice.EndDraw();

                this.graphicsDevice.Present();
            }
        }
        protected override void Draw(GameTime gameTime)
        {
            string gamePadStatus = this.GetGamePadStatus();

            if (this.graphicsDevice.BeginDraw())
            {
                this.graphicsDevice.Clear(Color.CornflowerBlue);

                this.graphics.Begin();

                this.graphics.DrawString(this.font, gamePadStatus, new Vector2(5, 5), Color.White);

                this.graphics.End();

                this.graphicsDevice.EndDraw();

                this.graphicsDevice.Present();
            }
        }
        protected override void Draw(GameTime gameTime)
        {
            if (this.graphicsDevice.BeginDraw())
            {
                this.graphicsDevice.Clear(Color.Black);

                this.graphics.Begin();

                Vector2 oneThirdScreen = new Vector2((int)(this.graphicsDevice.BackBufferWidth / 3), (int)(this.graphicsDevice.BackBufferHeight / 3));

                Rectangle oneThirdScreenRectangle = new Rectangle(0, 0, (int)oneThirdScreen.X, (int)oneThirdScreen.Y);

                for (int y = 0; y < 3; y++)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        oneThirdScreenRectangle.X = (int)oneThirdScreen.X * x;
                        oneThirdScreenRectangle.Y = (int)oneThirdScreen.Y * y;
                        this.graphics.DrawFilledRectangle(oneThirdScreenRectangle, new Color((byte)(80 * x), (byte)(80 * (x - y)), (byte)(80 * (3 - y)), 255));
                    }
                }

                this.graphics.DrawTextBlock(this.topLeftTextBlock, new Vector2(0, 0), Color.White);
                this.graphics.DrawTextBlock(this.topCenterTextBlock, new Vector2(oneThirdScreen.X, 0), Color.White);
                this.graphics.DrawTextBlock(this.topRightTextBlock, new Vector2(oneThirdScreen.X * 2, 0), Color.White);

                this.graphics.DrawTextBlock(this.middleLeftTextBlock, new Vector2(0, oneThirdScreen.Y), Color.White);
                this.graphics.DrawTextBlock(this.middleCenterTextBlock, new Vector2(oneThirdScreen.X, oneThirdScreen.Y), Color.White);
                this.graphics.DrawTextBlock(this.middleRightTextBlock, new Vector2(oneThirdScreen.X * 2, oneThirdScreen.Y), Color.White);

                this.graphics.DrawTextBlock(this.bottomLeftTextBlock, new Vector2(0, oneThirdScreen.Y * 2), Color.White);
                this.graphics.DrawTextBlock(this.bottomCenterTextBlock, new Vector2(oneThirdScreen.X, oneThirdScreen.Y * 2), Color.White);
                this.graphics.DrawTextBlock(this.bottomRightTextBlock, new Vector2(oneThirdScreen.X * 2, oneThirdScreen.Y * 2), Color.White);

                this.graphics.End();

                this.graphicsDevice.EndDraw();

                this.graphicsDevice.Present();
            }
        }
 protected override void Update(GameTime gameTime)
 {
     this.gamePad.Update();
 }
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Update the keyboard.
            this.keyboard.Update();

            // Run logic to move the sprite on the screen.

            Vector2 delta = Vector2.Zero;

            if (this.keyboard.IsKeyDown(Keys.Left))
                delta.X -= 100.0f * gameTime.ElapsedTotalSeconds;

            if (this.keyboard.IsKeyDown(Keys.Right))
                delta.X += 100.0f * gameTime.ElapsedTotalSeconds;

            if (this.keyboard.IsKeyDown(Keys.Up))
                delta.Y -= 100.0f * gameTime.ElapsedTotalSeconds;

            if (this.keyboard.IsKeyDown(Keys.Down))
                delta.Y += 100.0f * gameTime.ElapsedTotalSeconds;

            this.sprite.Position += delta;

            this.animationTimer += gameTime.ElapsedTotalSeconds;
            if (this.animationTimer >= 0.5f)
            {
                this.animationTimer -= 0.5f;

                this.animationFrame++;
                if (this.animationFrame > 1)
                    this.animationFrame = 0;
            }

            if (delta.Y != 0.0f)
            {
                if (delta.Y < 0.0f)
                {
                    this.animationOffset = 3;
                }
                else
                {
                    this.animationOffset = 1;
                }
            }
            else if (delta.X != 0.0f)
            {
                if (delta.X < 0.0f)
                {
                    this.animationOffset = 2;
                }
                else
                {
                    this.animationOffset = 0;
                }
            }

            this.sprite.Frame = animationOffset + (this.animationFrame * 4);
        }