Example #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                // We haven't been disposed yet.

                if (disposing)
                {
                    /* The method has been called directly or indirectly by a
                     * user's code.  Dispose of managed resources here.
                     */
                    if (this.thrusterSound != null)
                    {
                        this.thrusterSound.Dispose();
                        this.thrusterSound = null;
                    }

                    if (this.thrusterChannel != null)
                    {
                        this.thrusterChannel.Dispose();
                        this.thrusterChannel = null;
                    }
                }

                // Dispose of unmanaged resources _only_ out here.

                this.disposed = true;
            }
        }
Example #2
0
        public void FireThruster()
        {
            int shipDirectionDeg = this.owner.SpriteSheet.CurrentDirectionDeg;

            int thrustDirectionDeg;
            int forceDirectionDeg;
            if (this.reverseThruster)
            {
                forceDirectionDeg = (shipDirectionDeg + 180) % 360;
                thrustDirectionDeg = shipDirectionDeg;
            }
            else
            {
                forceDirectionDeg = shipDirectionDeg;
                thrustDirectionDeg = (shipDirectionDeg + 180) % 360;
            }

            // Force to add to the ship.
            Vector v = Vector.FromDirection(forceDirectionDeg, this.Power);

            // Add the force to the ship.
            this.owner.Velocity += v;

            // Set the min/max angle for the spray cone.
            double shipDirectionRadians = (Math.PI / 180d) * thrustDirectionDeg;
            double halfConeRadians = (Math.PI / 180d) * this.exhaustConeDegRange / 2d;
            this.particlePixelEmitter.DirectionMin = Convert.ToSingle(shipDirectionRadians - halfConeRadians);
            this.particlePixelEmitter.DirectionMax = Convert.ToSingle(shipDirectionRadians + halfConeRadians);

            Point thrusterOriginPoint = SolidEntity.GetPosition(this.owner.Center, thrustDirectionDeg, this.engineLength);

            this.particlePixelEmitter.X = thrusterOriginPoint.X;
            this.particlePixelEmitter.Y = thrusterOriginPoint.Y;

            if (!this.particlePixelEmitter.Emitting)
            {
                this.particlePixelEmitter.Emitting = true;
                try
                {
                    this.thrusterChannel = this.thrusterSound.Play(true);
                }
                catch
                {
                    // Must be out of sound channels.
                }
            }
        }
Example #3
0
        // Play a sound or Music with a specific Volume information
        //
        private void PlayBt_Click(object sender, EventArgs e)
        {
            if (nameTb.Text != "")
            {
                if (nameTb.Text.Contains("."))
                {
                    string[] ext = nameTb.Text.Split('.');
                    if (ext[1].ToString().ToLower() == "wav")
                    {
                        if (SoundPlayer != null)
                        {
                            SoundPlayer.Volume = VolumeTb.Value;
                            if (channelSound != null)
                            {
                                channelSound.Stop();
                                channelSound.Dispose();
                            }
                            int volumeTemp = Convert.ToInt32(Convert.ToDouble(CompteurVolumeTb.Text.Replace('.', ',')) * 128);
                            SoundPlayer.Volume = volumeTemp;

                            this.channelSound = SoundPlayer.Play(Convert.ToInt32(repeatNUD.Value));

                        }
                        else
                        {
                            MessageBox.Show("Sorry, this format is currently not supported by Krea");
                        }
                    }
                    else
                    {
                        if (MusicFile != null)
                        {
                            MusicPlayer.Volume = VolumeTb.Value;
                            if (MusicPlayer.IsPlaying) MusicPlayer.Stop();
                            int volumeTemp = Convert.ToInt32(Convert.ToDouble(CompteurVolumeTb.Text.Replace(".", ",")) * 128);
                            MusicPlayer.Volume = volumeTemp;
                            MusicPlayer.Load(MusicFile);
                            MusicPlayer.Play(1);
                        }
                        else
                        {
                            MessageBox.Show("Sorry, this format is currently not supported by this software");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please load an Audio file (.wav, .mp3, .ogg, .m4a) before!");
                }
            }
            else {
                MessageBox.Show("Please load an Audio file (.wav, .mp3, .ogg, .m4a) before!");
            }
        }
Example #4
0
        public void EndThruster()
        {
            if (this.particlePixelEmitter.Emitting)
            {
                this.particlePixelEmitter.Emitting = false;

                this.thrusterChannel.Stop();
                this.thrusterChannel = null;
            }
        }
Example #5
0
        // Import an sound file
        //
        private void importBt_Click(object sender, EventArgs e)
        {
            // We clean previous Audio file
            //
            if (channelSound != null)
            {
                channelSound.Dispose();
                channelSound = null;
            }
            if (SoundPlayer != null) SoundPlayer.Dispose();
            if (MusicPlayer.IsPlaying) MusicPlayer.Stop();
            if (MusicFile != null) MusicFile.Dispose();

            //Open dialogue to get the file
            //
            OpenFileDialog openFileD = new OpenFileDialog();
            openFileD.Multiselect = false;
            openFileD.DefaultExt = ".wav";
            openFileD.AddExtension = false;

            //Configure allowed extensions
            //
            openFileD.Filter = "Audio files (*.wav)|*.wav|MP3 (*.mp3)|*.mp3|OGG (*.ogg)|*.ogg|M4a (*.m4a)|*.m4a";

            if (openFileD.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (File.Exists(openFileD.FileName))
                    {
                        string directoryDest = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Native-Software\\Asset Manager";
                        if (!Directory.Exists(directoryDest))
                            Directory.CreateDirectory(directoryDest);

                        string fileNameDest = directoryDest+"\\"+this.MainForm.CurrentAssetProject.ProjectName+"\\"+openFileD.SafeFileName;
                        File.Copy(openFileD.FileName, fileNameDest,true);
                        //Get File Name and Path
                        AudioFile.name = openFileD.SafeFileName;
                        AudioFile.path = fileNameDest;
                        this.nameTb.Text = AudioFile.name;

                        //Load a sound or a music regarding the format
                        // (only wav and ogg are supported by SDL_mixer library :(
                        // TODO : Found an other Audio Library
                        //
                        string[] ext = nameTb.Text.Split('.');

                        if (ext[1].ToString().ToLower() == "wav")
                        {
                            SoundPlayer = new Sound(fileNameDest);

                        }
                        else if (ext[1].ToString().ToLower() == "ogg")
                        {
                            MusicFile = new Music(fileNameDest);

                        }
                        else
                        {
                            //If the format is not supported, we make sure that no Audio file is loaded
                            //
                            SoundPlayer = null;
                            MusicFile = null;
                        }

                        this.nameTb.Text = AudioFile.name;
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during image loading ! \n\n " + ex.Message);
                }
            }
        }