| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- namespace DiamondArrow
- {
- public sealed partial class DiamondArrowGame
- {
- RectTransform Sheet(string title,float height=740,bool dismiss=true,string id=null)
- {
- CloseModal();CurrentModal=id??title;modal=Node(root,"Modal "+CurrentModal,0,0,750,1334);
- var shade=modal.gameObject.AddComponent<Image>();shade.color=new Color(.01f,0,.025f,.88f);shade.raycastTarget=true;
- if(dismiss){var b=modal.gameObject.AddComponent<Button>();b.transition=Selectable.Transition.None;b.onClick.AddListener(()=>{if(!chestBusy)CloseAndRefresh();});}
- var panel=Panel(modal,title,35,(1334-height)/2,680,height);panel.GetComponent<NeonPanel>().raycastTarget=true;panel.gameObject.AddComponent<Button>().transition=Selectable.Transition.None;
- Label(panel,title,30,24,530,52,30,Color.white,TextAnchor.MiddleLeft);Rule(panel,30,104,620,Neon.Purple);
- if(dismiss)CloseImageButton(panel);
- return panel;
- }
- void CloseImageButton(RectTransform panel)
- {
- var r=Node(panel,"Close",576,10,88,88);var hit=r.gameObject.AddComponent<Image>();hit.color=Color.clear;hit.raycastTarget=true;
- var face=Node(r,"Close artwork",0,0,88,88).gameObject.AddComponent<Image>();face.sprite=theme.closeButton;face.preserveAspect=true;face.raycastTarget=false;
- var button=r.gameObject.AddComponent<Button>();button.targetGraphic=face;var colors=button.colors;colors.pressedColor=new Color(.6f,.45f,.7f);button.colors=colors;r.gameObject.AddComponent<ButtonDepth>();button.onClick.AddListener(()=>{Sound(SoundCue.Tap);if(!chestBusy)CloseAndRefresh();});
- }
- RectTransform FooterButton(RectTransform panel,string name,float x,float width,string title,Action action,bool primary=true)
- {return Button(panel,name,x,panel.rect.height-128,width,96,title,action,primary);}
- void CloseModal()
- {
- if(modal){modal.gameObject.SetActive(false);Destroy(modal.gameObject);modal=null;}
- CurrentModal=null;if(gemsText)gemsText.text=Save.gems.ToString();
- }
- void CloseAndRefresh(){CloseModal();if(CurrentScreen=="Lobby")ShowLobby();}
- public void ShowQuit()
- {
- if(Run==null||CurrentScreen!="Game")return;if(Run.Status!=RunStatus.Playing)return;
- var p=Sheet("LEAVE THIS LEVEL?",420);Label(p,"Your progress in this attempt will be lost.\nYour diamonds and cleared levels are safe.",35,110,610,112,24,Neon.Muted);
- FooterButton(p,"Stay",32,290,"STAY",CloseModal,false);FooterButton(p,"Leave",352,295,"LEAVE",ShowMap,true);
- }
- public void ShowFail()
- {
- if(Run==null)return;if(CurrentModal!="Fail")Sound(SoundCue.Fail);bool time=Run.Status==RunStatus.FailedTime;var p=Sheet(time?"TIME UP":"OUT OF HEARTS",650,false,"Fail");
- Icon(p,time?10:12,273,88,130);Label(p,"Level "+Run.Level.number+" · "+Run.Remaining+" arrows left",30,235,620,40,26,Neon.Ice);
- Label(p,time?"A little more time. One more chance.":"Find a clear path and try again.",30,286,620,56,22,Neon.Muted);
- if(Save.gems>=40)Button(p,"Revive",70,382,540,96,time?"+30 SECONDS · 40":"REVIVE · 40",()=>{if(!Run.Revive(Save))return;Sound(SoundCue.Heart);Persist();CloseModal();resultScheduled=false;readyAt=Time.unscaledTime+.35f;UpdateGameHud();},true);
- else Label(p,"40 diamonds needed to revive",30,392,620,44,22,Neon.Muted);
- FooterButton(p,"Map",30,295,"MAP",ShowMap,false);FooterButton(p,"Retry",355,295,"RETRY",()=>StartLevel(Run.Level.number),true);
- }
- public void ShowResult()
- {
- if(Run==null||Run.Status!=RunStatus.Cleared)return;var reward=Economy.Clear(Run,Save);Persist();Sound(SoundCue.Clear);var p=Sheet("LEVEL CLEAR",880,false,"Result");
- for(int i=0;i<3;i++)Icon(p,2,216+i*86,112,78,new Color(1,1,1,i<Run.Stars?1:.2f));
- Label(p,"LEVEL "+Run.Level.number+" · "+Run.Mistakes+" MISTAKES · "+Clock(Run.TimeLeft)+" LEFT",20,196,640,35,20,Neon.Ice);
- var rewards=Panel(p,"Rewards",32,245,616,125,false);Icon(rewards,1,15,23,76);Label(rewards,"+"+reward.Total+" DIAMONDS",105,8,485,47,29,Color.white,TextAnchor.MiddleLeft);
- Label(rewards,"Clear "+reward.basic+" First clear "+reward.first+" Time "+reward.time+(reward.keys>0?"\nMilestone: +1 chest key":""),105,57,485,60,19,Neon.Muted,TextAnchor.MiddleLeft);
- Label(p,"FASTEST CLEARS · OFFLINE BENCHMARK",32,388,616,32,19,Neon.Ice,TextAnchor.MiddleLeft);if(reward.newBest)Label(p,"NEW BEST",444,420,204,29,18,Neon.Gold);
- var rivals=new List<KeyValuePair<string,float>>();var seeded=new System.Random(Run.Level.number*7919+104729);var names=new List<string>{"Nova","Kito","Vega","Rin","Onyx","Sable","Mika","Juno","Zed","Lyra","Ace","Iris","Kai","Nyx","Rex","Yuna"};
- for(int i=0;i<12;i++){int k=seeded.Next(names.Count);rivals.Add(new KeyValuePair<string,float>(names[k],Run.Level.seconds*(.34f+Mathf.Pow((float)seeded.NextDouble(),.85f)*.66f)));names.RemoveAt(k);}
- const string playerKey="__player__";rivals.Add(new KeyValuePair<string,float>(playerKey,Save.best[Run.Level.number-1]));rivals=rivals.OrderBy(x=>x.Value).ToList();int rank=rivals.FindIndex(x=>x.Key==playerKey);
- var shown=new List<int>{0,1,2,3,rank<4?4:rank};for(int j=0;j<5;j++){int ix=shown[j];var row=rivals[ix];bool me=row.Key==playerKey;var box=Panel(p,"Score "+j,32,456+j*43,616,38,false);if(me){box.GetComponent<NeonPanel>().top=Neon.Hex("#67124F");}Label(box,(ix+1).ToString(),10,0,50,38,20,ix==0?Neon.Gold:Neon.Muted);Label(box,me?Save.name+" (You)":row.Key,70,0,365,38,21,me?Neon.Pink:Color.white,TextAnchor.MiddleLeft);Label(box,row.Value.ToString("0.0")+"s",450,0,150,38,22,Neon.Ice);}
- Label(p,"Your best: #"+(rank+1)+" / 13 · opponents are simulated",20,680,640,27,17,Neon.Muted);
- FooterButton(p,"Result map",32,280,"MAP",ShowMap,false);FooterButton(p,"Next level",337,310,Run.Level.number==30?"REPLAY":"NEXT LEVEL",()=>StartLevel(Mathf.Min(30,Run.Level.number+1)),true);
- }
- public void ShowCheckin()
- {
- var p=Sheet("DAILY CHECK-IN",860);Label(p,"A little sparkle, every day.",30,122,620,40,23,Neon.Ice);
- for(int i=0;i<7;i++){int day=i+1;var row=Panel(p,"Day "+day,30,182+i*65,620,56,false);if(day==Save.checkinDay)row.GetComponent<NeonPanel>().top=Neon.Hex("#571054");Label(row,"DAY "+day,14,4,110,48,21,day==Save.checkinDay?Neon.Gold:Neon.Muted);Label(row,Economy.CheckinLabels[i],140,4,455,48,22,Color.white,TextAnchor.MiddleLeft);}
- bool claimed=Save.checkinDate==Today;Label(p,"Missed days never reset your rewards.",25,656,630,36,19,Neon.Muted);FooterButton(p,"Claim",100,480,claimed?"CLAIMED TODAY":"CLAIM DAY "+Save.checkinDay,()=>{if(Economy.CheckIn(Save,Today)){Persist();Sound(SoundCue.Reward);ShowCheckin();Toast("Daily reward claimed");}else Toast("Come back tomorrow");},!claimed);
- }
- public void ShowShop()
- {
- var p=Sheet("SHOP",960);Icon(p,1,34,120,40);Label(p,Save.gems+" DIAMONDS",80,118,500,42,25,Neon.Ice,TextAnchor.MiddleLeft);int[] art={10,12,11,2,13,13,13};
- for(int i=0;i<7;i++){int product=i;float y=184+i*100;var row=Panel(p,"Product "+i,27,y,626,92,false);Icon(row,art[i],8,18,56);Label(row,Economy.Products[i],78,17,322,58,23,Color.white,TextAnchor.MiddleLeft);Button(row,"Buy "+Economy.Products[i],410,2,202,88,Economy.Prices[i]+" BUY",()=>{if(Economy.Buy(Save,product)){Persist();Sound(SoundCue.Reward);ShowShop();Toast("Added to your inventory");}else {Sound(SoundCue.Blocked);Toast("Not enough diamonds");}},Save.gems>=Economy.Prices[i]);}
- Label(p,"Inventory Spotlight "+Save.spotlight+" Hammer "+Save.hammer+" Hearts "+Save.heart,25,900,630,40,18,Neon.Muted);
- }
- public void ShowChest()
- {
- var p=Sheet("LUCKY CHEST",780);var chest=Icon(p,8,211,98,258);Label(p,"ONE CHEST. A LITTLE MORE SPARKLE.",24,375,632,32,19,Neon.Ice);Label(p,"20–300 diamonds, keys or power-ups\nEvery opening contains a reward.",45,425,590,80,23,Neon.Muted);
- Label(p,"CHEST KEYS: "+Save.keys+" DIAMONDS: "+Save.gems,25,525,630,36,21,Neon.Gold);
- string cost=Save.chestDate!=Today?"OPEN FREE":Save.keys>0?"OPEN · 1 KEY":"OPEN · 60";
- FooterButton(p,"Open chest",80,520,cost,()=>{if(chestBusy)return;if(!Economy.CanOpen(Save,Today)){Toast("No keys or diamonds");return;}string prize=Economy.OpenChest(Save,Today,random.NextDouble());Persist();chestBusy=true;Sound(SoundCue.ChestOpen);StartCoroutine(RevealChest(chest.rectTransform,prize));},true);
- }
- IEnumerator RevealChest(RectTransform chest,string prize)
- {
- for(float t=0;t<.9f;t+=Time.unscaledDeltaTime){if(!chest)yield break;chest.localScale=Vector3.one*(1+.08f*Mathf.Sin(t*45));chest.localRotation=Quaternion.Euler(0,0,Mathf.Sin(t*55)*4);yield return null;}
- chestBusy=false;Sound(SoundCue.Reward);Buzz();var p=Sheet("VAULT UNLOCKED",600);Icon(p,prize.Contains("KEY")?13:prize.Contains("HAMMER")?11:1,243,100,194);Label(p,prize,25,324,630,68,29,Neon.Gold);FooterButton(p,"Collect",100,480,"COLLECT",ShowChest,true);
- }
- public void ShowDiamonds()
- {
- var p=Sheet("DIAMONDS",690);Icon(p,1,250,100,180);Label(p,Save.gems.ToString(),25,296,630,75,54,Color.white);Label(p,"Earn diamonds by clearing levels,\nchecking in and opening your daily chest.\nSpend them on power-ups, keys and revives.",45,389,590,135,23,Neon.Muted);FooterButton(p,"Open shop",140,400,"VISIT SHOP",ShowShop,true);
- }
- public void ShowProfile()
- {
- var p=Sheet("PLAYER PROFILE",760);Avatar(p,250,94,180);Label(p,Save.name,30,295,620,48,33,Color.white);Label(p,"LEVELS CLEARED "+Save.Cleared+" / 30\nSTARS COLLECTED "+Save.TotalStars+" / 90\nDIAMONDS EARNED "+Save.earned+"\nCHECK-INS "+Save.checkinTotal,75,370,530,200,25,Neon.Ice,TextAnchor.MiddleLeft);FooterButton(p,"Edit identity",125,430,"EDIT IDENTITY",ShowStart,true);
- }
- public void ShowHelp()
- {
- var p=Sheet("HOW TO PLAY",800);string[] titles={"01 FIND A CLEAR PATH","02 WATCH YOUR HEARTS","03 BEAT THE CLOCK","04 USE A LITTLE HELP"};string[] bodies={"Tap an arrow. It slides in the direction of its tip.\nAnother arrow in front blocks the way.","Blocked taps cost a heart. Three mistakes end\nthe attempt. No mistakes earns three stars.","Clear every arrow before time runs out.\nSpare time earns extra diamonds.","Spotlight finds a free arrow. Hammer breaks one.\nHeart refill restores one heart, up to five."};for(int i=0;i<4;i++){Label(p,titles[i],35,122+i*133,610,36,23,Neon.Ice,TextAnchor.MiddleLeft);Label(p,bodies[i],35,163+i*133,610,74,21,Neon.Muted,TextAnchor.MiddleLeft);}FooterButton(p,"Got it",150,380,"GOT IT",CloseAndRefresh,true);
- }
- public void ShowSettings()
- {
- var p=Sheet("SETTINGS",720);string[] names={"Sound effects","Music","Haptics"};bool[] flags={Save.sfx,Save.music,Save.haptics};
- for(int i=0;i<3;i++){int k=i;Label(p,names[i],38,120+i*108,400,88,27,Color.white,TextAnchor.MiddleLeft);Button(p,"Toggle "+names[i],476,120+i*108,160,88,flags[i]?"ON":"OFF",()=>{if(k==0)Save.sfx=!Save.sfx;if(k==1)Save.music=!Save.music;if(k==2)Save.haptics=!Save.haptics;ApplyAudioPreferences();Persist();ShowSettings();},flags[i]);}
- Label(p,"All progress is saved on this device.\nDiamond Arrow Slide · 1.0",35,470,610,75,21,Neon.Muted);FooterButton(p,"Reset progress",100,480,"RESET LOCAL PROGRESS",ShowReset,false);
- }
- void ShowReset()
- {
- var p=Sheet("RESET PROGRESS?",430);Label(p,"This erases this game's levels, diamonds,\nitems, check-in and profile on this device.",35,115,610,110,24,Neon.Muted);FooterButton(p,"Cancel reset",30,295,"CANCEL",ShowSettings,false);FooterButton(p,"Confirm reset",355,295,"RESET",()=>{store.Reset();Save=new PlayerSave();ApplyAudioPreferences();Persist();ShowStart();},true);
- }
- void CreateAudio()
- {
- gameAudio=gameObject.AddComponent<GameAudio>();
- gameAudio.Initialize(theme,Save.music,Save.sfx);
- }
- void ApplyAudioPreferences(){if(gameAudio)gameAudio.ApplyPreferences(Save.music,Save.sfx);}
- void Sound(SoundCue cue){if(Save!=null&&Save.sfx&&gameAudio)gameAudio.Play(cue);}
- void CountdownAudio()
- {
- int second=Mathf.CeilToInt(Run.TimeLeft);
- if(Run.Status==RunStatus.Playing&&second>=1&&second<=5&&second!=lastCountdownSecond)
- {lastCountdownSecond=second;Sound(SoundCue.Countdown);}
- }
- void Buzz(){
- #if UNITY_IOS && !UNITY_EDITOR
- if(Save.haptics)Handheld.Vibrate();
- #endif
- }
- }
- }
|