ActiveModifications functionality

main
Benjamin Kraft 1 year ago
parent 19a8526696
commit 2e1ee2c7b0
  1. 2
      Assets/Scripts/Game/GameManager.cs
  2. 2
      Assets/Scripts/Game/Modification.cs
  3. 43
      Assets/Scripts/Game/Player.cs
  4. 1
      README.md

@ -101,7 +101,7 @@ namespace Game {
private IEnumerator Start() {
while (Application.isPlaying) {
yield return new WaitForSeconds(5);
yield return new WaitForSeconds(1);
SpawnModification();
}
}

@ -22,6 +22,8 @@ namespace Game {
element.RemoveFromHierarchy();
modifications.Remove(this);
}
}
public class Modification : NetworkBehaviour {

@ -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<ActiveModification> 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<TextElement>("score").text = score.ToString();
Panel.Q<TextElement>("score").text = Score.ToString();
}
protected void ClampInsideBorders() {

@ -2,7 +2,6 @@
### Game
- ActiveModification:
- Function
- Visuals
- Left,Right Buttons:
- Function

Loading…
Cancel
Save