//只有3种情况会死:任何状态下 => 1.被炮弹击中 2.被别的龟壳击中 3.被无敌角色触碰 public void die(GameObject ob) { isDied = true; StartCoroutine(GameControler.getInstance().ScoreUIControl(200, transform.localPosition, 0.1f)); AudioControler.getInstance().SE_Emy_Down.Play(); GetComponent <Rigidbody2D>().gravityScale = 3; GetComponent <Rigidbody2D>().mass = 1; if (GetComponent <CircleCollider2D>()) { Destroy(GetComponent <CircleCollider2D>()); } if (GetComponent <BoxCollider2D>()) { Destroy(GetComponent <BoxCollider2D>()); } if (GetComponent <CapsuleCollider2D>()) { Destroy(GetComponent <CapsuleCollider2D>()); } var obPos = ob.transform.position; if (obPos.x > transform.position.x) { rotateAngle = 10; m_rigidbody.AddForce(new Vector2(-400, 400), ForceMode2D.Force); } else { rotateAngle = -10; m_rigidbody.AddForce(new Vector2(400, 400), ForceMode2D.Force); } ownRotateSwitch = true; Destroy(gameObject, 5); }
//分数结算 public void balanceScore() { if (balanceScoreSwitch) { if (!AudioControler.getInstance().SE_SCORE_COUNT.isPlaying) { AudioControler.getInstance().SE_SCORE_COUNT.Play(); } int currentScore = 0; int.TryParse(GameObject.Find("ScoreNum").GetComponent <Text>().text, out currentScore); currentScore = currentScore - 10 > 0 ? currentScore - 10 : 0; var str_currentScore = currentScore.ToString(); while (str_currentScore.Length < 9) { str_currentScore = "0" + str_currentScore; } GameObject.Find("ScoreNum").GetComponent <Text>().text = str_currentScore; //分数兑换命数 ScoreToLives += 10; if (ScoreToLives >= 4000) { ScoreToLives = 0; oneUp(); } if (currentScore == 0) { balanceScoreSwitch = false; AudioControler.getInstance().SE_SCORE_COUNT.Stop(); AudioControler.getInstance().SE_SCORE_COUNT_FINISH.Play(); //排行榜界面 goToRankListScene(); } } }
public IEnumerator doEvent(string btnName) { btn_move_switch = true; btn_Story.GetComponent <Button>().interactable = false; btn_Quit.GetComponent <Button>().interactable = false; AudioControler.getInstance().SE_Confirm.Play(); if (btnName == "Story") { StartCoroutine(SceneTransition.getInstance().loadScene("MissionViewScene", 0, 2)); GameData.dataUpdate(); } else { SceneTransition.getInstance().IncreaseSwitch = true; yield return(new WaitForSeconds(2)); Application.Quit(); } }
//游戏倒计时 public void countDown() { //Debug.Log(LabelTimeLeft.GetComponent<Text>().text); var str_timeLeft = LabelTimeLeft.GetComponent <Text>().text; int result = 0; int.TryParse(str_timeLeft, out result); result = result <= 0 ? 0 : --result; str_timeLeft = result.ToString(); switch (str_timeLeft.Length) { case 1: str_timeLeft = "00" + str_timeLeft; break; case 2: str_timeLeft = "0" + str_timeLeft; break; default: break; } LabelTimeLeft.GetComponent <Text>().text = str_timeLeft; if (result <= 100 && !AudioControler.getInstance().BGM_Ground_Hurry.isPlaying) { //BGM AudioControler.getInstance().stopAllBGM(); AudioControler.getInstance().BGM_Ground_Hurry.PlayDelayed(2.5f); //SE AudioControler.getInstance().SE_HurryUp.Play(); } else if (result == 0) { gameOver(); } }
//无敌角色触碰导致食人花死亡 public void die(GameObject ob) { isDied = true; StartCoroutine(GameControler.getInstance().ScoreUIControl(200, transform.position, 0.1f)); AudioControler.getInstance().SE_Emy_Down.Play(); //更改绘制层级 0 => 4 GetComponent <SpriteRenderer>().sortingOrder = 4; gameObject.AddComponent <Rigidbody2D>(); GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; GetComponent <Rigidbody2D>().gravityScale = 3; GetComponent <Rigidbody2D>().mass = 1; if (GetComponent <BoxCollider2D>()) { Destroy(GetComponent <BoxCollider2D>()); } var obPos = ob.transform.position; if (obPos.x > transform.position.x) { rotateAngle = 10; GetComponent <Rigidbody2D>().AddForce(new Vector2(-400, 400), ForceMode2D.Force); } else { rotateAngle = -10; GetComponent <Rigidbody2D>().AddForce(new Vector2(400, 400), ForceMode2D.Force); } ownRotateSwitch = true; Destroy(gameObject.GetComponentInParent <Image>().gameObject, 5); //image没实际意义,只供删除父物体 }
private void Awake() { instance = this; }
//图块事件分发 public void DoEvent() { switch (BlockEvent) { case EventType.Coin: { gainCoin(); break; } case EventType.Goomba: { createGoomba(); break; } case EventType.TortoiseFly: { createTortoiseFly(); break; } case EventType.TortoiseLand: { createTortoiseLand(); break; } case EventType.UnmatchStar: { createUnmatchStar(); break; } case EventType.PlayBGM_SickCow: { if (!AudioControler.getInstance().BGM_SickCow.isPlaying) { AudioControler.getInstance().stopAllBGM(); AudioControler.getInstance().BGM_SickCow.Play(); } break; } case EventType.PlayBGM_Schnappi: { if (!AudioControler.getInstance().BGM_Schnappi.isPlaying) { AudioControler.getInstance().stopAllBGM(); AudioControler.getInstance().BGM_Schnappi.Play(); } break; } case EventType.PlaySE_Hahaha: { if (!AudioControler.getInstance().SE_Hahaha.isPlaying) { AudioControler.getInstance().SE_Hahaha.Play(); } break; } default: break; } }
private IEnumerator playSE() { yield return(new WaitForSeconds(1.3f)); AudioControler.getInstance().SE_GameOver.Play(); }
public void doBeTread(GameObject player) { if (Character.getInstance().isUnmatched) { die(player); return; } if (currentTime - doBeTreadUpdate > 0.2f) { StartCoroutine(GameControler.getInstance().ScoreUIControl(100, transform.localPosition, 0.1f)); //Debug.Log("doBeTread()"); doBeTreadUpdate = Time.time; if (TortoiseStatus == Status.isFly) { AudioControler.getInstance().SE_Emy_Down.Play(); } else { AudioControler.getInstance().SE_Emy_Fumu.Play(); } //角色受力 player.GetComponent <Rigidbody2D>().velocity = new Vector2(player.GetComponent <Rigidbody2D>().velocity.x, 0); //清空player竖直线速度 player.GetComponent <Rigidbody2D>().velocity = new Vector2(player.GetComponent <Rigidbody2D>().velocity.x, player.GetComponent <Rigidbody2D>().velocity.y + 10); switch (TortoiseStatus) { case Status.isFly: { TortoiseStatus = Status.isOnFoot; wingControl(); if (player.transform.position.x > transform.position.x) { TortoiseDirection = direction.left; } else { TortoiseDirection = direction.right; } break; } case Status.isOnFoot: { //龟壳爬行计时 beginCrawlUpdate = Time.time; TortoiseStatus = Status.isShellStatic; GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y); break; } case Status.isShellStatic: { TortoiseStatus = Status.isShellMove; pushOrTreadShell(player); break; } case Status.isShellMove: { //龟壳爬行计时 beginCrawlUpdate = Time.time; TortoiseStatus = Status.isShellStatic; break; } case Status.isCrawl: { //龟壳爬行计时 beginCrawlUpdate = Time.time; TortoiseStatus = Status.isShellStatic; break; } default: break; } } }
public void RayCollisionDetection() { #region isGrounded var CapColl2D = GetComponent <CapsuleCollider2D>(); var size = CapColl2D.size; var pos = CapColl2D.transform.localPosition; //获取胶囊碰撞器底部左右侧两端的pos float left_x = transform.localScale.x > 0 ? pos.x - size.x / 2 + CapColl2D.offset.x : pos.x - size.x / 2 - CapColl2D.offset.x; float left_y = transform.position.y - size.y / 2; float right_x = transform.localScale.x > 0 ? pos.x + size.x / 2 + CapColl2D.offset.x : pos.x + size.x / 2 - CapColl2D.offset.x; float right_y = transform.position.y - size.y / 2; var pos_left = new Vector2(left_x, left_y); var pos_right = new Vector2(right_x, right_y); //通过两点,向下发射线 var vector1 = new Vector2(pos_left.x, pos_left.y - 0.01f); var direction1 = vector1 - pos_left; var vector2 = new Vector2(pos_right.x, pos_right.y - 0.01f); var direction2 = vector2 - pos_right; var collider_left = Physics2D.Raycast(pos_left, direction1, 0.3f, 1 << LayerMask.NameToLayer("MapBlock")).collider; var collider_right = Physics2D.Raycast(pos_right, direction2, 0.3f, 1 << LayerMask.NameToLayer("MapBlock")).collider; //Debug.Log("colliderName1: " + collider_left); //Debug.Log("colliderName2: " + collider_right); //Debug.DrawRay(pos_left, direction1, Color.red, 0.05f); //Debug.DrawRay(pos_right, direction2, Color.red, 0.05f); if (collider_left == null & collider_right == null) { isGrounded = false; } else { isGrounded = true; } #endregion #region isHeaded float left_head_x = transform.localScale.x > 0 ? pos.x - size.x / 2 + CapColl2D.offset.x : pos.x - size.x / 2 - CapColl2D.offset.x; float left_head_y = pos.y + size.y / 2 + CapColl2D.offset.y; float right_head_x = transform.localScale.x > 0 ? pos.x + size.x / 2 + CapColl2D.offset.x : pos.x + size.x / 2 - CapColl2D.offset.x; float right_head_y = pos.y + size.y / 2 + CapColl2D.offset.y; var pos_head_left = new Vector2(left_head_x, left_head_y); var pos_head_right = new Vector2(right_head_x, right_head_y); //通过两点,向上发射线 var vectorHeadLeft = new Vector2(pos_head_left.x, pos_head_left.y + 0.01f); var directionHeadLeft = vectorHeadLeft - pos_head_left; var vectorHeadRight = new Vector2(pos_head_right.x, pos_head_right.y + 0.01f); var directionHeadRight = vectorHeadRight - pos_head_right; var collider_Head_Left = Physics2D.Raycast(pos_head_left, directionHeadLeft, 0.3f, 1 << LayerMask.NameToLayer("MapBlock")).collider; var collider_Head_Right = Physics2D.Raycast(pos_head_right, directionHeadRight, 0.3f, 1 << LayerMask.NameToLayer("MapBlock")).collider; //Debug.Log("collider1: " + collider_Head_Left); //Debug.Log("collider2: " + collider_Head_Right); //Debug.DrawRay(pos_head_left, directionHeadLeft, Color.red, 0.05f); //Debug.DrawRay(pos_head_right, directionHeadRight, Color.red, 0.05f); if (collider_Head_Left == null & collider_Head_Right == null) { isHeaded = false; } else { isHeaded = true; } #endregion #region bodyLeftRight var circlePos = GetComponent <CircleCollider2D>().transform.position; var posBodyLeft = new Vector2(circlePos.x - GetComponent <CircleCollider2D>().radius, circlePos.y - .2f); var targetBodyLeft = new Vector2(posBodyLeft.x - 1, posBodyLeft.y); var DirectionBodyLeft = targetBodyLeft - posBodyLeft; var posBodyRight = new Vector2(circlePos.x + GetComponent <CircleCollider2D>().radius, circlePos.y - .2f); var targetBodyRight = new Vector2(posBodyRight.x + 1, posBodyRight.y); var DirectionBodyRight = targetBodyRight - posBodyRight; //Debug.DrawRay(posBodyLeft, DirectionBodyLeft, Color.red, 0.2f); //Debug.DrawRay(posBodyRight, DirectionBodyRight, Color.red, 0.2f); var rayDistance = TortoiseStatus == Status.isShellMove ? 0.1f : 0.2f; var colliderBodyLeft = Physics2D.Raycast(posBodyLeft, DirectionBodyLeft, rayDistance, 1 << LayerMask.NameToLayer("MapBlock")).collider; var colliderBodyRight = Physics2D.Raycast(posBodyRight, DirectionBodyRight, rayDistance, 1 << LayerMask.NameToLayer("MapBlock")).collider; if (colliderBodyLeft) { if (!AudioControler.getInstance().SE_Hit_Block.isPlaying&& TortoiseStatus == Status.isShellMove) { AudioControler.getInstance().SE_Hit_Block.Play(); } isLeft = true; } else { isLeft = false; } if (colliderBodyRight) { if (!AudioControler.getInstance().SE_Hit_Block.isPlaying&& TortoiseStatus == Status.isShellMove) { AudioControler.getInstance().SE_Hit_Block.Play(); } isRight = true; } else { isRight = false; } #endregion }
public void OnDestroy() { dropTable = null; audioControler = null; uiControler = null; playerControler = null; inputManager = null; _instance = null; _stageControler = null; _Destroyed = true; }
//1UP加命 public void oneUp() { AudioControler.getInstance().SE_ONE_UP.Play(); Destroy(Instantiate(Resources.Load("Prefab/UI/1UP"), GameObject.Find("Canvas").transform), 1); ++GameData.MarioLives; }
public void closeMenu() { AudioControler.getInstance().SE_SYS_PAUSE.Play(); gameObject.SetActive(false); }
void SetStatics() { if (_inputManager && !inputManager) inputManager = _inputManager; if (!_instance) _instance = this; if (_playerControler && !playerControler) playerControler = _playerControler; if (_UIControler && !uiControler) uiControler = _UIControler; if (_AudioControler && !audioControler) audioControler = _AudioControler; if (_DropTable && !dropTable) dropTable = _DropTable; if (_optionsMenu && !optionsMenu) optionsMenu = _optionsMenu; if (_UICamera && !UICamera) UICamera = _UICamera; if (_TutorialControler && !TutorialControler) TutorialControler = _TutorialControler; }
void playSound() { AudioControler.getInstance().SE_vszed.Play(); }
public void onBtnQuitToTitle() { AudioControler.getInstance().SE_PlayExit.Play(); StartCoroutine(SceneTransition.getInstance().loadScene("TitleScene", 0, 2)); }
// Use this for initialization void Start() { instance = this; }