public void SetPowerup(GameUtil.Powerup powerup, int index) { this.powerup = powerup; this.index = index; if (powerup == GameUtil.Powerup.NONE) { this.gameObject.SetActive(false); return; } this.gameObject.SetActive(true); this.gameObject.transform.SetPositionAndRotation( GameUtil.ToBoardSpace(index), Quaternion.identity); if (powerup == GameUtil.Powerup.COMPRESS) { spriteRenderer.sprite = compressSprite; } else if (powerup == GameUtil.Powerup.FREEZE) { spriteRenderer.sprite = freezeSprite; } else if (powerup == GameUtil.Powerup.DELETE) { spriteRenderer.sprite = deleteSprite; } }
private bool TryGrabPowerup(out GameUtil.Powerup grabbedPowerup) { if (powerupPiece.GetPowerup() == GameUtil.Powerup.NONE || playerIndex != powerupPiece.GetIndex()) { grabbedPowerup = GameUtil.Powerup.NONE; return(false); } // Party time! grabbedPowerup = powerupPiece.GetPowerup(); powerupPiece.SetPowerup(GameUtil.Powerup.NONE, 0); return(true); }
private void RunPowerup(GameUtil.Powerup p) { StartPowerup(); if (p == GameUtil.Powerup.FREEZE) { soundManager.audioSource.PlayOneShot(soundManager.freeze); freezeTimer = freezeTimerAmount; EndPowerup(); } else if (p == GameUtil.Powerup.DELETE) { StartCoroutine(DeletePowerup()); } else if (p == GameUtil.Powerup.COMPRESS) { soundManager.audioSource.PlayOneShot(soundManager.compress); StartCoroutine(CompressPowerup()); } else { EndPowerup(); } }
private void RunGame() { GameUtil.Powerup grabbedPowerup = GameUtil.Powerup.NONE; if (!DropsPaused()) { dropTimer = dropTimer - Time.deltaTime; deleteTimer = deleteTimer - Time.deltaTime; } suckTimer = suckTimer - Time.deltaTime; powerupTimer = powerupTimer - Time.deltaTime; powerupExpiry = powerupExpiry - Time.deltaTime; freezeTimer = freezeTimer - Time.deltaTime; debounceTimer = debounceTimer + Time.deltaTime; if (powerupTimer < 0) { powerupTimer = GetNewPowerUpTimer(); powerupExpiry = powerupExpiryLimit; GameUtil.Powerup choice = (GameUtil.Powerup)(r.Next(GameUtil.NumPowerups()) + 1); int index = r.Next(GameUtil.BOARD_SIZE); powerupPiece.SetPowerup(choice, index); } if (powerupExpiry < 0 && powerupPiece.GetPowerup() != GameUtil.Powerup.NONE) { powerupPiece.SetPowerup(GameUtil.Powerup.NONE, 0); } if (dropTimer < 2 && previewPiece.GetCurrentPiece() == null) { previewPiece.SetPiece(CreateRandomPiece()); } if (deleteTimer < 4 && flaggedPiece == null) { if (pieces.Count == 0) { deleteTimer = deleteTimerLimit; } else { Piece choice = pieces[r.Next(pieces.Count)]; if (!choice.Locked) { soundManager.audioSource.PlayOneShot(soundManager.preDelete); flaggedPiece = choice; flaggedPiece.Flagged = true; } } } int presses = 0; while (debounceTimer - .05f > .25f) { presses++; debounceTimer -= .05f; } if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)) { debounceTimer = 0; MovePlayer(-GameUtil.BOARD_WIDTH); ghostPiece.Adjust(-GameUtil.BOARD_WIDTH); } else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { MovePlayer(-presses * GameUtil.BOARD_WIDTH); ghostPiece.Adjust(-presses * GameUtil.BOARD_WIDTH); } if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) { debounceTimer = 0; MovePlayer(GameUtil.BOARD_WIDTH); ghostPiece.Adjust(GameUtil.BOARD_WIDTH); } else if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { MovePlayer(presses * GameUtil.BOARD_WIDTH); ghostPiece.Adjust(presses * GameUtil.BOARD_WIDTH); } if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) { debounceTimer = 0; MovePlayer(1); ghostPiece.Adjust(1); } else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { MovePlayer(presses); ghostPiece.Adjust(presses); } if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) { debounceTimer = 0; MovePlayer(-1); ghostPiece.Adjust(-1); } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { MovePlayer(-presses); ghostPiece.Adjust(-presses); } if (Input.GetKeyDown(KeyCode.Space)) { if (!TryGrabPowerup(out grabbedPowerup) && !powerupActive) { PickUpOrDrop(); // Abandoned mechanic! // if (ghostPiece.GetCurrentPiece() == null) { // SuckInPieces(true); // } } } else if (Input.GetKey(KeyCode.Space) && ghostPiece.GetCurrentPiece() == null) { // SuckInPieces(false); } if (ghostPiece.GetCurrentPiece() != null) { player.gameObject.SetActive(false); ghostPiece.gameObject.SetActive(true); } else { player.gameObject.SetActive(true); ghostPiece.gameObject.SetActive(false); } DrawBoard(); if (!droppingBoard) { MaybeDropBoard(); } if (grabbedPowerup != GameUtil.Powerup.NONE) { RunPowerup(grabbedPowerup); } if (dropTimer < 0 && !DropsPaused()) { dropTimer = dropTimerLimit; if (!AddPiece(previewPiece.GetCurrentPiece())) { LoadGameOver(); } else { previewPiece.SetPiece(null); } } if (deleteTimer < 0 && !DropsPaused()) { deleteTimer = deleteTimerLimit; if (flaggedPiece == null) { // Anything? } else if (flaggedPiece.Locked) { // Lucky you! flaggedPiece.Flagged = false; flaggedPiece = null; } else { soundManager.audioSource.PlayOneShot(soundManager.delete); DeletePiece(flaggedPiece); flaggedPiece = null; } } }