public void TurnOn() { if (!timed) { if (!Switch.Activated) { touchSfx.Play("event:/game/general/touchswitch_any", null, 0f); if (Switch.Activate()) { SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot"); base.Add(new SoundSource("event:/game/general/touchswitch_last_cutoff")); } } } else { if (!TimedSwitch.Activated) { touchSfx.Play("event:/game/general/touchswitch_any", null, 0f); if (TimedSwitch.Activate()) { SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot"); base.Add(new SoundSource("event:/game/general/touchswitch_last_cutoff")); } } } }
public void TurnOn() { if (!Activated) { doEffect(() => touchSfx.Play(hitSound)); Activated = true; // animation doEffect(() => { wiggler.Start(); for (int i = 0; i < 32; i++) { float num = Calc.Random.NextFloat((float)Math.PI * 2f); level.Particles.Emit(TouchSwitch.P_FireWhite, Position + Calc.AngleToVector(num, 6f), num); } }); icon.Rate = 4f; HandleCollectedFlagTouchSwitch(flag, inverted, persistent, level, id, allTouchSwitchesInRoom, allMovingFlagTouchSwitchesInRoom, () => doEffect(() => { SoundEmitter.Play(completeSoundFromScene); Add(new SoundSource(completeSoundFromSwitch)); })); } }
static private async Task LoadAssetAsync(string filePath, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string assetPath = Path.GetFileNameWithoutExtension(filePath); // Get uncached asset to determine content type IAsset <object> uncachedAsset = _rawContentLibrary.GetAsset <object>(assetPath); object content = await uncachedAsset.GetContentAsync(cancellationToken); await uncachedAsset.ReleaseAsync(); switch (content) { case Texture2D _: _spriteLoader.AssetPath = assetPath; break; case SoundEffect _: const string key = nameof(key); _soundLoader.Remove(key); _soundLoader.Add(key, assetPath); await _soundLoader.LoadContent(_game.Engine.ContentLibrary); _soundEmitter.Play(key); break; case Song _: _songPlayer.AssetPath = assetPath; break; } }
private void turnOn() { if (!activated) { touchSfx.Play("event:/game/general/touchswitch_any"); activated = true; // animation wiggler.Start(); for (int i = 0; i < 32; i++) { float num = Calc.Random.NextFloat((float)Math.PI * 2f); level.Particles.Emit(TouchSwitch.P_FireWhite, Position + Calc.AngleToVector(num, 6f), num); } icon.Rate = 4f; if (persistent) { // this switch is persistent. save its activation in the session. level.Session.SetFlag(flag + "_switch" + id, true); } if ((SpringCollab2020MapDataProcessor.FlagTouchSwitches.Count <= level.Session.Area.ID || SpringCollab2020MapDataProcessor.FlagTouchSwitches[level.Session.Area.ID][(int)level.Session.Area.Mode][flag] .All(touchSwitchID => touchSwitchID.Level == level.Session.Level || level.Session.GetFlag(flag + "_switch" + touchSwitchID.ID))) && allTouchSwitchesInRoom.All(touchSwitch => touchSwitch.activated)) { // all switches in the room are enabled, and all session flags for switches outside the room are enabled. // so, the group is complete. foreach (FlagTouchSwitch touchSwitch in allTouchSwitchesInRoom) { touchSwitch.finish(); } SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot"); Add(new SoundSource("event:/game/general/touchswitch_last_cutoff")); // trigger associated switch gate(s). foreach (FlagSwitchGate switchGate in Scene.Tracker.GetEntities <FlagSwitchGate>().OfType <FlagSwitchGate>()) { if (switchGate.Flag == flag) { switchGate.Trigger(); } } // if all the switches are persistent, the flag it's setting is persistent. if (allTouchSwitchesInRoom.All(touchSwitch => touchSwitch.persistent)) { level.Session.SetFlag(flag, true); } } } }
private IEnumerator TurnOnSequence(CompanionSphere.Companion companion) { turnOnSequenceActive = true; companion.RunUseCoroutine(Center); while (!companion.Activated && companion.Activating) { yield return(null); } if (!switchComponent.Activated && companion.Activated) { companion.Slot = this; slottedCompanion = companion; Add(new SoundSource("event:/game/general/touchswitch_any")); if (Activate()) { SoundEmitter.Play("event:/game/general/touchswitch_last_oneshot"); Add(new SoundSource("event:/game/general/touchswitch_last_cutoff")); } } turnOnSequenceActive = false; }
private IEnumerator SmashRoutine(Player player, Level level) { Visible = false; Collidable = false; player.Stamina = 110f; SoundEmitter.Play(SFX.game_07_gem_get, this, null); Session session = (Scene as Level).Session; session.DoNotLoad.Add(GID); CommunalHelperModule.Session.SummitGems.Add(CustomGemSID); CommunalHelperModule.SaveData.RegisterSummitGem(CustomGemSID); level.Shake(0.3f); Celeste.Freeze(0.1f); P_Shatter.Color = particleColor ?? GemColors[Calc.Clamp(GemID, 0, 7)]; float angle = player.Speed.Angle(); level.ParticlesFG.Emit(P_Shatter, 5, Position, Vector2.One * 4f, angle - Calc.QuarterCircle); level.ParticlesFG.Emit(P_Shatter, 5, Position, Vector2.One * 4f, angle + Calc.QuarterCircle); SlashFx.Burst(Position, angle); for (int i = 0; i < 10; i++) { Scene.Add(new AbsorbOrb(Position, player, null)); } level.Flash(Color.White, true); Scene.Add((Entity)Activator.CreateInstance(t_BgFlash)); Engine.TimeRate = 0.5f; while (Engine.TimeRate < 1f) { Engine.TimeRate += Engine.RawDeltaTime * 0.5f; yield return(null); } RemoveSelf(); yield break; }
private IEnumerator UnlockRoutine(Follower fol) { SoundEmitter emitter = SoundEmitter.Play(unlockSfxName, this, null); emitter.Source.DisposeOnTransition = true; Level level = SceneAs <Level>(); Key key = fol.Entity as Key; Add(new Coroutine(key.UseRoutine(Center + new Vector2(0f, 2f)), true)); yield return(1.2f); UnlockingRegistered = true; bool flag = stepMusicProgress; if (flag) { AudioTrackState music = level.Session.Audio.Music; int progress = music.Progress; music.Progress = progress + 1; level.Session.Audio.Apply(false); } //level.Session.DoNotLoad.Add(this.ID); key.RegisterUsed(); while (key.Turning) { yield return(null); } Tag |= Tags.TransitionUpdate; Collidable = false; emitter.Source.DisposeOnTransition = false; yield return(sprite.PlayRoutine("open", false)); level.Shake(0.3f); Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium); yield return(sprite.PlayRoutine("burst", false)); RemoveSelf(); yield break; }
public void Update() { InteractWith(); soundEmitter.SetPosition(Entity.Position, Entity.Scene.Entities.FindEntity("hero").Position); soundEmitter.Play(); }
private IEnumerator CollectRoutine(Player player) { Level level = Scene as Level; AreaKey area = level.Session.Area; string poemID = AreaData.Get(level).Mode[(int)area.Mode].PoemID; bool completeArea = IsCompleteArea(false); level.CanRetry = false; if (completeArea) { Audio.SetMusic(null); Audio.SetAmbience(null); } if (completeArea) { List <Strawberry> strawbs = new List <Strawberry>(); foreach (Follower follower in player.Leader.Followers) { if (follower.Entity is Strawberry) { strawbs.Add(follower.Entity as Strawberry); } } foreach (Strawberry strawb in strawbs) { strawb.OnCollect(); } } string sfxEvent = "event:/game/general/crystalheart_blue_get"; if (area.Mode == AreaMode.BSide) { sfxEvent = "event:/game/general/crystalheart_red_get"; } else if (area.Mode == AreaMode.CSide) { sfxEvent = "event:/game/general/crystalheart_gold_get"; } sfx = SoundEmitter.Play(sfxEvent, this); Add(new LevelEndingHook(delegate { sfx.Source.Stop(); })); walls.Add(new InvisibleBarrier(new Vector2(level.Bounds.Right, level.Bounds.Top), 8f, level.Bounds.Height)); walls.Add(new InvisibleBarrier(new Vector2(level.Bounds.Left - 8, level.Bounds.Top), 8f, level.Bounds.Height)); walls.Add(new InvisibleBarrier(new Vector2(level.Bounds.Left, level.Bounds.Top - 8), level.Bounds.Width, 8f)); foreach (InvisibleBarrier wall in walls) { Scene.Add(wall); } Add(white = GFX.SpriteBank.Create("heartGemWhite")); Depth = -2000000; yield return(null); Celeste.Freeze(0.2f); yield return(null); Engine.TimeRate = 0.5f; player.Depth = -2000000; for (int i = 0; i < 10; i++) { Scene.Add(new AbsorbOrb(Position)); } level.Shake(); Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium); level.Flash(Color.White); level.FormationBackdrop.Display = true; level.FormationBackdrop.Alpha = 1f; light.Alpha = (bloom.Alpha = 0f); Visible = false; for (float t3 = 0f; t3 < 2f; t3 += Engine.RawDeltaTime) { Engine.TimeRate = Calc.Approach(Engine.TimeRate, 0f, Engine.RawDeltaTime * 0.25f); yield return(null); } yield return(null); if (player.Dead) { yield return(100f); } Engine.TimeRate = 1f; Tag = Tags.FrozenUpdate; level.Frozen = true; RegisterAsCollected(level, poemID); if (completeArea) { level.TimerStopped = true; level.RegisterAreaComplete(); } string poemText = null; if (!string.IsNullOrEmpty(poemID)) { poemText = Dialog.Clean("poem_" + poemID); } poem = new Poem(poemText, (int)area.Mode, (area.Mode == AreaMode.CSide) ? 1f : 0.6f); poem.Alpha = 0f; Scene.Add(poem); for (float t2 = 0f; t2 < 1f; t2 += Engine.RawDeltaTime) { poem.Alpha = Ease.CubeOut(t2); yield return(null); } while (!Input.MenuConfirm.Pressed && !Input.MenuCancel.Pressed) { yield return(null); } sfx.Source.Param("end", 1f); if (!completeArea) { level.FormationBackdrop.Display = false; for (float t = 0f; t < 1f; t += Engine.RawDeltaTime * 2f) { poem.Alpha = Ease.CubeIn(1f - t); yield return(null); } player.Depth = 0; EndCutscene(); } else { yield return(new FadeWipe(level, wipeIn: false) { Duration = 3.25f }.Duration); level.CompleteArea(spotlightWipe: false, skipScreenWipe: true, skipCompleteScreen: false); } }
private IEnumerator SmashRoutine(Player player, Level level) { level.CanRetry = false; inCollectAnimation = true; Collidable = false; // mute sound Audio.SetMusic(null); Audio.SetAmbience(null); // collect all berries List <IStrawberry> list = new List <IStrawberry>(); ReadOnlyCollection <Type> berryTypes = StrawberryRegistry.GetBerryTypes(); foreach (Follower follower in player.Leader.Followers) { if (berryTypes.Contains(follower.Entity.GetType()) && follower.Entity is IStrawberry) { list.Add(follower.Entity as IStrawberry); } } foreach (IStrawberry item in list) { item.OnCollect(); } // play the collect jingle SoundEmitter.Play("event:/SC2020_heartShard_get", this); // overlap a white sprite Add(white = new Sprite(GFX.Game, "CollabUtils2/miniheart/white/white")); white.AddLoop("idle", "", 0.1f, animationFrames); white.Play("idle"); white.CenterOrigin(); // slow down time, visual effects Depth = -2000000; yield return(null); Celeste.Freeze(0.2f); yield return(null); Engine.TimeRate = 0.5f; player.Depth = -2000000; for (int i = 0; i < 10; i++) { Scene.Add(new AbsorbOrb(Position)); } level.Shake(); Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium); level.Flash(Color.White); light.Alpha = (bloom.Alpha = 0f); level.FormationBackdrop.Display = true; level.FormationBackdrop.Alpha = 1f; // slow down time further, to a freeze Visible = false; for (float time = 0f; time < 2f; time += Engine.RawDeltaTime) { Engine.TimeRate = Calc.Approach(Engine.TimeRate, 0f, Engine.RawDeltaTime * 0.25f); yield return(null); } yield return(null); if (player.Dead) { yield return(100f); } Engine.TimeRate = 1f; Tag = Tags.FrozenUpdate; level.Frozen = true; // level is done! stop timer, save completion SaveData.Instance.RegisterHeartGem(level.Session.Area); level.TimerStopped = true; level.PauseLock = true; level.RegisterAreaComplete(); // display an endscreen if enabled in mod options AND speedrun timer is enabled (or else the endscreen won't show anything anyway). if (CollabModule.Instance.Settings.DisplayEndScreenForAllMaps && Settings.Instance.SpeedrunClock != SpeedrunType.Off) { Scene.Add(new AreaCompleteInfoInLevel()); // force the player to wait a bit, so that the info shows up yield return(0.5f); // wait for an input while (!Input.MenuConfirm.Pressed && !Input.MenuCancel.Pressed) { yield return(null); } } else { // wait 1 second max float timer = 0f; while (!Input.MenuConfirm.Pressed && !Input.MenuCancel.Pressed && timer <= 1f) { yield return(null); timer += Engine.DeltaTime; } } // get out of here, back to the lobby level.DoScreenWipe(false, () => Engine.Scene = new LevelExitToLobby(LevelExit.Mode.Completed, level.Session)); }
public static Entity CreateEntityCopy(Entity savedEntity, string tag = "EntitiesSavedButNotLoaded") { Entity loadedEntity = null; Type savedType = savedEntity.GetType(); if (savedEntity.GetEntityData() != null) { // 一般 Entity 都是 EntityData + Vector2 loadedEntity = (savedType.GetConstructor(new[] { typeof(EntityData), typeof(Vector2) }) ?.Invoke(new object[] { savedEntity.GetEntityData(), Vector2.Zero })) as Entity; if (loadedEntity == null) { // 部分例如草莓则是 EntityData + Vector2 + EntityID loadedEntity = savedType .GetConstructor(new[] { typeof(EntityData), typeof(Vector2), typeof(EntityID) }) ?.Invoke(new object[] { savedEntity.GetEntityData(), Vector2.Zero, savedEntity.GetEntityId2().EntityId }) as Entity; } if (loadedEntity == null && savedType.IsType <CrystalStaticSpinner>()) { loadedEntity = new CrystalStaticSpinner(savedEntity.GetEntityData(), Vector2.Zero, (CrystalColor)savedEntity.GetField(typeof(CrystalStaticSpinner), "color")); } if (loadedEntity == null && savedType.IsType <TriggerSpikes>()) { loadedEntity = new TriggerSpikes(savedEntity.GetEntityData(), Vector2.Zero, (TriggerSpikes.Directions)savedEntity.GetField(typeof(TriggerSpikes), "direction")); } if (loadedEntity == null && savedType.IsType <Spikes>()) { loadedEntity = new Spikes(savedEntity.GetEntityData(), Vector2.Zero, ((Spikes)savedEntity).Direction); } if (loadedEntity == null && savedType.IsType <TriggerSpikes>()) { loadedEntity = new Spring(savedEntity.GetEntityData(), Vector2.Zero, ((Spring)savedEntity).Orientation); } if (loadedEntity != null) { loadedEntity.Position = savedEntity.Position; loadedEntity.CopyEntityData(savedEntity); loadedEntity.CopyEntityId2(savedEntity); return(loadedEntity); } } // TODO 如果是他们的子类该怎么办…… if (savedType.IsType <BadelineDummy>()) { loadedEntity = new BadelineDummy(savedEntity.GetStartPosition()); } else if (savedType.IsType <AngryOshiro>()) { loadedEntity = new AngryOshiro(savedEntity.GetStartPosition(), (bool)savedEntity.GetField("fromCutscene")); } else if (savedType.IsType <Snowball>()) { loadedEntity = new Snowball(); } else if (savedType.IsType <SlashFx>() && savedEntity is SlashFx slashFx) { loadedEntity = slashFx.Clone(); } else if (savedType.IsType <SpeedRing>() && savedEntity is SpeedRing speedRing) { loadedEntity = speedRing.Clone(); } else if (savedType.IsType <FinalBossShot>() && savedEntity is FinalBossShot finalBossShot) { loadedEntity = finalBossShot.Clone(); } else if (savedType.IsType <FinalBossBeam>() && savedEntity is FinalBossBeam finalBossBeam) { loadedEntity = finalBossBeam.Clone(); } else if (savedType.IsType <BirdTutorialGui>() && savedEntity is BirdTutorialGui birdTutorialGui) { loadedEntity = birdTutorialGui.Clone(); } else if (savedType.IsType <SoundEmitter>() && savedEntity is SoundEmitter soundEmitter) { loadedEntity = SoundEmitter.Play(soundEmitter.Source.EventName, new Entity(soundEmitter.Position)); if (SoundSourceAction.PlayingSoundSources.FirstOrDefault(source => source.EventName == soundEmitter.Source.EventName) == null) { (loadedEntity as SoundEmitter)?.Source.TryCopyObject(soundEmitter.Source); } else { (loadedEntity as SoundEmitter)?.Source.Stop(); } } else if (savedType.IsType <Debris>() && savedEntity is Debris debris) { loadedEntity = Engine.Pooler.Create <Debris>() .Init(debris.GetStartPosition(), (char)debris.GetField("tileset"), (bool)debris.GetField("playSound")); } else if (savedType == typeof(TalkComponent.TalkComponentUI)) { // ignore } else if (savedType.IsType <Entity>()) { loadedEntity = new Entity(savedEntity.GetStartPosition()); } else { if (savedEntity.GetType().FullName == "Celeste.MoveBlock+Debris") { loadedEntity = (savedEntity as Actor).CloneMoveBlockDebris(); } else if (savedEntity.ForceCreateInstance(tag) is Entity newEntity) { loadedEntity = newEntity; } } if (loadedEntity == null) { return(null); } loadedEntity.Position = savedEntity.Position; loadedEntity.CopyEntityId2(savedEntity); loadedEntity.CopyStartPosition(savedEntity); return(loadedEntity); }