protected override async Task <bool> PrepareContent() { loaded = false; startTime = TimeSpan.Zero; if (sound != null) { instance.Stop(); instance.Dispose(); UnloadAsset(sound); } await base.PrepareContent(); sound = LoadAsset <Sound>(AssetItem.Location); if (sound == null) { return(false); } instance = sound.CreateInstance(null, true); instance.SetRange(new PlayRange(TimeSpan.Zero, TimeSpan.Zero)); loaded = true; return(true); }
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 }
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(); } }
/// <summary> /// Called when the script is first initialized /// </summary> public override void Start() { base.Start(); navigation = Entity.Get <NavigationComponent>(); character = Entity.Get <CharacterComponent>(); if (character == null) { throw new ArgumentException("Please add a CharacterComponent to the entity containing PlayerController!"); } if (PunchCollision == null) { throw new ArgumentException("Please add a RigidbodyComponent as a PunchCollision to the entity containing PlayerController!"); } modelChildEntity = Entity.GetChild(0); moveDestination = Entity.Transform.WorldMatrix.TranslationVector; PunchCollision.Enabled = false; beepSoundInstance = BeepEffect?.CreateInstance(); beepSoundInstance.Stop(); commandInterpreter.moveHandler = RemoteMove; commandInterpreter.moveCurrentHandler = RemoteMoveCurrentDirection; commandInterpreter.canMoveHandler = RemoteCanMove; commandInterpreter.turnHandler = RemoteTurn; commandInterpreter.haltHandler = HaltMovement; commandInterpreter.beepHandler = PlayBeep; commandInterpreter.signalHandler = Signal; commandInterpreter.markerHandler = MarkerUpDown; }
public override void OnDestroyed() { if (sound != null) { sound.Stop(); sound = null; } }
protected override void OnDeactivated(ShutdownContext context) { if (sound != null) { sound.Stop(); sound = null; } }
void EnsureStopped() { if (Instance != null) { Instance.Stop(); Instance = null; } }
/** * <summary> * Stops the current sound if any * </summary> */ private void StopSound() { if (si != null) { si.Stop(); si = null; lastActionSound = wo.GetAction(); } }
public override void Start() { base.Start(); triggeredEvent = (Trigger != null) ? new EventReceiver <bool>(Trigger.TriggerEvent) : null; sfxInstance = SoundEffect?.CreateInstance(); sfxInstance?.Stop(); }
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(); } }
public override void Start() { bulletsRemaining = MagazineCapacity; gunSfxInstance = GunSound?.CreateInstance(); if (gunSfxInstance != null) { // boost sfx volume gunSfxInstance.Volume = 10; gunSfxInstance.Stop(); } }
public void Explode() { m_ExplodeSoundInstance.Stop(); if (!m_GameOver) { m_ExplodeSoundInstance.Play(); } SpawnExplosion(); }
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(); } }
/// <summary> /// Stops this instance. /// </summary> public override void Stop() { if (sound == null) { return; } if (soundInstance == null) { soundInstance = sound.CreateInstance(); } soundInstance.Stop(); }
protected override bool OnPerish(ActorBase collider) { if (noise != null) { noise.Stop(); noise = null; } CreateDeathDebris(collider); api.PlayCommonSound(this, "Splat"); TryGenerateRandomDrop(); return(base.OnPerish(collider)); }
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(); } }
protected override bool OnPerish(ActorBase collider) { if (noise != null) { noise.Stop(); noise = null; } CreateDeathDebris(collider); levelHandler.PlayCommonSound("Splat", Transform.Pos); TryGenerateRandomDrop(); return(base.OnPerish(collider)); }
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(); } } }
public override void Start() { animPos[0] = new Vector3(-0.585f, 0f, 0f); animPos[1] = new Vector3(0f, 0f, -0.75f); animPos[2] = new Vector3(0.5f, 0f, -0.5f); animPos[3] = new Vector3(0.8f, 0f, -0.325f); animRot[0] = new Vector3(2.0944f, 0f, 0f); animRot[1] = new Vector3(0f, 0f, 1.5708f); animRot[2] = new Vector3(0f, -0.523599f, 1.5708f); animRot[3] = new Vector3(0f, -1.3962634f, 1.5708f); // Initialization of the script. swordSfxInstance = SwordSound?.CreateInstance(); swordSfxInstance?.Stop(); }
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(); } }
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(); } }
public void Destroy() { m_UFOMesh.Enabled = false; m_UFOTIMesh.Enabled = false; m_UFOBIMesh.Enabled = false; b_Done = false; m_Hit = false; if (m_LargeUFOSoundInstance != null) { m_LargeUFOSoundInstance.Stop(); } if (m_SmallUFOSoundInstance != null) { m_SmallUFOSoundInstance.Stop(); } }
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); } }
void FireShot() { if (Input.IsKeyPressed(Keys.LeftCtrl) || Input.IsKeyPressed(Keys.Space)) { for (int shot = 0; shot < 4; shot++) { if (!m_Shots[shot].Active()) { m_FireSoundInstance.Stop(); m_FireSoundInstance.Play(); float speed = 35; Vector3 dir = new Vector3((float)Math.Cos(m_Rotation) * speed, (float)Math.Sin(m_Rotation) * speed, 0); Vector3 offset = new Vector3((float)Math.Cos(m_Rotation) * m_Radius, (float)Math.Sin(m_Rotation) * m_Radius, 0); m_Shots[shot].Spawn(m_Position + offset, dir + m_Velocity * 0.75f, 1.55f); break; } } } }
protected override bool OnPerish(ActorBase collider) { if (soundThrow != null) { soundThrow.Stop(); soundThrow = null; } speedX = speedY = 0f; collisionFlags = CollisionFlags.None; SetTransition((AnimState)1073741829, false, delegate { base.OnPerish(collider); }); PlaySound("BananaSplat", 0.6f); return(false); }
public override void Update() { if (m_RockMesh.Enabled && !m_Hit && !m_Pause) { base.Update(); CheckForEdge(); if (m_Hit = CheckCollisions()) { m_SoundInstance.Stop(); if (!m_GameOver) { m_SoundInstance.Play(); } SpawnExplosion(); } } }
public void Fire(Vector3 position, float rotation) { FireSI.Stop(); FireSI.Play(); IsActive = true; Position = position; Position.Z = 0; Rotation.Z = rotation; Velocity = Vector3.Zero; Acceleration = Vector3.Zero; if (LifeTimer == null) { Entity lifeTimerE = new Entity { new Timer() }; SceneSystem.SceneInstance.RootScene.Entities.Add(lifeTimerE); LifeTimer = lifeTimerE.Get <Timer>(); } LifeTimer.Reset(6); }
public override void Cancel() { music?.Stop(); }
public override void Update() { if (Character == null) { return; } if (!isAlive) { WaitingToRespawn(); return; } var dt = (float)Game.UpdateTime.Elapsed.TotalSeconds; if (invulnerabilityCooldown > 0) { invulnerabilityCooldown -= dt; if (invulnerabilityCooldown <= 0) { ModelChildEntity.Get <ModelComponent>().Enabled = true; } else { ModelChildEntity.Get <ModelComponent>().Enabled = !ModelChildEntity.Get <ModelComponent>().Enabled; } } // Jump if (ControlInput.Jump) { if (Character.IsGrounded) { jumpSfxInstance?.Stop(); Character.Jump(); jumpSfxInstance?.Play(); } } // Left stick: movement var moveDirection = ControlInput.WalkDirection; // Broadcast the movement vector as a world-space Vector3 to allow characters to be controlled var worldSpeed = (Camera != null) ? Utils.LogicDirectionToWorldDirection(moveDirection, Camera, Vector3.UnitY) : new Vector3(moveDirection.X, 0, moveDirection.Y); Character.SetVelocity(worldSpeed * MaxRunSpeed); // Facing direction if (ModelChildEntity == null) { return; } // Character orientation if (moveDirection.Length() > 0.001) { yawOrientation = MathUtil.RadiansToDegrees((float)Math.Atan2(worldSpeed.Z, -worldSpeed.X) + MathUtil.PiOverTwo); } // Left stick: movement var faceDirection = ControlInput.FaceDirection; if (faceDirection.Length() > 0.001) { // Broadcast the movement vector as a world-space Vector3 to allow characters to be controlled var worldFacing = (Camera != null) ? Utils.LogicDirectionToWorldDirection(faceDirection, Camera, Vector3.UnitY) : new Vector3(faceDirection.X, 0, faceDirection.Y); if (faceDirection.Length() > 0.001) { yawOrientation = MathUtil.RadiansToDegrees((float)Math.Atan2(worldFacing.Z, -worldFacing.X) + MathUtil.PiOverTwo); } } if (MachineGun != null) { var canShoot = ControlInput.Shoot & !ControlInput.Attack; if (Sword != null) { canShoot &= Sword.SwingCooldown <= 0; } MachineGun.IsShooting = canShoot; } if (Sword != null && ControlInput.Attack) { Sword.Slash(); } ModelChildEntity.Transform.Rotation = Quaternion.RotationYawPitchRoll(MathUtil.DegreesToRadians(yawOrientation), 0, 0); }
public void Disable() { HitSI.Stop(); HitSI.Play(); IsActive = false; }