public void SetUp() { _game = new Game(); _gameObject = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarRed.prefab", typeof(GameObject))) as GameObject; if (_gameObject == null) return; _autoBehaviour = _gameObject.AddComponent<CarBehaviour>(); _car = new Car(_autoBehaviour); _gameObjectOther = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarBlue.prefab", typeof(GameObject))) as GameObject; if (_gameObjectOther == null) return; _gameObjectOther.AddComponent<CarBehaviour>(); _carOther = new Car(_gameObjectOther.GetComponent<CarBehaviour>()); List<Car> cars = new List<Car>(); for (int i = 0; i < GameData.CARS_AMOUNT; i++) { Car c = new Car(_autoBehaviour); cars.Add(c); } MainScript.Cars = cars; MainScript.SelfCar = new Car { CarObject = _autoBehaviour }; }
public void SetUp() { _midScreenWidth = (float)Screen.width / 2; _driver = new Driver(); NetworkView = new Mock<INetworkView>(); NetworkViewOther = new Mock<INetworkView>(); _gameObject = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarRed.prefab", typeof(GameObject))) as GameObject; if (_gameObject == null) return; _autoBehaviour = _gameObject.AddComponent<CarBehaviour>(); _autoBehaviour.NetworkView = NetworkView.Object; _gameObjectOther = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarBlue.prefab", typeof(GameObject))) as GameObject; if (_gameObjectOther == null) return; _autoBehaviourOther = _gameObjectOther.AddComponent<CarBehaviour>(); _autoBehaviourOther.NetworkView = NetworkViewOther.Object; _carDriver = new Car(_autoBehaviour); _player = new Player(_carDriver, _driver); _carOther = new Car(_autoBehaviourOther); _gameObjectCountDownController = GameObject.CreatePrimitive(PrimitiveType.Cube); _countdownController = _gameObjectCountDownController.AddComponent<CountdownController>(); MainScript.SelfPlayer = new Player { Role = new Driver() }; MainScript.SelfCar = _carDriver; }
public void PositionUpdated(CarBehaviour carObj, bool isSelf) { if (!isSelf) { return; } MoveCameraWithCar(carObj); }
public static float GetAccelerationFactor(PlayerAction action, CarBehaviour carObj) { if (action == PlayerAction.SpeedUp) { return carObj.Speed < 0 ? 10 : 5; } return action == PlayerAction.SpeedDown ? (carObj.Speed < 0 ? 10 : 50) : 0; }
public void HandleCollision(CarBehaviour carObj, Collision2D collision) { if (collision.gameObject.tag == GameData.TAG_FINISH) { CollisionFinishEnd(carObj); } else { CollisionEdge(carObj, collision); } }
public void SetUp() { _restartButtonPart = new RestartButtonPart(); _gameObject = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarRed.prefab", typeof(GameObject))) as GameObject; _networkViewMock = new Mock<INetworkView>(); if (_gameObject == null) return; _autoBehaviour = _gameObject.AddComponent<CarBehaviour>(); _car = new Car(_autoBehaviour) { CarObject = { NetworkView = _networkViewMock.Object } }; }
public void HandleTrigger(CarBehaviour carObj, Collider2D collider) { if (collider.tag == GameData.TAG_FINISH) { CollisionFinish(carObj); } else if (collider.tag == GameData.TAG_MUD) { CollisionMud(carObj); } }
public void SetUp() { _gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); _networkController = _gameObject.AddComponent<NetworkController>(); _carBehaviour = _gameObject.AddComponent<CarBehaviour>(); _server = _gameObject.AddComponent<Server>(); NetworkView = new Mock<INetworkView>(); _networkController.NetworkView = NetworkView.Object; _carBehaviour.NetworkView = NetworkView.Object; MainScript.NetworkController = _networkController; }
public void SetUp() { _car = new Car(); _gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); _autoBehaviour = _gameObject.AddComponent<CarBehaviour>(); _carAutoBehaviour = new Car(_autoBehaviour); _carCarNumber = new Car(0); _driverRole = new Driver(); _throttlerRole = new Throttler(); _driver = new Player(); _throttler = new Player(); _driver.Role = _driverRole; _throttler.Role = _throttlerRole; }
public void SetupServer() { _networkPlayer = new NetworkPlayer(); _gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); _testServer = _gameObject.AddComponent<Server>(); _carObject = _gameObject.AddComponent<CarBehaviour>(); Network = new Mock<INetwork>(); NetworkView = new Mock<INetworkView>(); _testServer.Game = new Game(); _testServer.Network = Network.Object; _testServer.StartServer(); _testServer.NetworkView = NetworkView.Object; _carObject.NetworkView = NetworkView.Object; var cars = new List<Car>(); for (var i = 0; i < GameData.CARS_AMOUNT; i++) { var c = new Car(_carObject); cars.Add(c); } MainScript.Cars = cars; }
public void Setup() { NetworkView = new Mock<INetworkView>(); _gameObject = Object.Instantiate(Resources.LoadAssetAtPath("Assets/CarRed.prefab", typeof(GameObject))) as GameObject; if (_gameObject != null) { _autoBehaviour = _gameObject.AddComponent<CarBehaviour>(); _gameObject.GetComponent<CarBehaviour>().NetworkView = NetworkView.Object; } var cars = new List<Car>(); for (var i = 0; i < GameData.CARS_AMOUNT; i++) { _autoBehaviour.NetworkView = NetworkView.Object; var c = new Car(_autoBehaviour); cars.Add(c); } MainScript.Cars = cars; MainScript.SelfCar = new Car { CarObject = _autoBehaviour }; MainScript.SelfPlayer = new Player { Role = new Driver() }; }
private void HandleCollisionAngle(CarBehaviour carObj, float angle) { if (90 - GameData.MINIMUM_SLIDE_ANGLE <= angle && angle <= 90 + GameData.MINIMUM_SLIDE_ANGLE) { if (carObj.Speed < 0) { carObj.Speed = Mathf.Min(0, carObj.Speed + GameData.SLIDE_SLOWDOWN); } else { carObj.Speed = Mathf.Max(0, carObj.Speed - GameData.SLIDE_SLOWDOWN); } } else { BounceCollision(carObj); } }
private void ControlPlayerSpeed(CarBehaviour carObj) { PlayerAction action = GetPlayerAction(); ApplySpeed(carObj, Action.GetAccelerationIncrease(action), Action.GetAccelerationFactor(action, carObj)); if (action != PlayerAction.SpeedUp && action != PlayerAction.SpeedDown) { HandleSpeed(carObj); } }
private void rotateCar(CarBehaviour carObj, float rotateFactor) { float angle = rotateFactor * MathUtils.ForceInInterval(carObj.Speed * 3f, -3, 3); carObj.transform.Rotate(new Vector3(0, 0, angle)); carObj.RotationUpdated(); }
private void HandleSpeed(CarBehaviour carObj) { if (carObj.Speed > 0) { ApplyFriction(carObj, -GameData.FRICTION_AMOUNT); } else if (carObj.Speed < 0) { ApplyFriction(carObj, GameData.FRICTION_AMOUNT); } else { carObj.Acceleration = 0f; } }
public void RotationUpdated(CarBehaviour carObj, bool isSelf) { NormalizeChild(carObj); }
public void RotationUpdated(CarBehaviour carObj, bool isSelf) { }
public void HandleTrigger(CarBehaviour carObj, Collider2D collider) { }
private void CollisionFinishEnd(CarBehaviour carObj) { carObj.Speed = 0; carObj.Acceleration = 0; }
public void HandleCollision(CarBehaviour carObj, Collision2D collision) { }
public void HandlePlayerAction(CarBehaviour carObj) { PlayerAction action = GetPlayerAction(); rotateCar(carObj, Time.deltaTime * Action.GetRotationSpeedFactor(action)); }
private void CollisionFinish(CarBehaviour carObj) { foreach (Car car in MainScript.Cars) { car.CarObject.NetworkView.RPC("notifyHasFinished", RPCMode.All, carObj.CarNumber, (float)TimeController.GetInstance().GetTime()); } }
// Since the sphere child of a car rotates along, and the midpoint of rotation // is not the midpoint of the sphere, the sphere has to be rotated back so that // only the position is synchronized with the car. private void NormalizeChild(CarBehaviour carObj) { GameObject child = carObj.GetChild(GameData.NAME_SPHERE); Transform carTransform = carObj.transform; float angle = Mathf.Deg2Rad * carTransform.rotation.eulerAngles.z; Vector3 normalizedVec = MathUtils.Vector2To3(MathUtils.Rotate(new Vector2(25f / 0.2f, 0f), Vector2.zero, -angle)); normalizedVec.y *= 2f; normalizedVec.z = -0.3f; child.transform.localPosition = normalizedVec; }
// Create Car with crtain CarBehaviour public Car(CarBehaviour gameObject) { CarObject = gameObject; }
private void CollisionMud(CarBehaviour carObj) { if (carObj.Speed > GameData.MAX_SPEED * GameData.MUD_SLOWDOWN_FACTOR) { carObj.Speed = 0; } }
public void MoveCameraWithCar(CarBehaviour carObj) { Camera.main.transform.position = carObj.transform.position; Camera.main.transform.Translate(new Vector3(0f, 0f, -1f)); }
public void SetUp() { _gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); _carBehaviour = _gameObject.AddComponent<CarBehaviour>(); }
private void MoveCar(CarBehaviour carObj) { carObj.transform.Translate(carObj.Speed * Time.deltaTime * 4f, 0, 0); carObj.PositionUpdated(); }
private void CollisionEdge(CarBehaviour carObj, Collision2D collision) { Vector2 normal = collision.contacts[0].normal; float a = MathUtils.CalculateAngle(normal) * Mathf.Rad2Deg; float b = carObj.transform.rotation.eulerAngles.z % 360; a = (a + 360) % 180; b = (b + 360) % 180; if (carObj.Speed < 0) { b = 180 - b; } float d = Math.Abs(a - b); HandleCollisionAngle(carObj, d); }
public void HandlePlayerAction(CarBehaviour carObj) { ControlPlayerSpeed(carObj); MoveCar(carObj); }