From 2e1ee2c7b0da7342ac9985b5735399175f00ee13 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Wed, 12 Apr 2023 14:18:11 +0200 Subject: [PATCH] ActiveModifications functionality --- Assets/Scripts/Game/GameManager.cs | 2 +- Assets/Scripts/Game/Modification.cs | 2 ++ Assets/Scripts/Game/Player.cs | 43 +++++++++++++++++++++++------ README.md | 1 - 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Game/GameManager.cs b/Assets/Scripts/Game/GameManager.cs index d2abe6b..07a1ebf 100644 --- a/Assets/Scripts/Game/GameManager.cs +++ b/Assets/Scripts/Game/GameManager.cs @@ -101,7 +101,7 @@ namespace Game { private IEnumerator Start() { while (Application.isPlaying) { - yield return new WaitForSeconds(5); + yield return new WaitForSeconds(1); SpawnModification(); } } diff --git a/Assets/Scripts/Game/Modification.cs b/Assets/Scripts/Game/Modification.cs index 5f424fb..4648b8d 100644 --- a/Assets/Scripts/Game/Modification.cs +++ b/Assets/Scripts/Game/Modification.cs @@ -22,6 +22,8 @@ namespace Game { element.RemoveFromHierarchy(); modifications.Remove(this); } + + } public class Modification : NetworkBehaviour { diff --git a/Assets/Scripts/Game/Player.cs b/Assets/Scripts/Game/Player.cs index f756b2e..fa74bbc 100644 --- a/Assets/Scripts/Game/Player.cs +++ b/Assets/Scripts/Game/Player.cs @@ -1,12 +1,14 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Transactions; using Unity.Netcode; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.Serialization; using UnityEngine.UIElements; namespace Game { @@ -22,15 +24,38 @@ namespace Game { public VisualElement Panel { get; private set; } public List Modifications { get; } = new(); - - [SerializeField] - public int score = 0; - + + private int Score { get; set; } + // Units per second - protected float Speed => 15; - + private const float BaseSpeed = 15; + private const float SpeedMultiplier = 1.5f; + protected float Speed { + get { + return Modifications.Where(m => m.Properties.effect == ModEffect.Speed) + .Aggregate(BaseSpeed, (current, speedMod) => current * speedMod.Properties.type switch { + ModType.Buff => SpeedMultiplier, + ModType.Nerf => 1 / SpeedMultiplier, + _ => throw new ArgumentOutOfRangeException() + }); + } + } + // Unit distance from zero - protected float Border => Dimensions.Singleton.Width / 2; + private readonly float baseBorder = Dimensions.Singleton.Width / 2 * 0.8f; + private readonly float borderSummand = Dimensions.Singleton.Width / 2 * 0.2f; + protected float Border { + get { + return Mathf.Min(Modifications.Where(m => m.Properties.effect == ModEffect.Border) + .Aggregate(baseBorder, (current, borderMod) => current + borderMod.Properties.type switch { + ModType.Buff => borderSummand, + ModType.Nerf => -borderSummand, + _ => throw new ArgumentOutOfRangeException() + }), + Dimensions.Singleton.Width / 2 + ); + } + } protected float Width => transform.localScale.x; @@ -42,12 +67,12 @@ namespace Game { protected float Y => transform.position.y; public void GainScore() { - score++; + Score++; UpdatePanel(); } private void UpdatePanel() { - Panel.Q("score").text = score.ToString(); + Panel.Q("score").text = Score.ToString(); } protected void ClampInsideBorders() { diff --git a/README.md b/README.md index ae27846..7e7f2cd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ### Game - ActiveModification: - - Function - Visuals - Left,Right Buttons: - Function