From 9a16182daefdc3cae4c67ab9d2c4f9c7b5a69973 Mon Sep 17 00:00:00 2001 From: Team-on Date: Sun, 31 Jan 2021 01:51:41 +0200 Subject: [PATCH] Better random --- .../GameTemplate/Scripts/Animators/ImageAnimator.cs | 2 +- GGJ21/Assets/Scripts/Game.cs | 12 +++++++----- GGJ21/Assets/Scripts/Pet/PetCard.cs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/GGJ21/Assets/Plugins/GameTemplate/Scripts/Animators/ImageAnimator.cs b/GGJ21/Assets/Plugins/GameTemplate/Scripts/Animators/ImageAnimator.cs index 2958486..4b10f91 100644 --- a/GGJ21/Assets/Plugins/GameTemplate/Scripts/Animators/ImageAnimator.cs +++ b/GGJ21/Assets/Plugins/GameTemplate/Scripts/Animators/ImageAnimator.cs @@ -51,7 +51,7 @@ public void SetSprites(Sprite[] _sprites) { public void SetSpritesDublicateInner(Sprite[] _sprites) { List list = new List(_sprites.Length * 2 - 2); list.AddRange(_sprites); - for (int i = _sprites.Length - 1; i >= 1; --i) + for (int i = _sprites.Length - 2; i >= 1; --i) list.Add(_sprites[i]); sprites = list.ToArray(); diff --git a/GGJ21/Assets/Scripts/Game.cs b/GGJ21/Assets/Scripts/Game.cs index 2c0ea7e..ca9e7eb 100644 --- a/GGJ21/Assets/Scripts/Game.cs +++ b/GGJ21/Assets/Scripts/Game.cs @@ -104,13 +104,16 @@ void OnNewClient() { StartLevel(); } else { + bool randomPet = Random.Range(0, 2) == 1; Array pets = Enum.GetValues(typeof(PetType)); Array accessory = Enum.GetValues(typeof(AccessoryType)); + PetType pet = randomPet ? (PetType)pets.GetValue(Random.Range(0, pets.Length)) : PetType.None; + AccessoryType acs = !randomPet ? (AccessoryType)accessory.GetValue(Random.Range(0, accessory.Length)) : AccessoryType.None; Client = new Client( - (PetType)pets.GetValue(Random.Range(0, pets.Length)), - (AccessoryType)accessory.GetValue(Random.Range(0, pets.Length)), - "Dialog text" + pet, + acs, + $"[{pet}] [{acs}] - Dialog text" ); cardsSelector.IsCanSelect = true; @@ -124,8 +127,7 @@ void OnNewClient() { cards[1].SetCard(Client.wantedPet, Client.wantedAccessory); } - dialog.ShowText($"[{Client.wantedPet}] [{Client.wantedAccessory}] - {Client.dialogText}"); - //dialog.ShowText(Client.dialogText); + dialog.ShowText(Client.dialogText); } } diff --git a/GGJ21/Assets/Scripts/Pet/PetCard.cs b/GGJ21/Assets/Scripts/Pet/PetCard.cs index e878962..22beeba 100644 --- a/GGJ21/Assets/Scripts/Pet/PetCard.cs +++ b/GGJ21/Assets/Scripts/Pet/PetCard.cs @@ -43,16 +43,23 @@ public void SetCard(PetType _petType, AccessoryType _accessoryType) { petSprites = petData.sprites.Random(); if (accessoryType == AccessoryType.None) { - int randomNum = Random.Range(0, petData.accessories.Length); - accessorySprite = petData.accessories[randomNum]; - accessoryType = (AccessoryType)(randomNum); + int randomNum = Random.Range(0, petData.accessories.Length + 1); + if(randomNum != petData.accessories.Length) { + accessorySprite = petData.accessories[randomNum]; + accessoryType = (AccessoryType)(randomNum); + } + else { + accessorySprite = null; + } } else { accessorySprite = petData.accessories[(int)(accessoryType) - 1]; ; } petImageAnimator.SetSpritesDublicateInner(petSprites.sprites); + accessoryImage.sprite = accessorySprite; + accessoryImage.color = accessoryImage.color.SetA(accessorySprite == null ? 0 : 1); } [Serializable]