void CreateCarriers() { // TODO part of the extract configs, ensure scale is consistent float amplitude = scale.z * (10f * 0.8f); // TODO remove magic numbers float radian_ratio = (2 * Mathf.PI) / GameProperties.carriers; for (int i = 0; i < GameProperties.carriers; i++) { Transform prefab = Constants.isHumanPlayers[i] ? playerPrefab : opponentPrefab; Transform t = Instantiate(prefab, carrierOffsetY, Quaternion.identity); t.name = Constants.playerNames[i]; // TODO Make use of // Color c = playerColors[i]; float r = radian_ratio * i; Vector3 v = new Vector3(Mathf.Cos(r), 0f, Mathf.Sin(r)); t.position += v * amplitude; t.LookAt(carrierOffsetY); BallCarrier bc = t.GetComponent <BallCarrier>(); bc.currentLives = (int)Mathf.Max(GameProperties.lives, 1f); // TODO Lives change event listener? Calls code to handle respawn broadcast etc, carriers.Add(bc); carriersFree.Add(bc); //addFreeCarrierEvent(); } }
void ThrowTo(BallCarrier t) { if (isMoving) { Debug.Log("Can't throw the ball. Ball is already thrown."); return; } if (t.HasBall()) { Debug.Log("Can't throw the ball. Target has a ball already."); return; } if (Owner != null) { transform.position = Owner.transform.position + (Vector3.up * DEFAULT_BALL_HEIGHT); speed = Owner.throwStrength; } else { // Should only happens on force gives (i.e. carrier didnt throw) speed = BallProperties.speed; } target = t; Owner = target; isMoving = true; }
private void Start() { playerMovement = this.EnsureComponent <PlayerMovement>(); ballCarrier = this.EnsureComponent <BallCarrier>(); stateManager = this.EnsureComponent <PlayerStateManager>(); player = this.EnsureComponent <Player>(); stateManager.CallOnStateEnter(State.Posession, StartTimer); stateManager.CallOnStateExit( State.Posession, () => StopShootBallCoroutines()); GameManager.instance.notificationManager.CallOnMessageIfSameObject( Message.PlayerPressedShoot, OnShootPressed, gameObject); GameManager.instance.notificationManager.CallOnMessageIfSameObject( Message.PlayerReleasedShoot, OnShootReleased, gameObject); Ball ball = GameObject.FindObjectOfType <Ball>(); InitializeCircularIndicators(); // This is for team selection screen // In this situation, maxChargeShotTime is irrelevant => change it to // make later logic more elegant. NOTE: If removing this, also change // the comment above (by the declaration of maxChargeShotTime) if (maxChargeShotTime <= 0.0f) { maxChargeShotTime = forcedShotTime; } }
void Start() { rb = GetComponent <Rigidbody>(); rb.velocity = Vector3.zero; target = Vector3.zero; dir = Vector3.zero; self = GetComponent <BallCarrier>(); throwBallTimer = Random.Range(OpponentProperties.minThrowTimer, OpponentProperties.maxThrowTimer); }
private static IEnumerator WaitAndRespawn(BallCarrier dead, float waitTime) { yield return(new WaitForSeconds(waitTime)); print("WaitAndRespawn " + Time.time); UpdateMaxBallHunterCount(); CreateBallPool(); CreateHunterPool(); dead.Respawn(); }
public Rush(BallCarrier rusher, BaseDefender tackler, int yards, int yardsAfterContact, bool fumble, bool touchdown) { this.rusher = rusher; this.tackler = tackler; this.yards = yards; this.yardsAfterContact = yardsAfterContact; this.fumbles = fumble ? 1 : 0; this.touchdowns = touchdown ? 1 : 0; attempts = 1; }
public void Capture(BallHunter bh) { if (Owner != null) { GameLoop.carriersFree.Add(Owner); Owner.ball = null; } //bh.Precious = null; Owner = null; }
// Use this for initialization void Start() { rb = GetComponent <Rigidbody>(); rb.velocity = Vector3.zero; target = Vector3.zero; dir = Vector3.zero; self = GetComponent <BallCarrier>(); isMoving = false; isRotating = false; }
void OnTriggerExit(Collider other) { if (!ownerCollided || Precious == null) { return; } BallCarrier carrier = other.transform.GetComponent <BallCarrier>(); ownerCollided = !(carrier != null && carrier == Precious.Owner); //straightEnter = false; // probably not neccesary since resets in ontriggerenter }
public void RotatePlayer() { if (freezeRotation) { return; } Vector2 direction = lastDirection; if (direction != Vector2.zero) { // Only do if nonzero, otherwise [SignedAngle] returns 90 degrees // and player snaps to up direction if (instantRotation) { rb2d.rotation = Vector2.SignedAngle(Vector2.right, direction); } else { float maxAngleChange = Vector2.SignedAngle(transform.right, direction); float sign = Mathf.Sign(maxAngleChange); float speedChange = rotationSpeed * Time.deltaTime; float actualChange = sign * Mathf.Min(Mathf.Abs(maxAngleChange), speedChange); float finalRotation = rb2d.rotation + actualChange; if (finalRotation <= 0) { finalRotation = 360 - Mathf.Repeat(-finalRotation, 360); } finalRotation = Mathf.Repeat(finalRotation, 360); BallCarrier ballCarrier = GetComponent <BallCarrier>(); if (ballCarrier != null && ballCarrier.Ball != null && (Time.time - ballCarrier.timeCarryStarted) >= minBallForceRotationTime) { Ball ball = ballCarrier.Ball; Vector3 ballDirection = (ball.transform.position - transform.position).normalized; Vector3 unitFinal = Quaternion.AngleAxis(finalRotation, Vector3.forward) * Vector2.right; float angleDifference = Vector2.SignedAngle(ballDirection, unitFinal); if (Mathf.Abs(angleDifference) >= maxAwayFromBallAngle) { finalRotation = Vector2.SignedAngle(Vector2.right, ballDirection) + Mathf.Sign(angleDifference) * maxAwayFromBallAngle; } } if (finalRotation <= 0) { finalRotation = 360 - Mathf.Repeat(-finalRotation, 360); } finalRotation = Mathf.Repeat(finalRotation, 360); rb2d.rotation = finalRotation; } } }
void OnTriggerEnter(Collider other) { if (other.tag == "Player" && !rigid.isKinematic && hasAuthority) { BallCarrier _carrier = other.GetComponent <BallCarrier>(); Shooting shooty = other.GetComponent <Shooting>(); if (_carrier && shooty && !shooty.dead) { _carrier.CmdCarry(gameObject); carrier = _carrier; } } }
private void Start() { playerMovement = this.EnsureComponent <PlayerMovement>(); rb = this.EnsureComponent <Rigidbody2D>(); stateManager = this.EnsureComponent <PlayerStateManager>(); carrier = this.EnsureComponent <BallCarrier>(); tronMechanic = this.EnsureComponent <PlayerTronMechanic>(); cameraShake = GameObject.FindObjectOfType <CameraShake>(); GameManager.instance.notificationManager.CallOnMessageIfSameObject( Message.PlayerPressedDash, DashPressed, this.gameObject); GameManager.instance.notificationManager.CallOnMessageIfSameObject( Message.PlayerReleasedDash, ChargeReleased, this.gameObject); }
void OwnerChanged() // this could change signature to accept Owner param { Debug.Log("My precious has changed owners or has been claimed."); BallCarrier bc = Precious.Owner; if (bc != null) { target = bc.transform; //targetRb = target.GetComponent<Rigidbody>(); } else { StopChasePrecious(); Precious = null; // will null target } }
public static BallCarrier GetFreeBallCarrier() { // TODO Can change to random index or based on scores if (carriersFree.Count > 0) { BallCarrier bc = carriersFree[0]; carriersFree.Remove(bc); //removeFreeCarrierEvent(); return(bc); } else { Debug.Log("No free carriers!"); return(null); } }
//public bool straightAngle; //public bool momentumCheck; void OnTriggerEnter(Collider other) { //if (other.tag == "Wall") rb.velocity = -rb.velocity * 0.3f; // lose some speed if (ownerCollided || Precious == null) { return; } BallCarrier carrier = other.transform.GetComponent <BallCarrier>(); ownerCollided = carrier != null && carrier == Precious.Owner; //if(ownerCollided) //{ // //straightEnter = Vector3.Dot(Precious.Owner.transform.position, transform.forward) > 1f - straightAngleThreshold; // Debug.Log(Quaternion.Angle(transform.rotation, Quaternion.LookRotation(Precious.Owner.transform.position))); // straightEnter = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(Precious.Owner.transform.position)) < straightAngleThreshold; //} }
public void ResetBall(float?lengthOfEffect = null) { // Reset values circleCollider.enabled = true; renderer.enabled = true; SetSpriteToNeutral(); transform.position = start_location; trailRenderer.enabled = false; Ownable = true; rigidbody.velocity = Vector2.zero; Owner = null; LastOwner = null; // Start Spawn effect if (lengthOfEffect != null) { StartCoroutine(ImplosionEffect(lengthOfEffect.Value)); } }
// Use this for initialization private void Start() { rb2d = this.EnsureComponent <Rigidbody2D>(); stateManager = this.EnsureComponent <PlayerStateManager>(); player = this.EnsureComponent <Player>(); // TODO dkonik: Remove this dependency on ball carrier ballCarrier = this.EnsureComponent <BallCarrier>(); GameManager.NotificationManager.CallOnMessageWithSender( Message.PlayerStick, playerPair => { Tuple <Vector2, GameObject> pair = playerPair as Tuple <Vector2, GameObject>; GameObject player = pair?.Item2; if (pair != null && this != null && player == this.gameObject) { eventSent = true; lastDirection = pair.Item1; } }); stateManager.OnStateChange += HandleNewPlayerState; goal = GameObject.FindObjectOfType <GoalAimPoint>()?.gameObject; this.FrameDelayCall(() => { TeamManager team = player.Team; if (team == null) { return; } foreach (Player teammate in team.teamMembers) { if (teammate != player) { this.teammate = teammate.gameObject; } } }, 2); // Subscribe to events GameManager.NotificationManager.CallOnMessage(Message.SlowMoEntered, HandleSlowMo); GameManager.NotificationManager.CallOnMessage(Message.SlowMoExited, HandleSlowMo); }
void HandleInput() { if (self.HasBall()) { if (throwBallTimer > 0) { throwBallTimer -= Time.deltaTime; } else if (throwBallTimer <= 0) { BallCarrier t = GameLoop.GetFreeBallCarrier(); if (t != null) { self.SendMessage("ThrowBall", t); throwBallTimer = Random.Range(OpponentProperties.minThrowTimer, OpponentProperties.maxThrowTimer); } } } }
void ThrowBall(BallCarrier target) { if (!HasBall()) // what about sendmessage just not being able to find listener { Debug.Log("Can't throw the ball. No ball to throw!"); return; } if (target.HasBall()) { Debug.Log("Can't throw the ball. Target has a ball already!"); return; } if (ball.Owner != this) { Debug.Log("Can't throw the ball. Have not caught it yet!"); return; } ball.SendMessage("ThrowTo", target); // pass strength parameter here? and change owner here? ball = null; }
void HandleInput() { if (Input.GetMouseButton(1) || Input.GetMouseButtonUp(1)) // Right click up event { Vector3 result = GetWorldPositionOnPlane(Input.mousePosition, Camera.main.transform.position.z); if (result != null) { target = result; target.y = transform.position.y; dir = Vector3.Normalize(target - transform.position); isMoving = true; isRotating = true; } } if (Input.GetMouseButtonUp(0)) { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit, LayerMask.GetMask("Opponents"))) { // Use sendmessage to check these things instead? if (hit.rigidbody != null) // check it is also tagged "Opponent"? Redundant? { BallCarrier throwTarget = hit.rigidbody.transform.GetComponent <BallCarrier>(); if (throwTarget != null) { Debug.Log(throwTarget.transform.name); self.SendMessage("ThrowBall", throwTarget); } else { Debug.Log("That's not a BallCarrier."); } } } } }
public static void KillAndRespawnIfHaveLife(BallCarrier dead) { dead.currentLives -= 1; numLivesLeft -= 1; if (dead.currentLives == 0) { // cant respawn Debug.Log("Player Defeated!"); numPlayersLeft -= 1; // KILL IT WITH FIRE!!! carriersFree.Remove(dead); // not sure if its actually in there right now if (Constants.isHumanPlayers[carriers.IndexOf(dead)]) { Debug.Log("Player is elimiated!"); endText.gameObject.SetActive(true); } carriers.Remove(dead); carriersFree.Remove(dead); carriersDead.Add(dead); dead.GetComponent <MeshRenderer>().enabled = false; // hidden //Destroy(dead.gameObject); // conseqs of this? if (carriers.Count == 1) // game over! last man wins! { Debug.Log(carriers[0] + " wins!"); return; } } else { dead.StartCoroutine(WaitAndRespawn(dead, 2f)); // TODO Extract wait to config constant } // dead guy shouldnt be doing things! some portal object maybe? // fix so we dont pass dead twice dead.StartCoroutine(WaitGiveChaseBalls(4f)); // TODO Extract wait to config constant }
private void Start() { playerMovement = this.EnsureComponent <PlayerMovement>(); ballCarrier = this.EnsureComponent <BallCarrier>(); stateManager = this.EnsureComponent <PlayerStateManager>(); player = this.EnsureComponent <Player>(); GameManager.NotificationManager.CallOnMessageIfSameObject( Message.PlayerPressedShoot, OnShootPressed, gameObject); GameManager.NotificationManager.CallOnMessageIfSameObject( Message.PlayerReleasedShoot, OnShootReleased, gameObject); stateManager.OnStateChange += HandleNewPlayerState; InitializeCircularIndicators(); // This is for team selection screen // In this situation, maxChargeShotTime is irrelevant => change it to // make later logic more elegant. NOTE: If removing this, also change // the comment above (by the declaration of maxChargeShotTime) if (maxChargeShotTime <= 0.0f) { maxChargeShotTime = forcedShotTime; } }
static void GiveFreeBalls() { // TODO Send out no more than MAX count (will allow decrease over time) int extraBalls = balls.Count - maxBallCount; for (int i = ballsFree.Count - 1; i >= 0; i--) { if (extraBalls > 0) { extraBalls--; Ball extra = ballsFree[i]; balls.Remove(extra); ballsFree.RemoveAt(i); } if (ballsFree[i].Owner != null) { // do anything here? return; } Ball b = ballsFree[i]; BallCarrier bc = GetFreeBallCarrier(); // FIXME Null pointer exception if no free carrier if (bc != null) { //b.transform.position = bc.transform.position; // undo the hiding! b.SendMessage("ThrowTo", bc); if (b.Owner != null) { // we dont want to say that the ball cant be hunted //ballsFree.RemoveAt(i); //removeFreeBallEvent(); } } } }
private Color ColorFromBallCarrier(BallCarrier carrier) { TeamManager carrierTeam = carrier.EnsureComponent <Player>().team; return(carrierTeam != null ? carrierTeam.teamColor.color : Color.white); }
// Use this for initialization void Awake() { cam = GetComponentInChildren <Camera>(); movement = GetComponent <FirstPersonController>(); carrier = GetComponent <BallCarrier>(); }
private Ball TrySteal(Player otherPlayer) { BallCarrier otherCarrier = otherPlayer.gameObject.GetComponent <BallCarrier>(); return(otherCarrier?.Ball); }