Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : Character
- {
- public byte playerNum;
- public byte charNum;
- public float maxspeed, speedcount, speedrate, turnrate; //speed floats
- public float jumpheld, jumpreset; //jump floats
- public float MercyTime, defaultMercyTime, launcherDist;
- public byte downstep, upstep, leftstep, rightstep, punchcount;
- public float isFacing, moveDelay, moveThisMuch, stunTime, leftBuffer, downBuffer, upBuffer, rightBuffer; //various other floats
- public bool isOnFloor, solidfloor, isAttack, landed, leftPress, rightPress, downPress, upPress; //various bools
- public string lastmove;
- public string Horizontal, Vertical, A, B, C;
- public byte canAirAttack;
- // Use this for initialization
- public override void Start()
- {
- health = 1;// playerNum == 1 ? GameManager.Lives1 : GameManager.Lives2;
- Horizontal = playerNum == 1 ? Controls.H1 : Controls.H2;
- Vertical = playerNum == 1 ? Controls.V1 : Controls.V2;
- A = playerNum == 1 ? Controls.A1 : Controls.A2;
- B = playerNum == 1 ? Controls.B1 : Controls.B2;
- C = playerNum == 1 ? Controls.C1 : Controls.C2;
- gravity = maxgravity;
- facing = 1;
- state = "alive";
- base.Start();
- }
- // Update is called once per frame
- public override void Update()
- {
- base.Update();
- if (!isOnFloor)
- {
- solidfloor = false;
- }
- DirPresses();
- if (health < 0)
- { //if the players health is less than or equal to 0
- state = "dead"; //they are dead
- }
- if (state == "alive")
- { //if the player is alive
- stunTime = 0.5f;
- if (MercyTime > 0f)
- {
- MercyTime -= Time.deltaTime;
- }
- Movement(); //execute movement commands
- Animations(); //execute attack commands
- Attacks(); //players can only attack when not in landing animation
- } else if (state == "stun")
- {
- Stun();
- } else if (state == "dead")
- {
- Dead();
- }
- }
- public virtual void Movement()
- {
- if (!isAttack)
- {
- if (Controls.GetAxis(Horizontal) != 0)
- {
- speed = Mathf.Clamp(speed + (speedrate * Time.deltaTime), 0, maxspeed);
- transform.rotation = Quaternion.AngleAxis(180 * (Controls.GetAxis(Horizontal) < 0).CompareTo(false), Vector3.up);
- facing = Controls.GetAxis(Horizontal);
- }
- else
- {
- speed = Mathf.Clamp(speed - (speedrate * Time.deltaTime), 0, maxspeed);
- }
- if (Controls.GetAxis(Horizontal) > 0)
- {
- isFacing = Mathf.Min(isFacing + (turnrate * Time.deltaTime), 1);
- }
- if (Controls.GetAxis(Horizontal) < 0)
- {
- isFacing = Mathf.Max(isFacing - (turnrate * Time.deltaTime), -1);
- }
- } else
- {
- speed = 0;
- }
- rb.velocity = new Vector3((speed * isFacing), rb.velocity.y);
- Jumping();
- }
- public virtual void Jumping()
- {
- if (Controls.GetButtonDown(A) && isOnFloor && Controls.GetAxis(Vertical) >= 0 && (notPlaying("uu", "dd", "aa", "adb")))
- {
- if (lastmove == "")
- lastmove = anim.CurrentClip.name;
- isAttack = false;
- jump = maxjump;
- downstep = 0;
- upstep = 0;
- }
- if (!isAttack)
- {
- if (!isOnFloor && jump > jumprate*-1.5)
- {
- jump -= jumprate * Time.deltaTime;
- }
- if ((Controls.GetButtonUp(A) && jump > 0) || (isOnFloor && jump < 0))
- {
- jump = 0;
- }
- } else
- {
- jump = 0;
- }
- rb.velocity = new Vector3(rb.velocity.x, jump);
- }
- public virtual void Animations()
- {
- if (!isAttack)
- {
- if (!isOnFloor)
- {
- if (jump > 0)
- {
- playThis("jump");
- }
- if (jump < 0)
- {
- playThis("fall");
- }
- }
- else
- {
- if (Controls.GetAxis(Horizontal) == 0)
- {
- playThis("idle");
- }
- else
- {
- playThis("run");
- }
- }
- }
- }
- public virtual void Attacks()
- {
- if (moveDelay > 0f)
- {
- moveDelay -= Time.deltaTime;
- }
- if (moveDelay <= 0f)
- {
- lastmove = "";
- }
- if (isOnFloor)
- {
- canAirAttack = 0;
- }
- if (Controls.GetButtonDown(B) && Controls.GetAxis(Vertical) == 0 && notPlaying("rb", "da", "dd", "adb", "ub", "aa") && punchcount < 3 && lastmove != "b" && lastmove != "bb" && (canAirAttack & 1) == 0)
- {
- isAttack = true;
- punchcount++;
- if (anim.IsPlaying("uu"))
- {
- canAirAttack |= 32;
- }
- if (anim.IsPlaying("aa"))
- {
- canAirAttack |= 128;
- }
- if (punchcount % 2 == 1)
- {
- anim.Play("b");
- } else
- {
- anim.Play("bb");
- }
- }
- if (endOfAnim("b"))
- {
- lastmove = "b";
- canAirAttack |= 1;
- moveDelay = 0.4f + (0.0f * (punchcount >= 4).CompareTo(false));
- isAttack = false;
- punchcount = 0;
- }
- if (endOfAnim("bb"))
- {
- lastmove = "bb";
- canAirAttack |= 1;
- moveDelay = 0.4f;
- isAttack = false;
- punchcount = 0;
- }
- if (!Controls.GetButton(B) && lastmove != "dd" && (Controls.GetButtonDown(A) || (Controls.GetButton(A) && (anim.CurrentClip.name[0] == 'a' || anim.CurrentClip.name[0] == 'j') && anim.CurrentFrame < 1)) && Controls.GetAxis(Vertical) < 0 && notPlaying("da", "aa", "dd", "adb", "ub") && lastmove != "da" && (canAirAttack & 2) == 0 && (!anim.IsPlaying("rb") || (anim.IsPlaying("rb") && Controls.GetAxis(Horizontal) == -facing)))
- {
- if ((anim.IsPlaying("rb") && Controls.GetAxis(Horizontal) == -facing)){
- transform.rotation = Quaternion.AngleAxis(180 * (Controls.GetAxis(Horizontal) < 0).CompareTo(false), Vector3.up);
- facing = Controls.GetAxis(Horizontal);
- }
- isAttack = true;
- playThis("da");
- }
- if (endOfAnim("da"))
- {
- lastmove = "da";
- canAirAttack |= 34;
- moveDelay = 0.4f;
- isAttack = false;
- punchcount = 0;
- }
- if (!Controls.GetButton(B) && !Controls.GetButton(A) && ((rightstep >= 2 && leftstep == 0) || (leftstep >= 2 && rightstep == 0)) && notPlaying("rb", "da", "dd", "ub", "adb", "aa") && lastmove != "rb" && (canAirAttack & 4) == 0)
- {
- if (anim.IsPlaying("uu"))
- {
- canAirAttack |= 32;
- }
- isAttack = true;
- anim.Play("rb");
- }
- if (anim.IsPlaying("rb"))
- {
- rb.velocity = new Vector3(maxspeed * 3f/2f * facing, 0);
- }
- if (endOfAnim("rb"))
- {
- lastmove = "rb";
- canAirAttack |= 36;
- moveDelay = 0.4f;
- isAttack = false;
- punchcount = 0;
- }
- if (Controls.GetButton(B) && lastmove != "dd" && !Controls.GetButton(A) && Controls.GetAxis(Vertical) > 0 && notPlaying("rb", "da", "dd", "uu", "adb", "aa", "ub") && lastmove != "ub" && (canAirAttack & 8) == 0)
- {
- isAttack = true;
- playThis("ub");
- }
- if (endOfAnim("ub"))
- {
- lastmove = "ub";
- canAirAttack |= 40;
- moveDelay = 0.3f;
- isAttack = false;
- punchcount = 0;
- }
- if (Controls.GetButton(B) && !Controls.GetButton(A) && lastmove != "dd" && lastmove != "ub" && lastmove != "da" && Controls.GetAxis(Vertical) < 0 && !isOnFloor && notPlaying("rb", "da", "dd", "ub", "aa") && lastmove != "adb" && (canAirAttack & 16) == 0)
- {
- if (anim.IsPlaying("uu"))
- {
- canAirAttack |= 32;
- }
- if (anim.IsPlaying("aa"))
- {
- canAirAttack |= 128;
- }
- isAttack = true;
- playThis("adb");
- }
- if (endOfAnim("adb"))
- {
- lastmove = "adb";
- canAirAttack |= 176;
- moveDelay = 0.4f;
- isAttack = false;
- punchcount = 0;
- }
- if (downstep >= 2 && upstep == 0 && !Controls.GetButton(B) && !Controls.GetButton(A) && !solidfloor && (!anim.IsPlaying("jump") || (anim.IsPlaying("jump") && anim.CurrentFrame > 0)) && notPlaying("rb", "aa", "uu", "adb", "ub", "da") && lastmove != "dd")
- {
- if (isOnFloor)
- {
- boxcol.isTrigger = true;
- }
- rb.velocity = Vector3.zero;
- isAttack = true;
- anim.Play("dd");
- }
- if (anim.IsPlaying("dd") && !isOnFloor)
- {
- rb.velocity = new Vector3(0, -maxspeed * 3f);
- }
- }
- public virtual void Stun()
- {
- }
- public virtual void Dead()
- {
- }
- public virtual void Sounds()
- {
- }
- public void DirPresses() //this determines what direction is tapped
- {
- if (leftBuffer > 0f)
- {
- leftBuffer -= Time.deltaTime;
- }
- if (leftBuffer <= 0f)
- {
- leftstep = 0;
- }
- if (rightBuffer > 0f)
- {
- rightBuffer -= Time.deltaTime;
- }
- if (rightBuffer <= 0f)
- {
- rightstep = 0;
- }
- if (downBuffer > 0f)
- {
- downBuffer -= Time.deltaTime;
- }
- if (downBuffer <= 0f)
- {
- downstep = 0;
- }
- if (upBuffer > 0f)
- {
- upBuffer -= Time.deltaTime;
- }
- if (upBuffer <= 0f)
- {
- upstep = 0;
- }
- if (Controls.GetAxis(Vertical) == 0)
- {
- downPress = true;
- upPress = true;
- }
- else
- {
- if (downPress)
- {
- if (Controls.GetAxis(Vertical) < 0)
- {
- downstep += 1;
- downBuffer = 0.33f;
- }
- downPress = false;
- }
- if (upPress)
- {
- if (Controls.GetAxis(Vertical) > 0)
- {
- upstep += 1;
- upBuffer = 0.33f;
- }
- upPress = false;
- }
- }
- if (Controls.GetAxis(Horizontal) == 0)
- {
- leftPress = true;
- rightPress = true;
- }
- else
- {
- if (leftPress)
- {
- if (Controls.GetAxis(Horizontal) < 0)
- {
- leftstep += 1;
- leftBuffer = 0.33f;
- }
- leftPress = false;
- }
- if (rightPress)
- {
- if (Controls.GetAxis(Horizontal) > 0)
- {
- rightstep += 1;
- rightBuffer = 0.33f;
- }
- rightPress = false;
- }
- }
- }
- public bool isFloorCollision(Collision c)
- {
- foreach (ContactPoint col in c)
- {
- if (transform.position.y > col.point.y && Mathf.Abs((transform.position.y + boxcol.center.y) - col.point.y) >= boxcol.size.y / 2f)
- {
- //Debug.Log("floor");
- return true;
- }
- }
- return false;
- }
- public bool isCeilingCollision(Collision c)
- {
- foreach (ContactPoint col in c)
- {
- if (transform.position.y < col.point.y && Mathf.Abs((transform.position.y + boxcol.center.y) - col.point.y) >= boxcol.size.y / 2f)
- {
- //Debug.Log("ceiling");
- return true;
- }
- }
- return false;
- }
- public bool isWallCollision(Collision c)
- {
- foreach (ContactPoint col in c)
- {
- if (Mathf.Abs(transform.position.y - col.point.y) < boxcol.size.y / 2f && Mathf.Abs(transform.position.x - col.point.x) >= boxcol.size.x/2f)
- {
- //Debug.Log("wall");
- return true;
- }
- }
- return false;
- }
- public void OnCollisionEnter(Collision col)
- {
- if (col.gameObject.tag.Contains("Floor") && anim.IsPlaying("dd"))
- {
- lastmove = "dd";
- moveDelay = 0.8f;
- isAttack = false;
- punchcount = 0;
- }
- if (col.gameObject.tag.Contains("Floor"))
- {
- //Debug.Log("AAAAAAAAAAA");
- if (isFloorCollision(col))
- {
- if (col.gameObject.tag.Contains("Solid"))
- {
- solidfloor = true;
- }
- isOnFloor = true;
- boxcol.isTrigger = false;
- }
- if (isCeilingCollision(col) || (isWallCollision(col) && transform.position.y < col.gameObject.transform.position.y))
- {
- boxcol.isTrigger = true;
- }
- }
- }
- public void OnCollisionStay(Collision col)
- {
- if (col.gameObject.tag == "Wall")
- {
- if (isWallCollision(col) && facing == Mathf.Sign(col.transform.position.x - transform.position.x))
- {
- speed = 0;
- }
- }
- }
- public void OnCollisionExit(Collision col)
- {
- if (col.gameObject.tag.Contains("Floor"))
- {
- isOnFloor = false;
- }
- }
- public void OnTriggerEnter(Collider col)
- {
- if (col.gameObject.tag.Contains("Floor") && !anim.IsPlaying("dd"))
- {
- transform.position += new Vector3(0, 32, 0);
- }
- }
- public void OnTriggerStay(Collider col)
- {
- if (col.gameObject.tag.Contains("Floor") && !anim.IsPlaying("dd"))
- {
- transform.position += new Vector3(0, 32, 0);
- }
- }
- public void OnTriggerExit(Collider col)
- {
- if (col.gameObject.tag.Contains("Floor"))
- {
- boxcol.isTrigger = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement