Example #1
0
 public GameSequence(int tempo, int times, Color[] colors, SpheroMovementType[] movements, int tempoColorSwitch)
 {
     Tempo = tempo;
     Times = times;
     Colors = colors;
     Movements = movements;
     TempoColorSwitch = tempoColorSwitch;
 }
Example #2
0
        void ProcessLevel(CanvasAnimatedUpdateEventArgs args)
        {
            if (_gameState == GameState.LevelUp)
            {
                _currentLevel++;
                if (_currentLevel > _gameSequence.Length - 1)
                    _currentLevel = _gameSequence.Length - 1;
                _currentBeatTime = 0;
                _currentSequence = _gameSequence[_currentLevel];
                _currentElapsedTime = TimeSpan.Zero;

                _gameState = GameState.ThreeTwoOneGo;
            }

            if (_gameState != GameState.ThreeTwoOneGo && _gameState2 != GameState.GotPoints)
                return;

            if (!_tribal.IsPlaying)
            {
                _tribal.Play();
            }

            if (_tapType == SpheroTapType.DoubleTap)
            {
                _tapType = SpheroTapType.None;
            }

            _previousElapsedTime = _elapsedTime;
            _elapsedTime = args.Timing.ElapsedTime;
            _currentElapsedTime += _elapsedTime;
            _rewardElapsedTime += _elapsedTime;

            if ((_gameState2 == GameState.GotPoints || _gameState2 == GameState.Failed) &&
                _currentElapsedTime.TotalMilliseconds > 2000)
            {
                _gameState2 = GameState.None;
                _rewardElapsedTime = TimeSpan.Zero;
            }

            if (_gameState2 == GameState.CheckMovement &&
                _rewardElapsedTime.TotalMilliseconds > 1000)
            {
                int beat = _currentBeatTime - 1;
                if (beat < 0)
                    beat = 0;
                if (_currentMovType == _currentSequence.Movements[beat])
                {
                    _gameState2 = GameState.GotPoints;
                    _currentIdxReward = RAND.Next(0, _rewardMessage.Length - 1);
                    _points += (_currentIdxReward + 1) * _currentLevel * beat;
                }
                else
                {
                    _currentMovType = SpheroMovementType.None;
                    _gameState2 = GameState.Failed;
                    _numFails++;
                }
            }

            if (_currentBeatTime < _currentSequence.Times)
            {
                _posSpheroSeq.X -= 1; // TODO syncronize the movement with the song and active color

                if (_currentElapsedTime.TotalMilliseconds > _currentSequence.Tempo ||
                    _currentElapsedTime.TotalMilliseconds > _currentSequence.Tempo + _currentSequence.TempoColorSwitch)
                {
                    _currentColor = _currentSequence.Colors[_currentBeatTime];
                    if (_currentElapsedTime.TotalMilliseconds > _currentSequence.Tempo + _currentSequence.TempoColorSwitch)
                        _currentElapsedTime = TimeSpan.Zero;

                    _robot.SetRGBLED(_currentColor.R,
                                     _currentColor.G,
                                     _currentColor.B);

                    _prevBeatTime = _currentBeatTime;
                    _currentBeatTime++;

                    _gameState2 = GameState.CheckMovement;

                    if (_currentBeatTime == _currentSequence.Times)
                        _gameState = GameState.LevelUp;
                }
            }

            if (_currentBeatTime >= _currentSequence.Times &&
                _movType == SpheroMovementType.ShakeIt)
            {
                _movType = SpheroMovementType.None;
                _currentMovType = SpheroMovementType.None;
                _tribal.Stop();

                _currentBeatTime = 0;
                _currentLevel = 0;
                _currentElapsedTime = TimeSpan.Zero;
            }

            if (_numFails > 6)
            {
                _gameState = GameState.GameOver;
                _movType = SpheroMovementType.None;
                _tribal.Stop();

                _currentColor = Colors.Red;
                _currentBeatTime = 0;
                _currentBeatTime = 0;
                _currentLevel = 0;
                _currentElapsedTime = TimeSpan.Zero;
            }
        }
Example #3
0
        private void ProcessMovementType()
        {
            float minValue = -650;
            float maxValue = 650;
            float minShakeValue = -1400;
            float maxShakeValue = 1400;

            _movType = SpheroMovementType.None;

            //if (_gameState2 == GameState.CheckMovement)
            {
                if (_gyroscopeX > maxValue)
                    _movType = SpheroMovementType.PitchForward;
                else if (_gyroscopeX < minValue && _movType == SpheroMovementType.None)
                    _movType = SpheroMovementType.PitchBackwards;
                else if (_gyroscopeY > maxValue && _movType == SpheroMovementType.None)
                    _movType = SpheroMovementType.RollLeft;
                else if (_gyroscopeY < minValue && _movType == SpheroMovementType.None)
                    _movType = SpheroMovementType.RollRight;
                else if (_gyroscopeZ > maxValue && _movType == SpheroMovementType.None)
                    _movType = SpheroMovementType.YawlCounterClockwise;
                else if (_gyroscopeZ < minValue && _movType == SpheroMovementType.None)
                    _movType = SpheroMovementType.YawlClockwise;

            }

            if (_gyroscopeX > maxShakeValue || _gyroscopeX < minShakeValue ||
                _gyroscopeY > maxShakeValue || _gyroscopeY < minShakeValue ||
                _gyroscopeZ > maxShakeValue || _gyroscopeZ < minShakeValue)
            {
                _movType = SpheroMovementType.ShakeIt;
            }

            if (_movType != SpheroMovementType.None)
            {
                _currentMovType = _movType;
            }
        }