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() { private IEnumerator Start() {
while (Application.isPlaying) { while (Application.isPlaying) {
yield return new WaitForSeconds(5); yield return new WaitForSeconds(1);
SpawnModification(); SpawnModification();
} }
} }

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

@ -1,12 +1,14 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Transactions; using System.Transactions;
using Unity.Netcode; using Unity.Netcode;
using UnityEditor; using UnityEditor;
using UnityEditor.UIElements; using UnityEditor.UIElements;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.Serialization;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace Game { namespace Game {
@ -22,15 +24,38 @@ namespace Game {
public VisualElement Panel { get; private set; } public VisualElement Panel { get; private set; }
public List<ActiveModification> Modifications { get; } = new(); public List<ActiveModification> Modifications { get; } = new();
[SerializeField] private int Score { get; set; }
public int score = 0;
// Units per second // 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 // 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; protected float Width => transform.localScale.x;
@ -42,12 +67,12 @@ namespace Game {
protected float Y => transform.position.y; protected float Y => transform.position.y;
public void GainScore() { public void GainScore() {
score++; Score++;
UpdatePanel(); UpdatePanel();
} }
private void UpdatePanel() { private void UpdatePanel() {
Panel.Q<TextElement>("score").text = score.ToString(); Panel.Q<TextElement>("score").text = Score.ToString();
} }
protected void ClampInsideBorders() { protected void ClampInsideBorders() {

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

Loading…
Cancel
Save