private void Window_KeyDown(object sender, KeyEventArgs e) { Send(e.Key.ToString(), "/l"); if (Common.IsHost) { if (e.Key.ToString().Contains(LetterBox.Text)) { Combo1++; ComboBox1.Text = Combo1.ToString(); Score1 += 2 * Combo1; ScoreBox1.Text = Score1.ToString(); Margin_Letter = 0; InitPicTimer1(); LetterBox.Text = NormArr[GenerateNext()]; EnemyImg.Margin = new Thickness(0, 0, 0, 350); } else { Combo1 = 0; ComboBox1.Text = Combo1.ToString(); } } else { if (e.Key.ToString().Contains(LetterBox.Text)) { Combo2++; ComboBox2.Text = Combo2.ToString(); Score2 += 2 * Combo2; ScoreBox2.Text = Score2.ToString(); InitPicTimer2(); Margin_Letter = 0; LetterBox.Text = NormArr[GenerateNext()]; EnemyImg.Margin = new Thickness(0, 0, 0, 350); } else { Combo2 = 0; ComboBox2.Text = Combo2.ToString(); } } }
private void Receive() { byte[] buffer = new byte[1024]; while (true) { try { using (Socket listener = new Socket(localIp.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { listener.Bind(localEP); listener.Listen(5); using (Socket socket = listener.Accept()) { int count = 0; count = socket.Receive(buffer); message = Encoding.UTF8.GetString(buffer, 0, count); if (message.Contains("/s") && message.Contains("1")) { Player1Start = true; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { CheckStart(); }); } if (message.Contains("/s") && message.Contains("2")) { Player2Start = true; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { CheckStart(); }); } if (message.Contains("/l")) { if (message.Contains(NormArr[next])) { if (Common.IsHost) { Combo2++; Score2 += Combo2 * 2; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { ScoreBox2.Text = Score2.ToString(); ComboBox2.Text = Combo2.ToString(); Margin_Letter = 0; InitPicTimer2(); LetterBox.Text = NormArr[GenerateNext()]; EnemyImg.Margin = new Thickness(0, 0, 0, 350); }); } else { Combo1++; Score1 += Combo1 * 2; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { ScoreBox1.Text = Score1.ToString(); ComboBox1.Text = Combo1.ToString(); Margin_Letter = 0; InitPicTimer1(); LetterBox.Text = NormArr[GenerateNext()]; EnemyImg.Margin = new Thickness(0, 0, 0, 350); }); } } else { if (Common.IsHost) { Combo2 = 0; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { ComboBox2.Text = Combo2.ToString(); }); } else { Combo1 = 0; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { ComboBox1.Text = Combo1.ToString(); }); } } } if (message.Contains("/p")) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { Margin_Letter = 0; timerMove.Stop(); timerPlay.Stop(); TimeBox.Text = ""; LetterBox.Text = ""; EnemyImg.Visibility = Visibility.Hidden; LetterBox.Visibility = Visibility.Hidden; EnemyImg.Margin = new Thickness(0, 0, 0, 350); Player1Start = false; Player2Start = false; }); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
// Update is called once per frame void Update() { //Make sure joystick has returned to neutral state from last intput if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal") == 0) { joyStickInput = true; playedError = false; } if (BeatMan.instance.onTime && !haveMoved) //Won't work off beat, but won't kill a combo offbeat either currently { if (joyStickInput && mashingMove == 0) //Only move once per beat. { //Jump if (Input.GetAxis("Vertical") > 0 && rayUp.collider == null) { if (grounded) { lerpDestination = new Vector2(transform.position.x, transform.position.y + lerpDistance); haveMoved = true; joyStickInput = false; AudioMan.instance.AddClipToLiveQueue(jumpAudio[beatCycleNum]); } else { //Double Jump if (aerialMove) { lerpDestination = new Vector2(transform.position.x, transform.position.y + lerpDistance); haveMoved = true; aerialMove = false; joyStickInput = false; AudioMan.instance.AddClipToLiveQueue(jumpAudio[beatCycleNum]); } } } //Fall else if (Input.GetAxis("Vertical") < 0) { if (canFall) { lerpDestination = new Vector2(transform.position.x, transform.position.y - lerpDistance); haveMoved = true; joyStickInput = false; AudioMan.instance.AddClipToLiveQueue(fall); } } //Right else if (Input.GetAxis("Horizontal") > 0 && rayRight.collider == null) { //Don't need to have a seperate aerialCheck because it will be set back to true on the ground if (aerialMove) { lerpDestination = new Vector2(transform.position.x + lerpDistance, transform.position.y); haveMoved = true; joyStickInput = false; aerialMove = false; if (flipped) { Flip(); } AudioMan.instance.AddClipToLiveQueue(dash[beatCycleNum]); } } //Left else if (Input.GetAxis("Horizontal") < 0 && rayLeft.collider == null) { if (aerialMove) { lerpDestination = new Vector2(transform.position.x - lerpDistance, transform.position.y); haveMoved = true; joyStickInput = false; aerialMove = false; if (!flipped) { Flip(); } AudioMan.instance.AddClipToLiveQueue(dash[beatCycleNum]); } } } } else { //If mashing move shake and don't move next beat if (joyStickInput && (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)) { shake = 30f; if (BeatMan.instance.onTime) { mashingMove = 3; } else { mashingMove = 2; } if (!playedError) { AudioMan.instance.AddClipToLiveQueue(error); playedError = true; } } } //Shake if (shake > 0f) { Vector2 shakeOffset = UnityEngine.Random.insideUnitCircle * 0.05f; transform.position = transform.position + new Vector3(shakeOffset.x, shakeOffset.y, 0f); } //Set Checkpoints setCheckpoint(); if (finish != null) { if (finish.GetComponent <BoxCollider2D>().IsTouching(this.GetComponent <BoxCollider2D>())) { finishLevel(); } } if (spikes != null) { for (int i = 0; i < spikes.Length; i++) { if (spikes[i].GetComponent <BoxCollider2D>().IsTouching(this.GetComponent <BoxCollider2D>())) { ResettoCheck(); } } } //Attack if (enemyRayHit.collider != null) { Debug.Log("I see an enemy"); currentEnemy = enemyRayHit.transform.gameObject.GetComponent <Combo2>(); CombatInput(); } }