Пример #1
0
        protected override void Draw(GameTime time)
        {
            this.Graphics.Clear(Color4.Black);

            this.spriteRenderer.Begin(this.shaderProgram);

            string text = string.Format("FPS: {0}", fps);

            Size textSize = this.font.MeasureString(text);
            int halfWindowWidth = this.Window.Width / 2;
            int halfWindowHeight = this.Window.Height / 2;
            int halfTextWidth = textSize.Width / 2;
            int halfTextHeight = textSize.Height / 2;

            this.spriteRenderer.DrawString(
                this.font,
                text,
                new Rectangle(halfWindowWidth - halfTextWidth, halfWindowHeight - halfTextHeight, textSize.Width, textSize.Height),
                tint: Color4.CornflowerBlue,
                origin: new Vector2(halfTextWidth, halfTextHeight),
                rotation: MathHelper.ToRadians(45.0f),
                layerDepth: 0.5f);

            foreach (Plane plane in this.planes)
            {
                this.spriteRenderer.Draw(
                    this.planeSpriteSheet,
                    plane.StartFrame + plane.FrameOffset,
                    plane.Position,
                    origin: new Vector2(32, 32),
                    rotation: MathHelper.ToRadians(plane.Rotation)
                );
            }

            this.spriteRenderer.End();

            this.Graphics.SwapBuffers();

            this.fpsCount++;
            this.fpsTimer += (float)time.ElapsedTime.TotalSeconds;
            if (this.fpsTimer >= 1.0f)
            {
                this.fps = this.fpsCount;
                this.fpsTimer -= 1.0f;
                this.fpsCount = 0;
            }
        }
Пример #2
0
        protected override void Draw(GameTime elapsed)
        {
            this.Graphics.Clear(Color4.CornflowerBlue);

            Matrix4 projection = Matrix4.InvertedYAxis;

            this.shaderProgram.SetValue("projection", ref projection);
            this.shaderProgram.SetValue("palette", this.palette);
            this.shaderProgram.SetValue("centerX", this.centerX);
            this.shaderProgram.SetValue("centerY", this.centerY);
            this.shaderProgram.SetValue("scale", this.scale);
            this.shaderProgram.SetValue("iterations", this.iterations);

            this.Graphics.Draw(PrimitiveType.Triangles, this.vertexBuffer);

            this.Graphics.SwapBuffers();
        }
Пример #3
0
        public void Update(GameTime time)
        {
            this.frameTimer += time.ElapsedTime;

            if (this.frameTimer >= FrameDuration)
            {
                this.FrameOffset++;
                this.frameTimer -= FrameDuration;

                if (this.FrameOffset >= FrameCount)
                    this.FrameOffset -= FrameCount;
            }

            Vector2 position = this.Position;
            Vector2 newPosition = new Vector2(position.X, position.Y - ((float)time.ElapsedTime.TotalSeconds * Speed));

            RotateAboutOrigin(ref newPosition, ref position, MathHelper.ToRadians(this.Rotation), out newPosition);

            if (newPosition.X < -HalfSize)
            {
                newPosition.X += this.windowSize.Width + Size;
            }
            else if (newPosition.X >= this.windowSize.Width + HalfSize)
            {
                newPosition.X -= this.windowSize.Width + Size;
            }

            if (newPosition.Y < -HalfSize)
            {
                newPosition.Y += this.windowSize.Height + Size;
            }
            else if (newPosition.Y >= this.windowSize.Height + HalfSize)
            {
                newPosition.Y -= this.windowSize.Height + Size;
            }

            this.Position = newPosition;
        }
Пример #4
0
        protected override void Update(GameTime gameTime)
        {
            if (this.keyboard.IsKeyDown(Key.Left))
                this.centerX -= (2f * this.scale) * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.Right))
                this.centerX += (2f * this.scale) * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.Up))
                this.centerY -= (2f * this.scale) * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.Down))
                this.centerY += (2f * this.scale) * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.A))
                this.scale -= 0.5f * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.Z))
                this.scale += 0.5f * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.Q))
                this.iterations -= 10.0f * (float)gameTime.ElapsedTime.TotalSeconds;

            if (this.keyboard.IsKeyDown(Key.W))
                this.iterations += 10.0f * (float)gameTime.ElapsedTime.TotalSeconds;

            this.keyboard.Update();
        }
Пример #5
0
 protected override void Update(GameTime time)
 {
     foreach (Plane plane in this.planes)
     {
         plane.Update(time);
     }
 }
Пример #6
0
 /// <summary>
 /// Called by the Run method when game logic should run.
 /// </summary>
 /// <param name="time"></param>
 protected virtual void Update(GameTime time)
 {
 }
Пример #7
0
 /// <summary>
 /// Called by the Run method when the game should draw.
 /// </summary>
 /// <param name="time"></param>
 protected virtual void Draw(GameTime time)
 {
 }
Пример #8
0
        /// <summary>
        /// Starts the game loop.
        /// </summary>
        public void Run()
        {
            this.Window.Show();

            this.Initialize();

            this.time = new GameTime();
            this.stopwatch = new Stopwatch();
            this.timeBetweenTicks = 1000 / this.options.FramesPerSecond;

            this.stopwatch.Start();
            long elapsed = stopwatch.ElapsedMilliseconds;
            this.lastTick = elapsed;
            this.nextTick = elapsed;

            this.Window.Run();

            this.Shutdown();
        }
Пример #9
0
        protected override void Draw(GameTime gameTime)
        {
            this.Graphics.Clear();

            this.Graphics.Draw(PrimitiveType.Triangles, this.vertexBuffer);

            this.Graphics.SwapBuffers();
        }
Пример #10
0
        protected override void Draw(GameTime time)
        {
            this.Graphics.Clear(Color4.CornflowerBlue);

            Matrix4 projection = new Matrix4()
            {
                M11 = 2f / this.Window.Width,
                M22 = -2f / this.Window.Height,
                M33 = 1f,
                M44 = 1f,
                M41 = -1f,
                M42 = 1f
            };

            totalElapsedSeconds += (float)time.ElapsedTime.TotalSeconds;

            this.shader.SetValue("projection", ref projection);
            this.shader.SetValue("startX", (float)((this.Window.Width - this.texture.Width) / 2));
            this.shader.SetValue("time", totalElapsedSeconds);
            this.shader.SetValue("texture0", this.texture);

            this.Graphics.Draw(PrimitiveType.Triangles, this.vertexBuffer, this.indexBuffer);

            this.Graphics.SwapBuffers();
        }