// Update is called once per frame void Update() { // For preview purposes, update current angle to the start angle in editor only if (!Application.isPlaying) { CurrentAngleDegrees = StartAngleDegrees; } // Set position based on Current Angle Vector2 OffsetVector = new Vector2(Mathf.Cos(Mathf.Deg2Rad * CurrentAngleDegrees), Mathf.Sin(Mathf.Deg2Rad * CurrentAngleDegrees)); transform.position = RotationCenter.position + (Vector3)OffsetVector * RadiusAwayFromCenter; //Set rotation based on Current Angle transform.rotation = Quaternion.Euler(0, 0, CurrentAngleDegrees); // Update the Current Angle to move to target direction Vector2 TargetVector = new Vector2(MinigameInputHelper.GetHorizontalAxis(PlayerNum), MinigameInputHelper.GetVerticalAxis(PlayerNum)).normalized; if (Mathf.Abs(TargetVector.x) > 0 || Mathf.Abs(TargetVector.y) > 0) { float TargetAngleDegrees = Mathf.Rad2Deg * Mathf.Atan2(TargetVector.y, TargetVector.x); float AngleDistance = Mathf.DeltaAngle(CurrentAngleDegrees, TargetAngleDegrees); float AngleDirection = Mathf.Sign(AngleDistance); if (Mathf.Abs(AngleDistance) < RotationSpeedDegreePerSecond) { CurrentAngleDegrees = TargetAngleDegrees; } else { CurrentAngleDegrees += RotationSpeedDegreePerSecond * AngleDirection; } } }
private void OnCollisionStay2D(Collision2D collision) { ContactPoint2D point = collision.GetContact(0); // Movement is allowed only when the player is touching the floor if (point.point.y < transform.position.y - 0.01f) { ///transform.position += new Vector3(MinigameInputHelper.GetHorizontalAxis(playerNumber) * 5.0f * Time.deltaTime ,0,0); if (MinigameInputHelper.GetHorizontalAxis(playerNumber) == 1) { body.AddForce(new Vector3(rollSpeed, 0, 0)); } else if (MinigameInputHelper.GetHorizontalAxis(playerNumber) == -1) { body.AddForce(new Vector3(-1 * (rollSpeed), 0, 0)); } } if (body.velocity.x < airSpeedIncreaseLimit) { ///transform.position += new Vector3(MinigameInputHelper.GetHorizontalAxis(playerNumber) * 5.0f * Time.deltaTime ,0,0); if (MinigameInputHelper.GetHorizontalAxis(playerNumber) == 1) { body.AddForce(new Vector3(rollSpeed / 2, 0, 0)); } else if (MinigameInputHelper.GetHorizontalAxis(playerNumber) == -1) { body.AddForce(new Vector3(-1 * (rollSpeed / 2), 0, 0)); } } }
private void checkForInput() { if (Mathf.Abs(MinigameInputHelper.GetHorizontalAxis(1)) < 1) { recentlyMoved = false; } if (!recentlyMoved && MinigameInputHelper.GetHorizontalAxis(1) == 1) { frets[currentFret].deselectFret(); currentFret = (currentFret + 1) % 4; frets[currentFret].selectFret(); recentlyMoved = true; } else if (!recentlyMoved && MinigameInputHelper.GetHorizontalAxis(1) == -1) { frets[currentFret].deselectFret(); currentFret = (currentFret + 3) % 4; frets[currentFret].selectFret(); recentlyMoved = true; } if (recentlyPressed && (Time.time - lastBtnPress >= 0.03f)) { // double press timer elapsed, single press is registered processScore(frets[currentFret].strumFret(false)); recentlyPressed = false; } bool button1 = MinigameInputHelper.IsButton1Down(1); bool button2 = MinigameInputHelper.IsButton2Down(1); if (button1 || button2) { // both buttons pressed at exact same frame if (button1 && button2) { processScore(frets[currentFret].strumFret(true)); } // if no recent button press, set up double press timer else if (!recentlyPressed) { recentlyPressed = true; lastBtnPress = Time.time; } // there was recent button press, and another press came within double press timer else if (Time.time - lastBtnPress < 0.05f) { processScore(frets[currentFret].strumFret(true)); recentlyPressed = false; } } }
void MovePaddle() { // Set velocity float joystick = MinigameInputHelper.GetHorizontalAxis(playerNumber); Vector2 pos = transform.position; pos.x = pos.x + joystick * MAX_VELOCITY * Time.deltaTime; pos.x = Mathf.Clamp(pos.x, leftBound, rightBound); transform.position = pos; }
// Update is called once per frame void Update() { if (hand.isBurned()) { rbody.MovePosition(rbody.transform.position + new Vector3(0, hand.getBurnRatio()) * Time.deltaTime * moveSpeed); rbody.MoveRotation(Mathf.Lerp(rbody.rotation, 2 * maxRot * Random.Range(-1.0f, 1.0f), 0.4f)); } else { float HorizontalAxis = MinigameInputHelper.GetHorizontalAxis(hand.player); float VerticalAxis = MinigameInputHelper.GetVerticalAxis(hand.player); rbody.MovePosition(rbody.transform.position + new Vector3(HorizontalAxis, VerticalAxis) * Time.deltaTime * moveSpeed); rbody.MoveRotation(Mathf.Lerp(rbody.rotation, maxRot * -HorizontalAxis, 0.1f)); } }
// Called every frame private void Update() { // Update the description, character by character if (!descr_fully_visible()) { time_til_next_char -= Time.deltaTime; while (time_til_next_char < 0 && !descr_fully_visible()) { incr_descr_length(); } } // Check for input from this player, to select an option (as long as the animation is done) if (descr_fully_visible()) { if (current_element is TimeBytes_Fork) { if (MinigameInputHelper.IsButton1Down(player)) { TimeBytes_Fork fork = current_element as TimeBytes_Fork; choose_option(fork.Option1); } else if (MinigameInputHelper.IsButton2Down(player)) { TimeBytes_Fork fork = current_element as TimeBytes_Fork; choose_option(fork.Option1); } } else if (current_element is TimeBytes_Extension) { if (MinigameInputHelper.IsButton1Down(player) || MinigameInputHelper.IsButton2Down(player)) { TimeBytes_Extension extension = current_element as TimeBytes_Extension; choose_option(extension.continuation); } } } // If any joystick input was given, skip the rest of the text animation bool hor_skip = Mathf.Abs(MinigameInputHelper.GetHorizontalAxis(player)) > TimeBytes_Config.joystick_skip_thresh; bool vert_skip = Mathf.Abs(MinigameInputHelper.GetVerticalAxis(player)) > TimeBytes_Config.joystick_skip_thresh; if (hor_skip || vert_skip) { description_TMP.maxVisibleCharacters = description_TMP.text.Length; } }
// Update is called once per frame void Update() { // checks for button 2 input every frame if (MinigameInputHelper.IsButton2Down(playerNumber) && hasHook) { // gets player number playerNumber = GetComponent <MovementController>().playerNumber; // gets direction player is moving float xDirection = MinigameInputHelper.GetHorizontalAxis(playerNumber); float yDirection = MinigameInputHelper.GetVerticalAxis(playerNumber); // only shoot the hook if the player is not sitting still if (xDirection != 0 || yDirection != 0) { shootHookInDirection(this.gameObject.transform, xDirection, yDirection); } } }
void CheckUserInput() { time = time + Time.deltaTime; //holds /*if (Input.GetKeyDown(KeyCode.RightShift) || Input.GetKeyDown(KeyCode.LeftShift) || && FindObjectOfType<Game>().GetHoldTime()) || { || enabled = false; || FindObjectOfType<Game>().SetNull(this); || transform.rotation = Quaternion.identity; || transform.position = FindObjectOfType<Game>().transform.position + 6 * Vector3.right + 9 * Vector3.up; || if (!FindObjectOfType<Game>().GetHold()) || { || FindObjectOfType<Game>().SetHold(this); || FindObjectOfType<Spawner>().SpawnNext(); || } || else || { || Tetromino t = FindObjectOfType<Game>().GetHoldTetromino(); || t.enabled = true; || FindObjectOfType<Game>().SetHold(this); || if (t.whereSpawn) || { || t.transform.position += 38 * Vector3.up / 4 + 9 * Vector3.right / 4 + Vector3.down / 4; + } + else + { + t.transform.position = 38 * Vector3.up / 4 + 9 * Vector3.right / 4 + Vector3.left / 4; + } + } + FindObjectOfType<Game>().SetHoldTime(false); + }*/ //go right (joystick right) if (MinigameInputHelper.GetHorizontalAxis(2) > 0 && time > nextMove) { nextMove = time + nextMoveDelta; transform.position += Vector3.right / 2; if (!CheckIsValidPosition()) { transform.position += Vector3.left / 2; } else { FindObjectOfType <Game_2>().UpdateGrid(this); } nextMove = nextMove - time; time = 0.0F; } //go left (joystick left) else if (MinigameInputHelper.GetHorizontalAxis(2) < 0 && time > nextMove) { nextMove = time + nextMoveDelta; transform.position += Vector3.left / 2; if (!CheckIsValidPosition()) { transform.position += Vector3.right / 2; } else { FindObjectOfType <Game_2>().UpdateGrid(this); } nextMove = nextMove - time; time = 0.0F; } //rotate (joystick up) else if (isVerticalReset && MinigameInputHelper.GetVerticalAxis(2) > 0) { transform.Rotate(0, 0, -90); foreach (Transform mino in transform) { mino.Rotate(0, 0, -90); } if (!CheckIsValidPosition()) { transform.Rotate(0, 0, 90); foreach (Transform mino in transform) { mino.Rotate(0, 0, 90); } } else { FindObjectOfType <Game_2>().UpdateGrid(this); } } //rotate other direction (other button) else if (MinigameInputHelper.IsButton2Down(2)) { transform.Rotate(0, 0, 90); foreach (Transform mino in transform) { mino.Rotate(0, 0, 90); } if (!CheckIsValidPosition()) { transform.Rotate(0, 0, -90); foreach (Transform mino in transform) { mino.Rotate(0, 0, -90); } } else { FindObjectOfType <Game_2>().UpdateGrid(this); } } //hard drop (other button) else if (MinigameInputHelper.IsButton1Down(2)) { while (CheckIsValidPosition()) { transform.position += Vector3.down / 2; } transform.position += Vector3.up / 2; FindObjectOfType <Game_2>().UpdateGrid(this); enabled = false; FindObjectOfType <Game_2>().DecreaseAboveRows(); FindObjectOfType <Spawner_2>().SpawnNext(); } //go down (joystick down) else if (((MinigameInputHelper.GetVerticalAxis(2) < 0) || Time.time - fallTime >= fallSpeed) && time > nextMove) { nextMove = time + nextMoveDelta; transform.position += Vector3.down / 2; fallTime = Time.time; if (!CheckIsValidPosition()) { transform.position += Vector3.up / 2; enabled = false; FindObjectOfType <Game_2>().UpdateGrid(this); FindObjectOfType <Game_2>().DecreaseAboveRows(); FindObjectOfType <Spawner_2>().SpawnNext(); //FindObjectOfType<Spawner>().SpawnPreview(); } else { FindObjectOfType <Game_2>().UpdateGrid(this); } nextMove = nextMove - time; time = 0.0F; } isVerticalReset = !MinigameInputHelper.IsVerticalAxisInUse(2); }
private void checkForInput() { float vertical = MinigameInputHelper.GetVerticalAxis(2); float horizontal = MinigameInputHelper.GetHorizontalAxis(2); int switchTo = -1; if (vertical == 1f && horizontal == 0f) { switchTo = 0; } else if (vertical == 1f && horizontal == 1f) { switchTo = 1; } else if (vertical == 0f && horizontal == 1f) { switchTo = 2; } else if (vertical == -1f && horizontal == 1f) { switchTo = 3; } else if (vertical == -1f && horizontal == 0f) { switchTo = 4; } else if (vertical == -1f && horizontal == -1f) { switchTo = 5; } else if (vertical == 0f && horizontal == -1f) { switchTo = 6; } else if (vertical == 1f && horizontal == -1f) { switchTo = 7; } if (switchTo == -1) { if (currentDrum != -1) { drums[currentDrum].deselectDrum(); frogDrummer.selectSprite(8); } currentDrum = -1; } else if (switchTo != currentDrum) { if (currentDrum != -1) { drums[currentDrum].deselectDrum(); } currentDrum = switchTo; drums[switchTo].selectDrum(); frogDrummer.selectSprite(switchTo); } if (MinigameInputHelper.IsButton1Down(2) || MinigameInputHelper.IsButton2Down(2)) { if (currentDrum != -1) { processScore(drums[currentDrum].hitDrum()); } } }
// Update is called once per frame void Update() { //Don't take any input if stunned if (stunned) { stunTime -= Time.deltaTime; if (stunTime <= 0) { stunned = false; } thisRigidBody.velocity = new Vector2(0, thisRigidBody.velocity.y); } else { //Horizontal movement. Maintains y velocity inputVector = new Vector2(MinigameInputHelper.GetHorizontalAxis(playerNumber) * moveSpeed, thisRigidBody.velocity.y); if (inputVector != thisRigidBody.velocity && !isDashing) { thisRigidBody.velocity = inputVector; } //Jump input if (MinigameInputHelper.IsButton1Down(playerNumber) || MinigameInputHelper.GetVerticalAxis(playerNumber) == 1) { //Only jumps if the player is not already jumping or falling if (thisRigidBody.velocity.y < 0.01f && thisRigidBody.velocity.y > -0.01f) { //jump by adding upward force thisRigidBody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse); doubleJumpUsed = false; animator.SetBool("isJumping", true); } //Double jump else if (!doubleJumpUsed && hasDoubleJump) { thisRigidBody.velocity = new Vector3(thisRigidBody.velocity.x, 0, 0); thisRigidBody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse); doubleJumpUsed = true; } } else if (thisRigidBody.velocity.y < 0.01f && thisRigidBody.velocity.y > -0.01f) { animator.SetBool("isJumping", false); } // Dash if (MinigameInputHelper.IsButton2Down(playerNumber) && hasDash && !isDashing) { if (this.gameObject.GetComponent <SpriteRenderer>().flipX == false) { thisRigidBody.AddForce(transform.right * 15f, ForceMode2D.Impulse); isDashing = true; Invoke("resetDash", 0.5f); } else { thisRigidBody.AddForce(transform.right * -15f, ForceMode2D.Impulse); isDashing = true; Invoke("resetDash", 0.5f); } } //Jetpack input if (MinigameInputHelper.IsButton1Held(playerNumber) && hasJetPack) { velVector = new Vector3(thisRigidBody.velocity.x, jetPackVelocity, 0); thisRigidBody.velocity = velVector; } } //Animation stuff tagged = GetComponent <Tag>().isTagged; animator.SetFloat("verticalVelocity", thisRigidBody.velocity.y); GameObject bomb = GetComponent <Tag>().bomb; //Adjust speed for moving platforms if (transform.parent != null && transform.parent.gameObject.GetComponent <Rigidbody2D>() != null) { Vector2 parentVelocity = transform.parent.gameObject.GetComponent <Rigidbody2D>().velocity; thisRigidBody.velocity += parentVelocity; animator.SetFloat("horizontalSpeed", Mathf.Abs(thisRigidBody.velocity.x - parentVelocity.x)); if (thisRigidBody.velocity.x - parentVelocity.x > 0.1) { this.gameObject.GetComponent <SpriteRenderer>().flipX = false; bomb.transform.localPosition = new Vector3(Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z); } else if (thisRigidBody.velocity.x - parentVelocity.x < -0.1) { this.gameObject.GetComponent <SpriteRenderer>().flipX = true; bomb.transform.localPosition = new Vector3(-1f * Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z); } } else { animator.SetFloat("horizontalSpeed", Mathf.Abs(thisRigidBody.velocity.x)); //Flip the sprite if (thisRigidBody.velocity.x > 0.1) { this.gameObject.GetComponent <SpriteRenderer>().flipX = false; bomb.transform.localPosition = new Vector3(Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z); } else if (thisRigidBody.velocity.x < -0.1) { this.gameObject.GetComponent <SpriteRenderer>().flipX = true; bomb.transform.localPosition = new Vector3(-1f * Mathf.Abs(bomb.transform.localPosition.x), bomb.transform.localPosition.y, bomb.transform.localPosition.z); } } //Explode if game is complete float completion = MinigameController.Instance.GetPercentTimePassed(); if (completion >= 1) { bombAnimator.SetTrigger("explode"); //Stop bomb particles bombAnimator.gameObject.GetComponent <ParticleSystem>().Stop(); bombAnimator.gameObject.GetComponent <ParticleSystem>().Clear(); //Scale the bomb to make the exlosion big bombTransform.localScale = new Vector2(2, 2); } }
void Update() { if (direction) { spriteRenderer.flipX = false; } else { spriteRenderer.flipX = true; } float horizontal_axis = MinigameInputHelper.GetHorizontalAxis(player + 1); bool button1 = MinigameInputHelper.IsButton1Down(player + 1); bool button2 = MinigameInputHelper.IsButton2Down(player + 1); bool button2Up = MinigameInputHelper.IsButton2Up(player + 1); float pos_x = gameObject.transform.position.x; float pos_y = gameObject.transform.position.y; float o_pos_x = other.transform.position.x; float o_pos_y = other.transform.position.y; //double p1_height = this.GetComponent<MoveScript>().playerHeight; double p1_width = 0.6 * this.GetComponent <MoveScript>().playerWidth; time += Time.deltaTime; if (horizontal_axis < -0.1) { direction = true; //left } else if (horizontal_axis > 0.1) { direction = false; //right } if ((button1 || MinigameInputHelper.IsButton1Held(player + 1)) && time >= cooldown && TYPE != 4 && ballCharge < 30) { ballCharge++; } if (MinigameInputHelper.IsButton1Up(player + 1) && time >= cooldown && ballCharge > 0 && TYPE != 4) { if (player == 0) { animator.Play("Attack"); } else { animator.Play("Attack2"); } //animator.SetInteger("state", 3 + TYPE); attacktime = 0; time = 0; GameObject p; attacktime = 0; if (direction && !gameObject.GetComponent <ActionScript>().defenseOn) { p = Instantiate(projectile, transform.position - new Vector3((float)2, -1, 0), transform.rotation); p.GetComponent <Rigidbody2D>().velocity = new Vector2(-2.5f, 1.0f) * ballCharge; } else if (!gameObject.GetComponent <ActionScript>().defenseOn) { p = Instantiate(projectile, transform.position + new Vector3((float)2, 1, 0), transform.rotation); p.GetComponent <Rigidbody2D>().velocity = new Vector2(2.5f, 1.0f) * ballCharge; } ballCharge = 0; } //if(attacktime > 0.5 && animator.GetInteger("state") == 3 + TYPE) animator.SetInteger("state", 0 + TYPE); if (button1 && time >= cooldown && TYPE != 0) //kick { double xdist = gameObject.transform.position.x - other.transform.position.x; /*if (!direction && ((pos_x < 0 && xdist > 0 && xdist < 2) || * (pos_x > 0 && xdist < 0 && xdist > -2)) && * other.GetComponent<ActionScript>().defenseOn) * { * other.GetComponent<ActionScript>().shieldHits = other.GetComponent<ActionScript>().shieldHits + 1; * }*/ time = 0; if (player == 0) { animator.Play("K_Attack"); } else { animator.Play("Attack_K2"); } if (direction && xdist > 0 && xdist < 3 * p1_width) /*((pos_x < 0 && xdist > 0 && xdist < 2*p1_width) || * (pos_x > 0 && xdist < 0 && xdist > -2*p1_width)))*/ { if (!other.GetComponent <ActionScript>().defenseOn) { gameObject.GetComponent <HealthScript>().TakeDamage(1); Debug.Log("reached here"); } else { other.GetComponent <ActionScript>().shieldHits++; other.GetComponent <Renderer>().material.SetColor("_Color", Color.blue); Debug.Log(shieldHits); /*if (shieldHits >= 3) * { * shield.transform.localScale = new Vector3(0, 0, 0); * defenseOn = false; * shieldHits = 0; * defCooldown = 0; * }*/ } } /*if (direction && ((pos_x < 0 && xdist < 0 && xdist > -2) || * (pos_x > 0 && xdist > 0 && xdist < 2)) && * other.GetComponent<ActionScript>().defenseOn) * { * other.GetComponent<ActionScript>().shieldHits++; * }*/ if (!direction && xdist < 0 && xdist > -3 * p1_width) /*((pos_x < 0 && xdist < 0 && xdist > -2*p1_width) || * (pos_x > 0 && xdist > 0 && xdist < 2*p1_width)))*/ { if (!other.GetComponent <ActionScript>().defenseOn) { gameObject.GetComponent <HealthScript>().TakeDamage(1); Debug.Log("reached here"); } else { other.GetComponent <ActionScript>().shieldHits++; other.GetComponent <Renderer>().material.SetColor("_Color", Color.blue); Debug.Log(shieldHits); /*if (shieldHits >= 3) * { * shield.transform.localScale = new Vector3(0, 0, 0); * defenseOn = false; * shieldHits = 0; * defCooldown = 0; * }*/ } } } /*if (button1 && TYPE != 0) { * Debug.Log("karate attack"); * * //animator.SetInteger("state", 3 + TYPE); * Debug.Log(animator.GetInteger("state")); * attacktime = 0; * } * /*dif (button1 && time >= cooldown && TYPE != 0 && !other.GetComponent<ActionScript>().defenseOn){//punch //IS THERE A SHIELD CHECK HERE?? yes! * double xdist = pos_x - o_pos_x; * if (!direction && ((pos_x < 0 && xdist > 0 && xdist < 2*p1_width) || * (pos_x > 0 && xdist < 0 && xdist > -2*p1_width))) * { * gameObject.GetComponent<HealthScript>().TakeDamage(1); * } * if (direction && ((pos_x < 0 && xdist < 0 && xdist > -2*p1_width) || * (pos_x > 0 && xdist > 0 && xdist < 2*p1_width))) * { * gameObject.GetComponent<HealthScript>().TakeDamage(1); * } * }*/ defCooldown += Time.deltaTime; if (defCooldown > 3 && !defenseOn) { GameObject.Find("shieldready" + player).transform.localScale = new Vector3(1, 1, 1); } else { GameObject.Find("shieldready" + player).transform.localScale = new Vector3(0, 0, 0); } if (button2 && TYPE != 8 && defCooldown > 3) { shield.transform.localScale = new Vector3(1, 1, 1); defenseOn = true; defCooldown = 0; } if (shieldHits >= 3) { shield.transform.localScale = new Vector3(0, 0, 0); defenseOn = false; shieldHits = 0; defCooldown = 0; } if (button2Up) { shield.transform.localScale = new Vector3(0, 0, 0); defenseOn = false; } attacktime += Time.deltaTime; }
// Update is called once per frame void Update() { if (MinigameInputHelper.GetHorizontalAxis(player) < 0.1 && MinigameInputHelper.GetHorizontalAxis(player) > -0.1 /*&& * animator.GetInteger("state") < 2 + TYPE*/) { animator.SetInteger("state", 0 + TYPE); } else if (animator.GetInteger("state") < 2 + TYPE) { animator.SetInteger("state", 1 + TYPE); } jumpTime += Time.deltaTime; if (animator.GetInteger("state") == 2 + TYPE && jumpTime > 1 + TYPE) { jumpTime = 0; animator.SetInteger("state", 0 + TYPE); } pos = set_vec2(this.transform.position.x, this.transform.position.y); pos2 = set_vec2(other.transform.position.x, other.transform.position.y); read_vel2 = (pos2 - pos2_old) / Time.deltaTime; pos2_old = set_vec2(other.transform.position.x, other.transform.position.y); joystick = set_vec2( MinigameInputHelper.GetHorizontalAxis(player), MinigameInputHelper.GetVerticalAxis(player) ); float ground = (platform.pos.y + platform.height + (float)(0.3 * playerHeight)); if (joystick.y > 0 && (up == false || pos.y <= ground + 0.1)) { if (pos.x <= platform.pos.x + platform.width / 2 && pos.x >= platform.pos.x - platform.width / 2 && pos.y <= ground) { jump_count = 0; } if (jump_count < max_jump) // || (double_jump && jump_count < 1)){ { jump(); up = true; } } if (joystick.y > 0) { up = true; } else { up = false; } //collision with platform if (within_bounds(pos, platform) && !up) { vel.y = 0; //transform.position.y = platform; transform.Translate(0f, (float)(ground - pos.y), 0f); } else if (pos.y < -8) { vel.y = 0; //stops from infinite falling vel.x = 0; double spawn; animator.SetInteger("state", 1); if (pos2.x < platform.pos.x) { spawn = 6.5; //actually fell on the left side gameObject.GetComponent <ActionScript>().setDirection(true); dir = -1; } else { spawn = -6.5; //assuming fell on right side gameObject.GetComponent <ActionScript>().setDirection(false); dir = 1; } const int start_y = 5; transform.Translate((float)(spawn - pos.x), (float)(start_y - pos.y), 0f); other.GetComponent <HealthScript>().TakeDamage(5); sound.PlayDie(); } if (pos.y <= ground) //+thresh? { if (pos.x <= platform.pos.x + platform.width / 2 && pos.x >= platform.pos.x - platform.width / 2 && !up) { jump_count = 0; } run((run_vel / 10) * joystick.x); } else if (abs(joystick.x) > 0) { run((float)0.9 * joystick.x); //slight air movement } else { accel.x = (float)(-0.001 * vel.x); } vel.x += accel.x; vel.y += accel.y; vel.x = clamp(-max_vel, max_vel, vel.x); //clamped at max_vel m/s vel.y = clamp(-2 * max_vel, 2 * max_vel, vel.y); //terminal velocity if (abs(pos.x - pos2.x) <= playerWidth && abs(pos.y - pos2.y) <= playerHeight) { collision(ground); is_in = true; } else { is_in = false; } float ballcharge = this.GetComponent <ActionScript>().ballCharge; //arrow.transform.Translate(0, 0, 0); if (MinigameInputHelper.GetHorizontalAxis(player) < 0) { dir = -1; } else if (MinigameInputHelper.GetHorizontalAxis(player) > 0) { dir = 1; } if (ballcharge > 0 && TYPE == 0) { arrow.transform.Rotate(new Vector3(0, 0, 1), dir * ((3 * ballcharge) * Time.deltaTime)); arrow.transform.localScale = new Vector3((float)(0.2), (float)(0.2), 1); } else { arrow.transform.rotation = Quaternion.identity; arrow.transform.localScale = new Vector3(0, 0, 0); } //if(player == 0){ if (dir < 0) { arrow.GetComponent <SpriteRenderer>().flipX = false; } else if (dir > 0) { arrow.GetComponent <SpriteRenderer>().flipX = true; } this.transform.localScale = new Vector3((float)(1.2 * playerWidth), (float)(1.2 * playerHeight), 1); transform.Translate( vel.x * Time.deltaTime, vel.y * Time.deltaTime, 0.0f ); }
void FixedUpdate() { float moveHorizontal = MinigameInputHelper.GetHorizontalAxis(player_num); float moveVertical = MinigameInputHelper.GetVerticalAxis(player_num); Vector3 movement = Vector3.Normalize(new Vector3(moveHorizontal, 0.0f, moveVertical)); anim.SetFloat("Speed", 0); //when tongue is not moving, you can run and jump freely // if (!tongue.moving) { tonguePos = transform.position; if (movement.magnitude > 0.1) { rb.MovePosition(transform.position + movement * horizontalSpeed); Quaternion q = Quaternion.LookRotation(-1 * movement, Vector3.up); if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Ghost_Armature|TongueOut")) { rb.MoveRotation(q); } facingDirection = Vector3.Normalize(movement); anim.SetFloat("Speed", moveHorizontal * moveHorizontal + moveVertical * moveVertical); } if (grounded && MinigameInputHelper.IsButton1Held(player_num)) { anim.SetBool("Grounded", false); anim.SetTrigger("Jump"); audio.PlayOneShot(jumpingSound, 1.0F); grounded = false; rb.AddForce(Vector3.up * jumpPower); } else { anim.ResetTrigger("Jump"); } if (!grounded && rb.transform.position.y < .01) { grounded = true; anim.SetBool("Grounded", true); } if (!grounded) { rb.AddForce(Vector3.down * fallPower); } if (MinigameInputHelper.IsButton2Held(player_num) && !tongue.moving) { anim.SetTrigger("Tongue"); audio.PlayOneShot(tongueSound, 1.0F); tongue.setDestination(transform.position + facingDirection * tongueDistance); } else { anim.ResetTrigger("Tongue"); } } // //move fruits being eaten closer to the mouth // foreach(GameObject fruit in eating) // { // if (fruit != null) // { // Vector3 newPos = Vector3.Lerp(fruit.transform.position, mouth.position, eatingSpeed * Time.deltaTime); // fruit.transform.position = new Vector3(newPos.x, fruit.transform.position.y, newPos.z); // } // } }
// Update is called once per frame void Update() { if (MinigameInputHelper.IsButton1Down(1) || MinigameInputHelper.IsButton2Down(1) || MinigameInputHelper.IsButton1Down(2) || MinigameInputHelper.IsButton2Down(2)) { if (selected == 1) { cooldown2 = 0.7f; if (side == "left") { calibration -= (calibration <= -1 ? 0.0f : 0.01f); } else if (side == "right") { calibration += (calibration < 1 ? 0.01f : 0.0f); } } else if (selected == 0) { cooldown2 = 0.7f; if (side == "left") { masterVolume -= (masterVolume <= 0 ? 0 : 1); } else if (side == "right") { masterVolume += (masterVolume <= 100 ? 1 : 0); } } else if (selected == 2) { calibra = calibration; volume = masterVolume; } else if (selected == 3) { returnToMainMenu(); } } float joystickx1, joystickx2; float joysticky1, joysticky2; if (cooldown > 0) { cooldown -= Time.deltaTime; } else { joystickx1 = MinigameInputHelper.GetHorizontalAxis(1); joystickx2 = MinigameInputHelper.GetHorizontalAxis(2); joysticky1 = MinigameInputHelper.GetVerticalAxis(1); joysticky2 = MinigameInputHelper.GetVerticalAxis(2); if (joysticky1 < 0 || joysticky2 < 0) //scroll up { selected = (selected + 1) % 4; cooldown = 0.28f; } else if (joysticky1 > 0 || joysticky2 > 0) //scroll down { selected = (selected - 1 + 4) % 4; cooldown = 0.28f; } if (selected < 2) { if (joystickx1 < 0 || joystickx2 < 0) //left nudge { side = "left"; cooldown2 = 1.3f; if (selected == 0) { masterVolume -= (masterVolume <= 0 ? 0 : 1); cooldown = 0.1f; } else { calibration -= (calibration <= -1 ? 0.0f : 0.01f); cooldown = 0.1f; } } else if (joystickx1 > 0 || joystickx2 > 0) //right nudge { side = "right"; cooldown2 = 1.3f; if (selected == 0) { masterVolume += (masterVolume < 100 ? 1 : 0); cooldown = 0.1f; } else { calibration += (calibration <= 1 ? 0.01f : 0.0f); cooldown = 0.1f; } } } } //eventCap.GetComponent<UnityEngine.EventSystems.EventSystem>().SetSelectedGameObject(null); if (true) { if (selected == 0) { volumeSliderTool[1].GetComponent <Button>().Select(); } else if (selected == 1) { calibratorTool[1].GetComponent <Button>().Select(); } else if (selected == 2) { applyButtn.GetComponent <Button>().Select(); } else { returnButtn.GetComponent <Button>().Select(); } } if (cooldown2 > 0) { if (side == "left") { if (selected == 0) { volumeSliderTool[0].GetComponent <Button>().Select(); } else { calibratorTool[0].GetComponent <Button>().Select(); } } else { if (selected == 0) { volumeSliderTool[2].GetComponent <Button>().Select(); } else { calibratorTool[2].GetComponent <Button>().Select(); } } cooldown2 -= Time.deltaTime; } t_calibration.text = "Delay: " + (Mathf.Round(calibration * 100) / 100).ToString(); calibration_bar.fillAmount = (calibration + 1) / 2; t_m_volume.text = "Master Volume: " + masterVolume.ToString(); volume_bar.fillAmount = ((float)masterVolume) / 100; }