Esempio n. 1
0
        public void Update(long delta)
        {
            _ellapsed += delta;

            if (Keyboard.IsKeyDown(Key.Enter))
            {
                Keyboard.KeyUp(Key.Enter);
                Game.Instance.SetScreen();
            }

            if (_ellapsed >= UpdateTime)
            {
                for (var i = 0; i < _logo.Count; i++)
                {
                    _logo[i] = new Point(_logo[i].X - 1, _logo[i].Y);
                }
                _ellapsed -= UpdateTime;
                _steps++;
                Redraw();
                if (_steps >= 38)
                {
                    Game.Instance.SetScreen();
                }
            }
        }
Esempio n. 2
0
        public void Update(long delta)
        {
            //Увеличение прошедшего времени
            _ellapsed         += delta;
            _keyboardEllapsed += delta;

            if (Keyboard.IsKeyDown(Key.P))
            {
                _pause = !_pause;
                AudioPlayer.Pause(_pause);
                Keyboard.KeyUp(Key.P);
                Redraw();
            }

            if (_pause)
            {
                return;
            }

            _updateTime = Keyboard.IsKeyDown(Key.Space) ? 50L : _levelTime;

            //Обработка нажатых клавиш
            if (_keyboardEllapsed >= KeyboardUpdate)
            {
                if (Keyboard.IsKeyDown(Key.Down))
                {
                    if (_wayDelta.Y != -1)
                    {
                        _wayDelta = new Point(0, 1);
                        AudioPlayer.PlayEffect(AudioPlayer.EffectDirection);
                        Keyboard.KeyUp(Key.Down);
                    }
                }
                else if (Keyboard.IsKeyDown(Key.Up))
                {
                    if (_wayDelta.Y != 1)
                    {
                        _wayDelta = new Point(0, -1);
                        AudioPlayer.PlayEffect(AudioPlayer.EffectDirection);
                        Keyboard.KeyUp(Key.Up);
                    }
                }
                else if (Keyboard.IsKeyDown(Key.Left))
                {
                    if (_wayDelta.X != 1)
                    {
                        _wayDelta = new Point(-1, 0);
                        AudioPlayer.PlayEffect(AudioPlayer.EffectDirection);
                        Keyboard.KeyUp(Key.Left);
                    }
                }
                else if (Keyboard.IsKeyDown(Key.Right))
                {
                    if (_wayDelta.X != -1)
                    {
                        _wayDelta = new Point(1, 0);
                        AudioPlayer.PlayEffect(AudioPlayer.EffectDirection);
                        Keyboard.KeyUp(Key.Right);
                    }
                }
            }

            //Падение фигуры
            if (_ellapsed >= _updateTime)
            {
                var head = new Point
                {
                    X = _snake[_snake.Count - 1].X + _wayDelta.X,
                    Y = _snake[_snake.Count - 1].Y + _wayDelta.Y
                };
                if (head.X == _newBlock.X && head.Y == _newBlock.Y)
                {
                    _snake.Add(head);
                    AudioPlayer.PlayEffect(AudioPlayer.EffectBite);
                    GenerateNewBlock();
                }
                else if (Intersects(head))
                {
                    AudioPlayer.Pause(false);
                    var gameOver = new GameOver(_canvas, _buffer, _game, this);
                    _game.PushScreen(gameOver);
                    return;
                }
                else
                {
                    for (int i = 0; i < _snake.Count - 1; i++)
                    {
                        _snake[i] = _snake[i + 1];
                    }
                    _snake[_snake.Count - 1] = head;
                }
                _ellapsed = 0;
                Redraw();
            }
        }
Esempio n. 3
0
        public void Update(long delta)
        {
            if (_repeat)
            {
                Start();
                _repeat = false;
            }

            //Увеличение прошедшего времени
            _ellapsed         += delta;
            _keyboardEllapsed += delta;

            //Ускорение падения при нажатии ВНИЗ
            _updateTime = Keyboard.IsKeyDown(Key.Down) ? 10L : 1000L;

            if (Keyboard.IsKeyDown(Key.P))
            {
                _pause = !_pause;
                AudioPlayer.Pause(_pause);
                Keyboard.KeyUp(Key.P);
                Redraw();
            }

            if (_pause)
            {
                return;
            }

            if (_animate)
            {
                Redraw();
                return;
            }

            //Обработка нажатых клавиш
            if (_keyboardEllapsed >= KeyboardUpdate)
            {
                if (Keyboard.IsKeyDown(Key.Left))
                {
                    _block.MoveLeft(_field);
                    Redraw();
                }
                if (Keyboard.IsKeyDown(Key.Right))
                {
                    _block.MoveRight(_field);
                    Redraw();
                }
                if (Keyboard.IsKeyDown(Key.F))
                {
                    _drawFeature = !_drawFeature;
                    Keyboard.KeyUp(Key.F);
                    Redraw();
                }
                if (Keyboard.IsKeyDown(Key.Space))
                {
                    while (!CheckCollisins())
                    {
                        _block.MoveDown();
                    }
                    AudioPlayer.PlayEffect(AudioPlayer.EffectDrop);
                    Keyboard.KeyUp(Key.Space);
                    _block.MoveDown();
                    Redraw();
                }
                if (Keyboard.IsKeyDown(Key.Enter) || Keyboard.IsKeyDown(Key.Up))
                {
                    _block.Rotate(_field);
                    AudioPlayer.PlayEffect(AudioPlayer.EffectRotate);
                    Keyboard.KeyUp(Key.Enter);
                    Keyboard.KeyUp(Key.Up);
                    Redraw();
                }
                _keyboardEllapsed = 0;
            }

            //Падение фигуры
            if (_ellapsed >= _updateTime)
            {
                CheckCollisins();
                _block.MoveDown();
                Redraw();
                _ellapsed = 0;
            }
        }