void TryGrab() { int resultsCount = Physics2D.OverlapCircleNonAlloc(this.transform.position, this.GrabRadius, _grabResults, GrabbableItemMask); for (int i = 0; i < resultsCount; i++) { Grabbable p = _grabResults[i].GetComponent <Grabbable>(); if (p == null || p.gameObject == this.gameObject) { continue; } if (p.IsHeld == false) { RatPlayer player = p.GetComponent <RatPlayer>(); if (player != null && player.Dead == true) { continue; } p.Grab(this); this._heldItem = p; SetState(State.Holding); //Debug.Log("Grab"); break; } } }
public void Respawn(RatPlayer rp, float delay = 0f) { this._myRatPlayer = rp; if (rp.Dead) { } else { rp.gameObject.SetActive(false); } StartCoroutine(RespawnRoutine(delay)); }
private void Update() { RatPlayer winner = GameState.Winner; if (winner == null) { return; } bool lookAtNull = this.Camera.LookAt == null; this.Camera.Follow = winner.transform; }
private void CreateContext() { //Initialize PLayers Pinky = new RatPlayer(); Pinky.Score = 0; Pinky.LetterOfIdentification = 'P'; Brain = new RatPlayer(); Brain.Score = 0; Brain.LetterOfIdentification = 'B'; //read map from file string path = @"resources\Pinkyandthebrain.maze"; string[] lines = System.IO.File.ReadAllLines(path); Matrix = new List <List <char> >(); for (int i = 0; i < lines.Length; i++) { Matrix.Add(new List <char>());//for each i add a line to Matrix char[] CharsInCurrentLine = lines[i].ToCharArray(); for (int j = 0; j < CharsInCurrentLine.Length; j++) { Matrix[i].Add(CharsInCurrentLine[j]); // populate matrix with content of map //calculate number of total sprouts on map if (CharsInCurrentLine[j] == SproutElement) { remainingSprouts++; } if (CharsInCurrentLine[j] != SproutElement && CharsInCurrentLine[j] != WallEleemet) // if character is neither a sprout, neither a wall { if ((Brain.LineIndex != 0 & Brain.ColumnIndex != 0) && (Pinky.LineIndex == 0 & Pinky.ColumnIndex == 0)) // set position of Pinky on first empthy character { Matrix[i][j] = Pinky.LetterOfIdentification; Pinky.LineIndex = i; Pinky.ColumnIndex = j; } if (Brain.LineIndex == 0 & Brain.ColumnIndex == 0) // set position of Brain on first empthy character { Matrix[i][j] = Brain.LetterOfIdentification; Brain.LineIndex = i; Brain.ColumnIndex = j; } } } } }
public static RatPlayer FindCurrentWinner() { RatPlayer winner = null; int highestScore = int.MinValue; bool tie = false; foreach (RatPlayer player in _players) { player.GetComponent <RatBrain>().SetCrownWinner(false); } foreach (RatPlayer player in _players) { if (PlayerManager.Instance.IsPlaying(player.PlayerID) == false) { continue; } if (player.Score > highestScore) { tie = false; winner = player; highestScore = player.Score; } else if (player.Score == highestScore) { tie = true; } } foreach (RatPlayer player in _players) { if (player.Score == highestScore) { player.GetComponent <RatBrain>().SetCrownWinner(true); } } if (tie) { return(null); } return(winner); }
protected override void EnterState(State nextState) { Debug.Log(nextState); StartView?.Toggle(nextState == State.GameStart); GameplayView?.Toggle(nextState == State.InGame); WinnerView?.Toggle(nextState == State.VictoryScreen); switch (nextState) { case State.GameStart: AudioManager.Instance.Mixer.FindSnapshot("Title").TransitionTo(0.2f); PlayerManager.Instance.Reset(); PlayerManager.Instance.Locked = false; RatPlayer.ResetAllPlayers(); AudioManager.Instance.PlaySong(AudioManager.Song.Main); break; case State.InGame: AudioManager.Instance.Mixer.FindSnapshot("Gameplay").TransitionTo(1f); GameTimer = _gameDuration; _timerRunning = false; RatPlayer.SetupPlayersForPlay(ShipDelay); foreach (var go in GameObject.FindGameObjectsWithTag("Item")) { PoolManager.ReleaseObject(go); } StartCoroutine(StartDirectorRoutine()); SpawnManager.Instance.SpawningActive = false; AudioManager.Instance.PlaySound(WelcomeSFX.GetRandom(), this.transform.position, AudioManager.MixerGroup.Announcer, 1f); break; case State.VictoryScreen: AudioManager.Instance.Mixer.FindSnapshot("Title").TransitionTo(0.2f); StartCoroutine(VictoryScreenDelay()); WinnerDirector.gameObject.SetActive(true); AudioManager.Instance.PlaySong(AudioManager.Song.Nothing); AudioManager.Instance.PlaySound(WinnerSFX.GetRandom(), this.transform.position, AudioManager.MixerGroup.Announcer, 1f); break; default: break; } }
public void MovePlayerInMatrix(RatPlayer player, int futureLineIndex, int futureColumnIndex) { char affectedElement = Matrix[futureLineIndex][futureColumnIndex]; //get the below element if (affectedElement != WallEleemet) //check the above element { Matrix[futureLineIndex][futureColumnIndex] = player.LetterOfIdentification; Matrix[player.LineIndex][player.ColumnIndex] = '='; player.LineIndex = futureLineIndex; player.ColumnIndex = futureColumnIndex; if (affectedElement == SproutElement) { player.Score++; remainingSprouts--; } } }
void Awake() { _animator = GetComponent <Animator>(); _controller = GetComponent <RatController>(); _player = GetComponent <RatPlayer>(); _yeeter = GetComponent <Yeeter>(); _ratPlayer = GetComponent <RatPlayer>(); _ratCalculator = GetComponent <RatCalculator>(); _grabbable = GetComponent <Grabbable>(); _grabbable.OnGrabCallback += this.OnGrab; _grabbable.OnReleaseCallback += this.OnRelease; _myRigidbody = GetComponent <Rigidbody2D>(); // listen to some events for illustration purposes _controller.onControllerCollidedEvent += onControllerCollider; _controller.onTriggerEnterEvent += OnTriggerEnterEvent; _controller.onTriggerExitEvent += OnTriggerExitEvent; crownSprite.enabled = false; }
private void Awake() { _brain = GetComponent <RatBrain>(); _playerID = GetComponent <RatPlayer>().PlayerID; _ratPlayer = GetComponent <RatPlayer>(); }
private void OnCollisionEnter2D(Collision2D collision) { if (IsHeld == true) { return; } if (IsPlayer) { RatBrain brain = GetComponent <RatBrain>(); if (brain.IsYote == false) { return; } } if (_killMode == true) { Debug.Log("killhit " + collision.collider.gameObject.name); } if (collision.collider.CompareTag("Player") && _killMode && Kills) { RatPlayer yeeter = this.LastYeeter.GetComponent <RatPlayer>(); RatPlayer hit = collision.collider.GetComponent <RatPlayer>(); hit.Kill(); if (hit != yeeter) { yeeter.AwardPoint(); } Cinemachine.CinemachineImpulseSource impulse = GetComponent <Cinemachine.CinemachineImpulseSource>(); impulse?.GenerateImpulse(this.MyRigidbody.velocity); AudioManager.Instance.PlaySound(HitSFX, this.transform.position); if (!IsPlayer) { PoolManager.Instance.releaseObject(this.gameObject); } Cloud.Spawn(collision.contacts[0].point, Cloud.Size.Large); _killMode = false; } else { if (_killMode) { AudioManager.Instance.PlaySound(HitGroundSFX, collision.contacts[0].point, AudioManager.MixerGroup.SFX, 0.8f); Cloud.Spawn(collision.contacts[0].point, Cloud.Size.Small); } _killMode = false; } if (SpinOnThrow) { this.Animator?.Play("ItemSpin"); } else { this.Animator?.Play("ItemIdle"); } if (collision.collider.CompareTag("Planet")) { var r2d = GetComponent <Rigidbody2D>(); r2d.velocity = Vector3.zero; r2d.Sleep(); } if (IsPlayer) { ReleaseAndSetKinematic(); } }
private void Update() { if (Rewired.ReInput.players.GetPlayer(0).GetButtonDoublePressDown("Exit")) { Application.Quit(); } //update logic switch (this._currentState) { case State.GameStart: //poll player manager to see if we're readied up if (PlayerManager.Instance.IsAllReady()) { //timer for a short delay before setting state StartDelay -= Time.deltaTime; Debug.Log(StartDelay.ToString("0.0")); if (StartDelay <= 0f) { this.SetState(State.InGame); } this.Countdown.gameObject?.SetActive(true); } else { //if not readied, reset timer StartDelay = StartDelayDuration; this.Countdown.gameObject?.SetActive(false); } break; case State.InGame: if (_timerRunning) { GameTimer -= Time.deltaTime; } if (GameTimer <= 0f) { var winner = RatPlayer.FindCurrentWinner(); Winner = winner; if (winner != null) { SetState(State.VictoryScreen); } else { if (SuddenDeathDirector.gameObject.activeSelf == false) { AudioManager.Instance.PlaySound(this.SuddenDeathSFX.GetRandom(), this.transform.position, AudioManager.MixerGroup.Announcer, 1f); } SuddenDeathDirector.gameObject.SetActive(true); } } break; case State.VictoryScreen: break; default: break; } }
public static void Spawn(RatPlayer rp, float delay = 0f) { GameObject ship = PoolManager.SpawnObject(rp.MyShip); ship.GetCreateComponent <RatShipRespawner>().Respawn(rp, delay); }