Example #1
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         PlayerInputContainer pcon = collision.GetComponent <PlayerInputContainer>();
         if (pcon.GetAButton() && !pcon.isOperatingStation)
         {
             if (shipInfo.SetFixer(collision.gameObject)) // returns true when there is nobody controlling
             {
                 pcon.isOperatingStation = true;
                 shipInfo.freezePlayer(collision.gameObject);
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(false);
             }
         }
         else if (pcon.GetBButton() && pcon.isOperatingStation)
         {
             //Debug.Log("Attempting to remove pilot");
             if (shipInfo.RemoveFixer(collision.gameObject)) // returns true if collision.gameObject is the player set as pilot
             {
                 pcon.isOperatingStation = false;
                 shipInfo.unfreezePlayer(collision.gameObject);
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(true);
             }
         }
     }
 }
 public void TryShoot(PlayerInputContainer pcon)
 {
     for (int i = 0; i < guns.Count; i++)
     {
         ((GameObject)guns[i]).GetComponent <GunControl>().Fire(pcon);
     }
 }
Example #3
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         PlayerInputContainer pcon = collision.GetComponent <PlayerInputContainer>();
         if (pcon.GetAButton() && !pcon.isOperatingStation)
         {
             if (shipInfo.SetPilot(collision.gameObject)) // returns true when there is nobody controlling
             {
                 //Debug.Log("Name on pilot collision: " + collision.gameObject.name);
                 //Debug.Log(collision.gameObject.name + "'s a button: " + pcon.GetAButton());
                 pcon.isOperatingStation = true;
                 shipInfo.freezePlayer(collision.gameObject);
                 //collision.gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                 //collision.gameObject.GetComponent<Rigidbody2D>().isKinematic = true;
                 //collision.gameObject.GetComponent<Collider2D>().isTrigger = true;
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(false);
             }
         }
         else if (pcon.GetBButton() && pcon.isOperatingStation)
         {
             //Debug.Log("Attempting to remove pilot");
             if (shipInfo.RemovePilot(collision.gameObject)) // returns true if collision.gameObject is the player set as pilot
             {
                 pcon.isOperatingStation = false;
                 shipInfo.unfreezePlayer(collision.gameObject);
                 //collision.gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
                 //collision.gameObject.GetComponent<Rigidbody2D>().isKinematic = false;
                 //collision.gameObject.GetComponent<Collider2D>().isTrigger = false;
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(true);
             }
         }
     }
 }
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         PlayerInputContainer pcon = collision.GetComponent <PlayerInputContainer>();
         if (pcon.GetAButton() && !pcon.isOperatingStation)
         {
             if (shipInfo.SetPilot(collision.gameObject)) // returns true when there is nobody controlling
             {
                 Debug.Log("Name on pilot collision: " + collision.gameObject.name);
                 Debug.Log(collision.gameObject.name + "'s a button: " + pcon.GetAButton());
                 pcon.isOperatingStation = true;
                 //collision.gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                 collision.gameObject.GetComponent <Rigidbody2D>().isKinematic = true;
                 //collision.gameObject.GetComponent<BoxCollider2D>().enabled = false;
                 //disabling box collider fixes awkward flying if player is colliding with control station while flying, but then player can't exit station
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(false);
             }
         }
         else if (pcon.GetBButton() && pcon.isOperatingStation)
         {
             Debug.Log("Attempting to remove pilot");
             if (shipInfo.RemovePilot(collision.gameObject)) // returns true if collision.gameObject is the player set as pilot
             {
                 pcon.isOperatingStation = false;
                 //collision.gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
                 collision.gameObject.GetComponent <Rigidbody2D>().isKinematic = false;
                 //collision.gameObject.GetComponent<BoxCollider2D>().enabled = true;
                 collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(true);
             }
         }
     }
 }
 public void TryRepair(PlayerInputContainer pcon)
 {
     if (pcon.GetRTButton() == 1 && GameController.instance.boostBroken)
     {
         timer += regenAmt;
         GameController.instance.SetBoost(timer);
         GameController.instance.UpdateBoost();
         if (timer >= coolDownTime)
         {
             timer = 0;
             GameController.instance.boostBroken = false;
         }
     }
 }
    public void MoveReticle(PlayerInputContainer pcon)
    {
        Vector2 stickInput = new Vector2(pcon.GetHorizontal(), pcon.GetVertical());

        stickInput = Vector2.ClampMagnitude(stickInput, 1);   //clamp magnitude to keep circle boundary for x/y-axis, instead of square
        if (stickInput.magnitude < reticleDeadZone)
        {
            stickInput.x = 0;
            stickInput.y = 0;
        }

        if (stickInput.x == 0 && stickInput.y == 0)
        {
        }
        else
        {
            Quaternion eulerRot = Quaternion.Euler(0, 0, Mathf.Atan2(-stickInput.x, stickInput.y) * 180 / Mathf.PI);
            weaponAimControlCenter.transform.rotation = Quaternion.Slerp(weaponAimControlCenter.transform.rotation, eulerRot, Time.deltaTime * reticleRotationSpeed);
        }
    }
    public void MoveShip(PlayerInputContainer pic)
    {
        if (pic.isOperatingStation && !isDeflecting)
        {
            if (pic.GetRTButton() == 1 && !GameController.instance.boostBroken)
            {
                GameController.instance.isBoosting = true;
                GameController.instance.SendMessage("UseBoost", usageAmt);
                timeStamp = Time.time + coolDownPeriod;
                if (boostTimeStamp == 0 && GameController.instance.GetCurrentBoost() == 0)
                {
                    boostTimeStamp = Time.time + GameController.instance.getTimeToBreak();
                }
                inputAcceleration = baseAccel + accelIncrease;
                velocityDrag      = baseDrag - dragDecrease;
                maxSpeed          = baseSpeed + maxSpeedIncrease;
                //Debug.Log("pressing RT, max speed: " + maxSpeed);
            }
            else
            {
                GameController.instance.isBoosting = false;
                //velocityDrag = baseDrag;
                inputAcceleration = baseAccel;
                maxSpeed          = baseSpeed;
            }
            if (Time.time > boostTimeStamp && GameController.instance.isBoosting && GameController.instance.GetCurrentBoost() == 0)
            {
                GameController.instance.boostBroken = true;
            }

            if (Time.time >= timeStamp && !GameController.instance.boostBroken)
            {
                GameController.instance.SendMessage("RegenerateBoost", regenAmt);
            }
            // apply forward input
            acceleration = new Vector3(pic.GetHorizontal() * inputAcceleration, pic.GetVertical() * inputAcceleration, 0f);
            velocity    += acceleration * Time.deltaTime;
        }
        velocityDrag      = baseDrag;
        inputAcceleration = baseAccel;
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            //Debug.Log("Ship controls collided with a player");
            PlayerInputContainer pcon = collision.GetComponent <PlayerInputContainer>();
            if (pcon.GetAButton() && !pcon.isOperatingStation)
            {
                if (shipInfo.SetGunner(collision.gameObject)) // returns true when there is nobody controlling
                {
                    Debug.Log("Name on gunner collision: " + collision.gameObject.name);
                    Debug.Log(collision.gameObject.name + "'s a button: " + pcon.GetAButton());
                    pcon.isOperatingStation = true;
                    collision.gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
                    collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(false);
                }
            }

            else if (pcon.GetBButton() && pcon.isOperatingStation)
            {
                Debug.Log("Attempting to remove gunner");
                if (shipInfo.RemoveGunner(collision.gameObject)) // returns true if collision.gameObject is the player set as pilot
                {
                    pcon.isOperatingStation = false;
                    collision.gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
                    collision.gameObject.GetComponent <CameraHolder>().playerCamera.SetActive(true);
                }
            }
            if (pcon.GetBButton())
            {
                Debug.Log("B was pressed inside gunner collider");
            }
            if (pcon.GetAButton())
            {
                Debug.Log("A was pressed inside gunner collider");
            }
        }
    }
    public void Fire(PlayerInputContainer pcon)
    {
        if (timer < shootFrequency)
        {
            return;
        }

        if ((fireButton == "A" && pcon.GetAButton()) ||
            (fireButton == "X" && pcon.GetXButton()) ||
            (fireButton == "Y" && pcon.GetYButton()) ||
            (fireButton == "RT" && pcon.GetRTButton() == 1))
        {
            for (int i = 0; i < projectilesFiredPerPress; i++)
            {
                Instantiate(projectile, transform.position, transform.rotation);
            }
            if (gunAnim != null)
            {
                gunAnim.SetTrigger("Fire");
            }
            timer = 0;
        }
    }
    public void MoveShip(PlayerInputContainer pic)
    {
        if (pic.isOperatingStation)
        {
            if (pic.GetXButton() && GameController.instance.GetCurrentBoost() > 0)
            {
                Debug.Log("pressing X");

                movementSpeed = baseSpeed + speedIncrease;
                GameController2.instance.SendMessage("UseBoost", usageAmt);
                timeStamp = Time.time + coolDownPeriod;
            }

            if (Time.time >= timeStamp)
            {
                GameController.instance.SendMessage("RegenerateBoost", regenAmt);
            }

            transform.position += new Vector3(pic.GetHorizontal(), pic.GetVertical(), 0f) * movementSpeed;
        }

        Debug.Log(movementSpeed);
        movementSpeed = baseSpeed;
    }
Example #11
0
 // Use this for initialization
 void Start()
 {
     container1 = Player1.GetComponent <PlayerInputContainer>();
     container2 = Player2.GetComponent <PlayerInputContainer>();
 }
 // Use this for initialization
 void Start()
 {
     pic  = GetComponent <PlayerInputContainer>();
     ship = GameObject.Find("Ship");
 }
Example #13
0
 // Use this for initialization
 void Start()
 {
     rb2d = GetComponent <Rigidbody2D>();
     pic  = GetComponent <PlayerInputContainer>();
 }
Example #14
0
 public void AssignInputSet(PlayerInputContainer set)
 {
     Input.SteeringInput.Variable     = set.Steering;
     Input.AccelerationInput.Variable = set.Acceleration;
     Input.BrakeInput.Variable        = set.Braking;
 }