public void Equip(Equipment newItem) { if (Player.name == "Player1") { Subtitles.AddPlayer1Subtitle("Equipped " + newItem.name); } else { Subtitles.AddPlayer2Subtitle("Equipped " + newItem.name); } newItem.equipmentManager = this; int slotIndex = (int)newItem.equipSlot; int index = inventory.items.IndexOf(newItem); Equipment oldItem = null; if (currentEquipment[slotIndex] != null) { oldItem = currentEquipment[slotIndex]; inventory.Add(oldItem); } if (onEquipmentChanged != null) { onEquipmentChanged.Invoke(newItem, oldItem); } if (newItem.weaponID > -1) { weaponPossession.weaponID = newItem.weaponID; } currentEquipment[slotIndex] = newItem; equipmentUI.equipmentSlotDisplays[slotIndex].equipmentIcon.enabled = true; equipmentUI.equipmentSlotDisplays[slotIndex].equipmentIcon.sprite = currentEquipment[slotIndex].icon; equipmentUI.equipmentSlotDisplays[slotIndex].itemName.text = currentEquipment[slotIndex].name; if (newItem.stackable) { equipmentUI.equipmentSlotDisplays[slotIndex].numberOfItemsInStack.text = inventory.itemsInSlot[index].ToString(); } else { equipmentUI.equipmentSlotDisplays[slotIndex].numberOfItemsInStack = null; } }
void Update() { scoreText.text = "Score: " + score.ToString(); if (this == pl1Score1 || this == pl2Score1) { if (weaponScore >= changeWeaponAtWeaponScore) { int prevWeaponId = player.GetComponent <PlayerController>().weaponPossession.weaponID; player.GetComponent <PlayerController>().weaponPossession.weaponID = Random.Range(0, 4); if (player.GetComponent <PlayerController>().weaponPossession.weaponID == prevWeaponId) { if (prevWeaponId > 0) { player.GetComponent <PlayerController>().weaponPossession.weaponID--; } else if (prevWeaponId < 3) { player.GetComponent <PlayerController>().weaponPossession.weaponID++; } } weaponScore -= changeWeaponAtWeaponScore; if (this == pl1Score1) { Subtitles.AddPlayer1Subtitle("Weapon Changed!"); } else if (this == pl2Score1) { Subtitles.AddPlayer2Subtitle("Weapon Changed!"); } } } if (pl1Score1 != null) { pl1Score2.score = pl1Score1.score; pl1Score2.weaponScore = pl1Score1.score; } if (pl2Score1 != null) { pl2Score2.score = pl2Score1.score; pl2Score2.weaponScore = pl2Score1.score; } }
void Start() { if (toPlayer1) { Subtitles.AddPlayer1Subtitle(subtitleTextToAdd); } if (toPlayer2 && !GameManager.singleGame) { Subtitles.AddPlayer2Subtitle(subtitleTextToAdd); } if (deleteObject) { Destroy(gameObject); } if (deleteComponent) { Destroy(this); } }
private void OnTriggerEnter2D(Collider2D collider) { inventory = collider.GetComponentInParent <Inventory>(); Debug.Log("collider belongs to " + collider.name); if (inventory) { Debug.Log("Inventory belongs to " + inventory.gameObject.name); } if (collider.gameObject.name == "Player1") { Subtitles.AddPlayer1Subtitle("Picked up " + item.name); } else if (collider.gameObject.name == "Player2") { Subtitles.AddPlayer2Subtitle("Picked up " + item.name); } Interact(); }
public bool processCriticalHit() { if (hitComboCount >= 3 && !wasHitCritical) { wasHitCritical = Random.Range(0f, 1f) < criticalHitChance * hitComboCount; } if (wasHitCritical) { if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Critical Hit! Combo x" + hitComboCount + "!"); } else { Subtitles.AddPlayer2Subtitle("Critical Hit! Combo x" + hitComboCount + "!"); } } return(wasHitCritical); }
public void processHitCombo() { if (didAttackHitEnemy > 0) { hitComboCount += didAttackHitEnemy; hitComboTimer = hitComboMaxTime; if (hitComboCount >= 3) { if (lastHitComboTextObject != null) { lastHitComboTextObject.transform.GetChild(0).GetComponent <Animator>().Play("HitComboPop", 0, 0f); lastHitComboTextObject.transform.position = transform.position + new Vector3(0f, 0.72f, 0f); } else { lastHitComboTextObject = Instantiate(hitComboTextObject, transform.position + new Vector3(0f, 0.72f, 0f), Quaternion.Euler(0f, 0f, Random.Range(-5f, 5f))); } if (wasHitCritical) { Time.timeScale = 0f; criticalHitTimePauseTimer = criticalHitTimePause; if (weaponPossession.weaponID == 2) //Time Whip { timeSlowMoTimer = timeSlowMoTime; if (aud != null && TogglesValues.sound) { aud.PlayOneShot(slowMoSound); } lastHitComboTextObject.transform.GetChild(0).GetChild(0).gameObject.GetComponent <TextMeshPro>().text = "slow mo!"; lastHitComboTextObject.transform.GetChild(0).GetChild(1).gameObject.GetComponent <TextMeshPro>().text = "slow mo!"; if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Slow Mo! Combo x" + hitComboCount.ToString() + "!"); } else { Subtitles.AddPlayer2Subtitle("Slow Mo! Combo x" + hitComboCount.ToString() + "!"); } } else { lastHitComboTextObject.transform.GetChild(0).GetChild(0).gameObject.GetComponent <TextMeshPro>().text = "critical!"; lastHitComboTextObject.transform.GetChild(0).GetChild(1).gameObject.GetComponent <TextMeshPro>().text = "critical!"; if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Critical! Combo x" + hitComboCount.ToString() + "!"); } else { Subtitles.AddPlayer2Subtitle("Critical! Combo x" + hitComboCount.ToString() + "!"); } } } else { lastHitComboTextObject.transform.GetChild(0).GetChild(0).gameObject.GetComponent <TextMeshPro>().text = "combo x" + hitComboCount.ToString(); lastHitComboTextObject.transform.GetChild(0).GetChild(1).gameObject.GetComponent <TextMeshPro>().text = "combo x" + hitComboCount.ToString(); if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Combo x" + hitComboCount.ToString() + "!"); } else { Subtitles.AddPlayer2Subtitle("Combo x" + hitComboCount.ToString() + "!"); } } } } else { hitComboCount = 0; hitComboTimer = 0f; } didAttackHitEnemy = 0; wasHitCritical = false; }
private void Update() { //if (Time.timeScale > 0f) { if (!animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing")) // && !isDashing) { walkInput = new Vector2(Input.GetAxisRaw(walkHorizontalInput + inputExtensionString), Input.GetAxisRaw(walkVerticalInput + inputExtensionString)); /* * if (GameManager.singleGame) * { * if(walkInput.x == 0f) * walkInput.x = Input.GetAxisRaw(walkHorizontalInput + "2"); * if(walkInput.y == 0f) * walkInput.y = Input.GetAxisRaw(walkVerticalInput + "2"); * } */ if (walkInput.x != 0 && walkInput.y != 0) { walkInput /= 1.5f; } if (walkInput != Vector2.zero) { if (!isDashing) { speed = walkSpeed * (1 + (4 * timeSlowMoEffectValue)); } animator.SetBool("isWalking", true); if (walkInput.y < 0) { animator.SetInteger("direction", 2); if (prevWalkState == 0) { comboKeys += "D"; } } else if (walkInput.y > 0) { animator.SetInteger("direction", 0); if (prevWalkState == 0) { comboKeys += "U"; } } else if (walkInput.x > 0) { animator.SetInteger("direction", 1); if (prevWalkState == 0) { comboKeys += "R"; } } else if (walkInput.x < 0) { animator.SetInteger("direction", 3); if (prevWalkState == 0) { comboKeys += "L"; } } if (walkInput.x > 0) { sprRenderer.flipX = true; } else { sprRenderer.flipX = false; } } else { speed = 0f; animator.SetBool("isWalking", false); } } //Potion if (Input.GetButtonDown(attackInput + inputExtensionString)) { potionTimer = potionAttackButtonPressMinTime; } if (Input.GetButtonUp(attackInput + inputExtensionString)) { potionTimer = -1000f; } if (potionTimer <= 0 && potionTimer > -900f) { EquipmentManager eqMan = GetComponent <EquipmentManager>(); if (eqMan != null && eqMan.GetCurrentEquipment() != null && eqMan.GetCurrentEquipment().Length > 1 && eqMan.GetCurrentEquipment()[1] != null) { eqMan.UsePotion(GetComponent <EquipmentManager>().GetCurrentEquipment()[1]); if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Potion Used"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("Potion Used"); } } else { if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Potion not equipped"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("Potion not equipped"); } } potionTimer = -1000f; potionUsed = true; } else if (potionTimer > 0f && potionTimer > -900f) { potionTimer -= Time.deltaTime; } //Attack if (actionPoints >= attackActionDeplete && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing") && !isDashing && (Input.GetButtonUp(attackInput + inputExtensionString) /*|| GameManager.singleGame && Input.GetButtonDown(attackInput + "2")*/)) { if (!potionUsed) { comboKeys += "A"; if (comboKeys != "UA" && comboKeys != "RA" && comboKeys != "DA" && comboKeys != "LA") { animator.SetBool("isAttacking", true); speed = attackSpeed * (1 + (4 * timeSlowMoEffectValue)); /* * if (playerNo == 1) * Subtitles.AddPlayer1Subtitle("TEST_Player 1 Attacking"); * else if (playerNo == 2) * Subtitles.AddPlayer2Subtitle("TEST_Player 2 Attacking"); */ if (animator.GetBool("isWalking")) { attackSpeedTimer = attackSpeedTime; } else { int dir = animator.GetInteger("direction"); if (dir == 0) { walkInput.x = 0; walkInput.y = 1; } else if (dir == 1) { walkInput.x = 1; walkInput.y = 0; } else if (dir == 2) { walkInput.x = 0; walkInput.y = -1; } else if (dir == 3) { walkInput.x = -1; walkInput.y = 0; } attackSpeedTimer = attackSpeedTime / 2f; } actionPoints -= attackActionDeplete; if (aud != null && TogglesValues.sound) { aud.PlayOneShot(weaponSounds[weaponPossession.weaponID + 1], weaponSoundVolumes[weaponPossession.weaponID + 1]); } } } potionUsed = false; } //Push if (pushPossible != null && !animator.GetBool("isPushing") && !animator.GetBool("isAttacking") && !animator.GetBool("isThrowing") && !isDashing && (comboKeys == "UU" || comboKeys == "RR" || comboKeys == "DD" || comboKeys == "LL")) { animator.SetBool("isPushing", true); speed = 0f; if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("TEST_Player 1 Pushing"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("TEST_Player 2 Pushing"); } actionPoints -= pushActionDeplete; pushPossible = null; comboKeys = ""; } //Dash if (actionPoints >= dashActionDeplete && !isDashing && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing") && (comboKeys == "UU" || comboKeys == "RR" || comboKeys == "DD" || comboKeys == "LL" || comboKeys == "UR" || comboKeys == "UL" || comboKeys == "DR" || comboKeys == "DL" || comboKeys == "RU" || comboKeys == "RD" || comboKeys == "LU" || comboKeys == "LD") && hitCheck.knockback == Vector2.zero) { isDashing = true; dashTimer = dashTime / (1 + (4 * timeSlowMoEffectValue)); speed = dashSpeed * (1 + (4 * timeSlowMoEffectValue)); gameObject.layer = 10; actionPoints -= dashActionDeplete; if (aud != null && TogglesValues.sound) { aud.PlayOneShot(dashSound); } comboKeys = ""; } //Throw if (!animator.GetBool("isThrowing") && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !isDashing && (((keyComboTimer <= keyComboMaxTimeGap / 3.8f) && (comboKeys == "UA" || comboKeys == "RA" || comboKeys == "DA" || comboKeys == "LA")) || ((Input.GetButtonDown(attackInput + inputExtensionString)) && (Input.GetButtonDown(walkHorizontalInput + inputExtensionString) || Input.GetButtonDown(walkVerticalInput + inputExtensionString)))) ) { animator.SetBool("isThrowing", true); speed = attackSpeed * (1 + (4 * timeSlowMoEffectValue)); attackSpeedTimer = attackSpeedTime / 2f; actionPoints -= throwActionDeplete; if (throwFXObject && nextFXdelay < 0f) { GameObject FX = Instantiate(throwFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); nextFXdelay = MINIMUM_TIME_BETWEEN_FX; } comboKeys = ""; } if (actionPoints < 1f) { actionPoints += regenerateActionPointsPerSec * Time.deltaTime * (1 + (4 * timeSlowMoEffectValue)); } if (isDashing && dashTimer <= 0f) { isDashing = false; speed = walkSpeed * (1 + (4 * timeSlowMoEffectValue)); gameObject.layer = 8; } else if (dashTimer > 0f || (attackSpeedTimer > 0f && attackSpeedTimer < attackSpeedTime / 3f)) { GameObject ghostSpriteFX = Instantiate(dashFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); SpriteRenderer GSFX_sprRend = ghostSpriteFX.GetComponent <SpriteRenderer>(); if (dashFXObject && nextFXdelay < 0f) { GameObject FX = Instantiate(dashFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); FX.GetComponent <SpriteRenderer>().sprite = sprRenderer.sprite; nextFXdelay = MINIMUM_TIME_BETWEEN_FX; } GSFX_sprRend.sprite = sprRenderer.sprite; if (name == "Player1") { GSFX_sprRend.color = Color.red; GSFX_sprRend.material.color = Color.red; } else { GSFX_sprRend.color = Color.green; GSFX_sprRend.material.color = Color.green; } } if ((animator.GetBool("isAttacking") || animator.GetBool("isThrowing")) && attackSpeedTimer <= 0f) { speed = 0f; } if (keyComboTimer >= keyComboMaxTimeGap) { comboKeys = ""; } if (comboKeys != "") { keyComboTimer += Time.deltaTime; } else { keyComboTimer = 0f; } if (hitComboTimer <= 0f) { hitComboCount = 0; } else { hitComboTimer -= Time.deltaTime; } if (criticalHitTimePauseTimer <= 0f) { if (Time.timeScale >= 0.05f && Time.timeScale <= 0.1f) { Time.timeScale = 1f; } else if (timeSlowMoTimer > 0f) { timeSlowMoTimer -= Time.unscaledDeltaTime; Time.timeScale = Mathf.Lerp(Time.timeScale, 0.5f, 0.025f); ImageEffect.SetImageEffectMaterialIndex(2); timeSlowMoEffectValue = Mathf.Lerp(timeSlowMoEffectValue, 0.25f, 0.025f); ImageEffect.SetImageEffectValue(timeSlowMoEffectValue); } else if (timeSlowMoTimer <= 0f) { if (Time.timeScale >= 0.5f && Time.timeScale != 1f) { if (Time.timeScale <= 0.505f && aud != null && TogglesValues.sound) { aud.PlayOneShot(slowMoToNormalSound); } Time.timeScale = Mathf.Lerp(Time.timeScale, 1f, 0.05f); if (Time.timeScale >= 0.98f) { Time.timeScale = 1f; } } if (timeSlowMoEffectValue <= 0f) { ImageEffect.SetImageEffectMaterialIndex(0); ImageEffect.SetImageEffectValue(0.04f); timeSlowMoEffectValue = 0f; } else { timeSlowMoEffectValue -= Time.unscaledDeltaTime / 5f; ImageEffect.SetImageEffectValue(timeSlowMoEffectValue); } } } else { Time.timeScale = 0.06f; criticalHitTimePauseTimer -= Time.unscaledDeltaTime; } animator.speed = 1f * (1 + (4 * timeSlowMoEffectValue)); attackSpeedTimer -= Time.deltaTime; dashTimer -= Time.deltaTime; nextFXdelay -= Time.deltaTime; // don't spam FX every frame prevWalkState = walkInput == Vector2.zero ? 0 : 1; } }
private void OnTriggerEnter2D(Collider2D collision) { if (active && collision.CompareTag("Player") && player == null) { // A Portal MUST lead to some other Portal //Make sure that portalActivePair is in the list of activePortals if (portalActivePair != null) { portalActivePair.gameObject.SetActive(true); } // update active portal index GetActivePortalIndices(); // store reference to player player = collision.gameObject; // no exits, bail // @TODO: notify user somehow? if (activePortals.Count == 0) { player = null; return; } // if there's only one exit, just go there else if (activePortals.Count <= 2) //the second exit is the same portal itself { TransportPlayer(exits[activePortals[0]]); if (player.name == "Player1") { Subtitles.AddPlayer1Subtitle("Player Teleported!"); } else if (player.name == "Player2") { Subtitles.AddPlayer2Subtitle("Player Teleported!"); } } // otherwise start "selection mode" else { // Reset selectionIndex selectedIndex = 0; // Store inputs and disable player controller playerController = player.GetComponent <PlayerController>(); attackInput = playerController.attackInput; horizontalInput = playerController.walkHorizontalInput; playerController.enabled = false; // Move camera to show portal selection playerCamera = FindPlayerCamera(); previousCameraTrack = playerCamera.tr; previousPlayerFocusFactor = playerCamera.playerFocusFactor; playerCamera.playerFocusFactor = 0f; PreviewSelection(); //Minimap Focus and Subtitle MinimapController.instances[0].focus = true; if (player.name == "Player1") { MinimapController.instances[2].focus = true; Subtitles.AddPlayer1Subtitle("Select the Portal"); } else if (player.name == "Player2") { MinimapController.instances[1].focus = true; Subtitles.AddPlayer2Subtitle("Select the Portal"); } } } }