コード例 #1
0
    public void GameLoop()
    {
        int sizeChromaLink = GetColorArraySize1D(Device1D.ChromaLink);
        int sizeHeadset    = GetColorArraySize1D(Device1D.Headset);
        int sizeKeyboard   = GetColorArraySize2D(Device2D.Keyboard);
        int sizeKeypad     = GetColorArraySize2D(Device2D.Keypad);
        int sizeMouse      = GetColorArraySize2D(Device2D.Mouse);
        int sizeMousepad   = GetColorArraySize1D(Device1D.Mousepad);

        int[] colorsChromaLink = new int[sizeChromaLink];
        int[] colorsHeadset    = new int[sizeHeadset];
        int[] colorsKeyboard   = new int[sizeKeyboard];
        int[] colorsKeypad     = new int[sizeKeypad];
        int[] colorsMouse      = new int[sizeMouse];
        int[] colorsMousepad   = new int[sizeMousepad];

        int[] tempColorsChromaLink = new int[sizeChromaLink];
        int[] tempColorsHeadset    = new int[sizeHeadset];
        int[] tempColorsKeyboard   = new int[sizeKeyboard];
        int[] tempColorsKeypad     = new int[sizeKeypad];
        int[] tempColorsMouse      = new int[sizeMouse];
        int[] tempColorsMousepad   = new int[sizeMousepad];

        while (_mWaitForExit)
        {
            // start with a blank frame
            Array.Clear(colorsChromaLink, 0, sizeChromaLink);
            Array.Clear(colorsHeadset, 0, sizeHeadset);
            Array.Clear(colorsKeyboard, 0, sizeKeyboard);
            Array.Clear(colorsKeypad, 0, sizeKeypad);
            Array.Clear(colorsMouse, 0, sizeMouse);
            Array.Clear(colorsMousepad, 0, sizeMousepad);

#if !USE_ARRAY_EFFECTS
            SetupAnimation1D(ANIMATION_FINAL_CHROMA_LINK, Device1D.ChromaLink);
            SetupAnimation1D(ANIMATION_FINAL_HEADSET, Device1D.Headset);
            SetupAnimation2D(ANIMATION_FINAL_KEYBOARD, Device2D.Keyboard);
            SetupAnimation2D(ANIMATION_FINAL_KEYPAD, Device2D.Keypad);
            SetupAnimation2D(ANIMATION_FINAL_MOUSE, Device2D.Mouse);
            SetupAnimation1D(ANIMATION_FINAL_MOUSEPAD, Device1D.Mousepad);
#endif

            BlendAnimations(_mScene,
                            colorsChromaLink, tempColorsChromaLink,
                            colorsHeadset, tempColorsHeadset,
                            colorsKeyboard, tempColorsKeyboard,
                            colorsKeypad, tempColorsKeypad,
                            colorsMouse, tempColorsMouse,
                            colorsMousepad, tempColorsMousepad);

            if (_mAmmo)
            {
                // SHow health animation
                {
                    int[] keys =
                    {
                        (int)Keyboard.RZKEY.RZKEY_F1,
                        (int)Keyboard.RZKEY.RZKEY_F2,
                        (int)Keyboard.RZKEY.RZKEY_F3,
                        (int)Keyboard.RZKEY.RZKEY_F4,
                        (int)Keyboard.RZKEY.RZKEY_F5,
                        (int)Keyboard.RZKEY.RZKEY_F6,
                    };
                    int keysLength = keys.Length;

                    float t  = _mTimeMS * 0.002f;
                    float hp = (float)Math.Abs(Math.Cos(Math.PI / 2.0f + t));
                    for (int i = 0; i < keysLength; ++i)
                    {
                        int color;
                        if (((i + 1) / ((float)keysLength + 1)) < hp)
                        {
                            color = ChromaAnimationAPI.GetRGB(0, 255, 0);
                        }
                        else
                        {
                            color = ChromaAnimationAPI.GetRGB(0, 100, 0);
                        }
                        int key = keys[i];
                        SetKeyColor(colorsKeyboard, key, color);
                    }
                }

                // Show ammo animation
                {
                    int[] keys =
                    {
                        (int)Keyboard.RZKEY.RZKEY_F7,
                        (int)Keyboard.RZKEY.RZKEY_F8,
                        (int)Keyboard.RZKEY.RZKEY_F9,
                        (int)Keyboard.RZKEY.RZKEY_F10,
                        (int)Keyboard.RZKEY.RZKEY_F11,
                        (int)Keyboard.RZKEY.RZKEY_F12,
                    };
                    int keysLength = keys.Length;

                    float t  = _mTimeMS * 0.001f;
                    float hp = (float)Math.Abs(Math.Cos(Math.PI / 2.0f + t));
                    for (int i = 0; i < keysLength; ++i)
                    {
                        int color;
                        if (((i + 1) / ((float)keysLength + 1)) < hp)
                        {
                            color = ChromaAnimationAPI.GetRGB(255, 255, 0);
                        }
                        else
                        {
                            color = ChromaAnimationAPI.GetRGB(100, 100, 0);
                        }
                        int key = keys[i];
                        SetKeyColor(colorsKeyboard, key, color);
                    }
                }
            }

            if (_mHotkeys)
            {
                // Show hotkeys
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_ESC, 255, 255, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_W, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_A, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_S, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_D, 255, 0, 0);

                if (_mAmmo)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_A, 0, 255, 0);
                }

                // Highlight R if rainbow is active
                if (_mScene._mEffects[_mIndexRainbow]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_R, 0, 255, 0);
                }

                // Highlight S if spiral is active
                if (_mScene._mEffects[_mIndexSpiral]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_S, 0, 255, 0);
                }

                // Highlight L if landscape is active
                if (_mScene._mEffects[_mIndexLandscape]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_L, 0, 255, 0);
                }

                // Highlight L if landscape is active
                if (_mScene._mEffects[_mIndexFire]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_F, 0, 255, 0);
                }

                if (_mHotkeys)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_H, 0, 255, 0);
                }
            }

#if USE_ARRAY_EFFECTS
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.ChromaLink, colorsChromaLink);
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.Headset, colorsHeadset);
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.Mousepad, colorsMousepad);

            ChromaAnimationAPI.SetCustomColorFlag2D((int)Device2D.Keyboard, colorsKeyboard);
            ChromaAnimationAPI.SetEffectKeyboardCustom2D((int)Device2D.Keyboard, colorsKeyboard);

            ChromaAnimationAPI.SetEffectCustom2D((int)Device2D.Keypad, colorsKeypad);
            ChromaAnimationAPI.SetEffectCustom2D((int)Device2D.Mouse, colorsMouse);
#else
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_CHROMA_LINK, 0, 0.1f, colorsChromaLink, sizeChromaLink);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_HEADSET, 0, 0.1f, colorsHeadset, sizeHeadset);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_KEYBOARD, 0, 0.1f, colorsKeyboard, sizeKeyboard);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_KEYPAD, 0, 0.1f, colorsKeypad, sizeKeypad);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_MOUSE, 0, 0.1f, colorsMouse, sizeMouse);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_MOUSEPAD, 0, 0.1f, colorsMousepad, sizeMousepad);

            // display the change
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_CHROMA_LINK, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_HEADSET, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_KEYBOARD, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_KEYPAD, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_MOUSE, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_MOUSEPAD, 0);
#endif

            Thread.Sleep(33); //30 FPS
        }
    }