|
|
@ -4,11 +4,12 @@ using UnityEngine; |
|
|
|
using UnityEngine.InputSystem; |
|
|
|
using UnityEngine.InputSystem; |
|
|
|
|
|
|
|
|
|
|
|
namespace Game { |
|
|
|
namespace Game { |
|
|
|
public class Player : NetworkBehaviour { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum ESide {Top, Bottom} |
|
|
|
public enum Side {Top, Bottom} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Player : NetworkBehaviour { |
|
|
|
|
|
|
|
|
|
|
|
public ESide Side { get; set; } |
|
|
|
public Side Side { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
private int score; |
|
|
|
private int score; |
|
|
|
|
|
|
|
|
|
|
@ -18,15 +19,15 @@ namespace Game { |
|
|
|
protected float Speed => 10; |
|
|
|
protected float Speed => 10; |
|
|
|
|
|
|
|
|
|
|
|
// Unit distance from zero |
|
|
|
// Unit distance from zero |
|
|
|
private float Border => 7; |
|
|
|
private float Border => 10; |
|
|
|
|
|
|
|
|
|
|
|
private SpeedModification speedModification; |
|
|
|
private SpeedModification speedModification; |
|
|
|
private BorderModification borderModification; |
|
|
|
private BorderModification borderModification; |
|
|
|
|
|
|
|
|
|
|
|
protected float Width => transform.localScale.x; |
|
|
|
protected float Width => transform.localScale.x; |
|
|
|
|
|
|
|
|
|
|
|
private float LeftSide => X() - Width / 2; |
|
|
|
private float LeftEdge => X() - Width / 2; |
|
|
|
private float RightSide => X() + Width / 2; |
|
|
|
private float RightEdge => X() + Width / 2; |
|
|
|
|
|
|
|
|
|
|
|
protected float X() { |
|
|
|
protected float X() { |
|
|
|
return transform.position.x; |
|
|
|
return transform.position.x; |
|
|
@ -37,10 +38,10 @@ namespace Game { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void ClampInsideBorders() { |
|
|
|
protected void ClampInsideBorders() { |
|
|
|
if (LeftSide < -Border) |
|
|
|
if (LeftEdge < -Border) |
|
|
|
transform.Translate(Vector2.right * (-Border - LeftSide), Space.World); |
|
|
|
transform.Translate(Vector2.right * (-Border - LeftEdge), Space.World); |
|
|
|
if (RightSide > Border) |
|
|
|
if (RightEdge > Border) |
|
|
|
transform.Translate(Vector2.left * (RightSide - Border), Space.World); |
|
|
|
transform.Translate(Vector2.left * (RightEdge - Border), Space.World); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void TryLinearMove(float h) { |
|
|
|
protected void TryLinearMove(float h) { |
|
|
@ -52,16 +53,15 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
|
|
private void Start() { |
|
|
|
private void Start() { |
|
|
|
float y = Side switch { |
|
|
|
float y = Side switch { |
|
|
|
ESide.Bottom => BorderSize.Singleton.y1, |
|
|
|
Side.Bottom => BorderSize.Singleton.y1, |
|
|
|
ESide.Top => BorderSize.Singleton.y2, |
|
|
|
Side.Top => BorderSize.Singleton.y2, |
|
|
|
_ => throw new ArgumentOutOfRangeException() |
|
|
|
_ => throw new ArgumentOutOfRangeException() |
|
|
|
}; |
|
|
|
}; |
|
|
|
transform.position = new Vector2(0, y); |
|
|
|
transform.position = new Vector2(0, y); |
|
|
|
if (Side == ESide.Top) { |
|
|
|
if (Side == Side.Top) |
|
|
|
transform.Rotate(transform.forward, 180); |
|
|
|
transform.Rotate(transform.forward, 180); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class RealPlayer : Player { |
|
|
|
public class RealPlayer : Player { |
|
|
|
public bool isThisClient; |
|
|
|
public bool isThisClient; |
|
|
|