using UnityEngine; namespace Auralis { // A sheltered, persistent side loop: both the high crossing and the maintenance floor have real support. public sealed class BelfrySideGallery:MonoBehaviour { public static BelfrySideGallery I; public const string FeedKey="belfry-second-conduit",BellKey="belfry-second-bell",LiftKey="belfry-second-lift-upper"; public static bool Inside=>I&&GameSession.I&&GameSession.I.Player&&I.RoomBounds.Contains(GameSession.I.Player.transform.position); public Rect RoomBounds=>Rect.MinMaxRect(25.1f,79.75f,59,102.6f); public bool Fed=>GameSession.I.Save.Data.mechanisms.Contains(FeedKey); public bool Rung=>GameSession.I.Save.Data.mechanisms.Contains(BellKey); public bool Powered=>Rung&&releaseAge>=3; public Vector2 At(float x,float y)=>new Vector2(BelfrySpatialRoute.SideX+(x-768)*.022f,BelfrySpatialRoute.SideY+(800-y)*.022f); public Vector2 Entry=>At(217,800);public Vector2 FeedStand=>At(1130,390);public Vector2 BellStand=>At(447,390); public LevelDoor Entrance,ReturnDoor; public BelfrySpatialRoute SpatialRoute{get;private set;} public ClimbableLadder EntryLadder,Recovery; public BelfryLift Lift;public Rigidbody2D BellBody; public ResonanceTarget FeedTarget,BellTarget; public float BeatAge{get;private set;}public int Answers{get;private set;} public bool AnswerWindow=>Fed&&!Rung&&BeatAge>=1.5f&&BeatAge<=3.5f; public float WeightLift{get;private set;}public bool WeightWarning=>weightClock<2||weightClock>=9&&weightClock<11; float weightClock,releaseAge=10;int lastBeat=-1;bool answeredThisBeat; Transform weight,clapper;SpriteRenderer indicator,pulse;LineRenderer conduit;Sprite bellSprite,clapperSprite,weightSprite; BoxCollider2D weightCollider;Vector3 clapperRest;LineRenderer[] weightRopes;Sprite weightBeam,weightRail; public static BelfrySideGallery Create(Transform parent) {var o=new GameObject("Glockenumlauf II · Gegengewicht und antwortendes Licht");o.transform.SetParent(parent);I=o.AddComponent();I.Build();return I;} void Build() { var art=ArtLibrary.Sprite("Eigener oberer Schieferumlauf",ArtLibrary.Get("BelfrySideGallery"),Vector2.zero,3,transform); art.transform.localScale=Vector3.one*art.sprite.pixelsPerUnit*.022f;art.transform.position+=(Vector3)At(768,800)-ArtLibrary.TexturePoint(art,new Vector2(.5f,800f/1024)); Floor("Durchgehender getragener Wartungsboden",30,1500,800);Floor("Linke breite Glockenbank",121,752,390);Floor("Rechte breite Antwortbank",893,1415,390); Wall(43);Wall(1490); EntryLadder=Ladder("Gemalte feste linke Kupferleiter",377,800,390);Recovery=Ladder("Gemalte feste rechte Rückleiter",1333,800,390); PortalCurtain.InArch(art,180,273,798,672,622,1536,1024,7,transform,()=>true); var hall=BelfryLowerHall.I;var oldArt=hall.GetComponentInChildren(); // The upper doorway is part of the original hall, never a second overlaid arch. PortalCurtain.InArch(oldArt,1023,1137,264,170,131,1254,1254,7,hall.transform,()=>hall.Powered); // I→II is now the open exterior tower, in both directions. These // retained anchors give a local sign and never teleport Lio. Entrance=LevelDoor.Create(hall.At(1080,267),transform,"Äußerer Glockenstieg · rechts hinauf",()=>hall.Powered,()=>GameSession.I.Hud.Toast("Äußerer Glockenstieg",2)); ReturnDoor=LevelDoor.Create(Entry,transform,"Äußerer Glockenstieg · links hinunter",()=>Inside,()=>GameSession.I.Hud.Toast("Glocke I · links hinunter",2)); BuildMechanisms(); Lift=BelfryLift.Create(hall,transform,At(147,800),At(147,390),LiftKey,()=>Powered,1); FeedTarget=ResonanceTarget.Create(FeedStand+Vector2.up*1.25f,transform,()=>Inside&&!Fed,Feed);FeedTarget.Label="Leitung I in den Umlauf rufen"; var plate=ArtLibrary.Sprite("Kupferner Leitungsanschluss",ArtLibrary.Get("ThreadProps",0),FeedStand+Vector2.up*.85f,10,transform);ArtLibrary.Height(plate,.72f); BellTarget=ResonanceTarget.Create(BellStand+Vector2.up*1.25f,transform,()=>Inside&&Fed&&!Rung,Answer);BellTarget.Label="Beim hellen Glockenlicht antworten"; conduit=new GameObject("Kupferleitung II · sichtbarer wandernder Impuls").AddComponent();conduit.transform.SetParent(transform);conduit.sharedMaterial=ArtLibrary.Unlit;conduit.positionCount=4;conduit.SetPositions(new[]{(Vector3)(FeedStand+Vector2.up*1.25f),(Vector3)At(1120,325),(Vector3)At(447,325),(Vector3)(BellStand+Vector2.up*1.25f)});conduit.sortingOrder=6;conduit.startWidth=conduit.endWidth=.035f;conduit.startColor=conduit.endColor=new Color(.49f,.33f,.18f,.8f); pulse=ArtLibrary.Sprite("Licht erreicht die zweite Glocke",ArtLibrary.Soft,BellStand+Vector2.up*1.4f,12,transform,false);pulse.transform.localScale=Vector3.one*.6f; foreach(var p in new[]{new Vector2(214,281),new Vector2(333,653),new Vector2(698,652),new Vector2(950,652),new Vector2(1113,291)})RainFlow.Lamp("Warmes Öllicht im Seitenumlauf",At(p.x,p.y),3,new Color(1,.66f,.32f),.2f,transform); AmbientEmitter.Create("Staub in den geschützten Fensterstrahlen",transform,At(760,500),new Vector2(27,11),new Color(.91f,.85f,.72f,.22f),.8f,8,new Vector2(.012f,.025f),new Vector2(.035f,-.02f),7,12); releaseAge=Rung?10:0;BellBody.constraints=Rung?RigidbodyConstraints2D.None:RigidbodyConstraints2D.FreezeRotation; SpatialRoute=BelfrySpatialRoute.Create(hall,this,transform.parent); } void BuildMechanisms() { var t=Resources.Load("GameArt/BelfrySecondMechanisms"); bellSprite=Sprite.Create(t,new Rect(90,1024-706,660,706),new Vector2(.5f,1),100,0,SpriteMeshType.FullRect); clapperSprite=Sprite.Create(t,new Rect(356,1024-1010,128,304),new Vector2(.5f,1),100,0,SpriteMeshType.FullRect); weightSprite=Sprite.Create(t,new Rect(990,1024-880,470,765),new Vector2(.5f,0),100,0,SpriteMeshType.FullRect); var bell=new GameObject("Glocke II · gespaltene Kupferform");bell.transform.SetParent(transform);bell.transform.position=At(447,114);BellBody=bell.AddComponent();BellBody.mass=8;BellBody.gravityScale=1;BellBody.angularDamping=.4f;BellBody.centerOfMass=Vector2.down*2;BellBody.inertia=26;BellBody.interpolation=RigidbodyInterpolation2D.Interpolate; var hinge=bell.AddComponent();hinge.autoConfigureConnectedAnchor=false;hinge.connectedAnchor=bell.transform.position;hinge.useLimits=true;hinge.limits=new JointAngleLimits2D{min=-6,max=6}; var s=ArtLibrary.Sprite("Hauptglocke mit erhabener II",bellSprite,bell.transform.position,9,bell.transform);ArtLibrary.Width(s,4.4f); var c=ArtLibrary.Sprite("Eigener beweglicher Klöppel II",clapperSprite,bell.transform.position+Vector3.down*3.2f,8,bell.transform);ArtLibrary.Height(c,1.6f);clapper=c.transform;clapperRest=clapper.localPosition; weight=new GameObject("Langsames Gegengewicht in gemalten Kupferführungen").transform;weight.SetParent(transform);weight.gameObject.layer=6; var a=ArtLibrary.Sprite("Eigenes Eichen-Kupfer-Gegengewicht",weightSprite,Vector2.zero,10,weight);ArtLibrary.Width(a,2.1f); weightCollider=weight.gameObject.AddComponent();weightCollider.size=new Vector2(1.92f,3.1f);weightCollider.offset=Vector2.up*1.55f; var rb=weight.gameObject.AddComponent();rb.bodyType=RigidbodyType2D.Kinematic;rb.interpolation=RigidbodyInterpolation2D.Interpolate; indicator=ArtLibrary.Sprite("Warmlicht kündigt die Bewegung an",ArtLibrary.Soft,Vector2.zero,11,weight,false);indicator.transform.localPosition=Vector3.up*1.7f;indicator.transform.localScale=Vector3.one*1.25f; weight.position=At(823,390); // The moving mass remains mechanically suspended above the original short painted guide rails. var architecture=Resources.Load("GameArt/BelfrySideGallery");weightBeam=Sprite.Create(architecture,new Rect(319,1024-134,240,38),new Vector2(.5f,.5f),100,0,SpriteMeshType.FullRect); var beam=ArtLibrary.Sprite("Tragender Eichenquerbalken über den verlängerten Führungen",weightBeam,At(823,31),8,transform);ArtLibrary.Width(beam,3.5f); weightRail=Sprite.Create(architecture,new Rect(767,1024-365,18,140),new Vector2(.5f,.5f),100,0,SpriteMeshType.FullRect); foreach(float x in new[]{775f,870f}){var rail=ArtLibrary.Sprite("Massive gemalte Kupferführung bis zum Querbalken",weightRail,At(x,119),8,transform,false);ArtLibrary.Height(rail,178*.022f);} weightRopes=new LineRenderer[2];for(int i=0;i<2;i++){var rope=new GameObject("Tragendes Kupferseil des Gegengewichts "+i).AddComponent();rope.transform.SetParent(transform);rope.sharedMaterial=ArtLibrary.Unlit;rope.sortingOrder=9;rope.positionCount=2;rope.startWidth=rope.endWidth=.045f;rope.startColor=rope.endColor=new Color(.43f,.29f,.17f);weightRopes[i]=rope;FlexibleCord.Attach(rope);} } public void Enter(){GameSession.I.Player.Teleport(Entry+new Vector2(.9f,.05f));weightClock=0;GameSession.I.Camera.Snap();ScreenReveal.Begin();} void Save(string key){var g=GameSession.I;if(!g.Save.Data.mechanisms.Contains(key))g.Save.Data.mechanisms.Add(key);g.Save.Write();} void Feed(){Save(FeedKey);BeatAge=0;lastBeat=-1;GameSession.I.Hud.Toast("Das Licht wandert zur Glocke II. Antworte dort zweimal, wenn sie hell wird.",5);} void Answer() { BellTarget.Rearm();if(!AnswerWindow||answeredThisBeat){GameSession.I.Hud.Toast("Warte, bis das Licht die Glocke erreicht.",2);return;} answeredThisBeat=true;Answers++;WorldEffects.I.Burst(BellTarget.transform.position,ArtLibrary.Gold,12,1);AudioDirector.I.Play("chime2",BellTarget.transform.position,.5f); if(Answers<2)return;Save(BellKey);releaseAge=0;BellBody.constraints=RigidbodyConstraints2D.None;BellBody.angularVelocity=2; AudioDirector.I.Play("WayBellLastTone",BellStand,.55f);HapticsDirector.Impact(BellStand,.4f,.7f);GameSession.I.Hud.Toast("Glocke II antwortet. Der zweite Aufzug erwacht.",4); } void Update() { var g=GameSession.I;if(!g||!g.Playing)return;float dt=Time.deltaTime; if(Inside) { if(Rung)releaseAge+=dt; if(Fed&&!Rung){float previous=BeatAge;BeatAge=(BeatAge+dt)%4.5f;if(BeatAgeAt(823,390).y-1&&g.Player.transform.position.y=10.95f&&weightClock<11.05f&&under))weightClock=(weightClock+dt)%16; g.Hud.SetRoomProgress(!Fed?"GLOCKENUMLAUF II\nRechts die Kupferleitung mit RB / K rufen":!Rung?"DAS LICHT DER ZWEITEN GLOCKE\nLinks zweimal im hellen Licht antworten":"GLOCKE II KLINGT\nDer zweite Aufzug bleibt verfügbar"); } WeightLift=Powered?1:weightClock<2?0:weightClock<5?Mathf.SmoothStep(0,1,(weightClock-2)/3):weightClock<11?1:weightClock<14?1-Mathf.SmoothStep(0,1,(weightClock-11)/3):0; weight.position=At(823,390)+Vector2.up*(WeightLift*4.5f);indicator.color=new Color(1,.72f,.32f,WeightWarning?.3f+.12f*Mathf.Sin(Time.time*4):.12f); for(int i=0;i<2;i++){float dx=i==0?-.48f:.48f;weightRopes[i].SetPosition(0,At(823,38)+Vector2.right*dx);weightRopes[i].SetPosition(1,weight.position+new Vector3(dx,3.28f));} float travel=Mathf.Clamp01(BeatAge/1.5f);pulse.enabled=Fed;pulse.transform.position=Rung?BellTarget.transform.position:Vector3.Lerp(FeedTarget.transform.position,BellTarget.transform.position,travel);pulse.color=new Color(.74f,1,.88f,Rung?.3f:AnswerWindow?.7f:.35f);pulse.transform.localScale=Vector3.one*(AnswerWindow?1.6f:.55f); if(clapper){clapper.localPosition=clapperRest;clapper.localRotation=Quaternion.Euler(0,0,-BellBody.rotation*.6f);} } void FixedUpdate(){if(Rung&&Inside&&GameSession.I.Playing)BellBody.AddTorque(Mathf.Sin(Time.time*.8f)*.8f);} public static string Journal=>!I||!I.Fed?"Der äußere Glockenstieg führt von der ersten Halle zum Seitenumlauf. Steige über die Kupferleiter auf die Holzbank. Das warme Licht am Gegengewicht kündigt seinen langsamen Hub an. Quere die Öffnung, wenn die Last oben wartet, und rufe am rechten Kupferanschluss mit RB / K das Licht der ersten Glocke. Der feste Boden und zwei Leitern sichern jeden Sturz ab.":!I.Rung?"Die Kupferleitung ist verbunden. Kehre zur großen Glocke II auf der linken Bank zurück. Ein Licht wandert regelmäßig von rechts zu ihr. Wenn sie hell aufleuchtet, antworte mit RB / K. Zwei Antworten in zwei Lichtphasen genügen; ein zu früher Versuch kostet nichts.":"Glocke II schwingt wieder. Ihr linker Aufzug verbindet dauerhaft den Wartungsboden mit der Glockenbank. Die dritte Hauptglocke schweigt noch. Die obere rechte Tür führt zum offenen Windfenster. Vom linken Rand führt der äußere Glockenstieg zurück zur geschützten ersten Halle."; void Floor(string n,float a,float b,float y){var o=new GameObject(n);o.transform.SetParent(transform);o.transform.position=At((a+b)/2,y);o.layer=6;var c=o.AddComponent();c.size=new Vector2((b-a)*.022f,.18f);c.offset=Vector2.down*.09f;o.AddComponent();o.AddComponent().Material=y==800?GroundMaterial.Stone:GroundMaterial.Wood;} void Wall(float x){var o=new GameObject("Feste Seitenwand des Umlaufs");o.transform.SetParent(transform);float top=At(x,430).y+11.5f,bottom=x==43?85.2f:top-23;o.transform.position=new Vector2(At(x,430).x,(bottom+top)*.5f);o.layer=6;o.AddComponent().size=new Vector2(.15f,top-bottom);} ClimbableLadder Ladder(string n,float x,float b,float t){var o=new GameObject(n);o.transform.SetParent(transform);var l=o.AddComponent();l.Init(At(x,b).x,At(x,b).y,At(x,t).y);l.ExtendTo(At(x,t).y);foreach(var s in o.GetComponentsInChildren())s.enabled=false;foreach(var line in o.GetComponentsInChildren())line.enabled=false;return l;} void OnDestroy(){if(I==this)I=null;if(bellSprite)Destroy(bellSprite);if(clapperSprite)Destroy(clapperSprite);if(weightSprite)Destroy(weightSprite);if(weightBeam)Destroy(weightBeam);if(weightRail)Destroy(weightRail);} } }