Beispiel #1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            TakeItem();
        }

        if (Input.GetMouseButtonUp(0))
        {
            DropItem();
        }

        if (TakedObject != null && Input.GetMouseButton(0))
        {
            if (TakedObject.mass > maxMass)
            {
                TakedObject.AddForce(Vector2.ClampMagnitude((Vector2)target.position - TakedObject.position, 1f) * Force);
            }
            else
            {
                TakedObject.velocity = ((Vector2)RigTakeObj.position - TakedObject.position) * 20f;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            TakedObject?.GetComponent <GenericItem>()?.Action(this);
        }
    }
 /// <summary>
 /// Checks if car is not moving
 /// </summary>
 private void checkIdleCar()
 {
     if (car?.GetComponent <Rigidbody2D>().velocity.magnitude < CarIdle)
     {
         CarSound.Instance?.PlayIdleCarSound();
     }
 }
Beispiel #3
0
 private void KnockBackTheEnemy(Collider2D other, Rigidbody2D OtherRigidbody)
 {
     OtherRigidbody.GetComponent <Enemy>().EnemyCurrentState = EnemyState.stagger;
     other.GetComponent <Enemy>().Knock(OtherRigidbody, KnockTime, Damage);
 }
    void fireWeaponAtAngle(Vector3 offset, Quaternion rot, Vector3 vel)
    {
        Rigidbody2D bullet = Instantiate(laserPrefab, transform.position + offset, rot) as Rigidbody2D;

        bullet.GetComponent <Rigidbody2D>().velocity = vel;
    }
Beispiel #5
0
    //Con esta funcion activamos el power up en el personaje correspondiente y si este ya dispone de un power up desactivamos la caja sin dar nada al personaje
    private void OnTriggerStay2D(Collider2D collision)
    {
        //Escudo
        if (type == 0)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled  = false;
                GetComponent <SpriteRenderer>().enabled = false;
                GetComponent <AudioSource>().Play();
                player.GetComponent <PlayerScript>().shielded = true;
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }

            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled   = false;
                GetComponent <SpriteRenderer>().enabled  = false;
                NPC1.GetComponent <NPCScript>().shielded = 1;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled   = false;
                GetComponent <SpriteRenderer>().enabled  = false;
                NPC2.GetComponent <NPCScript>().shielded = 1;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
        //Salto doble
        if (type == 1)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled              = false;
                GetComponent <SpriteRenderer>().enabled             = false;
                player.GetComponent <PlayerScript>().doubleJump     = true;
                player.GetComponent <PlayerScript>().remainingJumps = 3;
                playerBootL.enabled = true;
                playerBootR.enabled = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled         = false;
                GetComponent <SpriteRenderer>().enabled        = false;
                NPC1.GetComponent <NPCScript>().doubleJump     = 1;
                NPC1.GetComponent <NPCScript>().remainingJumps = 3;
                NPCBootL.enabled = true;
                NPCBootR.enabled = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled         = false;
                GetComponent <SpriteRenderer>().enabled        = false;
                NPC2.GetComponent <NPCScript>().doubleJump     = 1;
                NPC2.GetComponent <NPCScript>().remainingJumps = 3;
                NPC2BootL.enabled = true;
                NPC2BootR.enabled = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
        //Trampa
        if (type == 2)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled       = false;
                GetComponent <SpriteRenderer>().enabled      = false;
                player.GetComponent <PlayerScript>().canTrap = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled  = false;
                GetComponent <SpriteRenderer>().enabled = false;
                NPC1.GetComponent <NPCScript>().canTrap = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled  = false;
                GetComponent <SpriteRenderer>().enabled = false;
                NPC2.GetComponent <NPCScript>().canTrap = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
        //Bola de energia simple
        if (type == 3)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled            = false;
                GetComponent <SpriteRenderer>().enabled           = false;
                player.GetComponent <PlayerScript>().energySimple = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled       = false;
                GetComponent <SpriteRenderer>().enabled      = false;
                NPC1.GetComponent <NPCScript>().energySimple = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled       = false;
                GetComponent <SpriteRenderer>().enabled      = false;
                NPC2.GetComponent <NPCScript>().energySimple = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
        //Bola de energia oscura
        if (type == 4)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled          = false;
                GetComponent <SpriteRenderer>().enabled         = false;
                player.GetComponent <PlayerScript>().darkEnergy = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled     = false;
                GetComponent <SpriteRenderer>().enabled    = false;
                NPC1.GetComponent <NPCScript>().darkEnergy = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled     = false;
                GetComponent <SpriteRenderer>().enabled    = false;
                NPC2.GetComponent <NPCScript>().darkEnergy = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
        //Niebla
        if (type == 5)
        {
            if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground&& !used && !player.GetComponent <PlayerScript>().powered)
            {
                used = true;
                playerAnim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled      = false;
                GetComponent <SpriteRenderer>().enabled     = false;
                player.GetComponent <PlayerScript>().canFog = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping&& !used && !NPC1.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC1Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled  = false;
                GetComponent <SpriteRenderer>().enabled = false;
                NPC1.GetComponent <NPCScript>().canFog  = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
            }
            else if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping&& !used && !NPC2.GetComponent <NPCScript>().powered)
            {
                used = true;
                NPC2Anim.gameObject.SetActive(true);
                GetComponent <BoxCollider2D>().enabled  = false;
                GetComponent <SpriteRenderer>().enabled = false;
                NPC2.GetComponent <NPCScript>().canFog  = true;
                GetComponent <AudioSource>().Play();
                NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
            }
        }
    }
Beispiel #6
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     //Si el que choca contra la trampa es el jugador
     if ((collision.attachedRigidbody == player.GetComponent <Rigidbody2D>()) && player.GetComponent <PlayerScript>().ground)
     {
         //Si este tiene escudo se desactiva el escudo
         if (player.GetComponent <PlayerScript>().shielded)
         {
             player.GetComponent <PlayerScript>().shielded = false;
             player.GetComponent <PlayerScript>().powered  = false;
         }
         //Si no dispone de escudo se queda atrapado y la camara tiembla
         else
         {
             GetComponent <AudioSource>().Stop();
             GetComponent <AudioSource>().Play();
             player.GetComponent <PlayerScript>().trapped = true;
             cam.GetComponent <CameraController>().TriggerShake(2.0f);
             player.GetComponent <PlayerScript>().trappedTime = Time.fixedTime;
         }
         GetComponent <AudioSource>().Stop();
         GetComponent <AudioSource>().Play();
         //Se desactiva la trampa activada
         GetComponent <BoxCollider2D>().enabled  = false;
         GetComponent <SpriteRenderer>().enabled = false;
         //Se cambia la disposicion del nivel, eliminando la trampa
         NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, player.GetComponent <PlayerScript>().numPlat - 1, player.GetComponent <PlayerScript>().pos] = 1;
     }
     //Cuando el que choca es un NPC
     if ((collision.attachedRigidbody == NPC1.GetComponent <Rigidbody2D>()) && NPC1.GetComponent <NPCScript>().ground&& !NPC1.GetComponent <NPCScript>().jumping)
     {
         //Si este tiene escudo se desactiva el escudo
         if (NPC1.GetComponent <NPCScript>().shielded == 1)
         {
             NPC1.GetComponent <NPCScript>().shielded = 0;
             NPC1.GetComponent <NPCScript>().powered  = false;
         }
         //Si no dispone de escudo se queda atrapado
         else
         {
             NPC1.GetComponent <NPCScript>().trapped     = true;
             NPC1.GetComponent <NPCScript>().trappedTime = Time.fixedTime;
         }
         GetComponent <AudioSource>().Stop();
         GetComponent <AudioSource>().Play();
         //Se desactiva la trampa activada
         GetComponent <BoxCollider2D>().enabled  = false;
         GetComponent <SpriteRenderer>().enabled = false;
         //Se cambia la disposicion del nivel, eliminando la trampa
         NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC1.GetComponent <NPCScript>().numPlat - 1, NPC1.GetComponent <NPCScript>().pos] = 1;
     }
     if ((collision.attachedRigidbody == NPC2.GetComponent <Rigidbody2D>()) && NPC2.GetComponent <NPCScript>().ground&& !NPC2.GetComponent <NPCScript>().jumping)
     {
         //Si este tiene escudo se desactiva el escudo
         if (NPC2.GetComponent <NPCScript>().shielded == 1)
         {
             NPC2.GetComponent <NPCScript>().shielded = 0;
             NPC2.GetComponent <NPCScript>().powered  = false;
         }
         //Si no dispone de escudo se queda atrapado
         else
         {
             GetComponent <AudioSource>().Stop();
             GetComponent <AudioSource>().Play();
             NPC2.GetComponent <NPCScript>().trapped     = true;
             NPC2.GetComponent <NPCScript>().trappedTime = Time.fixedTime;
         }
         GetComponent <AudioSource>().Stop();
         GetComponent <AudioSource>().Play();
         //Se desactiva la trampa activada
         GetComponent <BoxCollider2D>().enabled  = false;
         GetComponent <SpriteRenderer>().enabled = false;
         //Se cambia la disposicion del nivel, eliminando la trampa
         NPC1.GetComponent <NPCScript>().plat[NPC1.GetComponent <NPCScript>().playingLevel, NPC2.GetComponent <NPCScript>().numPlat - 1, NPC2.GetComponent <NPCScript>().pos] = 1;
     }
 }
Beispiel #7
0
 // Start is called before the first frame update
 void Start()
 {
     currHealth = maxHealth;
     Player     = GameObject.FindGameObjectWithTag("Player").transform;
     rb.GetComponent <Rigidbody2D>();
 }
Beispiel #8
0
    // Update is called once per frame
    void Update()
    {
        Enemypos = transform.position;



        if (groundCheck)
        {
            isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, isGroundLayer);
        }


        //if the player is on the ground

        //  rb.velocity = new Vector2(-speed, rb.velocity.y);


        if (isGrounded)
        {
            anim.SetBool("jump", false);
            if (jumps > 0)
            {
                shield = true;

                anim.SetBool("attack", false);
                rb.velocity = new Vector2(0, jumpForce);
                jumps      -= 1;
            }

            else if (shots > 0 && jumps <= 0)
            {
                shield = false;
                anim.SetBool("attack", false);
                rb.velocity = new Vector2(0, 0);

                if (projectile && projectileSpawnPoint)
                {
                    if (nextShot > 0)
                    {
                        nextShot -= 1;
                        anim.SetBool("attack", true);
                    }
                    if (nextShot <= 0)
                    {
                        Rigidbody2D temp = Instantiate(projectile, projectileSpawnPoint.position, projectileSpawnPoint.rotation);
                        Physics2D.IgnoreCollision(GetComponent <Collider2D>(), temp.GetComponent <Collider2D>(), true);
                        temp.AddForce(-projectileSpawnPoint.right * projectileForce, ForceMode2D.Impulse);
                        shots   -= 1;
                        nextShot = 80;
                    }
                }
            }
            else if (shots <= 0 && jumps <= 0)
            {
                rb.velocity = new Vector2(0, 0);
                jumps       = Random.Range(1, 10);
                shots       = 4;
            }

            if (health < 1)
            {
                Destroy(gameObject);
                if (_player.mute == false)
                {
                    EnemyKilled.Play();
                }
            }
        }
        if (!isGrounded)
        {
            anim.SetBool("jump", true);
            rb.velocity += Vector2.up * Physics2D.gravity.y * (fallSpeed - 1) * Time.deltaTime;
        }
    }
 // Update is called once per frame
 void FixedUpdate()
 {
     if (orbitAround != null)
     {
         rB.velocity += (MyUniverse.CalculateGravity(orbitAround.transform.position, orbitAround.mass, rB.transform.position, rB.mass, orbitAround.GetComponent <Planet>().gravityMult)) * Time.deltaTime;
     }
 }
    void Update()
    {
        current_energy = PlayerPrefs.GetInt("energy");
        GameObject skori   = GameObject.Find("Bro");
        movement   keimeno = skori.GetComponent <movement> ();

        current_score = keimeno.total;
        //
        if (current_score < 100)
        {
            hey_text.text = "Damn you scored " + current_score + ",my grandma can score more...";
        }
        else
        {
            hey_text.text = "Wow " + current_score + " awesome score dude...";
        }
        //
        energy = PlayerPrefs.GetInt("energy");

        energy_text.text = "" + energy;

        if (energy == 0)
        {
            Application.LoadLevel(0);
        }

        GameObject player_object = GameObject.Find("Bro");

        Vector3 player_pos_x = player_object.transform.position;


        Vector3 temp = player_object.transform.position;

        temp.x       = player_object.transform.position.x;
        player_pos_x = temp;

        if (player_pos_x.x > 168)
        {
            pause_butt.enabled = false;
            GameObject  nokia_3 = GameObject.Find("nokia_3");
            Rigidbody2D n3      = nokia_3.GetComponent <Rigidbody2D>();


            GameObject  nokiaa_1 = GameObject.Find("nokia_1");
            Rigidbody2D n2       = nokiaa_1.GetComponent <Rigidbody2D>();

            GameObject  nokia = GameObject.Find("nokia");
            Rigidbody2D n     = nokia.GetComponent <Rigidbody2D>();

            BoxCollider2D b1 = n.GetComponent <BoxCollider2D> ();
            BoxCollider2D b2 = n2.GetComponent <BoxCollider2D> ();
            BoxCollider2D b3 = n3.GetComponent <BoxCollider2D> ();



            b1.enabled = false;
            b2.enabled = false;
            b3.enabled = false;

            //	n.AddForce(Vector2.up*100f);
            //	n2.AddForce(Vector2.up*100f);
            //n3.AddForce(Vector2.up*100f);
            StartCoroutine("wat2");
        }
    }
Beispiel #11
0
 void Start()
 {
     Physics2D.IgnoreLayerCollision(0, 13);
     Physics2D.IgnoreLayerCollision(10, 10, true);
     Rb2D.GetComponent <Rigidbody2D>();
 }
Beispiel #12
0
        private void Update2DColliders()
        {
            for (int i = 0; i < colliders2D.Count; i++)
            {
                Collider2D source = colliders2D[i];
                if (source == null || !source.enabled || !source.gameObject.activeInHierarchy)
                {
                    continue;
                }

                Rigidbody2D rb = source.GetComponentInParent <Rigidbody2D>();
                ObiCollider oc = source.GetComponent <ObiCollider>();

                // Get the adequate rigidBodyIndex. If several colliders share a rigidbody, they'll get the same rigidBodyIndex.
                int rigidBodyIndex = -1;
                if (rb != null)
                {
                    if (!rigidbodyIDs.TryGetValue(rb.GetInstanceID(), out rigidBodyIndex))
                    {
                        ObiRigidbody or = rb.GetComponent <ObiRigidbody>();

                        rigidBodyIndex = Oni.GetRigidbodyCount(oniColliderGroup);
                        Oni.SetRigidbodies(oniColliderGroup, new Oni.Rigidbody[] {
                            new Oni.Rigidbody(rb, (or != null) ? or.kinematicForParticles : false)
                        }, 1, rigidBodyIndex);
                        rigidbodyIDs[rb.GetInstanceID()] = rigidBodyIndex;
                    }
                }

                float thickness = (oc != null)?oc.thickness:0;

                if (source is CircleCollider2D)
                {
                    Oni.SetColliders(oniColliderGroup, new Oni.Collider[] {
                        new Oni.Collider(source, Oni.ShapeType.Sphere, thickness, Oni.GetShapeCount(oniColliderGroup, Oni.ShapeType.Sphere), rigidBodyIndex, (oc != null)?oc.materialIndex:0)
                    }, 1, Oni.GetColliderCount(oniColliderGroup));
                    Oni.SetSphereShapes(oniColliderGroup, new Oni.SphereShape[] {
                        new Oni.SphereShape(source as CircleCollider2D)
                    }, 1, Oni.GetShapeCount(oniColliderGroup, Oni.ShapeType.Sphere));
                }
                else if (source is BoxCollider2D)
                {
                    Oni.SetColliders(oniColliderGroup, new Oni.Collider[] {
                        new Oni.Collider(source, Oni.ShapeType.Box, thickness, Oni.GetShapeCount(oniColliderGroup, Oni.ShapeType.Box), rigidBodyIndex, (oc != null)?oc.materialIndex:0)
                    }, 1, Oni.GetColliderCount(oniColliderGroup));
                    Oni.SetBoxShapes(oniColliderGroup, new Oni.BoxShape[] {
                        new Oni.BoxShape(source as BoxCollider2D)
                    }, 1, Oni.GetShapeCount(oniColliderGroup, Oni.ShapeType.Box));
                }
                else if (source is EdgeCollider2D)
                {
                    EdgeCollider2D           mc = source as EdgeCollider2D;
                    EdgeColliderShapeAndData shapeAndData;

                    if (!edgeColliderData.TryGetValue(source as EdgeCollider2D, out shapeAndData))
                    {
                        // Get current amount of triangle mesh shapes:
                        int shapeIndex = Oni.GetShapeCount(oniColliderGroup, Oni.ShapeType.EdgeMesh);

                        // Generate mesh collider triangle data and shape:
                        Oni.EdgeMeshData  data  = new Oni.EdgeMeshData(mc);
                        Oni.EdgeMeshShape shape = new Oni.EdgeMeshShape(mc,
                                                                        thickness,
                                                                        data.AddrOfVertexData(),
                                                                        data.AddrOfEdgeData());

                        // Pack both in a small wrapper:
                        shapeAndData = new EdgeColliderShapeAndData(data, shape, shapeIndex);

                        // Tell Oni we want to define a new triangle mesh:
                        Oni.SetEdgeMeshShapes(oniColliderGroup,
                                              new Oni.EdgeMeshShape[] { shapeAndData.meshShape },
                                              1, shapeIndex);

                        Oni.UpdateEdgeMeshShapes(oniColliderGroup, 1, shapeIndex);

                        // Store mesh collider data:
                        edgeColliderData[mc] = shapeAndData;
                    }

                    Oni.SetColliders(oniColliderGroup, new Oni.Collider[] {
                        new Oni.Collider(source, Oni.ShapeType.EdgeMesh, thickness, shapeAndData.shapeIndex, rigidBodyIndex, (oc != null)?oc.materialIndex:0)
                    }, 1, Oni.GetColliderCount(oniColliderGroup));
                }
                else
                {
                    Debug.LogWarning("2D Collider type " + source.GetType() + " not supported by Obi. Ignoring it.");
                }
            }
        }
Beispiel #13
0
 private void Start()
 {
     body2D.GetComponent <Rigidbody2D>();
 }
Beispiel #14
0
    public void updateOther(Portal enter, Portal exit)
    {
        if (other == null)
        {
            Rigidbody2D bodyEnter = enter.GetComponent <Rigidbody2D>();
            Rigidbody2D bodyExit  = exit.GetComponent <Rigidbody2D>();

            Rigidbody2D body = GetComponent <Rigidbody2D>();


            //Duplicate self

            other = Instantiate(gameObject).GetComponent <CanEnterPortal>();

            //Ignore collisions with the other wall

            Physics2D.IgnoreCollision(other.GetComponent <Collider2D>(), exit.on);


            Rigidbody2D bodyOther = other.GetComponent <Rigidbody2D>();

            other.other = this;


            //Position it correctly

            //float dx = bodyExit.GetComponent<Collider2D>().bounds.size.x;


            //TODO: Use angle instead

            if (exit.isLeft)
            {
                //  dx *= -1;
            }


            float relX = body.position.x - bodyEnter.position.x; //positive if to the right
            float relY = body.position.y - bodyEnter.position.y; //positive if above


            float a = bodyEnter.rotation * Mathf.PI / 180;


            float dx = Mathf.Cos(a) * relX + Mathf.Sin(a) * relY + bodyEnter.GetComponent <BoxCollider2D>().size.x *bodyEnter.transform.localScale.x;
            float dy = Mathf.Cos(a) * relY + Mathf.Sin(a) * relX;


            float a2 = bodyEnter.rotation * Mathf.PI / 180;


            float x = bodyExit.position.x + Mathf.Cos(a) * dx + Mathf.Sin(a) * dy;
            float y = bodyExit.position.y + Mathf.Cos(a) * dy + Mathf.Sin(a) * dx;


            bodyOther.position = new Vector3(x, y, 0);



            //Transfer velocity

            //TODO: Angels
            //Note that velocities are equal of portal is pointing opposite direction


            bodyOther.velocity = body.velocity;
        }
    }
Beispiel #15
0
    void Shoot(float h, float v)
    {
        Vector2     shotDirection = Vector2.zero;
        Rigidbody2D rb            = (Rigidbody2D)Instantiate(laser, transform.position, transform.rotation);
        Transform   t             = rb.GetComponent <Transform> ();

        /*
         * Shot Orientation
         */

        if (h < 0)
        {
            Vector3 flipped = t.localScale;
            flipped.x    = -flipped.x;
            t.localScale = flipped;
        }

        /*
         * Player Orientation
         */

        PlayerMovement pm = GetComponent <PlayerMovement> ();

        if (h < 0 && pm.facingRight)
        {
            pm.Flip();
        }
        else if (h > 0 && !pm.facingRight)
        {
            pm.Flip();
        }


        /*
         * Shot Direction
         */

        // Shooting right
        if ((h == 0 && v == 0) || (h > 0 && v == 0))
        {
            shotDirection = Vector2.right;
        }
        // Shooting up + right
        else if (h > 0 && v > 0)
        {
            shotDirection      = new Vector2(1f, 1f);
            t.localEulerAngles = new Vector3(0f, 0f, 45f);
        }
        // Shooting down + right
        else if (h > 0 && v < 0)
        {
            shotDirection      = new Vector2(1f, -1f);
            t.localEulerAngles = new Vector3(0f, 0f, -45f);
        }
        // Shooting left
        else if (h < 0 && v == 0)
        {
            shotDirection = -Vector2.right;
        }
        // Shooting up + left
        else if (h < 0 && v > 0)
        {
            shotDirection      = new Vector2(-1f, 1f);
            t.localEulerAngles = new Vector3(0f, 0f, -45f);
        }
        // Shooting down + left
        else if (h < 0 && v < 0)
        {
            shotDirection      = new Vector2(-1f, -1f);
            t.localEulerAngles = new Vector3(0f, 0f, 45f);
        }
        // Shooting up
        else if (h == 0 && v > 0)
        {
            shotDirection      = Vector2.up;
            t.localEulerAngles = new Vector3(0f, 0f, 90f);
        }
        // Shooting down
        else if (h == 0 && v < 0)
        {
            shotDirection      = -Vector2.up;
            t.localEulerAngles = new Vector3(0f, 0f, -90f);
        }

        rb.AddForce(shotDirection * shotForce);
    }
Beispiel #16
0
    // Update is called once per frame
    void Update()
    {
        healthText.text = "Boss Health: " + health.ToString();
        if (health <= 0)
        {
            healthText.text = "Boss Health: 0";

            _particles.transform.position = gameObject.transform.position;
            _particles.Play();
            GameManager end = FindObjectOfType <GameManager>();
            end.OpenWin();
            Destroy(gameObject);
        }
        if (health <= 67)
        {
            phase = 2;
        }
        if (health <= 33)
        {
            phase = 3;
        }
        if (phase == 1)
        {
            if (timer < 5.0f)
            {
                Boss4Sword swo = FindObjectOfType <Boss4Sword>();
                swo.Idle();
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.red;
                currColor.a           = currA;
                render.material.color = currColor;
                PlayerMovement player = FindObjectOfType <PlayerMovement>();

                Vector2 direction = player.transform.position - transform.position;
                direction.Normalize();

                myRigidbody.velocity = direction * 2.0f;
            }
            else if (timer > 5.0f && timer < 6.0f)
            {
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.blue;
                currColor.a           = currA;
                render.material.color = currColor;
                Boss4Sword swo = FindObjectOfType <Boss4Sword>();
                swo.Swing();
            }
            else
            {
                Boss4Sword swo = FindObjectOfType <Boss4Sword>();
                swo.Idle();
                myRigidbody.velocity = new Vector2(0, 0);
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.green;
                currColor.a           = currA;
                render.material.color = currColor;
            }
            if (timer >= 8.0f && timer < 9.0f)
            {
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.yellow;
                currColor.a           = currA;
                render.material.color = currColor;
            }
            if (timer > 9.0f)
            {
                timer = 0;
                Debug.Log("work");
            }
        }
        else if (phase == 2)
        {
            if (timer < 5.0f)
            {
                Boss4Sword swo = FindObjectOfType <Boss4Sword>();
                swo.Swing();
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.blue;
                currColor.a           = currA;
                render.material.color = currColor;
                PlayerMovement player = FindObjectOfType <PlayerMovement>();

                Vector2 direction = player.transform.position - transform.position;
                direction.Normalize();

                myRigidbody.velocity = direction * 3.0f;
            }
            else
            {
                Boss4Sword swo = FindObjectOfType <Boss4Sword>();
                swo.Idle();
                myRigidbody.velocity = new Vector2(0, 0);
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.green;
                currColor.a           = currA;
                render.material.color = currColor;
            }
            if (timer >= 10.0f && timer < 11.0f)
            {
                Renderer render    = myRigidbody.GetComponent <Renderer>();
                Color    currColor = Color.yellow;
                currColor.a           = currA;
                render.material.color = currColor;
            }
            if (timer > 11.0f)
            {
                timer = 0;
            }
        }
        else
        {
            Boss4Sword swo = FindObjectOfType <Boss4Sword>();
            swo.Slow();
            Renderer render    = myRigidbody.GetComponent <Renderer>();
            Color    currColor = Color.black;
            currColor.a           = currA;
            render.material.color = currColor;
            myRigidbody.velocity  = new Vector2(0, 0);
            myRigidbody.rotation += 0.1f;
        }
        timer += Time.deltaTime;
    }
 // Start is called before the first frame update
 void Start()
 {
     rigidbody.GetComponent <Rigidbody2D> ();
 }
Beispiel #18
0
    //"Respawn" the player, for debugging purposes only
    private void RespawnPlayerDebug()
    {
        Vector2 respawnPosition = new Vector2(Camera.main.transform.position.x, Camera.main.transform.position.y + myRigidbody.GetComponent <Renderer>().bounds.size.y);

        myRigidbody.position = respawnPosition;
    }
    public void Shoot()
    {
        Rigidbody2D projectileClone = (Rigidbody2D)Instantiate(Projectile, transform.position, transform.rotation);

        projectileClone.GetComponent <Projectile>().bulletDamage = projectileDamage;
    }
Beispiel #20
0
    // Update is called once per frame
    void Update()
    {
        // Initiating touch event
        // if touch event takes place
        if (Input.touchCount > 0)
        {
            // get touch position
            Touch touch = Input.GetTouch(0);


            // obtain touch position
            Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);


            // get touch to take a deal with
            switch (touch.phase)
            {
            // if you touches the screen
            case TouchPhase.Began:


                // if you touch the ball
                if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos))
                {
                    // get the offset between position you touches
                    // and the center of the game object
                    deltaX = touchPos.x - transform.position.x;
                    deltaY = touchPos.y - transform.position.y;


                    // if touch begins within the ball collider
                    // then it is allowed to move
                    moveAllowed = true;


                    // restrict some rigidbody properties so it moves
                    // more  smoothly and correctly
                    rb.freezeRotation = true;
                    rb.velocity       = new Vector2(0, 0);
                    rb.gravityScale   = 0;
                }
                break;


            // you move your finger
            case TouchPhase.Moved:
                // if you touches the ball and movement is allowed then move
                if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos) && moveAllowed)
                {
                    rb.MovePosition(new Vector2(touchPos.x - deltaX, touchPos.y - deltaY));
                }
                break;


            // you release your finger
            case TouchPhase.Ended:


                // restore initial parameters
                // when touch is ended
                moveAllowed = false;

                rb.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;


                break;
            }
        }
    }
    //.................................>8.......................................
    void Update()
    {
        if (codescreen.GetComponent <LevelGenerator>().gamestate == stateLib.GAMESTATE_IN_GAME)
        {
            AudioSource ad = GetComponent <AudioSource>();
            if (!walkloop && Input.GetAxis("Horizontal") != 0f &&
                GetComponent <Rigidbody2D>().velocity.y == 0 &&
                !onWall)
            {
                ad.Play();
                walkloop = true;
                ad.loop  = true;
            }
            if (Input.GetAxis("Horizontal") == 0f ||
                GetComponent <Rigidbody2D>().velocity.y != 0 ||
                onWall)
            {
                ad.loop  = false;
                walkloop = false;
            }

            //firing
            if ((Input.GetKeyDown("left ctrl") || Input.GetKeyDown("right ctrl")) &&
                Time.time > nextFire &&
                !onWall &&
                !lg.isAnswering &&
                lg.toolsAirborne == 0 &&
                GetComponent <Rigidbody2D>().velocity == Vector2.zero &&
                projectilecode >= 0 &&
                selectedTool.GetComponent <SelectedTool>().toolCounts[projectilecode] + selectedTool.GetComponent <SelectedTool>().bonusTools[projectilecode] > 0)
            {
                throwing = true;
                anim.SetBool("throw", true);
                nextFire  = Time.time + fireRate;
                animDelay = Time.time + animTime;
                Rigidbody2D newstar = (Rigidbody2D)Instantiate(projectiles[projectilecode], transform.position, transform.rotation);
                if (facingRight)
                {
                    newstar.GetComponent <Rigidbody2D>().AddForce(Vector2.right * 300);
                }
                else
                {
                    newstar.GetComponent <Rigidbody2D>().AddForce(Vector2.right * -300);
                }
            }
            if (Time.time > animDelay)
            {
                anim.SetBool("throw", false);
            }

            //quit
            if (Input.GetKeyDown(KeyCode.Escape) == true)
            {
                quitting = true;
            }
            if (quitting)
            {
                if (Input.GetKeyDown("y"))
                {
                    Application.Quit();
                }
                else if (Input.GetKeyDown("n"))
                {
                    quitting = false;
                }
            }
        }
        else
        {
            GetComponent <AudioSource>().loop = false;
        }
    }
Beispiel #22
0
    // Update is called once per frame
    void Update()
    {
        speed     = 350f;
        jumpSpeed = 750f;

        GravChange gravitacional = GetComponent <GravChange> ();
        //Obtenemos el Rigid Body del Queco para que al saltar le podamos aplicar fuerzas.
        Rigidbody2D QuecoRig = this.gameObject.GetComponent <Rigidbody2D> ();
        //Vamos a obtener la velocidad del personaje en todo momento para controlar la velocidad del salto.
        float airVelocity    = calcularVelocidadEnAire(gravitacional, QuecoRig);
        float groundVelocity = calcularVelocidadEnTierra(gravitacional, QuecoRig);

        //Asignamos dichas velocidades a los valores que controlan las animaciones
        GlobalStats.currentStats.jugador.GetComponent <Animator>().SetFloat("SpeedX", airVelocity);
        GlobalStats.currentStats.jugador.GetComponent <Animator>().SetFloat("SpeedY", groundVelocity);

        if (Input.GetKey(KeyCode.D))
        {
            if (gravitacional.abajo || gravitacional.arriba)
            {
                QuecoRig.velocity = new Vector2(speed, QuecoRig.velocity.y);
                if (gravitacional.abajo)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(90, 270, 0, 359));
            }
            if (gravitacional.abajo)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.arriba)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.A))
        {
            if (gravitacional.abajo || gravitacional.arriba)
            {
                QuecoRig.velocity = new Vector2(-speed, QuecoRig.velocity.y);
                if (gravitacional.abajo)
                {
                    isFacingRight = true;
                }
                else
                {
                    isFacingRight = false;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(270, 90, 180, 179));
            }
            if (gravitacional.abajo)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.arriba)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.W))
        {
            if (gravitacional.izq || gravitacional.der)
            {
                QuecoRig.velocity = new Vector2(QuecoRig.velocity.x, speed);
                if (gravitacional.der)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(180, 0, 90, 89));
            }
            if (gravitacional.izq)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.der)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.S))
        {
            if (gravitacional.izq || gravitacional.der)
            {
                QuecoRig.velocity = new Vector2(QuecoRig.velocity.x, -speed);
                if (gravitacional.izq)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(360, 180, 270, 269));
            }
            if (gravitacional.der)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.izq)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (GlobalStats.currentStats.jugador.GetComponent <Animator>().GetBool("Ground") == true)
            {
                if (gravitacional.abajo)
                {
                    QuecoRig.velocity = new Vector2(0, jumpSpeed);
                }
                if (gravitacional.arriba)
                {
                    QuecoRig.velocity = new Vector2(0, -jumpSpeed);
                }
                if (gravitacional.izq)
                {
                    QuecoRig.velocity = new Vector2(jumpSpeed, 0);
                }
                if (gravitacional.der)
                {
                    QuecoRig.velocity = new Vector2(-jumpSpeed, 0);
                }
                GlobalStats.currentStats.jugador.GetComponent <Animator>().SetBool("Ground", false);
            }
        }

        if (QuecoRig.velocity == Vector2.zero)
        {
            QuecoRig.GetComponent <Animator>().SetBool("isIdle", true);
        }
    }
    // Use this for initialization
    void Start()
    {
        // Get Player Object on game start
        // Player = FindObjectOfType<Rigidbody2D> ();

        DeathParticle   = Resources.Load("Prefabs/Death Particle") as GameObject;
        RespawnParticle = Resources.Load("Prefabs/Respawn Particle") as GameObject;


        PlayerObject.SetActive(true);
        Player.WakeUp();
        Player.GetComponent <BoxCollider2D>().enabled = true;
        Player.GetComponent <Renderer> ().enabled     = true;

        // Player is Alive Again
        PlayerIsDead = false;

        // Reset Health
        HealthManager.Health = HealthManagerObj.MaxHealth;

        // Refill Ammo
        AmmoManager.AmmoCount = AmmoManagerObj.RespawnAmmo;
    }
Beispiel #24
0
 void Start()
 {
     thisObject.GetComponent <Rigidbody2D>();
 }
 void Start()
 {
     resetSpeedSqr = resetSpeed * resetSpeed;
     spring        = projectile.GetComponent <SpringJoint2D>();
 }
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     player = GameObject.FindGameObjectWithTag("Player").transform;
     rb     = animator.GetComponent <Rigidbody2D>();
     Physics2D.IgnoreCollision(rb.GetComponent <BoxCollider2D>(), player.GetComponent <Collider2D>(), true);
 }
Beispiel #27
0
    // Update is called once per frame
    void Update()
    {
        //rotation
        Vector3 mousePos = retical.recPos;

        mousePos.z = 5.23f;

        Vector3 objectPos = Camera.main.WorldToScreenPoint(transform.position);

        mousePos.x = mousePos.x - objectPos.x;
        mousePos.y = mousePos.y - objectPos.y;

        float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;

        transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));

        //Gun image will flip depending on where the mouse is relative to the player
        if (mousePos.x - 15 > player.transform.position.x)
        {
            transform.localScale = new Vector3(1, 1, 1);
        }
        else
        {
            transform.localScale = new Vector3(1, -1, 1);
        }

        if ((Input.GetButton("Fire1") || Input.GetAxis("RTrig") > 0.1) && Firable() && !HYPEController.lazers && !PlayerHealth.alreadyDying)
        {
            //shoot bullet
            AudioSource.PlayClipAtPoint(gunshot, transform.position);

            sTimerOn = true;
            inMag   -= 1;
            adjustCounter(inMag);
            var pos = retical.recPos;
            pos.z = transform.position.z - Camera.main.transform.position.z;
            pos   = Camera.main.ScreenToWorldPoint(pos);

            var         q  = Quaternion.FromToRotation(Vector3.up, pos - shootFrom.transform.position);
            Rigidbody2D go = Instantiate(bullet, shootFrom.transform.position, q) as Rigidbody2D;
            go.GetComponent <Rigidbody2D>().AddForce(go.transform.up * bulletSpeed);

            GameObject particles = (GameObject)Instantiate(shotParticles, shootFrom.transform.position, shootFrom.transform.rotation);
            particles.GetComponent <ParticleSystem>().Play();
            Destroy(particles, particles.GetComponent <ParticleSystem>().startLifetime);

            if (inMag <= 0)
            {
                AudioSource.PlayClipAtPoint(reload, transform.position);
                rTimerOn = true;
            }

            //if(player.GetComponent<)
            if (!player.GetComponent <CharControl>().isGrounded())
            {
                //Debug.Log(new Vector2(go.transform.up.x * -kickForce, go.transform.up.y * -kickForce));
                player.GetComponent <Rigidbody2D>().AddForce(new Vector2(go.transform.up.x * -kickForce, go.transform.up.y * -kickForce));
            }
        }

        if (Input.GetButtonDown("Reload") && inMag != magSize && !rTimerOn)
        {
            AudioSource.PlayClipAtPoint(reload, transform.position);
            //play reload anim
            rTimerOn = true;
        }

        //Timer for how long reload takes
        if (rTimerOn)
        {
            reloadTimer -= Time.deltaTime;
            if (reloadTimer <= 0)
            {
                rTimerOn = false;
                inMag    = magSize;
                adjustCounter(inMag);
                reloadTimer = reloadTime;
            }
        }

        //Timer for how long before you can shoot again
        if (sTimerOn)
        {
            shotTimer -= Time.deltaTime;
            if (shotTimer <= 0)
            {
                sTimerOn  = false;
                shotTimer = interShotDelay;
            }
        }
    }
Beispiel #28
0
    public void ForcePulseExplosion()
    {
        Instantiate(forcePulseWave, transform.position, Quaternion.identity, ParticleGenerator.holder);
        Vector2 point  = transform.position;
        int     layers = (1 << LayerSolid) | (1 << LayerProjectile);

        Collider2D[]       colliders = Physics2D.OverlapCircleAll(point, explosionRadius, layers);
        List <Rigidbody2D> rbs       = new List <Rigidbody2D>();

        for (int i = 0; i < colliders.Length; i++)
        {
            Collider2D col = colliders[i];
            if (col.attachedRigidbody.bodyType == RigidbodyType2D.Static)
            {
                continue;
            }
            bool found = false;
            for (int j = 0; j < rbs.Count; j++)
            {
                Rigidbody2D colRb = rbs[j];
                if (colRb == col.attachedRigidbody)
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                rbs.Add(col.attachedRigidbody);
            }
        }

        for (int i = 0; i < rbs.Count; i++)
        {
            Rigidbody2D colRb     = rbs[i];
            IStunnable  stunnable = colRb.GetComponent <IStunnable>();
            stunnable = stunnable ?? colRb.GetComponentInChildren <IStunnable>();
            stunnable?.Stun();

            if (colRb == rb)
            {
                continue;
            }
            Vector2 dir      = ((Vector2)colRb.transform.position - point).normalized;
            float   distance = Vector2.Distance(point, colRb.transform.position);
            if (distance >= explosionRadius)
            {
                continue;
            }
            colRb.velocity += dir * Mathf.Pow((explosionRadius - distance) / explosionRadius, 0.5f)
                              * explosionStrength;
            colRb.AddTorque((UnityEngine.Random.value > 0.5 ? 1f : -1f) * explosionStrength * 5f);
        }

        Vector2 screenPos = Camera.main.WorldToViewportPoint(transform.position);

        if (screenPos.x > -0.5f || screenPos.x < 1.5f || screenPos.y > -0.5f || screenPos.y < 1.5f)
        {
            screenRippleSO.StartRipple(this, distortionLevel: 0.03f,
                                       position: screenPos);
        }
    }
    // Throw direction should be a normalized vector. Initial anchor is probably the player's body
    public void Throw_Rope(Vector3 start_position, Vector2 throw_direction, float throw_force, Rigidbody2D initial_anchor, GameObject thrower)
    {
        // Spawn a number of segments
        for (int i = 0; i < number_of_segments; i++)
        {
            GameObject segment = ((GameObject)Instantiate(emptyPrefab,
                                                          new Vector3(start_position.x, start_position.y, 0), Quaternion.identity));
            joints.Add(segment);
            segment.transform.parent = transform;
        }

        // Connect them with hingejoints
        for (int j = 0; j < joints.Count - 1; j++)
        {
            joints[j].transform.parent = this.transform;
            joints[j].GetComponent <HingeJoint2D>().connectedBody = joints[j + 1].GetComponent <Rigidbody2D>();
        }

        // Set their neighbours
        for (int x = 0; x < number_of_segments; x++)
        {
            int above_int = Mathf.Clamp(x - 1, 0, number_of_segments - 1);
            int below_int = Mathf.Clamp(x + 1, 0, number_of_segments - 1);
            joints[x].GetComponent <Link>().above       = joints[above_int];
            joints[x].GetComponent <Link>().below       = joints[below_int];
            joints[x].GetComponent <Link>().top_most    = joints[0];
            joints[x].GetComponent <Link>().bottom_most = joints[number_of_segments - 1];
            joints[x].GetComponent <Link>().position_from_top_in_rope    = x;
            joints[x].GetComponent <Link>().position_from_bottom_in_rope = number_of_segments - x;
            joints[x].GetComponent <Link>().all_segments = joints;
            joints[x].GetComponent <Link>().rope         = this;
        }

        // Disable the hingejoint on the last rope semgnet
        if (initial_anchor == null)
        {
            joints[joints.Count - 1].GetComponent <HingeJoint2D>().enabled         = false;
            joints[joints.Count - 1].GetComponent <HingeJoint2D>().connectedAnchor = Vector2.zero;
        }
        else
        {
            // Make the end tied to the player's waist

            /*
             * joints[joints.Count - 1].GetComponent<HingeJoint2D>().connectedBody = initial_anchor;
             * joints[joints.Count - 1].GetComponent<HingeJoint2D>().connectedAnchor = Vector2.zero;
             *
             * initial_anchor.GetComponent<PlatformerCharacter2D>().connected_joint = joints[joints.Count - 1].GetComponent<HingeJoint2D>();
             */
            joints[joints.Count - 1].GetComponent <HingeJoint2D>().enabled         = false;
            joints[joints.Count - 1].GetComponent <HingeJoint2D>().connectedAnchor = Vector2.zero;

            // Activate the joint on the player object, and attach it to the end rope segment
            PlatformerCharacter2D player = initial_anchor.GetComponent <PlatformerCharacter2D>();
            player.connected_joint.enabled       = true;
            player.connected_joint.connectedBody = joints[joints.Count - 1].GetComponent <Rigidbody2D>();

            //player.rope_follower.SetActive(true);
            //player.rope_follower.GetComponent<FollowObject>().object_to_follow = joints[joints.Count - 1].transform;
            //player.connected_joint.connectedBody = player.rope_follower.GetComponent<Rigidbody2D>();
        }

        // Make the start attachable to the terrain, like a grappling hook
        AttachToTerrain terrain = joints[0].AddComponent <AttachToTerrain>();

        terrain.thrower = thrower;
        terrain.attach_to_thrower_if_in_range = true;
        terrain.attach_range = joints[0].GetComponent <CircleCollider2D>().radius * 2 * joints.Count;

        // First segment always has a spring with which to attack the player to
        SpringJoint2D spring = joints[0].AddComponent <SpringJoint2D>();

        spring.dampingRatio = 0;
        spring.frequency    = 0;
        spring.enabled      = false;

        // Name the segments
        joints[0].name = "FirstPiece";
        joints[joints.Count - 1].name = "EndPiece";

        // Create attach points at the top and bottom of the rope
        GameObject top = (GameObject)Instantiate(Resources.Load("RopeAttachPoint"), joints[0].transform.position, Quaternion.identity);

        top.transform.parent = joints[0].transform;
        GameObject bottom = (GameObject)Instantiate(Resources.Load("RopeAttachPoint"), joints[joints.Count - 1].transform.position, Quaternion.identity);

        bottom.transform.parent = joints[joints.Count - 1].transform;

        // Make the first segment able to attach to other ropes
        top.AddComponent <RopeCombiner>();

        // Add a force to the first rope segment

        for (int z = 0; z < joints.Count; z++)
        {
            Vector2 force_to_add = throw_direction * throw_force * (1f - (float)((float)(z) / (float)joints.Count));
            joints[z].GetComponent <Rigidbody2D>().AddForce(force_to_add);
        }

        /*
         * joints[0].GetComponent<Rigidbody2D>().AddForce(throw_direction * throw_force);
         * joints[1].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.5f));
         * joints[2].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.4f));
         * joints[3].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.3f));
         * joints[4].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.2f));
         * joints[5].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.1f));
         * joints[6].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.1f));
         * joints[7].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.1f));
         * joints[8].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.1f));
         * joints[9].GetComponent<Rigidbody2D>().AddForce(throw_direction * (throw_force * 0.1f));*/
        // Add rope to dictionary of ropes
        ObjectManager.object_manager.AddRope(this.gameObject);
    }
Beispiel #30
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Candy" && !(gameObject.tag == "FakeHead"))
        {
            Destroy(col.gameObject);
        }
        else if (col.gameObject.tag == "Finish" && Candies.Length == 0 &&
                 !(gameObject.tag == "FakeHead" && GameObject.Find("Zombie").GetComponent <BodyMovement>().isHeadConnected))
        {
            GameObject zombie = GameObject.Find("Zombie");
            isGameOver = true;
            zombie.GetComponent <BodyMovement>().enabled = false;
            animator.SetActive(false);
            body.GetComponent <SpriteRenderer>().enabled = true;
            head.GetComponent <SpriteRenderer>().enabled = true;
        }
        else if ((col.gameObject.tag == "Hazard") && !(gameObject.tag == "FakeHead"))
        {
            //Zombie logic
            GameObject zombie = GameObject.Find("Zombie");
            zombie.GetComponent <SpriteRenderer>().enabled  = false;
            zombie.GetComponent <Rigidbody2D>().isKinematic = true; //Stops the body from moving down, and being moveable.
            //zombie.GetComponent<BoxCollider2D>().enabled = false;
            //zombie.GetComponent<CircleCollider2D>().enabled = false;
            zombie.GetComponent <CapsuleCollider2D>().enabled = false;
            zombie.GetComponent <BodyMovement>().enabled      = false;
            animator.SetActive(false);
            headAnimator.GetComponent <SpriteRenderer>().enabled = true;
            headAnimator.GetComponent <Animator>().SetTrigger("Explode");


            //Head logic
            GameObject head = GameObject.Find("Head");
            head.GetComponent <SpriteRenderer>().enabled    = false;
            head.GetComponent <CircleCollider2D>().enabled  = false;
            head.GetComponent <CapsuleCollider2D>().enabled = false;
            head.GetComponent <Rigidbody2D>().isKinematic   = true;
            head.GetComponent <BallMovement>().enabled      = false;

            //DeadHead copy
            GameObject headDead = GameObject.Find("HeadDead");
            headDead.GetComponent <SpriteRenderer>().enabled   = true;
            headDead.GetComponent <CircleCollider2D>().enabled = true;
            headDead.GetComponent <Rigidbody2D>().isKinematic  = false;
            headDead.GetComponent <Rigidbody2D>().constraints  = RigidbodyConstraints2D.FreezePositionX;

            //A final bit of control, we stop animation from running.
            animator.SetActive(false);


            isDead = true;
            StartCoroutine(Wait());
        }

        else if (gameObject.name == "HeadDead" && col.gameObject.tag == "Hazard")
        {
            GetComponent <Rigidbody2D>().isKinematic = true;
            GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
        }

        //TO DO: End game script with body
        else if ((col.gameObject.tag == "Body"))
        {
            Physics2D.IgnoreCollision(head1.GetComponent <CapsuleCollider2D> (), GameObject.FindGameObjectWithTag("Body").GetComponent <BoxCollider2D> ());
        }
    }