void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("JumperModule")) { JumperData jumperData = col.GetComponent <JumperData>(); jumperData.Engaged = true; //TODO:Some kind of scoring maybe? Just a thought.. if (m_grounded) { SoundManager.Instance.playEngage(); } else { SoundManager.Instance.playPerfectEngage(); } StartCoroutine(Freeze(jumperData)); m_currentModuleEngaged = col.gameObject; m_currentModuleJumperData = jumperData; GetComponent <Rigidbody2D>().velocity = Vector2.zero; } else if (col.CompareTag("Star")) { m_scoring.starPickup(); Destroy(col.gameObject); } else if (col.CompareTag("Finish")) { m_scoring.goalReached(); } }
//进入战斗场景数据初始化完成 public static void EnterWarDataInitFinished() { Debug.Log("EnterWarDataInitFinished"); //开始跳转场景 if (jumperData != null) { _this.StartCoroutine(_this.loadScene(jumperData.levelName, jumperData.func_complete, jumperData.func_progress)); } jumperData = null; }
public static void LoadSceneAsyncWithLoading(string levelName, LuaFunction func_complete, LuaFunction func_progress = null) { if (jumperData == null) { jumperData = new JumperData(); } jumperData.levelName = levelName; jumperData.func_complete = func_complete; jumperData.func_progress = func_progress; SendEnterWarMsg(); }
void OnTriggerStay2D(Collider2D col) { //If contact with jumper module if (col.CompareTag("JumperModule")) { JumperData jumperData = col.GetComponent <JumperData>(); MoveAtoB moveComp = col.GetComponentInParent <MoveAtoB>(); if (moveComp) { moveComp.enabled = false; } //If this is first contact with jumper if (!jumperData.Engaged) { jumperData.Engaged = true; m_inputTouch.PlayerCurrentCol = col; m_inputTouch.PlayerLocked = true; m_windController.updateWind(); m_scoring.incrementScoreById(jumperData.ID, !m_grounded, jumperData.gameObject.transform.position); //If landing is perfect is the opposite of m_grounded when first touching the jumper if (m_grounded) { SoundManager.Instance.playEngage(); } else { SoundManager.Instance.playPerfectEngage(); } StartCoroutine(Freeze(col.gameObject)); m_currentModuleEngaged = col.gameObject; GetComponent <Rigidbody2D>().velocity = Vector2.zero; GetComponent <PlayerDeath>().setKillerHeight(jumperData.ID - 1); } else if (!m_frozen && jumperData.Active) //If we are no longer frozen then jump according to jumper module { col.GetComponent <Collider2D>().enabled = false; m_grounded = false; //Might not be needed GetComponent <Rigidbody2D>().velocity = Vector2.zero; GetComponent <Rigidbody2D>().AddForce(jumperData.JumpVec * m_jumpPower); m_animator.SetTrigger("jump"); SoundManager.Instance.playJump(); } //FIXME Faulty, good enough for now, make it linear or something.. if (m_frozen) { transform.position = Vector2.Lerp(transform.position, col.transform.position, Time.deltaTime); //"Pull" player toward middle of jumper } } }
//Freezes and unfreezes player for some time //Manipulates the look of engaged jumper module IEnumerator Freeze(JumperData jumperData) { GetComponent <Rigidbody2D>().gravityScale = 0.0f; m_frozen = true; while (!jumperData.Active) { yield return(new WaitForSeconds(0.1f)); } GetComponent <Rigidbody2D>().gravityScale = 1.0f; m_frozen = false; //StartCoroutine(Fade(jumperModule)); }
// Use this for initialization void Start() { m_lineRenderer = gameObject.AddComponent <LineRenderer>(); m_lineRenderer.material = m_lineMat; m_lineRenderer.material.color = m_green; m_lineRenderer.SetWidth(0.2F, 0.1F); m_lineRenderer.SetVertexCount(2); m_lineRenderer.SetPosition(0, new Vector3(0.0f, 0.0f, -2.0f)); m_lineRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; m_lineRenderer.receiveShadows = false; m_lineRenderer.enabled = false; m_lineRenderer.useWorldSpace = false; m_lineRenderer.sortingLayerName = "Foreground"; m_jumperData = GetComponent <JumperData>(); }
// Update is called once per frame void Update() { Vector2 lastPlatPos = m_newestPlatPos; //Newest platform //Vector2 firstPlatPos = m_jumperPlatforms.First.Value.transform.position; //Oldest platform Vector2 firstPlatPos = m_platformsInUse.Peek().transform.position; //Oldest platform //If newest platform is less than x units above player, spawn new platform if (m_player.transform.position.y - firstPlatPos.y > 15) { //TODO: Maybe bring this back instead of a static 4.0f // foreach(Transform child in m_jumperPlatforms.Last.Value.transform) // { // if(child.CompareTag("Platform")) // lastPlatWidth = child.collider2D.bounds.size.x; // } float newPosX, newPosY; do { newPosX = lastPlatPos.x + (Random.value - 0.5f) * m_xMax; }while(Mathf.Abs(newPosX - lastPlatPos.x) < m_xMin); //Maybe revert this to last platform width instead of static 4.0f newPosY = lastPlatPos.y + Random.Range(m_yMin, m_yMax); m_newestPlatPos = new Vector2(newPosX, newPosY); m_platformsInUse.Dequeue(); //This platform is no longer "in use" //Platform that is to be moved GameObject objToMove; float spawnValue = Random.value; if (spawnValue > 0.85f && m_player.transform.position.y - m_movingJumperPlatforms.Peek().transform.position.y > 15) { objToMove = m_movingJumperPlatforms.Dequeue(); m_movingJumperPlatforms.Enqueue(objToMove); } else { objToMove = m_jumperPlatforms.First.Value; //FIXME: This does not check if the platform is actually at a safe distance //Please review this list usage once again, doesn't feel too effective at the moment!!! //Remove it from start of list and add it to the end m_jumperPlatforms.RemoveFirst(); m_jumperPlatforms.AddLast(objToMove); } m_platformsInUse.Enqueue(objToMove); objToMove.transform.position = m_newestPlatPos; //Move the platform m_cosmeticsSpawner.SpawnClouds(m_newestPlatPos); //Spawn some clouds JumperActivate jumperActivate = objToMove.GetComponentInChildren <JumperActivate>(); jumperActivate.reInitialize(); JumperData jumperData = objToMove.GetComponentInChildren <JumperData>(); jumperData.reInitialize(); jumperData.ID = m_nextId; ++m_nextId; m_enemySpawner.rollSpawner(m_newestPlatPos); // if(m_nextId < 2) // temp = Instantiate(m_largePlat, newPlatPos, Quaternion.identity) as GameObject; // else // { // if(Random.Range(1, 10) > 8) // temp = Instantiate(m_smallPlat, newPlatPos, Quaternion.identity) as GameObject; // else // temp = Instantiate(m_largePlat, newPlatPos, Quaternion.identity) as GameObject; // } // temp.GetComponentInChildren<JumperData>().ID = m_nextId; // m_jumperPlatforms.AddLast(temp); // ++m_nextId; } // if(m_player.transform.position.y - firstPlatPos.y > 15) // { // Destroy(m_jumperPlatforms.First.Value.gameObject); // m_jumperPlatforms.RemoveFirst(); // } // LinkedListNode<GameObject> currentPlat; // currentPlat = m_jumperPlatforms.First; //Start at oldest platform node //Check if player passed a new height //GOTTA MAKE THIS HAPPEN WHEN WE ATTACH INSTEAD OF JUMP ABOVE // while(currentPlat != null) // { // if(currentPlat.Value.transform.position.y > m_killerHeight && m_player.position.y > currentPlat.Value.transform.position.y) // m_killerHeight = currentPlat.Previous.Value.transform.position.y; // // currentPlat = currentPlat.Next; // } }
// Update is called once per frame void Update() { if (!m_frozen) { m_groundCheckPos0 = new Vector2(transform.position.x - 0.545f, transform.position.y - 0.49f); m_groundCheckPos1 = new Vector2(transform.position.x + 0.545f, transform.position.y - 0.49f); if (Physics2D.Linecast(transform.position, m_groundCheckPos0, 1 << LayerMask.NameToLayer("Ground"))) { m_grounded = true; } else if (Physics2D.Linecast(transform.position, m_groundCheckPos1, 1 << LayerMask.NameToLayer("Ground"))) { m_grounded = true; } else { m_grounded = false; } if (GetComponent <Rigidbody2D>().velocity.x > 0.35f) { if (!m_facingRight) { flip(); } m_facingRight = true; } else if (GetComponent <Rigidbody2D>().velocity.x < -0.35f) { if (m_facingRight) { flip(); } m_facingRight = false; } if (m_grounded) { //Accelerate if (m_facingRight) { GetComponent <Rigidbody2D>().velocity += m_accVec * Time.deltaTime; } else { GetComponent <Rigidbody2D>().velocity += -1 * m_accVec * Time.deltaTime; } //Limit max speed if (Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x) > m_maxSpeed) { GetComponent <Rigidbody2D>().velocity = new Vector2(Mathf.Sign(GetComponent <Rigidbody2D>().velocity.x) * m_maxSpeed, GetComponent <Rigidbody2D>().velocity.y); } } } else { transform.position = Vector2.Lerp(transform.position, m_currentModuleEngaged.transform.position, Time.deltaTime); //"Pull" player toward middle of jumper } if (m_currentModuleEngaged != null && !m_frozen && m_currentModuleJumperData.Active) { m_currentModuleEngaged.GetComponent <Collider2D>().enabled = false; m_grounded = false; //Might not be needed GetComponent <Rigidbody2D>().velocity = Vector2.zero; GetComponent <Rigidbody2D>().AddForce(m_currentModuleJumperData.JumpVec * m_jumpPower); m_animator.SetTrigger("jump"); SoundManager.Instance.playJump(); m_currentModuleEngaged = null; m_currentModuleJumperData = null; } }