예제 #1
0
 private void startRain()
 {
     if (isRaining)
     {
         rainElapsed += 1;
         if (rainElapsed >= rainTime)
         {
             stopRain();
         }
         return;
         ////already raining
     }
     if (Common.getRandom(1, 50) == 25)
     {
         if (!isRaining)
         {
             rainIntensity = (WeatherTypes)Common.getRandom(1, 3);
             rain          = DSound.loadOgg(DSound.SoundPath + "\\wr" + rainIntensity + ".ogg");
             rain.play(true);
             isRaining = true;
         }
         ////if !isRaining
     }
     ////if random
 }
예제 #2
0
 public static void startGame()
 {
     if (!KeyMap.readFromFile())
     {
         OggBuffer kError = DSound.playOgg(DSound.NSoundPath + "\\kme.ogg");
         while (kError.isPlaying())
         {
             if (dxInput.isKeyHeldDown())
             {
                 break;
             }
             Thread.Sleep(10);
         }                 //while
         kError.stopOgg();
         kError = null;
     }
     Options.setDifficulty(Options.difficulties.easy);
     Interaction.clearData();
     mainMenu();
     if (!Options.requestedShutdown)
     {
         Common.startGame();
         if (Common.firstTimeLoad)
         {
             Common.firstTimeLoad = false;
             while (!Common.threadNotifier)
             {
                 Thread.Sleep(6000);
             }
         }
     }
 }
예제 #3
0
        public static void startGame(bool firstTimeLoad)
        {
            if (!firstTimeLoad)
            {
                return;
            }

            try
            {
                textBox1          = new TextBox();
                textBox1.Location = new System.Drawing.Point(0, 0);
                textBox1.Name     = "textBox1";
                textBox1.ReadOnly = true;
                textBox1.Size     = new System.Drawing.Size(100, 20);
                textBox1.TabIndex = 0;

                SapiSpeech.initialize();
                DSound.initialize(textBox1.Handle);
                dxInput.DInputInit(textBox1);

                DSound.initializeOgg();
                Options.readFromFile();
                KeyMap.initialize();
                //this.Deactivate += new EventHandler(GUI_Deactivate);
                //this.Activated += new EventHandler(GUI_Activated);

                if (!Common.isRegistered())
                {
                    MessageBox.Show("This game is not registered. Please contact"
                                    + " BPCPrograms SD to obtain a license.",
                                    "Registration");
                }
                register();
                OggBuffer introSound = DSound.playOgg(DSound.SoundPath + "\\i.ogg");
                while ((introSound.isPlaying() && !dxInput.isKeyHeldDown()))
                {
                    Thread.Sleep(5);
                }
                introSound.stopOgg();
                introSound = null;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + " " + err.StackTrace, "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                Environment.Exit(0);
            }
        }
예제 #4
0
 private void playMessage(String o, bool wait)
 {
     if (message != null)
     {
         message.stopOgg();
     }
     message = DSound.loadOgg(o);
     message.play();
     if (wait)
     {
         Interaction.stopAndMute(true);
         while (message.isPlaying())
         {
             Thread.Sleep(100);
         }
         message.stopOgg();
         Interaction.resumeAndUnmute();
     }             //if wait
 }
예제 #5
0
        private static void buildKeyMapMenu()
        {
            string[] devices = { "mainmenu_5_1_1.wav",
                                 "mainmenu_5_1_2.wav" };
            short    dO = Common.sVGenerateMenu("mainmenu_5_1_i.wav",
                                                devices);

            if (dO == -1)
            {
                return;
            }

            bool mapKeyboard = false;
            bool mapJoystick = false;

            if (dO == 0)
            {
                mapKeyboard = true;
            }
            else
            {
                mapJoystick = true;
            }

            short index = -1;

            Key[] r = null;
            Key[] m = null;
            ////modifiers will only be assigned if keyboard is used
            int[] jsKey = null;
            while (index != 0)
            {
                r     = null;
                m     = null;
                jsKey = null;
                string[] strKeys = null;
                if (mapKeyboard)
                {
                    strKeys = KeyMap.getKeyStrings(null);
                }
                else
                {
                    strKeys = KeyMap.getKeyStrings(Vehicle.Action.throttleUp,
                                                   Vehicle.Action.throttleDown,
                                                   Vehicle.Action.turnLeft,
                                                   Vehicle.Action.turnRight,
                                                   Vehicle.Action.bankLeft,
                                                   Vehicle.Action.bankRight,
                                                   Vehicle.Action.rollLeft,
                                                   Vehicle.Action.rollRight,
                                                   Vehicle.Action.brakeLeft,
                                                   Vehicle.Action.brakeRight,
                                                   Vehicle.Action.highGTurn,
                                                   Vehicle.Action.ascend,
                                                   Vehicle.Action.descend,
                                                   Vehicle.Action.level,
                                                   Vehicle.Action.togglePointOfView,
                                                   Vehicle.Action.increaseMusicVolume,
                                                   Vehicle.Action.decreaseMusicVolume);
                }
                index = (short)(Common.sVGenerateMenu("ki.wav",
                                                      strKeys) + 1);
                if (index > 0)
                {
                    if (mapKeyboard)
                    {
                        OggBuffer prompt = DSound.playOgg(DSound.NSoundPath + "\\kmp1.ogg");
                        while (dxInput.isKeyHeldDown())
                        {
                            ////wait till the user lets up on enter.
                            Application.DoEvents();
                        }
                        while (m == null)
                        {
                            m = dxInput.getKeys();
                        }
                        prompt.stopOgg();
                        prompt = null;

                        prompt = DSound.playOgg(DSound.NSoundPath + "\\kmp2.ogg");
                        while ((dxInput.isKeyHeldDown()))
                        {
                            ////wait till the user lets up on enter.
                            Application.DoEvents();
                        }
                        ////Next, get a key
                        while (r == null)
                        {
                            r = dxInput.getKeys();
                        }
                        prompt.stopOgg();
                        prompt = null;
                        if (m[0] == Key.Return)
                        {
                            KeyMap.addKey((Vehicle.Action)index, r[0]);
                        }
                        else
                        {
                            KeyMap.addKey((Vehicle.Action)index, m[0], r[0]);
                        }
                    }
                    else
                    {
                        ////joystick
                        OggBuffer prompt = DSound.playOgg(DSound.NSoundPath + "\\kmp3.ogg");
                        while (dxInput.isJSButtonHeldDown())
                        {
                            Application.DoEvents();
                        }
                        while (jsKey == null)
                        {
                            jsKey = dxInput.getJSKeys();
                            Application.DoEvents();
                        }
                        prompt.stopOgg();
                        prompt = null;
                        KeyMap.addKey((Vehicle.Action)index, dxInput.getJSKeys()[0]);
                    }
                    ////joystick
                }
                ////index>=0
            }

            ////Since the parent loop has been broken, the user has pressed escape.
            ////We need to save the new keymap data to a file now so that it will be restored when the game loads
            KeyMap.saveToFile();
        }
예제 #6
0
        public static void mainMenu()
        {
            Common.music = DSound.playOgg(DSound.SoundPath + "\\ms1.ogg", true);
            string[] m1       = { "mainmenu_1.wav", "mainmenu_2.wav", "mainmenu_3.wav", "mainmenu_5.wav", "mainmenu_4.wav" };
            bool     exitMenu = false;

            while (!exitMenu)
            {
                short index = Common.sVGenerateMenu("mainmenu_i.wav", m1);
                switch (index)
                {
                case 0:
                    ////start game
                    if (Options.mode == Options.Modes.racing)
                    {
                        if (selectTrack())
                        {
                            exitMenu = true;
                        }
                    }
                    if (Options.mode == Options.Modes.deathMatch)
                    {
                        exitMenu = true;
                    }
                    if (Options.mode == Options.Modes.mission)
                    {
                        exitMenu = true;
                    }

                    break;

                case 1:
                    ////select racing mode
                    string[] modeOptions = { "mainmenu_2_1.wav", "mainmenu_2_2.wav", "mainmenu_2_3.wav" };
                    short    modeIndex   = Common.sVGenerateMenu("", modeOptions);
                    if (modeIndex == -1)
                    {
                        break;
                    }

                    Options.mode = (Options.Modes)(modeIndex + 1);
                    if (Options.mode == Options.Modes.mission)
                    {
                        Mission.isMission = true;
                    }
                    else
                    {
                        Mission.isMission = false;
                        ////reset in case coming
                        ////out of mission mode
                    }

                    break;

                case 2:
                    ////speaker test
                    OggBuffer speakerTest = DSound.playOgg(DSound.SoundPath + "\\speakertest.ogg");
                    while (speakerTest.isPlaying())
                    {
                        Application.DoEvents();
                    }
                    speakerTest = null;
                    break;

                case 3:
                    ////options
                    string[] oArray = { "mainmenu_5_1.wav", "mainmenu_5_2.wav" };

                    short oIndex = 0;
                    while (oIndex != -1)
                    {
                        oIndex = Common.sVGenerateMenu("mainmenu_5_i.wav", oArray);
                        switch (oIndex)
                        {
                        case 0:
                            ////mapkeys
                            buildKeyMapMenu();
                            break;

                        case 1:
                            ////switch input device
                            showDevices();
                            break;
                        }
                    }

                    break;

                case 4:
                    ////exit
                    Options.requestedShutdown = true;
                    exitMenu = true;
                    break;
                }
            }
            Common.fadeMusic();

            if (Options.requestedShutdown)
            {
                Options.requestedShutdown = false;
                Common.shutdown();
                return;
            }
        }
예제 #7
0
        /// <summary>
        /// Initializes a joystick device using the specified global unique identifier.
        /// </summary>
        /// <param name="handle">A pointer to the application's master form.</param>
        /// <param name="g">The GUID of the device to initialize.</param>
        public static void DInputInit(IntPtr handle, Guid g)
        {
            if (JSDevice != null)
            {
                JSDevice.Unacquire();
                JSDevice = null;
            }

            JSDevice = new Joystick(input, g);
            int xAxisOffset = 0, yAxisOffset = 0;
            int nextOffset = 0;

            //            JSDevice.Properties.AutoCenter = true;
            foreach (DeviceObjectInstance d in JSDevice.GetObjects())
            {
                if ((d.ObjectId.Flags & DeviceObjectTypeFlags.ForceFeedbackActuator) == DeviceObjectTypeFlags.ForceFeedbackActuator)
                {
                    if (nextOffset == 0)
                    {
                        xAxisOffset = d.Offset;
                    }
                    else
                    {
                        yAxisOffset = d.Offset;
                    }
                    nextOffset++;
                }
                if (d.ObjectType == ObjectGuid.XAxis)
                {
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).Range = new InputRange(-5, 5);
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).DeadZone = 1000;
                }
                if (d.ObjectType == ObjectGuid.YAxis)
                {
                    JSDevice.GetObjectPropertiesById(d.ObjectId).Range = new InputRange(-9, 9);
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).DeadZone = 1000;
                }
                if (d.ObjectType == ObjectGuid.Slider)
                {
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).Range = new InputRange(0, 11);
                    JSSliderId            = d.ObjectId;
                    useSlider             = true;
                }
                if (d.ObjectType == ObjectGuid.ZAxis)
                {
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).Range = new InputRange(0, 11);
                    jsZId = d.ObjectId;
                    useZ  = true;
                }
                if (d.ObjectType == ObjectGuid.RzAxis)
                {
                    JSDevice.GetObjectPropertiesById(
                        d.ObjectId).Range = new InputRange(-5, 5);
                }
            }             //for
            if (useSlider && useZ)
            {
                useSlider = false;
            }
            JSDevice.SetCooperativeLevel(handle,
                                         CooperativeLevel.Background | CooperativeLevel.Exclusive);
            JSDevice.Acquire();
            updateJSState();
            TheJSButtons = JSState.Buttons;
            if (nextOffset > 0)
            {
                if (!dInputInitFD(JSDevice, xAxisOffset,
                                  yAxisOffset, nextOffset))
                {
                    OggBuffer error = DSound.loadOgg(DSound.SoundPath + "\\ffbd.ogg");
                    error.play();
                    while (error.isPlaying())
                    {
                        Thread.Sleep(10);
                    }
                    error.stopOgg();
                    error = null;
                    forceFeedbackEnabled = false;
                }
                else
                {
                    forceFeedbackEnabled = true;
                }
            }
        }