Example #1
0
        public static void Draw()
        {
            Graphics g = __Buffer.Graphics;

            //Background
            g.Clear(Color.Black);
            //g.DrawRectangle(Pens.White, new Rectangle(50, 50, 200, 200));
            //g.FillEllipse(Brushes.Red, new Rectangle(100, 50, 70, 120));

            foreach (var game_object in __GameObjects)
            {
                game_object?.Draw(g);
            }

            //if (__Bullet != null)
            //    __Bullet.Draw(g); - эквивалент
            __Spaceship.Draw(g);

            //__Bullet?.Draw(g);
            __Bullets.ForEach(bullet => bullet.Draw(g));

            if (!__Timer.Enabled)
            {
                return;
            }
            __Buffer.Render();
        }
Example #2
0
    public void Run()
    {
        const int      NUM_ENEMIES = 4;
        ConsoleKeyInfo userkey;

        Spaceship        ship = new Spaceship();
        MovingBackground back = new MovingBackground();
        Scoreboard       sb   = new Scoreboard();

        Enemy[] enemies = new Enemy[NUM_ENEMIES];
        enemies[0] = new EnemyLevel1();
        enemies[1] = new EnemyLevel2();
        enemies[2] = new EnemyLevel3();
        enemies[3] = new EnemyLevel4();
        Mothership ms    = new Mothership();
        PlayerShot shot1 = new PlayerShot(20, 10);
        EnemyShot  shot2 = new EnemyShot(15, 1);

        while (true)
        {
            // Update elements position and appearance
            back.Update();
            ms.Update();
            ship.Update();
            foreach (Enemy e in enemies)
            {
                e.Update();
            }
            shot1.Update();
            shot2.Update();

            // Screen update
            Console.Clear();
            back.Draw();
            sb.Draw();
            ms.Draw();
            ship.Draw();
            foreach (Enemy e in enemies)
            {
                e.Draw();
            }
            shot1.Draw();
            shot2.Draw();

            // Get user input
            userkey = Console.ReadKey(true);
            switch (userkey.Key)
            {
            case ConsoleKey.A: ship.MoveLeft(); break;

            case ConsoleKey.D: ship.MoveRight(); break;

            case ConsoleKey.Escape: return;
            }
        }
    }
Example #3
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            base.Draw(spriteBatch, gameTime);

            _bullets.ForEach(bullet => bullet.Draw(spriteBatch, gameTime));
            _asteroids.ForEach(ass => ass.Draw(spriteBatch, gameTime));
            _spaceship.Draw(spriteBatch, gameTime);

            spriteBatch.DrawString(_font, MainText + _score,
                                   new Vector2(10, 10), Color.White);
        }
Example #4
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();
            spriteBatch.Draw(background, Vector2.Zero, Color.White);
            spriteBatch.End();

            // Set render states.
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            spaceship.Draw();

            base.Draw(gameTime);
        }