You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

using System;
2 years ago
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using Unity.VisualScripting;
using UnityEngine;
2 years ago
using UnityEngine.Assertions;
using Object = UnityEngine.Object;
namespace Game {
public class GameManager : NetworkBehaviour {
2 years ago
public static GameManager Singleton { get; private set; }
private void OnEnable() {
Singleton = this;
}
public Object ballPrefab;
public Object playerPrefab;
2 years ago
public List<Ball> Balls { get; } = new();
private static void Tests() {
var v1 = new Vector2(1, 3);
var v2 = new Vector2(3, 2);
var v3 = new Vector2(4, 4);
var v4 = new Vector2(1, 1);
var v5 = new Vector2(4, 1);
var v6 = new Vector2(2, 5);
var v7 = new Vector2(2, 3);
var v8 = new Vector2(-1, 4);
var v9 = new Vector2(-2, 1);
var v10 = new Vector2(3, -1);
Assert.IsTrue(AIPlayer.Intersect(v8, v4, v1, v9, out _));
Assert.IsTrue(AIPlayer.Intersect(v1, v2, v4, v7, out _));
Assert.IsTrue(AIPlayer.Intersect(v10, v6, v9, v2, out _));
Assert.IsTrue(AIPlayer.Intersect(v9, v5, v8, v10, out _));
Assert.IsFalse(AIPlayer.Intersect(v8, v4, v6, v5, out _));
Assert.IsFalse(AIPlayer.Intersect(v3, v5, v6, v8, out _));
Assert.IsFalse(AIPlayer.Intersect(v10, v4, v8, v9, out _));
Assert.IsFalse(AIPlayer.Intersect(v1, v7, v3, v2, out _));
var v11 = new Vector2(0, 4.8f);
var v12 = new Vector2(0, 14.8f);
var v13 = new Vector2(-9.75f, 14.75f);
var v14 = new Vector2(9.75f, 14.75f);
Assert.IsTrue(AIPlayer.Intersect(v11, v12, v13, v14, out _));
}
private void Start() {
//var ball = Instantiate(ballPrefab, Vector2.zero, Quaternion.identity).GetComponent<Ball>();
2 years ago
var ball = FindObjectOfType(typeof(Ball)).GetComponent<Ball>();
Balls.Add(ball);
2 years ago
ball.Radius = 0.5f;
2 years ago
var p1Obj = Instantiate(playerPrefab);
var p2Obj = Instantiate(playerPrefab);
var p1 = p1Obj.AddComponent<AIPlayer>();
2 years ago
var p2 = p2Obj.AddComponent<AIPlayer>();
2 years ago
p1.Side = Player.ESide.Top;
p2.Side = Player.ESide.Bottom;
2 years ago
p1.Difficulty = AIPlayer.EDifficulty.VeryHard;
p2.Difficulty = AIPlayer.EDifficulty.VeryHard;
// p2.isThisClient = true;
2 years ago
Tests();
}
}
}