Compare commits

..

5 Commits

  1. 59
      Assets/Prefabs/BalanceValues.asset
  2. 8
      Assets/Prefabs/BalanceValues.asset.meta
  3. 34
      Assets/Scenes/Game.unity
  4. 7
      Assets/Scripts/Game/AIPlayer.cs
  5. 37
      Assets/Scripts/Game/BalanceValues.cs
  6. 3
      Assets/Scripts/Game/BalanceValues.cs.meta
  7. 2
      Assets/Scripts/Game/Ball.cs
  8. 49
      Assets/Scripts/Game/GameManager.cs
  9. 14
      Assets/Scripts/Game/Player.cs
  10. 4
      Assets/Scripts/Game/RoomSettings.cs
  11. 0
      Assets/Scripts/Game/RoomSettings.cs.meta
  12. 4
      Assets/Scripts/Game/Wormhole.cs
  13. 13
      Assets/Scripts/MenuUI.cs
  14. 4
      Assets/UI/Menu.uxml
  15. 2
      Assets/UI/Styles/menu.uss

@ -0,0 +1,59 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b6828f2f0908479394eb20d0c0beb8c0, type: 3}
m_Name: BalanceValues
m_EditorClassIdentifier:
spawnRates:
- spawnable: 0
values:
- spawnRate: 1
baseSeconds: 20
- spawnRate: 2
baseSeconds: 10
- spawnRate: 3
baseSeconds: 5
- spawnable: 1
values:
- spawnRate: 1
baseSeconds: 30
- spawnRate: 2
baseSeconds: 20
- spawnRate: 3
baseSeconds: 10
- spawnable: 2
values:
- spawnRate: 1
baseSeconds: 10
- spawnRate: 2
baseSeconds: 7
- spawnRate: 3
baseSeconds: 3
- spawnable: 3
values:
- spawnRate: 1
baseSeconds: 40
- spawnRate: 2
baseSeconds: 30
- spawnRate: 3
baseSeconds: 15
spawnArea: {x: 0.9, y: 0.5}
playerSpeed: 15
playerSpeedMultiplier: 1.5
playerWidth: 6
playerWidthMultiplier: 1.5
playerBorder: 0.85
playerBorderSummand: 0.15
aiFutureSecondsBase: 1
aiFutureSecondsPerDifficulty: 0.75
aiSmartIdleMinDifficulty: 2
ballSpeed: 15
ballSpeedMultiplier: 1.025

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a557c60a64523e194996165dd8bbf6a4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

@ -1017,39 +1017,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 52712ba5190f247fcab14f6d688872ba, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnRates:
- spawnable: 0
values:
- spawnRate: 1
baseSeconds: 20
- spawnRate: 2
baseSeconds: 10
- spawnRate: 3
baseSeconds: 5
- spawnable: 1
values:
- spawnRate: 1
baseSeconds: 30
- spawnRate: 2
baseSeconds: 20
- spawnRate: 3
baseSeconds: 10
- spawnable: 2
values:
- spawnRate: 1
baseSeconds: 10
- spawnRate: 2
baseSeconds: 7
- spawnRate: 3
baseSeconds: 3
- spawnable: 3
values:
- spawnRate: 1
baseSeconds: 40
- spawnRate: 2
baseSeconds: 30
- spawnRate: 3
baseSeconds: 15
balanceValues: {fileID: 11400000, guid: a557c60a64523e194996165dd8bbf6a4, type: 2}
ballPrefab: {fileID: 7041796185663956342, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
playerPrefab: {fileID: 5402279313309450415, guid: 32b3bb87d3699d314ace59ddb1674875, type: 3}
borderZonePrefab: {fileID: 4827788429173683660, guid: 50e7c76b45ba22fb18c0012e23b4b34c, type: 3}

@ -5,7 +5,7 @@ using UnityEngine.UIElements;
namespace Game {
public class AIPlayer : Player {
private const float SmoothTime = 0.2f;
private const float SmoothTime = 0.1f;
private float currentSmoothV;
@ -16,9 +16,9 @@ namespace Game {
public Difficulty Difficulty { get; set; }
private float FutureSeconds => (float) Difficulty * 0.5f;
private float FutureSeconds => GameManager.BalanceValues.aiFutureSecondsBase + (float) Difficulty * GameManager.BalanceValues.aiFutureSecondsPerDifficulty;
private float IdlePosition => Difficulty >= Difficulty.Medium ? 0 : X;
private float IdlePosition => Difficulty >= GameManager.BalanceValues.aiSmartIdleMinDifficulty ? 0 : X;
private float DistortAmount => 1 - 1 / ((float) Difficulty + 1);
@ -203,6 +203,7 @@ namespace Game {
while (approaching.Count > 0) {
// TODO nearest by impact time
// Nearest by Y-Distance
var ball = approaching.Aggregate(approaching[0], (prev, current) => YDistanceToBall(current) < YDistanceToBall(prev) ? current : prev);

@ -0,0 +1,37 @@
using System;
using System.Runtime.Remoting.Messaging;
using UnityEngine;
namespace Game {
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/BalanceValues", order = 0)]
public class BalanceValues : ScriptableObject {
[Serializable]
public struct SpawnRatesValue {
public SpawnRate spawnRate;
public float baseSeconds;
}
[Serializable]
public struct SpawnableSpawnRates {
public Spawnable spawnable;
public SpawnRatesValue[] values;
}
[Header("Spawning")]
public SpawnableSpawnRates[] spawnRates;
public Vector2 spawnArea;
[Header("Player")]
public float playerSpeed;
public float playerSpeedMultiplier;
public float playerWidth;
public float playerWidthMultiplier;
public float playerBorder;
public float playerBorderSummand;
[Header("AI")]
public float aiFutureSecondsBase;
public float aiFutureSecondsPerDifficulty;
public Difficulty aiSmartIdleMinDifficulty;
[Header("Ball")]
public float ballSpeed;
public float ballSpeedMultiplier;
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b6828f2f0908479394eb20d0c0beb8c0
timeCreated: 1681802462

@ -4,7 +4,7 @@ using UnityEngine;
namespace Game {
public class Ball : NetworkBehaviour {
private const float SpeedGain = 1.025f;
private float SpeedGain { get; } = GameManager.BalanceValues.ballSpeedMultiplier;
public Rigidbody2D Rb { get; private set; }

@ -11,18 +11,7 @@ using Random = UnityEngine.Random;
namespace Game {
public class GameManager : NetworkBehaviour {
[Serializable]
public struct SpawnRatesValue {
public SpawnRate spawnRate;
public float baseSeconds;
}
[Serializable]
public struct SpawnableSpawnRates {
public Spawnable spawnable;
public SpawnRatesValue[] values;
}
public SpawnableSpawnRates[] spawnRates;
public BalanceValues balanceValues;
public Object ballPrefab;
public Object playerPrefab;
@ -34,6 +23,8 @@ namespace Game {
public static GameManager Singleton { get; private set; }
public static BalanceValues BalanceValues => Singleton.balanceValues;
public List<Ball> Balls { get; } = new();
public Player Player1 { get; private set; }
@ -41,22 +32,22 @@ namespace Game {
public Player Player2 { get; private set; }
private void Awake() {
Singleton = this;
SetupPlayers();
}
private void OnEnable() {
Singleton = this;
// Move this to settings
Application.targetFrameRate = 144;
QualitySettings.vSyncCount = 0;
}
private IEnumerator SpawnLoop(Spawnable spawnable) {
SpawnRate required = Settings.SpawnRates[spawnable];
SpawnRate required = RoomSettings.SpawnRates[spawnable];
if (required == SpawnRate.Never)
yield break;
float baseSeconds = spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds;
float baseSeconds = balanceValues.spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds;
while (Application.isPlaying) {
yield return new WaitForSeconds(baseSeconds);
switch (spawnable) {
@ -89,12 +80,12 @@ namespace Game {
var p2Obj = Instantiate(playerPrefab);
Player p1, p2;
switch (Settings.Type) {
switch (RoomSettings.Type) {
case Type.AI:
p1 = p1Obj.AddComponent<AIPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((AIPlayer) p1).Difficulty = Settings.AIDifficulty;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
((AIPlayer) p1).Difficulty = RoomSettings.AIDifficulty;
((AIPlayer) p2).Difficulty = RoomSettings.AIDifficulty;
break;
case Type.RealOnline:
p1 = p1Obj.AddComponent<RealPlayer>();
@ -111,7 +102,7 @@ namespace Game {
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((RealPlayer) p1).isThisClient = true;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
((AIPlayer) p2).Difficulty = RoomSettings.AIDifficulty;
break;
default:
throw new ArgumentOutOfRangeException();
@ -126,25 +117,29 @@ namespace Game {
p1.borderZonePrefab = p2.borderZonePrefab = borderZonePrefab;
}
private Vector2 GetSpawnPosition() {
Vector2 area = balanceValues.spawnArea * Dimensions.Singleton.playGroundSize * 0.5f;
float x = Random.Range(-area.x, area.x);
float y = Random.Range(-area.y, area.y);
return new Vector2(x, y);
}
private void SpawnNewBall(bool permanent) {
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5));
Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent<NewBall>().IsPermanent = permanent;
Instantiate(newBallPrefab, GetSpawnPosition(), Quaternion.identity).GetComponent<NewBall>().IsPermanent = permanent;
}
private void SpawnWormhole() {
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5));
Instantiate(wormholePrefab, pos, Quaternion.identity);
Instantiate(wormholePrefab, GetSpawnPosition(), Quaternion.identity);
}
private void SpawnModification() {
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-2, 2));
var properties = modifications[Random.Range(0, modifications.Length)];
var mod = Instantiate(modificationPrefab, pos, Quaternion.identity).GetComponent<Modification>();
var mod = Instantiate(modificationPrefab, GetSpawnPosition(), Quaternion.identity).GetComponent<Modification>();
mod.Properties = properties;
}
public void SpawnBall(Player towards, bool isPermanent) {
const float startSpeed = 15;
float startSpeed = balanceValues.ballSpeed;
var position = new Vector2(0, -towards.transform.position.y * 0.5f);
var ball = Instantiate(ballPrefab, position, Quaternion.identity).GetComponent<Ball>();
ball.Rb.velocity = RandomDirectionTowards(towards) * startSpeed;

@ -17,15 +17,15 @@ namespace Game {
private Transform borderZoneLeft, borderZoneRight;
private const float BaseSpeed = 15;
private const float SpeedMultiplier = 1.5f;
private float BaseSpeed { get; } = GameManager.BalanceValues.playerSpeed;
private float SpeedMultiplier { get; } = GameManager.Singleton.balanceValues.playerSpeedMultiplier;
// Unit distance from zero
private readonly float baseBorder = Dimensions.Singleton.PlaySize.x / 2 * 0.85f;
private readonly float borderSummand = Dimensions.Singleton.PlaySize.x / 2 * 0.15f;
private float BaseBorder { get; } = Dimensions.Singleton.PlaySize.x / 2 * GameManager.BalanceValues.playerBorder;
private float BorderSummand { get; } = Dimensions.Singleton.PlaySize.x / 2 * GameManager.BalanceValues.playerBorderSummand;
private const float BaseWidth = 6;
private const float WidthMultiplier = 1.5f;
private float BaseWidth { get; } = GameManager.BalanceValues.playerWidth;
private float WidthMultiplier { get; } = GameManager.BalanceValues.playerWidthMultiplier;
protected bool goingLeftLinear, goingRightLinear;
@ -56,7 +56,7 @@ namespace Game {
}
protected float Border {
get {
float value = GetModified(ModEffect.Border, baseBorder, borderSummand, (f, f1) => f + f1, f => -f);
float value = GetModified(ModEffect.Border, BaseBorder, BorderSummand, (f, f1) => f + f1, f => -f);
return Mathf.Clamp(value, Width / 2, Dimensions.Singleton.PlaySize.x / 2);
}
}

@ -10,10 +10,10 @@ namespace Game {
public enum Spawnable {NewBallTemporary, NewBallPermanent, Modification, Wormhole}
public enum WinScore {Default, Custom}
public struct Settings {
public struct RoomSettings {
public static Type Type;
public static Difficulty AIDifficulty;
public static Dictionary<Spawnable, SpawnRate> SpawnRates;
public static readonly Dictionary<Spawnable, SpawnRate> SpawnRates = new();
public static WinScore WinScore;
public static int CustomWinScore;
}

@ -61,10 +61,10 @@ namespace Game {
Vector2 thisPos = new Vector2(transform.position.x, transform.position.y);
foreach (var ball in GameManager.Singleton.Balls) {
Vector2 diff = thisPos - ball.Rb.position;
if (diff.sqrMagnitude > Radius * Radius)
if (diff.sqrMagnitude > Radius * Radius * 2 * 2)
continue;
float dist = diff.magnitude;
Vector2 force = diff.normalized / dist * (Size * 5);
Vector2 force = diff.normalized / dist * (Size * 20);
force = Vector2.ClampMagnitude(force, 15);
ball.Rb.AddForce(force);
}

@ -32,6 +32,11 @@ public class MenuUI : MonoBehaviour {
private void PlayPressed(ClickEvent evt) {
mainMenu.style.display = DisplayStyle.None;
playMenu.style.display = DisplayStyle.Flex;
RoomSettings.SpawnRates[Spawnable.Modification] = SpawnRate.Many;
RoomSettings.SpawnRates[Spawnable.NewBallPermanent] = SpawnRate.Many;
RoomSettings.SpawnRates[Spawnable.NewBallTemporary] = SpawnRate.Few;
RoomSettings.SpawnRates[Spawnable.Wormhole] = SpawnRate.Many;
}
private void SettingsPressed(ClickEvent evt) {
@ -46,15 +51,15 @@ public class MenuUI : MonoBehaviour {
private void JoinPressed(ClickEvent evt) { }
private void BotPressed(ClickEvent evt) {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.VeryHard;
RoomSettings.Type = Type.Hybrid;
RoomSettings.AIDifficulty = Difficulty.VeryHard;
SceneManager.LoadScene("Game");
}
private void BotsPressed(ClickEvent evt) {
Settings.Type = Type.AI;
Settings.AIDifficulty = Difficulty.VeryHard;
RoomSettings.Type = Type.AI;
RoomSettings.AIDifficulty = Difficulty.VeryHard;
SceneManager.LoadScene("Game");
}

@ -2,11 +2,11 @@
<Style src="project://database/Assets/UI/Styles/menu.uss?fileID=7433441132597879392&amp;guid=a6abab2f6d20ba823bad41d2081810e9&amp;type=3#menu" />
<Style src="project://database/Assets/UI/Styles/global.uss?fileID=7433441132597879392&amp;guid=f6d2ff1ab9bcd826f88710e642615fa6&amp;type=3#global" />
<ui:Label text="Pong Reloaded" display-tooltip-when-elided="true" name="top_header" class="header" />
<ui:VisualElement name="main_menu" class="menu" style="display: none;">
<ui:VisualElement name="main_menu" class="menu" style="display: flex;">
<ui:Button text="Play" display-tooltip-when-elided="true" name="btn_play" />
<ui:Button text="Settings" display-tooltip-when-elided="true" name="btn_settings" />
</ui:VisualElement>
<ui:VisualElement name="play_menu" class="menu" style="display: flex;">
<ui:VisualElement name="play_menu" class="menu" style="display: none;">
<ui:Button text="Find opponent" display-tooltip-when-elided="true" name="btn_find" />
<ui:Button text="Host game" display-tooltip-when-elided="true" name="btn_host" />
<ui:Button text="Join game" display-tooltip-when-elided="true" name="btn_join" />

@ -25,8 +25,6 @@ Button {
border-top-width: 3px;
border-bottom-width: 3px;
font-size: 30px;
flex-grow: 1;
flex-shrink: 0;
}
Button:hover {

Loading…
Cancel
Save