Пример #1
0
        public void SetCurrentTime(TimeSpan value)
        {
            var wasPlaying = instance?.PlayState == PlayState.Playing;

            instance?.Stop();
            startTime = value;
            instance?.SetRange(new PlayRange(value, sound.TotalLength));

            if (wasPlaying)
            {
                instance?.Play();
            }
        }
Пример #2
0
        /// <summary>
        /// Open door - set sensor collision and opened sprite.
        /// </summary>
        public void Open()
        {
            Debug.WriteLine($"Open {Entity.Name}");
            OpenedState = true;

            var rb = Entity.Get <RigidbodyComponent>();

            rb.Enabled = false;

            var sprite = Entity.Get <SpriteComponent>().SpriteProvider as SpriteFromSheet;

            sprite.CurrentFrame = 13;

            doorSound?.Play();
        }
Пример #3
0
        private void FireShot()
        {
            if (Input.IsKeyDown(Keys.Space))
            {
                var bulletInstance = LaserShotPrefab.Instantiate();

                var bullet = bulletInstance[0];

                var playerSprite = Entity.Get <SpriteComponent>();

                var spawnPosition = new Vector3(Entity.Transform.Position.X, Entity.Transform.Position.Y + 0.35f, Entity.Transform.Position.Z);

                bullet.Transform.Position = spawnPosition;

                bullet.Transform.UpdateWorldMatrix();

                SceneSystem.SceneInstance.RootScene.Entities.Add(bullet);

                bullet.Get <RigidbodyComponent>().IsKinematic    = false;
                bullet.Get <RigidbodyComponent>().LinearVelocity = new Vector3(0, 20, 0);

                ShotSoundInstance.Stop();
                ShotSoundInstance.Volume = 0.5f;
                ShotSoundInstance.Play();
            }
        }
Пример #4
0
        protected void CollisionStarted()
        {
            activated = true;

            // Add visual effect
            var effectMatrix = Matrix.Translation(Entity.Transform.WorldMatrix.TranslationVector);

            this.SpawnPrefabInstance(CoinGetEffect, null, 1.8f, effectMatrix);

            Func <Task> cleanupTask = async() =>
            {
                await Game.WaitTime(TimeSpan.FromMilliseconds(1500));

                Game.RemoveEntity(Entity);
            };

            Script.AddTask(cleanupTask);

            // Play a sound effect
            sfxInstance?.Play();

            // Spawn a collectible coin
            // CoinSpawnModel
            Random rand     = new Random();
            var    numCoins = 3 + rand.Next(4);

            for (int i = 0; i < numCoins; i++)
            {
                var offsetVector = new Vector3((float)rand.NextDouble() - 0.5f, (float)rand.NextDouble(), (float)rand.NextDouble() - 0.5f);
                effectMatrix = Matrix.Scaling(0.7f + (float)rand.NextDouble() * 0.3f) * Matrix.Translation(Entity.Transform.WorldMatrix.TranslationVector + offsetVector * 2f);
                this.SpawnPrefabModel(CoinSpawnModel, null, effectMatrix, offsetVector * (3f + (float)rand.NextDouble() * 3f));
            }
        }
Пример #5
0
 /// <summary>
 /// Toggle light on/off
 /// </summary>
 public void Switch()
 {
     lightSprite.Enabled  = !lightSprite.Enabled;
     lightPhysics.Enabled = !lightPhysics.Enabled;
     this.EnabledState    = !EnabledState;
     lightSound?.Play();
 }
Пример #6
0
        void Fire()
        {
            if (fireSoundInstance.PlayState != PlayState.Playing && !Main.instance.gameOver)
            {
                fireSoundInstance.Play();
            }

            float angel = 0;

            switch (type)
            {
            case UFOType.Large:
                angel = AutoFire();
                break;

            case UFOType.Small:
                angel = AimedFire();
                break;
            }

            Vector3 dir    = Main.instance.VelocityFromAngle(angel, shotSpeed);
            Vector3 offset = Main.instance.VelocityFromAngle(angel, radius);

            if (!shotScript.IsActive())
            {
                shotScript.Spawn(position + offset, dir, 1.45f);
            }
        }
Пример #7
0
 private void EnableDamage()
 {
     Entity.Get <RigidbodyComponent>().Enabled      = true;
     Entity.Get <ParticleSystemComponent>().Enabled = true;
     Entity.Get <ParticleSystemComponent>().ParticleSystem.Play();
     swordSfxInstance?.Play();
 }
Пример #8
0
        public SoundInstance PlayAttachedSound(string url, Entity parent, float pitch = 1f, float volume = 1f, float distanceScale = 1f, bool looped = false)
        {
            Vector3 pos     = parent.Transform.WorldPosition();
            float   sqrDist = (pos - AudioEngine.DefaultListener.Position).LengthSquared();

            if (MaxSoundDistance > 0f && sqrDist >= MaxSoundDistance * MaxSoundDistance)
            {
                return(null);
            }
            SoundInstance s = getFreeInstance(url, true);

            if (s == null)
            {
                return(null);
            }
            s.Pitch     = pitch < 0f ? RandomPitch() : pitch;
            s.Volume    = volume * MasterVolume;
            s.IsLooping = looped;
            s.Pan       = 0f;
            s.Apply3D(pos, null, null, distanceScale);
            s.Play();
            var posSnd = new PositionalSound()
            {
                pos            = pos,
                soundInstance  = s,
                entity         = parent,
                distance_scale = distanceScale
            };

            lock (currentAttached) {
                currentAttached.Add(posSnd);
            }
            return(s);
        }
Пример #9
0
        public override async Task Execute()
        {
            var imgLeft  = Page?.RootElement.FindVisualChildOfType <ImageElement>("LeftWave");
            var imgRight = Page?.RootElement.FindVisualChildOfType <ImageElement>("RightWave");

            music  = SoundMusic.CreateInstance();
            effect = SoundEffect.CreateInstance();

            if (!IsLiveReloading)
            {
                // start ambient music
                music.IsLooping = true;
                music.Play();

                fontColor         = 0;
                originalPositionX = (imgRight != null) ? imgRight.GetCanvasRelativePosition().X : 0.65f;
            }

            while (Game.IsRunning)
            {
                if (Input.PointerEvents.Any(item => item.EventType == PointerEventType.Pressed)) // New click
                {
                    if (imgLeft != null && imgRight != null)
                    {
                        // reset wave position
                        imgLeft.SetCanvasRelativePosition(new Vector3(1 - originalPositionX, 0.5f, 0));
                        imgLeft.Opacity = 0;

                        imgRight.SetCanvasRelativePosition(new Vector3(originalPositionX, 0.5f, 0));
                        imgRight.Opacity = 0;
                    }

                    // reset transparency
                    fontColor = 1;

                    // play the sound effect on each touch on the screen
                    effect.Stop();
                    effect.Play();
                }
                else
                {
                    if (imgLeft != null && imgRight != null)
                    {
                        imgLeft.SetCanvasRelativePosition(imgLeft.GetCanvasRelativePosition() - new Vector3(0.0025f, 0, 0));
                        imgRight.SetCanvasRelativePosition(imgRight.GetCanvasRelativePosition() + new Vector3(0.0025f, 0, 0));

                        // changing font transparency
                        fontColor        = 0.93f * fontColor;
                        imgLeft.Opacity  = fontColor;
                        imgRight.Opacity = fontColor;
                    }
                }

                // wait for next frame
                await Script.NextFrame();
            }
        }
Пример #10
0
 private static void TestSoundMusicLoadingImpl(Game game)
 {
     Sound sound = null;
     Assert.DoesNotThrow(() => sound = game.Content.Load<Sound>("EffectBip"), "Failed to load the SoundMusic.");
     Assert.IsNotNull(sound, "The SoundMusic loaded is null.");
     testInstance = sound.CreateInstance(game.Audio.AudioEngine.DefaultListener);
     testInstance.Play();
     // Should hear the sound here.
 }
Пример #11
0
        private static void TestSoundMusicLoadingImpl(Game game)
        {
            var sound = game.Content.Load <Sound>("EffectBip");

            Assert.NotNull(sound);
            testInstance = sound.CreateInstance(game.Audio.AudioEngine.DefaultListener);
            testInstance.Play();
            // Should hear the sound here.
        }
Пример #12
0
        private static void TestSoundMusicLoadingImpl(Game game)
        {
            Sound sound = null;

            Assert.DoesNotThrow(() => sound = game.Content.Load <Sound>("EffectBip"), "Failed to load the SoundMusic.");
            Assert.IsNotNull(sound, "The SoundMusic loaded is null.");
            testInstance = sound.CreateInstance(game.Audio.AudioEngine.DefaultListener);
            testInstance.Play();
            // Should hear the sound here.
        }
Пример #13
0
        public new void Hit()
        {
            if (explodeSoundInstance.PlayState != PlayState.Playing && !Main.instance.gameOver)
            {
                explodeSoundInstance.Play();
            }

            SetExplode();
            Disable();
        }
Пример #14
0
        public override void Start()
        {
            bgmInstance = SoundMusic?.CreateInstance();

            if (bgmInstance != null)
            {
                // start ambient music
                bgmInstance.IsLooping = true;
                bgmInstance.Play();
            }
        }
Пример #15
0
        public void Explode()
        {
            m_ExplodeSoundInstance.Stop();

            if (!m_GameOver)
            {
                m_ExplodeSoundInstance.Play();
            }

            SpawnExplosion();
        }
Пример #16
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            music            = Content.Load <Sound>("MusicFishLampMp3").CreateInstance(Audio.AudioEngine.DefaultListener);
            effect           = Content.Load <Sound>("EffectBip").CreateInstance(Audio.AudioEngine.DefaultListener);
            music.IsLooping  = true;
            effect.IsLooping = true;
            music.Play();
            effect.Play();
        }
Пример #17
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            music = Content.Load<Sound>("MusicFishLampMp3").CreateInstance(Audio.AudioEngine.DefaultListener);
            effect = Content.Load<Sound>("EffectBip").CreateInstance(Audio.AudioEngine.DefaultListener);
            music.IsLooped = true;
            effect.IsLooped = true;
            music.Play();
            effect.Play();
        }
Пример #18
0
        /// <summary>
        /// Fill slot with an item to complete the task.
        /// </summary>
        /// <param name="item"></param>
        public void Fill(Item item)
        {
            VerifyConsistency();
            if (item != ItemType)
            {
                throw new InvalidOperationException();
            }

            taskComponent.Completed = true;
            (Entity.Get <SpriteComponent>().SpriteProvider as SpriteFromSheet).CurrentFrame = ItemType == Item.CutPipe ? 28 : 27;
            slotSound?.Play();
        }
Пример #19
0
 void TryMakeActive()
 {
     if (Instance == null)
     {
         Instance = manager.GetInstance(Sound, Entry.Attenuation, -1, 1, Position);
         if (Instance != null)
         {
             Instance.SetPitch(Pitch);
             Instance.Play(true);
         }
     }
 }
Пример #20
0
        public override void Update()
        {
            base.Update();

            if (IsActive() && !hit)
            {
                base.Update();

                if (!Main.instance.gameOver)
                {
                    if (type == UFOType.Large)
                    {
                        if (largeUFOSoundInstance.PlayState != PlayState.Playing)
                        {
                            largeUFOSoundInstance.Play();
                        }
                    }
                    else
                    {
                        if (smallUFOSoundInstance.PlayState != PlayState.Playing)
                        {
                            smallUFOSoundInstance.Play();
                        }
                    }
                }

                CheckForCollusion();

                if (position.X > edge.X || position.X < -edge.X)
                {
                    Disable();
                }

                CheckForEdge();
                vectorTimer.Tick();
                fireTimer.Tick();

                if (vectorTimer.TotalTime.Seconds > vectorAmount)
                {
                    vectorTimer.Reset();
                    ChangeVector();
                }

                if (fireTimer.TotalTime.Seconds > fireAmount)
                {
                    fireTimer.Reset();
                    Fire();
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Plays this instance.
        /// </summary>
        public override void Play()
        {
            if (sound == null)
            {
                return;
            }

            if (soundInstance == null)
            {
                soundInstance = sound.CreateInstance();
            }

            soundInstance.Play();
        }
Пример #22
0
        public override void Update()
        {
            if (MuzzleFlash != null)
            {
                if (IsShooting && cooldownRemaining <= 0f)
                {
                    MuzzleFlash.ParticleSystem.Play();
                }
                else
                {
                    MuzzleFlash.ParticleSystem.StopEmitters();
                }
            }

            if (bulletsRemaining <= 0)
            {
                bulletsRemaining  = MagazineCapacity;
                cooldownRemaining = ReloadCooldown;

                // Stop shoot sound effect
                gunSfxInstance?.Stop();
                // TODO Play reload sound effect
                return;
            }

            var dt = (float)Game.UpdateTime.Elapsed.TotalSeconds;

            if (cooldownRemaining > 0)
            {
                cooldownRemaining -= dt;
            }

            if (!IsShooting || cooldownRemaining > 0f)
            {
                // Stop shoot sound effect
                gunSfxInstance?.Stop();
                return; // Won't or can't shoot
            }

            bulletsRemaining--;
            ShootBullets(BulletPrefab, 2f, Entity.Transform.WorldMatrix);

            // Play shoot sound effect
            if (gunSfxInstance?.PlayState == SoundPlayState.Stopped)
            {
                gunSfxInstance?.Play();
            }

            // Do stuff every new frame
        }
Пример #23
0
        public override async Task Execute()
        {
            musicInstance = BackgroundMusic.CreateInstance();

            // Wait till the music is done loading
            await musicInstance.ReadyToPlay();

            while (Game.IsRunning)
            {
                // Play or pause
                DebugText.Print($"Space to play/pause. Currently: {musicInstance.PlayState}", new Int2(800, 40));
                if (Input.IsKeyPressed(Keys.Space))
                {
                    if (musicInstance.PlayState == PlayState.Playing)
                    {
                        musicInstance.Pause();
                    }
                    else
                    {
                        musicInstance.Play();
                    }
                }

                // Volume
                DebugText.Print($"Up/Down to change volume: {musicInstance.Volume:0.0}", new Int2(800, 60));
                if (Input.IsKeyPressed(Keys.Up))
                {
                    musicInstance.Volume = Math.Clamp(musicInstance.Volume + 0.1f, 0, 2);
                }
                if (Input.IsKeyPressed(Keys.Down))
                {
                    musicInstance.Volume = Math.Clamp(musicInstance.Volume - 0.1f, 0, 2);
                }

                // Panning
                DebugText.Print($"Left/Right to change panning: {musicInstance.Pan:0.0}", new Int2(800, 80));
                if (Input.IsKeyPressed(Keys.Left))
                {
                    musicInstance.Pan = Math.Clamp(musicInstance.Pan - 0.1f, -1, 1);
                }
                if (Input.IsKeyPressed(Keys.Right))
                {
                    musicInstance.Pan = Math.Clamp(musicInstance.Pan + 0.1f, -1, 1);
                }

                // Wait for next frame
                await Script.NextFrame();
            }
        }
Пример #24
0
        public override void Start()
        {
            currentHitpoints        = MaximumHitpoints;
            invulnerabilityCooldown = 1;

            jumpSfxInstance = JumpSound?.CreateInstance();
            jumpSfxInstance?.Stop();
            spawnSfxInstance = SpawnSound?.CreateInstance();
            if (spawnSfxInstance != null)
            {
                // boost sfx volme
                spawnSfxInstance.Volume = 10;
                spawnSfxInstance.Play();
            }
        }
Пример #25
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            foreach (var pointerEvent in Input.PointerEvents)
            {
                if (pointerEvent.EventType == PointerEventType.Released)
                {
                    music.Stop();
                    music.Play();
                    //effect.Stop();
                    //effect.Play();
                }
            }
        }
Пример #26
0
        public override async Task Execute()
        {
            music = SoundMusic.CreateInstance();

            if (!IsLiveReloading)
            {
                // start ambient music
                music.IsLooping = true;
                music.Play();
            }

            while (Game.IsRunning)
            {
                // wait for next frame
                await Script.NextFrame();
            }
        }
Пример #27
0
        public void Respawn(Vector3 respawnPosition)
        {
            Entity.Transform.Position = respawnPosition;
            Entity.Transform.UpdateLocalMatrix();
            Entity.Transform.UpdateWorldMatrix();

            Entity.Get <CharacterComponent>().Enabled = true;
            Entity.Get <RigidbodyComponent>().Enabled = true;
            Entity.Get <CharacterComponent>().Teleport(respawnPosition);
            Entity.Get <CharacterComponent>().UpdatePhysicsTransformation();
            this.SpawnInstance(RespawnEffect, null, 3f, Entity.Transform.WorldMatrix);

            isAlive = true;
            invulnerabilityCooldown = 1;
            currentHitpoints        = MaximumHitpoints;
            spawnSfxInstance?.Play();
        }
Пример #28
0
        public override async Task Execute()
        {
            music  = SoundMusic.CreateInstance();
            effect = SoundEffect.CreateInstance();

            if (!IsLiveReloading)
            {
                // start ambient music
                music.IsLooped = true;
                music.Play();

                fontColor         = Color.Transparent;
                originalPositionX = RightWave.Transform.Position.X;
            }

            while (Game.IsRunning)
            {
                if (Input.PointerEvents.Any(item => item.State == PointerState.Down)) // New click
                {
                    // reset wave position
                    LeftWave.Transform.Position.X  = -originalPositionX;
                    RightWave.Transform.Position.X = originalPositionX;

                    // reset transparency
                    fontColor = Color.White;

                    // play the sound effect on each touch on the screen
                    effect.Stop();
                    effect.Play();
                }
                else
                {
                    // moving wave position
                    LeftWave.Transform.Position.X  -= 0.025f;
                    RightWave.Transform.Position.X += 0.025f;

                    // changing font transparency
                    fontColor = 0.93f * fontColor;
                    LeftWave.Get <SpriteComponent>().Color  = fontColor;
                    RightWave.Get <SpriteComponent>().Color = fontColor;
                }

                // wait for next frame
                await Script.NextFrame();
            }
        }
Пример #29
0
        public override void Update()
        {
            // Play a sound
            DebugText.Print($"U to play the Ukelele once", new Int2(200, 580));
            if (Input.IsKeyPressed(Keys.U))
            {
                ukuleleInstance.Stop();
                ukuleleInstance.Play();
            }

            // Press right mouse button for gun fire sound
            DebugText.Print($"Press right mouse button fire gun", new Int2(200, 640));
            if (Input.IsMouseButtonPressed(MouseButton.Right))
            {
                gunSoundEmitter.Play();
            }
        }
Пример #30
0
 void TryMakeActive()
 {
     if (PlayOnce && Played)
     {
         return;
     }
     if (Instance == null)
     {
         Instance = manager.GetInstance(Sound, Entry.Attenuation, -1, 1, Position);
         if (Instance != null)
         {
             Instance.SetPitch(Pitch);
             Instance.Play(!PlayOnce);
             Played = true;
         }
     }
 }
Пример #31
0
        void Explode()
        {
            m_ExplodeSoundInstance.Stop();
            m_ExplodeSoundInstance.Play();
            b_Exploding = true;

            foreach (Line line in m_Explosion)
            {
                Vector3 linePos = m_Position;
                linePos.X += (float)m_Random.NextDouble() * 2 - 1;
                linePos.Y += (float)m_Random.NextDouble() * 2 - 1;
                float timer    = (float)m_Random.NextDouble() * 3 + 0.1f;
                float speed    = (float)m_Random.NextDouble() * 4 + 1;
                float rotspeed = (float)m_Random.NextDouble() * 2 + 0.25f;

                line.Spawn(linePos, RandomRadian(), timer, speed, rotspeed);
            }
        }
Пример #32
0
        public SoundInstance PlayCentralSound(string url, float pitch = 1f, float volume = 1f, float pan = 0f, bool looped = false)
        {
            SoundInstance s = getFreeInstance(url, false);

            if (s != null)
            {
                s.Pitch     = pitch < 0f ? RandomPitch() : pitch;
                s.Volume    = volume * MasterVolume;
                s.IsLooping = looped;
                s.Pan       = pan;
                if (s.IsSpatialized)
                {
                    s.Apply3D(AudioEngine.DefaultListener.Position);
                }
                s.Play();
            }
            return(s);
        }