// Interfaces we care about public void OnGetMessage(string _Message) { _Message = StripMessage(_Message); // other player is jumping, need to maybe set it so that the playercontroller has a bool looking at this List <object> m = MessageParser.ParseMessage(_Message); string type = (string)m[0]; if (type == "jump") { bool jumping = (bool)m[1]; Vector3 pos = new Vector3((float)m[2], (float)m[3], (float)m[4]); if (jumping) { playerController.RunnerDoJump(pos); } else { playerController.RunnerStopJump(pos); } } if (type == "block") { Vector3 pos = new Vector3((float)m[1], (float)m[2], (float)m[3]); GameObject block = blockManager.GetFromPool(); block.transform.position = pos; block.GetComponent <Block>().bitmask = -1; // Force an update in AdjustBitmasks blockManager.AdjustBitmasks(block); } if (type == "pos") { // Update position, incl. latency compensation System.DateTime theirDT = (System.DateTime)m[1]; System.DateTime ourDT = System.DateTime.Now; System.TimeSpan difference = ourDT - theirDT; float secs = difference.Seconds + (difference.Milliseconds / 1000f); Vector3 pos = new Vector3((float)m[2], (float)m[3], (float)m[4]); Vector3 vel = new Vector3((float)m[5], (float)m[6]); playerController.velocity = vel; playerController.velocity.y += playerController.acceleration.y * secs; playerController.velocity.y = Mathf.Clamp(playerController.velocity.y, -PlayerController.TERMINAL_VELOCITY, PlayerController.TERMINAL_VELOCITY); playerController.transform.position = new Vector3(pos.x + playerController.velocity.x * secs, pos.y + playerController.velocity.y * secs, playerController.transform.position.z); blockManager.GenerateGround(); } if (type == "ded") { gameIsPlaying = false; score = (int)m[1]; blockManager.generateGroundAheadOfPlayer = false; playerController.gameObject.SetActive(false); scoreText.GetComponent <Text>().text = "Score: " + score.ToString(); } if (type == "pit") { int count = (int)m[1]; StartCoroutine(blockManager.DelayGroundSpawningForCount(count)); } if (type == "blocks") { for (int i = 1; i < m.Count; ++i) { Vector3 pos = (Vector3)m[i]; Debug.LogWarning("CREATING BLOCK " + pos); GameObject block = blockManager.GetFromPool(); block.transform.position = pos; block.GetComponent <Block>().bitmask = -1; // Force an update in AdjustBitmasks blockManager.AdjustBitmasks(block); } } if (type == "restart") { SceneManager.LoadScene(1); } }
void Update() // That should work... { if (Bluetooth.connectedToAndroid && GameManager.instance.playerType == PlayerType.Runner) { // Get tap if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { DoJump(); } else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { // Midair jump stop (it's wrong NOT to have it) GameManager.instance.SendPlayerJump(false, transform.position); if (velocity.y > midairStopVelocity) { velocity.y = midairStopVelocity; } } } else if (Bluetooth.connectedToAndroid && GameManager.instance.playerType == PlayerType.Blocker) { //if(jumping) //{ // DoJump(); //} //else //{ // if (velocity.y > midairStopVelocity) { // velocity.y = midairStopVelocity; // } //} } else { // Get spacebar if (Input.GetKeyDown(KeyCode.Space)) { DoJump(); } else if (Input.GetKeyUp(KeyCode.Space)) { // Midair jump stop (it's wrong NOT to have it) if (velocity.y > midairStopVelocity) { velocity.y = midairStopVelocity; } } if (Input.GetMouseButtonDown(0)) { BlockManager bm = GameManager.instance.GetBlockManager(); Vector3 mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(mousePos); mousePos.z = 0; mousePos = new Vector3(Mathf.Floor(mousePos.x), Mathf.Floor(mousePos.y), mousePos.z); if (!bm.GetBlockInPos(mousePos)) { //GameManager.instance.CreateBlock(mousePos); GameObject block = bm.GetFromPool(); block.transform.position = mousePos; block.GetComponent <Block>().bitmask = -1; // Force an update in AdjustBitmasks bm.AdjustBitmasks(block); } } } // mooooooove bitch, get out da way if (moving) { velocity.x = moveSpeed; } else { velocity.x = 0f; } if (transform.position.y < -64) { transform.position = new Vector3(transform.position.x, 4f, transform.position.z); velocity.y = 0f; } }