Music defines a big sound played using streaming, so usually what we call a music :)
상속: SFML.System.ObjectBase
예제 #1
0
파일: Sound.cs 프로젝트: freemaul/SFML
        /// <summary>
        /// Play a music
        /// </summary>
        private static void PlayMusic()
        {
            // Load an ogg music file
            Music Music = new Music("datas/sound/lepidoptera.ogg");

            // Display music informations
            Console.WriteLine("lepidoptera.ogg :");
            Console.WriteLine(" " + Music.Duration      + " sec");
            Console.WriteLine(" " + Music.SampleRate    + " samples / sec");
            Console.WriteLine(" " + Music.ChannelsCount + " channels");

            // Play it
            Music.Play();

            // Loop while the music is playing
            while (Music.Status == SoundStatus.Playing)
            {
                // Display the playing position
                Console.CursorLeft = 0;
                Console.Write("Playing... " + Music.PlayingOffset + " sec     ");

                // Leave some CPU time for other processes
                Thread.Sleep(100);
            }
        }
예제 #2
0
        public static void Play(Musics Index, bool Loop = false)
        {
            string Directory = Directories.Musics.FullName + (byte)Index + Format;

            // Apenas se necessário
            if (Device != null)
            {
                return;
            }
            if (!Lists.Options.Musics)
            {
                return;
            }
            if (!File.Exists(Directory))
            {
                return;
            }

            // Carrega o áudio
            Device        = new SFML.Audio.Music(Directory);
            Device.Loop   = true;
            Device.Volume = 20;
            Device.Loop   = Loop;

            // Reproduz
            Device.Play();
            Current = (byte)Index;
        }
 void SfmlPlay(SFMLMusic audio)
 {
     audio.Stop();
     audio.Volume = m_Volume;
     audio.Play();
     m_CurrentMusic = audio;
 }
예제 #4
0
        public SoundInstance(ScriptEngine parent, string filename)
            : base(parent)
        {
            PopulateFunctions();

            string[] sounds = { ".wav", ".flac" };
            string[] music = { ".ogg" };

            if (!System.IO.File.Exists(filename)) {
                _soundType = SoundType.None;
                return;
            }

            _filename = filename;
            string ending = System.IO.Path.GetExtension(filename);
            if (Array.Exists(sounds, x => x == ending))
            {
                _sound = new Sound(new SoundBuffer(filename));
                _soundType = SoundType.Sound;
            }
            else if (Array.Exists(music, x => x == ending))
            {
                _music = new Music(filename);
                _soundType = SoundType.Music;
            }
        }
예제 #5
0
 /// <summary>
 /// コンストラクター
 /// </summary>
 /// <param name="fileName">ファイル名</param>
 public MusicTrack(string fileName)
 {
     if (fileName == null || fileName == "") {
         throw new ArgumentNullException ("FileName is null or empty");
     }
     this.fileName = fileName;
     this.data = new Music (fileName);
     this.data.Loop = true;
 }
예제 #6
0
파일: Audio.cs 프로젝트: Kukks/CryBits
 public static void Stop()
 {
     // Para a música que está tocando
     if (Device != null && Current != 0)
     {
         Device.Stop();
         Device.Dispose();
         Device = null;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioStream"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="streaming">if set to <c>true</c> [streaming].</param>
        public AudioStream(string fileName, bool streaming)
        {
            if (streaming)
                _outputStream = new Music(fileName);
            else
            {
                OutputBuffer = new SoundBuffer(fileName);
                _outputSound = new Sound(OutputBuffer);
            }

            Init(fileName, streaming);
        }
예제 #8
0
 /// <summary>
 /// Load a music file from a file path.
 /// </summary>
 /// <param name="source"></param>
 public Music(string source, bool loop = true)
 {
     if (!File.Exists(source))
     {
         music = new SFML.Audio.Music(Files.LoadFileBytes(source));
     }
     else
     {
         music = new SFML.Audio.Music(source);
     }
     music.Loop = loop;
     Initialize();
 }
        public EntityGraphicsComponent(Texture spriteSheet)
        {
            _entityBoundingBoxOutline = new RectangleShape
            {
                FillColor = Color.Transparent,
                OutlineColor = Color.Red,
                OutlineThickness = 1
            };

            _geometryBoundingBoxOutline = new RectangleShape
            {
                FillColor = Color.Transparent,
                OutlineColor = Color.White,
                OutlineThickness = 1
            };

            _sprite = new AnimatedSprite(Time.FromSeconds(0.1f), true, false);

            _south = new Animation(spriteSheet);
            AddFramesToAnimation(_south, SpriteHeight * 0);

            _north = new Animation(spriteSheet);
            AddFramesToAnimation(_north, SpriteHeight * 1);

            _east = new Animation(spriteSheet);
            AddFramesToAnimation(_east, SpriteHeight * 2);

            _west = new Animation(spriteSheet);
            AddFramesToAnimation(_west, SpriteHeight * 3);

            _northwest = new Animation(spriteSheet);
            AddFramesToAnimation(_northwest, SpriteHeight * 4);

            _northeast = new Animation(spriteSheet);
            AddFramesToAnimation(_northeast, SpriteHeight * 5);

            _southwest = new Animation(spriteSheet);
            AddFramesToAnimation(_southwest, SpriteHeight * 6);

            _southeast = new Animation(spriteSheet);
            AddFramesToAnimation(_southeast, SpriteHeight * 7);

            _currentAnimation = _south;

            _sprite.Animation = _currentAnimation;

            _footstepMusic = new Music("sounds/footstep.wav") { Loop = true };
        }
예제 #10
0
        static public bool LoadSounds()
        {
            for (int i = 0; i < sound.Count(); i++) sound[i] = new Sound();

            sounds.Add("jump", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.jump.wav")));
            sounds.Add("drop", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.drop.wav")));
            sounds.Add("pickup", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.pickup.wav")));
            sounds.Add("open", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.open.wav")));
            sounds.Add("explode", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.explode.wav")));
            sounds.Add("win", new SoundBuffer(assembly.GetManifestResourceStream("TrainBox.snd.win.wav")));

            music = new Music(assembly.GetManifestResourceStream("TrainBox.snd.m1.ogg"));
            endingMusic = new Music(assembly.GetManifestResourceStream("TrainBox.snd.m2.ogg"));

            return true;
        }
예제 #11
0
        public static void PlayMusic(string name)
        {
            var state = 0;
            var tween = Tween.Create(TweenType.OutQuad, 0, GameOptions.MusicVolume, 0.5f, () => state = 1);
            var music = new Music(Path.Combine(GameOptions.MusicLocation, name));
            var watch = new Stopwatch();

            currentMusic = music;

            music.Volume = 0;
            music.Play();

            watch.Start();

            Timer.EveryFrame(() =>
            {
                double dt = watch.Elapsed.TotalSeconds;
                watch.Restart();

                if (music != currentMusic && state != 3)
                    state = 2;

                switch (state)
                {
                    case 0: // fade in
                        music.Volume = (float)tween(dt);
                        break;
                    case 1: // normal play
                        if (music.PlayingOffset.TotalSeconds >= music.Duration.TotalSeconds - 1)
                            state = 2;
                        break;
                    case 2: // setup fadeout
                        tween = Tween.Create(TweenType.OutQuad, music.Volume, 0, 0.5f, () => state = 10);
                        state = 3;
                        break;
                    case 3: // fade out
                        music.Volume = (float)tween(dt);

                        if (state != 3)
                            return true;

                        break;
                }

                return false;
            });
        }
        public bool Load(string musicname, string filename)
        {
            filename = FullName(filename);
            Logger.WriteLine(Logger.Stage.INIT_SOUND, String.Format("loading music {0} file {1}", musicname, filename));
            try
            {
                SFMLMusic music = new SFMLMusic(filename);
                m_Musics.Add(musicname, music);
            }
            catch (Exception e)
            {
                Logger.WriteLine(Logger.Stage.INIT_SOUND, String.Format("failed to load music file {0} exception {1}.", filename, e.ToString()));
            }


            return(true);
        }
        public void Dispose()
        {
            Logger.WriteLine(Logger.Stage.CLEAN_SOUND, "disposing SFMLMusicManager...");
            foreach (string musicname in m_Musics.Keys)
            {
                SFMLMusic music = m_Musics[musicname];
                if (music == null)
                {
                    Logger.WriteLine(Logger.Stage.CLEAN_SOUND, String.Format("WARNING: null music for key {0}", musicname));
                    continue;
                }
                Logger.WriteLine(Logger.Stage.CLEAN_SOUND, String.Format("disposing music {0}.", musicname));
                music.Dispose();
            }

            m_Musics.Clear();
            Logger.WriteLine(Logger.Stage.CLEAN_SOUND, "disposing SFMLMusicManager done.");
        }
예제 #14
0
파일: Audio.cs 프로젝트: Kukks/CryBits
        public static void Play(Musics Index, bool Loop = false)
        {
            System.IO.FileInfo File = new System.IO.FileInfo(Directories.Musics.FullName + (byte)Index + Format);

            // Apenas se necessário
            if (Device != null) return;
            if (Editor_Maps.Objects.Visible && !Editor_Maps.Objects.butAudio.Checked) return;
            if (!File.Exists) return;

            // Carrega o áudio
            Device = new SFML.Audio.Music(Directories.Musics.FullName + (byte)Index + Format);
            Device.Loop = true;
            Device.Volume = 20;
            Device.Loop = Loop;

            // Reproduz
            Device.Play();
            Current = (byte)Index;
        }
예제 #15
0
        static void Main()
        {
            var cult = new Cult("Inversetroids") {ClearColor = Colors.Black};

            Fonts.Init();

            InitGame(cult);
            InitUI(cult);
            InitMainMenu(cult);
            InitGameOver(cult);

            cult.Undrawn = new World(cult);

            var music = new Music("rsc/music/Beat1.wav");
            music.Play();

            new Ticker(cult.Undrawn, music.Duration, delegate { music.Stop(); music.Play(); });

            cult.CurrentWorld = Menu;
            cult.Run();
        }
예제 #16
0
        public GameWorld()
        {
            mEntities = new List<Entity>();
            mEnemies  = new List<Enemy>();
            mPhysics  = new World(new Vector2(0f, 0.0981f));
            mWin      = true;

            mTimeText.Position  = new Vector2f(580f, 670f);
            mStartInfo.Position = new Vector2f(500f, 300f);
            mWinText.Position   = new Vector2f(400f, 200f);
            mLoseText.Position  = new Vector2f(400f, 200f);
            //mStartInfo.Color    = new Color(255, 0, 0);

            ConvertUnits.SetDisplayUnitToSimUnitRatio(8f);
            Delta.create();
            mCountdown.Start();
            mGameState = GameState.START;

            mMusic        = new Music("resources/sound/theme.wav");
            mMusic.Loop   = true;
            mMusic.Volume = 40f;
            mMusic.Play();
        }
예제 #17
0
 /// <summary>
 /// Load a music file from a file path.
 /// </summary>
 /// <param name="source"></param>
 public Music(string source, bool loop = true) {
     music = new SFML.Audio.Music(source);
     music.Loop = loop;
     Initialize();
 }
예제 #18
0
 public Music Music(string filename)
 {
     if (dctMusic.ContainsKey(filename)) return dctMusic[filename];
     var res = Resource(filename);
     if (res == null) return null;
     var music = new Music(res);
     dctMusic.Add(filename, music);
     return music;
 }
 public MusicResource(Music music)
 {
     this.music = music;
 }
 void Stop(SFMLMusic audio)
 {
     audio.Stop();
 }
예제 #21
0
 /// <summary>
 /// Load a music file from a file path.
 /// </summary>
 /// <param name="source"></param>
 public Music(string source, bool loop = true)
 {
     music      = new SFML.Audio.Music(source);
     music.Loop = loop;
     Initialize();
 }
 void Play(SFMLMusic audio)
 {
     audio.Stop();
     audio.Volume = m_Volume;
     audio.Play();
 }
예제 #23
0
        /// <summary>
        /// Loads all game content for later use.
        /// Should only be called during initialization.
        /// </summary>
        public static void Load()
        {
            Font = new Font("Content/font.ttf");

            CandyCane = new Texture("Content/Sprites/Candy/candy_cane.png");
            chocolates = new[]
                {
                    new Texture("Content/Sprites/Candy/dark_chocolate.png") { Repeated = true },
                    new Texture("Content/Sprites/Candy/milk_chocolate.png") { Repeated = true },
                    new Texture("Content/Sprites/Candy/white_chocolate.png") { Repeated = true }
                };

            DoubleCandyCane = new Texture("Content/Sprites/Candy/double_candy_cane.png");
            Logo = new Texture("Content/Sprites/logo.png");
            MeterBack = new Texture("Content/Sprites/meter_back.png");
            MeterFront = new Texture("Content/Sprites/meter_front.png");
            Noise = new Texture("Content/Sprites/noise.png");
            Player = new Texture("Content/Sprites/player.png");
            Powerup = new Texture("Content/Sprites/powerup.png");

            ranchers = new[]
                {
                    new Texture("Content/Sprites/Candy/rancher_green.png"),
                    new Texture("Content/Sprites/Candy/rancher_purple.png"),
                    new Texture("Content/Sprites/Candy/rancher_red.png"),
                    new Texture("Content/Sprites/Candy/rancher_teal.png")
                };
            Tileset = new Texture("Content/Sprites/tileset.png");

            Music = new Music("Content/Music/CandyRush.ogg") { Loop = true };

            JumpSound = new Sound(new SoundBuffer("Content/Sounds/jump.wav"));
            NoiseSound = new Sound(new SoundBuffer("Content/Sounds/noise.wav"));
            HitSound = new Sound(new SoundBuffer("Content/Sounds/hit.wav"));
            PowerupSound = new Sound(new SoundBuffer("Content/Sounds/powerup.wav"));
            ShatterSound = new Sound(new SoundBuffer("Content/Sounds/shatter.wav"));
            SliceSound = new Sound(new SoundBuffer("Content/Sounds/slice.wav"));

            TestMap = new TmxMap("Content/Levels/test.tmx");
            Level = new TmxMap("Content/Levels/level.tmx");

            var image = new Image(1, 1, Color.White);
            Pixel = new Texture(image);
        }
 bool IsPaused(SFMLMusic audio)
 {
     return(audio.Status == SoundStatus.Paused);
 }
예제 #25
0
파일: Game.cs 프로젝트: robodylan/4HJ1
 public void Start()
 {
     //Load Assets and Set Variables
     lose = false;
     m = new Music("Content/mixdown.ogg");
     m.Loop = true;
     m.Play();
     F = new Font("Content/Animated.ttf");
     BG = new Sprite(new Texture(new Image("Content/BG.png")), new IntRect(0, 0, W, H));
     pointSprite = new Sprite(new Texture(new Image("Content/Point.png")), new IntRect(0,0,16,16));
     window.MouseMoved += MouseInput;
     window.KeyPressed += KeyboardInput;
     window.KeyReleased += KeyboardReleaseInput;
     Player.Load();
     while(window.IsOpen())
     {
         window.DispatchEvents();
         window.Clear(new Color(0,0,0));
         Draw();
         window.Display();
     }
 }
예제 #26
0
        public static void InitializeMusic()
        {
            if (!Music) return;
            string rndmusic = GetRandomMusic ();
            if (rndmusic == null) return;

            CurrentMusic = new Music(rndmusic) {Loop = true};
            CurrentMusic.Play ();
        }
예제 #27
0
 public void setCurrentTrack(string key)
 {
     currentMusic = music[key];
 }
예제 #28
0
 public void add(string key, Music m)
 {
     music.Add(key, m);
     currentMusic = m;
 }
예제 #29
0
 /// <summary>
 /// Dispose the music. (I don't think this works right now.)
 /// </summary>
 public void Dispose() {
     musics.Remove(this);
     music.Dispose();
     music = null;
 }
예제 #30
0
 /// <summary>
 /// Load a music stream from an IO stream.
 /// </summary>
 /// <param name="stream"></param>
 public Music(Stream stream) {
     music = new SFML.Audio.Music(stream);
     music.Loop = true;
     Initialize();
 }
예제 #31
0
 void PlayMusic(String filename)
 {
     Music = new Music(filename);
     Music.Play();
 }
예제 #32
0
 public void SetMusic(Music music)
 {
     Music = music;
 }
예제 #33
0
        public void OnActivate()
        {
            // Store window
            window = Root.Singleton.Window;
            rctScreen = Util.ScreenRect(window.Size.X, window.Size.Y, 1.7778f);

            // Load sprites
            sprBackground = new Sprite(Root.Singleton.Material("img/main_menus/main_base2.png"));
            sprBackground.Position = new Vector2f(rctScreen.Left, rctScreen.Top);
            sprBackground.Scale = Util.Scale(sprBackground, new Vector2f(rctScreen.Width, rctScreen.Height));

            // Load audio
            mscMenu = Root.Singleton.Music("audio/music/bp_MUS_TitleScreen.ogg");
            sndButtonHover = Root.Singleton.Sound("audio/waves/ui/select_light1.wav");
            //mscMenu.Stop();
            //mscMenu.Play();

            // Load UI
            var btnContinue = new ImageButton();
            btnContinue.Image = Root.Singleton.Material("img/main_menus/continue_on.png");
            btnContinue.HoveredImage = Root.Singleton.Material("img/main_menus/continue_select2.png");
            btnContinue.DisabledImage = Root.Singleton.Material("img/main_menus/continue_off.png");
            btnContinue.Enabled = false;
            btnContinue.HoverSound = sndButtonHover;
            Util.LayoutControl(btnContinue,
                (int)(1200 - btnContinue.Image.Size.X), 260,
                (int)btnContinue.Image.Size.X,
                (int)btnContinue.Image.Size.Y,
                rctScreen);
            btnContinue.Parent = Root.Singleton.Canvas;
            btnContinue.Init();

            var btnNewGame = new ImageButton();
            btnNewGame.Image = Root.Singleton.Material("img/main_menus/start_on.png");
            btnNewGame.HoveredImage = Root.Singleton.Material("img/main_menus/start_select2.png");
            btnNewGame.DisabledImage = Root.Singleton.Material("img/main_menus/start_off.png");
            btnNewGame.Enabled = true;
            btnNewGame.HoverSound = sndButtonHover;
            btnNewGame.OnClick += (sender) =>
            {
                Root.Singleton.mgrState.FSMTransist<NewGame>();
            };
            Util.LayoutControl(btnNewGame,
                (int)(1200 - btnNewGame.Image.Size.X), 320,
                (int)btnNewGame.Image.Size.X,
                (int)btnNewGame.Image.Size.Y,
                rctScreen);
            btnNewGame.Parent = Root.Singleton.Canvas;
            btnNewGame.Init();

            var btnTutorial = new ImageButton();
            btnTutorial.Image = Root.Singleton.Material("img/main_menus/tutorial_on.png");
            btnTutorial.HoveredImage = Root.Singleton.Material("img/main_menus/tutorial_select2.png");
            btnTutorial.DisabledImage = Root.Singleton.Material("img/main_menus/tutorial_off.png");
            btnTutorial.Enabled = false;
            btnTutorial.HoverSound = sndButtonHover;
            Util.LayoutControl(btnTutorial,
                (int)(1200 - btnTutorial.Image.Size.X), 380,
                (int)btnTutorial.Image.Size.X,
                (int)btnTutorial.Image.Size.Y,
                rctScreen);
            btnTutorial.Parent = Root.Singleton.Canvas;
            btnTutorial.Init();

            var btnStats = new ImageButton();
            btnStats.Image = Root.Singleton.Material("img/main_menus/stats_on.png");
            btnStats.HoveredImage = Root.Singleton.Material("img/main_menus/stats_select2.png");
            btnStats.DisabledImage = Root.Singleton.Material("img/main_menus/stats_off.png");
            btnStats.Enabled = false;
            btnStats.HoverSound = sndButtonHover;
            Util.LayoutControl(btnStats,
                (int)(1200 - btnStats.Image.Size.X), 440,
                (int)btnStats.Image.Size.X,
                (int)btnStats.Image.Size.Y,
                rctScreen);
            btnStats.Parent = Root.Singleton.Canvas;
            btnStats.Init();

            var btnOptions = new ImageButton();
            btnOptions.Image = Root.Singleton.Material("img/main_menus/options_on.png");
            btnOptions.HoveredImage = Root.Singleton.Material("img/main_menus/options_select2.png");
            btnOptions.DisabledImage = Root.Singleton.Material("img/main_menus/options_off.png");
            btnOptions.Enabled = true;
            btnOptions.HoverSound = sndButtonHover;
            btnOptions.OnClick += (sender) => { Root.Singleton.mgrState.Activate<Gamestate.OptionsMenu>(); };
            Util.LayoutControl(btnOptions,
                (int)(1200 - btnOptions.Image.Size.X), 500,
                (int)btnOptions.Image.Size.X,
                (int)btnOptions.Image.Size.Y,
                rctScreen);
            btnOptions.Parent = Root.Singleton.Canvas;
            btnOptions.Init();

            var btnCredits = new ImageButton();
            btnCredits.Image = Root.Singleton.Material("img/main_menus/credits_on.png");
            btnCredits.HoveredImage = Root.Singleton.Material("img/main_menus/credits_select2.png");
            btnCredits.DisabledImage = Root.Singleton.Material("img/main_menus/credits_off.png");
            btnCredits.Enabled = false;
            btnCredits.HoverSound = sndButtonHover;
            Util.LayoutControl(btnCredits,
                (int)(1200 - btnCredits.Image.Size.X), 560,
                (int)btnCredits.Image.Size.X,
                (int)btnCredits.Image.Size.Y,
                rctScreen);
            btnCredits.Parent = Root.Singleton.Canvas;
            btnCredits.Init();

            var btnQuit = new ImageButton();
            btnQuit.Image = Root.Singleton.Material("img/main_menus/quit_on.png");
            btnQuit.HoveredImage = Root.Singleton.Material("img/main_menus/quit_select2.png");
            btnQuit.DisabledImage = Root.Singleton.Material("img/main_menus/quit_off.png");
            btnQuit.Enabled = true;
            btnQuit.HoverSound = sndButtonHover;
            btnQuit.OnClick += (sender) => { Root.Singleton.Exiting = true; };
            Util.LayoutControl(btnQuit,
                (int)(1200 - btnQuit.Image.Size.X), 620,
                (int)btnQuit.Image.Size.X,
                (int)btnQuit.Image.Size.Y,
                rctScreen);
            btnQuit.Parent = Root.Singleton.Canvas;
            btnQuit.Init();
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        public void Dispose()
        {
            if (_outputStream != null)
            {
                _outputStream.Dispose();
                _outputStream = null;
            }

            if (OutputBuffer != null)
            {
                OutputBuffer.Dispose();
                OutputBuffer = null;
            }

            if (_outputSound != null)
            {
                _outputSound.Dispose();
                _outputSound = null;
            }
        }
 bool SfmlIsPlaying(SFMLMusic audio)
 {
     return(audio.Status == SoundStatus.Playing);
 }
예제 #36
0
        public StandardMelee(InputHandler handler)
        {
            _mousePosition = new Vector2f(500, 500);

            CurrentStatus = StatusState.WaitingForPlayers;

            uiState = UIStateTypes.Normal;
            currentHotkey = null;
            currentHotkeySheet = null;
            standardHotkeys = Settings.GetSheet("standard_game_mode_controls");

            InputHandler = handler;
            myId = 0;
            map = new TileMap();

            allowMinimapCameraMove = true;
            selectedUnits = null;
            controlGroups = new Dictionary<Keyboard.Key, List<EntityBase>>();

            for (int i = 27; i <= 35; i++)
            {
                controlGroups.Add((Keyboard.Key) i, new List<EntityBase>());
            }

            controlBoxP1 = new Vector2f(0, 0);
            controlBoxP2 = new Vector2f(0, 0);
            selectedAttackMove = false;
            releaseSelect = false;

            CameraPosition = new Vector2f(0, 0);

            miniMap = new MiniMap(map, Fog, entities);

            //Load Sprites
            bottomHUDGUI = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/BottomGUI.png"));
            alertHUDAlert = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_Alert.png"));
            alertHUDUnitCreated = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_UnitCreated.png"));
            alertHUDBuildingCreated =
                new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_BuildingFinished.png"));

            avatarWorker = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_AVATAR_WORKER.png"));

            hudBoxUnit = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Unit.png"));
            hudBoxBuilding = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Building.png"));

            hudControlBox = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/ControlGroupBox.png"));
            hudControlBox.Origin = new Vector2f(hudControlBox.TextureRect.Width/2, 0);

            viewBounds = new Sprite(ExternalResources.GTexture("Resources/Sprites/Hud/ViewBounds.png"));

            //Load Sounds
            moveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/MoveCommand/0.wav"));
            attackMoveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/AttackCommand/0.wav"));

            backgroundMusic = new Music("Resources/Audio/Music/In Game/mario.wav");
            backgroundMusic.Loop = true;
            backgroundMusic.Volume = Settings.MUSICVOLUME;
            backgroundMusic.Play();
        }
 void Resume(SFMLMusic audio)
 {
     audio.Play();
 }
예제 #38
0
 public void PlayMusic(string musicName)
 {
     _currentMusic = _music[musicName];
     _currentMusic.Play();
 }
예제 #39
0
 /// <summary>
 /// Load a music stream from an IO stream.
 /// </summary>
 /// <param name="stream"></param>
 public Music(Stream stream)
 {
     music      = new SFML.Audio.Music(stream);
     music.Loop = true;
     Initialize();
 }
예제 #40
0
 public static Music Music(XElement el)
 {
     var m = new Music(StreamAttributeParse(el))
                 {
                     Pitch = FloatAttributeParse(el, "pitch", 1.0f),
                     Volume = FloatAttributeParse(el, "volume", 100f),
                     Loop = BoolAttributeParse(el, "loop"),
                     Position = VectorAttributeParse(el, "position")
                 };
     return m;
 }
예제 #41
0
        public Game()
        {
            Started = false;
            Running = false;

            // Setup Window
            Bounds = new FloatRect(0, 0, ResolutionDefault.X, ResolutionDefault.Y);
            WindowSettings = new ContextSettings();
            WindowSettings.AntialiasingLevel = 6;
            CreateWindow();

            // Black Bars (for fullscreen)
            Layer_BlackBars = new Layer();
            RectangleShape BlackBarLeft = new RectangleShape(new Vector2f(2000, 5000));
            BlackBarLeft.Position = new Vector2f(-BlackBarLeft.Size.X, 0);
            BlackBarLeft.FillColor = new Color(0, 0, 0);
            Layer_BlackBars.AddChild(BlackBarLeft);
            RectangleShape BlackBarRight = new RectangleShape(new Vector2f(2000, 5000));
            BlackBarRight.Position = new Vector2f(Size.X, 0);
            BlackBarRight.FillColor = new Color(0, 0, 0);
            Layer_BlackBars.AddChild(BlackBarRight);

            // Setup
            Layer_Background = new Layer();
            Layer_Other = new Layer();
            Layer_Objects = new Layer();
            Layer_OtherAbove = new Layer();
            Layer_GUI = new Layer();

            // Start Menu
            StartMenu = new StartMenu(this);
            Layer_GUI.AddChild(StartMenu);

            Music = new Music("assets/audio/music/Speed Pirate - LuigiSounds.ogg");
            Music.Loop = true;
            Music.Play();

            // Game Loop
            Stopwatch clock = new Stopwatch();
            clock.Start();
            while (Window.IsOpen())
            {
                // Process events
                Window.DispatchEvents();

                if (clock.Elapsed.TotalSeconds >= (1.0f / FPS))
                {
                    if (CloseNextUpdate)
                    {
                        Window.Close();
                        return;
                    }

                    // Clear screen
                    Window.Clear();

                    // Update Game
                    Update((float)clock.Elapsed.TotalSeconds);
                    clock.Restart();

                    // Draw Game
                    Draw();

                    // Update the window
                    Window.Display();
                }
            }
        }
 public void Load(string path)
 {
     this.music = new Music(path);
 }
예제 #43
0
파일: main.cs 프로젝트: Eisfuchs/sfml_cs
        public static void Main()
        {
            /*
            RenderWindow window = new RenderWindow(new VideoMode(200, 200), "SFML works!");

            Console.WriteLine("test");
            Console.ReadKey();
            */

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            window.Closed += new EventHandler(OnClose);

            // Load a sprite to display
            Texture texture = new Texture("media/image/mario.png");
            Sprite sprite = new Sprite(texture);

            // Create a graphical text to display
            Font font = new Font("media/font/arial.ttf");
            Text text = new Text("Hello SFML", font, 50);

            // Load & play music
            Music music = new Music("media/sound/mario.ogg");
            music.Play();

            // starts the Stopwatch
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            // last mouse position
            Vector2i last_mouse_position = new Vector2i(0, 0);

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                float speed = 0.1f * Convert.ToSingle(stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Reset();
                stopwatch.Start();

                if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y - speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y + speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    sprite.Position = new Vector2f(sprite.Position.X - speed, sprite.Position.Y);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    sprite.Position = new Vector2f(sprite.Position.X + speed, sprite.Position.Y);
                }

                // only if its a new mouse position
                if (!last_mouse_position.Equals(Mouse.GetPosition()))
                {
                    if (Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        Console.WriteLine("Klick Maustaste: Links; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Middle))
                    {
                        Console.WriteLine("Klick Maustaste: Mitte; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        Console.WriteLine("Klick Maustaste: Rechts; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                }

                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Draw the string
                window.Draw(text);

                // Update the window
                window.Display();
            }
        }
예제 #44
0
 /// <inheritdoc/>
 public override void Dispose()
 {
     if (data != null) {
         data.Dispose ();
         this.data = null;
     }
 }
 bool SfmlHasEnded(SFMLMusic audio)
 {
     return(audio.Status == SoundStatus.Stopped || audio.PlayingOffset >= audio.Duration);
 }
예제 #46
0
 /// <summary>
 /// Dispose the music. (I don't think this works right now.)
 /// </summary>
 public void Dispose()
 {
     musics.Remove(this);
     music.Dispose();
     music = null;
 }
 void SfmlStop(SFMLMusic audio)
 {
     audio.Stop();
     m_CurrentMusic = null;
 }