|
|
@ -31,44 +31,10 @@ namespace Game { |
|
|
|
public Player Player1 { get; private set; } |
|
|
|
public Player Player1 { get; private set; } |
|
|
|
public Player Player2 { get; private set; } |
|
|
|
public Player Player2 { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
Vector2 p, rs; |
|
|
|
|
|
|
|
Assert.IsTrue(AIPlayer.Intersect(v8, v4, v1, v9, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsTrue(AIPlayer.Intersect(v1, v2, v4, v7, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsTrue(AIPlayer.Intersect(v10, v6, v9, v2, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsTrue(AIPlayer.Intersect(v9, v5, v8, v10, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsFalse(AIPlayer.Intersect(v8, v4, v6, v5, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsFalse(AIPlayer.Intersect(v3, v5, v6, v8, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsFalse(AIPlayer.Intersect(v10, v4, v8, v9, out p, out rs)); |
|
|
|
|
|
|
|
Assert.IsFalse(AIPlayer.Intersect(v1, v7, v3, v2, out p, out rs)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var v11 = new Vector2(0, 0); |
|
|
|
|
|
|
|
var v12 = new Vector2(0, 5); |
|
|
|
|
|
|
|
var v13 = new Vector2(-2, 2); |
|
|
|
|
|
|
|
var v14 = new Vector2(2, 2); |
|
|
|
|
|
|
|
Assert.IsTrue(AIPlayer.Intersect(v11, v12, v13, v14, out p, out rs)); |
|
|
|
|
|
|
|
Assert.AreApproximatelyEqual(rs.x, 0.4f); |
|
|
|
|
|
|
|
Assert.AreApproximatelyEqual(rs.y, 0.5f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake() { |
|
|
|
private void Awake() { |
|
|
|
Settings.Type = Type.Hybrid; |
|
|
|
Settings.Type = Type.Hybrid; |
|
|
|
Settings.AIDifficulty = Difficulty.Hard; |
|
|
|
Settings.AIDifficulty = Difficulty.Hard; |
|
|
|
|
|
|
|
|
|
|
|
var ball = Instantiate(ballPrefab).GetComponent<Ball>(); |
|
|
|
|
|
|
|
Balls.Add(ball); |
|
|
|
|
|
|
|
ball.Radius = 0.5f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var p1Obj = Instantiate(playerPrefab); |
|
|
|
var p1Obj = Instantiate(playerPrefab); |
|
|
|
var p2Obj = Instantiate(playerPrefab); |
|
|
|
var p2Obj = Instantiate(playerPrefab); |
|
|
|
|
|
|
|
|
|
|
@ -99,8 +65,8 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
|
|
Player1 = p1; |
|
|
|
Player1 = p1; |
|
|
|
Player2 = p2; |
|
|
|
Player2 = p2; |
|
|
|
|
|
|
|
|
|
|
|
Tests(); |
|
|
|
SpawnBall(Player1, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator Start() { |
|
|
|
private IEnumerator Start() { |
|
|
@ -117,15 +83,28 @@ namespace Game { |
|
|
|
mod.Properties = properties; |
|
|
|
mod.Properties = properties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SpawnBall() { |
|
|
|
public void SpawnBall(Player towards, bool isPermanent) { |
|
|
|
Vector2 position = Vector2.zero; |
|
|
|
const float startSpeed = 15; |
|
|
|
Vector2 velocity = Vector2.up; |
|
|
|
Vector2 position = new Vector2(0, -towards.transform.position.y * 0.5f); |
|
|
|
var ball = Instantiate(ballPrefab, position, Quaternion.identity).GetComponent<Ball>(); |
|
|
|
var ball = Instantiate(ballPrefab, position, Quaternion.identity).GetComponent<Ball>(); |
|
|
|
var rb = ball.Rb; |
|
|
|
ball.Rb.velocity = RandomDirectionTowards(towards) * startSpeed; |
|
|
|
rb.velocity = velocity; |
|
|
|
ball.IsPermanent = isPermanent; |
|
|
|
|
|
|
|
ball.Radius = 0.5f; |
|
|
|
|
|
|
|
|
|
|
|
Balls.Add(ball); |
|
|
|
Balls.Add(ball); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Vector2 RandomDirectionTowards(Player player) { |
|
|
|
|
|
|
|
const float maxAngle = 45; |
|
|
|
|
|
|
|
float radians = Random.Range(-maxAngle, maxAngle) * Mathf.PI / 180; |
|
|
|
|
|
|
|
float x = Mathf.Sin(radians); |
|
|
|
|
|
|
|
float y = Mathf.Cos(radians) * player.Side switch { |
|
|
|
|
|
|
|
Side.Top => 1, |
|
|
|
|
|
|
|
Side.Bottom => -1, |
|
|
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException() |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return new Vector2(x, y); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void RemoveBall(Ball ball) { |
|
|
|
public void RemoveBall(Ball ball) { |
|
|
|
Balls.Remove(ball); |
|
|
|
Balls.Remove(ball); |
|
|
|