From 08f85edc51aaf97a125edcf8d7fb42765b0226dd Mon Sep 17 00:00:00 2001 From: RosimInc Date: Sun, 16 Aug 2015 00:43:36 -0400 Subject: [PATCH] Implemented color changes for friendship links Online/offline functionality tested and running Signed-off-by: RosimInc --- Assets/Scenes/Gameplay.unity | 6 ++--- Assets/Scripts/Link.cs | 36 ++++++++++++------------- Assets/Scripts/Models/Friendship.cs | 6 +++++ Assets/Scripts/Models/FriendshipLink.cs | 7 +++++ Assets/Scripts/Models/Person.cs | 2 +- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index c94c8b2..27da76c 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -1101,15 +1101,15 @@ Prefab: objectReference: {fileID: 724043967} - target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} propertyPath: levelOptions.NumPeople - value: 2 + value: 50 objectReference: {fileID: 0} - target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} propertyPath: levelOptions.AvgNumFriends - value: 1 + value: 8 objectReference: {fileID: 0} - target: {fileID: 11432906, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} propertyPath: levelOptions.FriendshipLikeliness - value: 1 + value: .600000024 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 136ea38d5deb4c9418beb879167d9b03, type: 2} diff --git a/Assets/Scripts/Link.cs b/Assets/Scripts/Link.cs index f2730c9..865a70e 100644 --- a/Assets/Scripts/Link.cs +++ b/Assets/Scripts/Link.cs @@ -9,8 +9,10 @@ public class Link : MonoBehaviour, IObserver private float highlightAlpha = 0.8f; private float defaultAlpha = 0.5f; - private Color currentDefaultColor; - private Color currentHighlightColor; + private Color color; + + private Color baseColor = new Color(0.3f, 0.7f, 1f); + private Color inactiveColor = new Color(0.15f, 0.15f, 0.05f); private static float defaultScale = 0.03f; private float hightlightScale = 0.2f; @@ -40,7 +42,7 @@ public class Link : MonoBehaviour, IObserver model.Subscribe(this); //Make it between 0.1 and 0.4 - GetColors(Model.Awareness); + GetColors(); hightlightScale = Model.Importance * 0.3f + 0.1f; Highlight(false); } @@ -66,8 +68,10 @@ public class Link : MonoBehaviour, IObserver public void Notify() { - GetColors(Model.Awareness); + GetColors(); UpdateBeam(); + if (Model.KillCount == 2) + hightlightScale = 0.1f; //TODO SR } @@ -115,29 +119,23 @@ public class Link : MonoBehaviour, IObserver UpdateBeam(); } - private void GetColors(float level) + private void GetColors() { - //If level is 0.0, green [0,1,0]. - //If level is 0.5, yellow [1,1,0]. - //If level is 1.0, red [1,0,0]. - - float r = 1f; - float g = 1f; - - if (level < 0.5f) - r = Mathf.Lerp(0, 1, level*2); + if (Model.KillCount == 0) + color = baseColor; + else if (Model.KillCount == 2) + color = inactiveColor; else - g = Mathf.Lerp(1, 0, level * 2 - 1); - - currentDefaultColor = new Color(r, g, 0f, defaultAlpha); - currentHighlightColor = new Color(r, g, 0f, highlightAlpha); + color = new Color(1f, Mathf.Lerp(1, 0, Model.Awareness), 0f); } private void UpdateBeam() { float width = isHighlighted ? hightlightScale : defaultScale; BeamLine.SetWidth(width, width); + + color.a = isHighlighted ? highlightAlpha : defaultAlpha; - _renderer.material.SetColor("_TintColor", isHighlighted ? currentHighlightColor : currentDefaultColor); + _renderer.material.SetColor("_TintColor", color); } } diff --git a/Assets/Scripts/Models/Friendship.cs b/Assets/Scripts/Models/Friendship.cs index a1ff053..9106811 100644 --- a/Assets/Scripts/Models/Friendship.cs +++ b/Assets/Scripts/Models/Friendship.cs @@ -27,6 +27,12 @@ namespace DeathBook.Model this.link = link; } + public void NotifyFriendWasKilled() + { + Link.KillCount++; + Self.NotifyFriendWasKilled(this); + } + public void Update(float deltaTime) { if (noticedDeath) diff --git a/Assets/Scripts/Models/FriendshipLink.cs b/Assets/Scripts/Models/FriendshipLink.cs index 231a861..5357c1a 100644 --- a/Assets/Scripts/Models/FriendshipLink.cs +++ b/Assets/Scripts/Models/FriendshipLink.cs @@ -20,6 +20,13 @@ namespace DeathBook.Model set { awareness = value; NotifyObservers(); } } + private int killCount = 0; //Number of people dead in this relationship + public int KillCount + { + get { return killCount; } + set { killCount = value; NotifyObservers(); } + } + public FriendshipLink(Person p1, Person p2, float importance) { friend1 = p1; diff --git a/Assets/Scripts/Models/Person.cs b/Assets/Scripts/Models/Person.cs index 857149b..51ec1ff 100644 --- a/Assets/Scripts/Models/Person.cs +++ b/Assets/Scripts/Models/Person.cs @@ -87,7 +87,7 @@ namespace DeathBook.Model Debug.Log("Person " + id + " died!"); alive = false; foreach (Friendship f in friendsList) - f.Friend.NotifyFriendWasKilled(f.Other); + f.Other.NotifyFriendWasKilled(); NotifyObservers(); return true;