Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Better random
Browse files Browse the repository at this point in the history
  • Loading branch information
Team-on committed Jan 30, 2021
1 parent 146b03d commit 9a16182
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void SetSprites(Sprite[] _sprites) {
public void SetSpritesDublicateInner(Sprite[] _sprites) {
List<Sprite> list = new List<Sprite>(_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();
Expand Down
12 changes: 7 additions & 5 deletions GGJ21/Assets/Scripts/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
13 changes: 10 additions & 3 deletions GGJ21/Assets/Scripts/Pet/PetCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9a16182

Please sign in to comment.