Ejemplo n.º 1
0
    private void CreateNewUziShot()
    {
        GameObject UziShot = new GameObject(bullet.bulletName);

        UziShot.transform.localPosition = transform.parent.TransformPoint(new Vector2(ShootingOffset.x * Side, ShootingOffset.y));
        Side *= -1;
        UziShot.transform.localScale = new Vector2(0.05f, 0.05f);

        UziShot.transform.rotation = transform.parent.rotation;

        SpriteRenderer spr = UziShot.AddComponent <SpriteRenderer>();

        spr.sprite          = bullet.sprite;
        spr.sortingOrder    = 1;
        spr.maskInteraction = SpriteMaskInteraction.VisibleOutsideMask;

        CapsuleCollider col = UziShot.AddComponent <CapsuleCollider>();

        col.isTrigger = true;

        Rigidbody rb = UziShot.AddComponent <Rigidbody>();

        rb.mass           = 0.01f;
        rb.useGravity     = false;
        rb.freezeRotation = true;

        bulletController bc = UziShot.AddComponent <bulletController>();

        bc.bullet  = bullet;
        bc.firedBy = transform.parent.gameObject;
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        preBullet        = Instantiate(bullet, new Vector3(barrel.position.x, barrel.position.y, barrel.position.z), barrel.rotation) as Rigidbody;
        prePosition      = preBullet.transform;
        bulletController = preBullet.gameObject.GetComponent <bulletController>();
        GameObject manager = GameObject.FindGameObjectWithTag("Manager");

        oscSender = manager.GetComponent <OscSender>();
    }
Ejemplo n.º 3
0
    void AddBullet()
    {
        // Debug.Log("pew");
        // creates bullet based on the position of the barrel obj and adds them to the bullets list
        bulletController obj = Instantiate(bullet, barrel.position, barrel.rotation, null).GetComponent <bulletController>();

        bullets.Add(obj);
        //  obj.GetComponent<Rigidbody>().AddForce(transform.forward * thrust,ForceMode.Force);
    }
Ejemplo n.º 4
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "bullet")
     {
         bulletController bulletController = collision.gameObject.GetComponent <bulletController>();
         if (!CompareTag(bulletController.shooter.tag))
         {
             TakeOneDamage(collision);
         }
     }
 }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "bullet")
     {
         // DDA Scaling for bullet damage
         bulletController bulletScript = collision.gameObject.GetComponent <bulletController>();
         health = health - bulletScript.bulletDamage;
         //Debug.Log(bulletScript.bulletDamage);
         Destroy(collision.gameObject);
     }
 }
Ejemplo n.º 6
0
 void SpawnBullet()
 {
     preBullet.AddForce(-barrel.transform.forward * bulletSpeed);
     bulletController.setIdx((int)(this.transform.position.y / 12.5f));
     //Debug.Log((int)(preBullet.transform.position.y / 12.5f));
     preBullet        = Instantiate(bullet, new Vector3(barrel.position.x, barrel.position.y, barrel.position.z), barrel.rotation) as Rigidbody;
     bulletController = preBullet.gameObject.GetComponent <bulletController>();
     //b.AddForce(b.transform.forward * bulletSpeed);
     oscSender.sendMessage("/fire/ " + 1);
     shootTime = Time.time;
 }
Ejemplo n.º 7
0
 private void fire()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         if (!goBullets)
         {
             goBullets    = Instantiate(bullet, transform.position, helper.transform.rotation) as GameObject;
             bullets      = goBullets.GetComponent <bulletController>();
             bullets.type = bulletController.TypeBullet.one;
         }
     }
 }
Ejemplo n.º 8
0
 private void fire()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         if (!goBullets)
         {
             goBullets = Instantiate(bullet, transform.position, helper.transform.rotation) as GameObject;
             bullets = goBullets.GetComponent<bulletController>();
             bullets.type = bulletController.TypeBullet.one;
         }
     }
 }
    void ShootBullet()
    {
        //initialGunAmmo--;
        GameObject       bulletInstance = gunQueue.Dequeue();
        bulletController controller     = bulletInstance.GetComponent <bulletController>();

        bulletInstance.SetActive(true);
        controller.canMove   = true;
        controller.direction = bulletDirection;
        bulletInstance.transform.position = playerRB.position;
        controller.existanceTime          = 0f;
        controller.bulletLife             = bulletLife;
    }
Ejemplo n.º 10
0
    public void ShootBullet()
    {
        GameObject.Find("/Audio Objects/SFX/" + WeaponType).GetComponent <AudioSource>().Play();
        if (shots_per_burst == 1)
        {
            GameObject thisBullet;
            if (transform.rotation.eulerAngles.y >= 179.9f)
            {
                thisBullet = Instantiate(bulletPrefab, weaponTransform.position + new Vector3(-GunOffset.x, GunOffset.y, GunOffset.z), weaponTransform.rotation);
            }
            else
            {
                thisBullet = Instantiate(bulletPrefab, weaponTransform.position + new Vector3(GunOffset.x, GunOffset.y, GunOffset.z), weaponTransform.rotation);
            }
            bulletController bulletController = thisBullet.GetComponent <bulletController>();
            bulletController.SetDamageAndKnockback(damage, staticKnockback, knockbackMultiplier);
            bulletController.SetBulletForce(bulletForce);
            bulletController.SetPlayer(gameObject.transform.parent.gameObject);
            Destroy(thisBullet, bulletLifespan);
        }
        else
        {
            GameObject thisBullet;
            Quaternion gunRotation;

            float angle;

            for (int i = 0; i < shots_per_burst; i++)
            {
                angle       = -burst_max_angle + (burst_max_angle * 2f / ((float)(shots_per_burst - 1)) * ((float)i));
                gunRotation = weaponTransform.rotation;
                gunRotation = (Quaternion.Euler(gunRotation.eulerAngles.x, gunRotation.eulerAngles.y, gunRotation.eulerAngles.z + angle));
                if (transform.rotation.eulerAngles.y >= 179.9f)
                {
                    thisBullet = Instantiate(bulletPrefab, weaponTransform.position + new Vector3(-GunOffset.x, GunOffset.y, GunOffset.z), gunRotation);
                }
                else
                {
                    thisBullet = Instantiate(bulletPrefab, weaponTransform.position + new Vector3(GunOffset.x, GunOffset.y, GunOffset.z), gunRotation);
                }
                bulletController bulletController = thisBullet.GetComponent <bulletController>();
                bulletController.SetDamageAndKnockback(damage, staticKnockback, knockbackMultiplier);
                bulletController.SetBulletForce(bulletForce);
                bulletController.SetPlayer(gameObject.transform.parent.gameObject);
                Destroy(thisBullet, bulletLifespan);
            }
        }
    }
Ejemplo n.º 11
0
 void OnTriggerEnter(Collider other)
 {
     Debug.Log("enter");
     if (other.CompareTag("FancyBullet"))
     {
         oscSender.decreaseEnemy();
         bulletController = other.gameObject.GetComponent <bulletController>();
         bulletController.getIdx();
         float posX = this.transform.position.x;
         float posZ = this.transform.position.z;
         int[] res  = findNearest(posX, posZ, 15);
         if (res[1] == 0)
         {
             oscSender.setRhythmTemplate(bulletController.getIdx(), res[0] / 2 + 1);
             GameObject oldSequenceEnemy = oscSender.getRhythmObject(bulletController.getIdx());
             if (oldSequenceEnemy == null)
             {
                 GameObject sequenceEnemy = Instantiate(SequenceEnemy, getSequenceLocation(bulletController.getIdx(), 25f, 0), Quaternion.identity) as GameObject;
                 sequenceEnemy.transform.eulerAngles = new Vector3(sequenceEnemy.transform.eulerAngles.x, sequenceEnemy.transform.eulerAngles.y - 90f, sequenceEnemy.transform.eulerAngles.z);
                 oscSender.setRhythmObjects(sequenceEnemy, bulletController.getIdx());
             }
             else
             {
                 sequenceEnemyController sec = oldSequenceEnemy.GetComponent <sequenceEnemyController>();
                 sec.setSequencePos(new int[] { bulletController.getIdx(), 0 });
             }
         }
         else
         {
             oscSender.setMelodyTemplate(bulletController.getIdx(), res[0]);
             GameObject oldSequenceEnemy = oscSender.getMelodyObjects(bulletController.getIdx());
             if (oldSequenceEnemy == null)
             {
                 GameObject sequenceEnemy = Instantiate(SequenceEnemy, getSequenceLocation(bulletController.getIdx(), 25f, 1), Quaternion.identity);
                 sequenceEnemy.transform.eulerAngles = new Vector3(sequenceEnemy.transform.eulerAngles.x, sequenceEnemy.transform.eulerAngles.y - 90f, sequenceEnemy.transform.eulerAngles.z);
                 oscSender.setMelodyObjects(sequenceEnemy, bulletController.getIdx());
             }
             else
             {
                 sequenceEnemyController sec = oldSequenceEnemy.GetComponent <sequenceEnemyController>();
                 sec.setSequencePos(new int[] { bulletController.getIdx(), 1 });
             }
         }
         Destroy(other.gameObject);
         DestorySelf();
     }
 }
Ejemplo n.º 12
0
 // Update is called once per frame
 void Update()
 {
     if (isFiring)
     {
         shotCounter -= Time.deltaTime;
         if (shotCounter <= 0)
         {
             shotCounter = timeBeetwenShots;
             bulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as bulletController;
             newBullet.speed = bulletSpeed;
         }
     }
     else
     {
         shotCounter = 0;
     }
 }
Ejemplo n.º 13
0
    void Fire()
    {
        bulletController control = m_ListBullet[m_IndexBulletReady].GetComponent <bulletController>();
        int direct = (int)transform.localScale.x;

        if (m_State == PlayerState.look || m_State == PlayerState.lookAttack)
        {
            direct *= -1;
        }
        control.StartFire(m_Shooter.transform.position);
        control.FindDirect(direct);
        control.SetType(0);
        control.m_IsReady = false;

        if (m_soundControl)
        {
            m_soundControl.PlayerClip(m_soundControl.m_PlayerShootClip);
        }
    }
Ejemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (isFiring)
        {
            // shotCounter counting down the whole time
            shotCounter -= Time.deltaTime;

            if (shotCounter <= 0)
            {
                // resetting shotCounter to full time
                shotCounter = timeBetweenShots;
                // creating bullet with all the properties of bulletController
                bulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as bulletController;
                newBullet.bulletSpeed = bulletSpeed;
            }
        }
        else
        {
            shotCounter = 0;
        }
    }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        // count down reload timer
        reload -= Time.deltaTime;

        gameController.updateReload(reload);


        /*
         * Button checks to get gun directionality
         */


        //if(Input.GetButton("AimUp")){
        if (Input.GetAxis("Vertical") < 0)
        {
            arm.SetActive(true);
            yVel = 1f;
        }

        if ((Input.GetAxis("AimHorizontal") > 0) && !playerController.wallR)
        {
            arm.SetActive(true);
            xVel = 1f;
        }

        //if(Input.GetButton("AimDown")){
        if (Input.GetAxis("Vertical") > 0)
        {
            arm.SetActive(true);
            yVel = -1f;
        }

        //if(Input.GetButton("AimLeft") && !playerController.wallL){
        if ((Input.GetAxis("AimHorizontal") < 0) && !playerController.wallL)
        {
            arm.SetActive(true);
            xVel = -1f;
        }

        //if (Input.GetButtonUp ("AimUp") || Input.GetButtonUp ("AimDown")) {
        if (Input.GetAxis("Vertical") == 0)
        {
            yVel = 0f;
        }

        //if (Input.GetButtonUp ("AimRight") || Input.GetButtonUp ("AimLeft")) {
        if (Input.GetAxis("AimHorizontal") == 0)
        {
            xVel = 0f;
        }


        /*
         * Button check to get fire
         */

        // Don't fire if we're not aiming
        if (Input.GetButtonDown("CustomFire") && !(yVel == 0 && xVel == 0) && !(Input.GetButton("SlowDown")) && reload < 0)
        {
            // Instantiate a new bullet
            bulletController curGO = (bulletController)Instantiate(bullet, gun.transform.position, Quaternion.identity);

            // Give it directional velocity
            curGO.GetComponent <Rigidbody2D> ().velocity = new Vector2(xVel, yVel);

            //update bullets in play and list of bullets
            bulletsInPlay += 1;
            bullets.Add(curGO);

            reload = 5;
        }

        // Button check to do slowdown
        if (Input.GetButtonDown("SlowDown"))
        {
            slow = true;
            slowDown();
        }
        else if (Input.GetButtonUp("SlowDown"))
        {
            slow = false;
            endSlowDown();
        }


        // angle check for rotating gun

        if (xVel < 0)
        {
            gunSprite.flipY = true;
        }
        else
        {
            gunSprite.flipY = false;
        }

        // straight
        if (xVel == 1 && yVel == 0)
        {
            arm.transform.rotation = Quaternion.Euler(0, 0, 0);
        }

        // up and right
        if (xVel == 1 && yVel == 1)
        {
            arm.transform.rotation = Quaternion.Euler(0, 0, 45);
        }

        // straight up
        if (xVel == 0 && yVel == 1)
        {
            arm.transform.rotation = Quaternion.Euler(0, 0, 90);
        }

        // up and back
        if (xVel == -1 && yVel == 1)
        {
            arm.transform.rotation = Quaternion.Euler(0, 0, 135);
        }

        // straight back
        if (xVel == -1 && yVel == 0)
        {
            arm.transform.rotation = Quaternion.Euler(0, 0, 180);
        }

        // Inactive
        if (xVel == 0 && yVel == 0)
        {
            arm.SetActive(false);
        }
    }
Ejemplo n.º 16
0
    public static void GenerateBullet(Bullet bulletType, Vector3 position, Quaternion rotation, GameObject shooter)
    {
        shooterPlayer = shooter;
        GameObject bulletObject = new GameObject(bulletType.bulletName);

        bulletObject.tag = "Bullet";

        bulletObject.transform.position = position;
        bulletObject.transform.rotation = rotation;

        SpriteRenderer spr = bulletObject.AddComponent <SpriteRenderer>();

        spr.sprite          = bulletType.sprite;
        spr.sortingOrder    = 1;
        spr.maskInteraction = SpriteMaskInteraction.VisibleOutsideMask;

        CapsuleCollider col = bulletObject.AddComponent <CapsuleCollider>();

        col.isTrigger = true;

        Rigidbody rb = bulletObject.AddComponent <Rigidbody>();

        rb.mass           = 0.01f;
        rb.freezeRotation = true;
        rb.useGravity     = false;

        if (bulletType.bulletId == 0)  //Hotdog Pistol
        {
            bulletController bc = bulletObject.AddComponent <bulletController>();
            bulletObject.transform.localScale = new Vector2(0.2f, 0.2f);
            bc.bullet  = bulletType;
            bc.firedBy = shooter;
        }

        if (bulletType.bulletId == 1)  //Hamburger Launcher
        {
            hamburgerController hc = bulletObject.AddComponent <hamburgerController>();
            hc.bulletType                     = bulletType;
            hc.transform.position             = position;
            hc.firedBy                        = shooter;
            hc.directionOfTravel              = rotation;
            bulletObject.transform.rotation   = new Quaternion();
            bulletObject.transform.localScale = new Vector2(0.2f, 0.2f);
            //bulletObject.tag = "Untagged";
            GameObject     radiusRange = new GameObject();
            SpriteRenderer radSprite   = radiusRange.AddComponent <SpriteRenderer>();
            radSprite.sprite                    = bulletType.extraSprites[0];
            radiusRange.transform.parent        = bulletObject.transform;
            radSprite.enabled                   = false;
            radSprite.sortingOrder              = 1;
            radiusRange.transform.localPosition = new Vector2(1.0f, 0.0f);
            radiusRange.transform.localScale    = new Vector2(2.0f, 2.0f);
        }

        if (bulletType.bulletId == 2)  //French Fry Shotgun
        {
            Destroy(spr);
            Destroy(rb);
            Destroy(col);
            frenchFryController ffc = bulletObject.AddComponent <frenchFryController>();
            ffc.bulletType   = bulletType;
            bulletObject.tag = "Untagged";
        }

        if (bulletType.bulletId == 3)  //Sauce Sniper Rifle
        {
            sauceSniperController ssc = bulletObject.AddComponent <sauceSniperController>();
            ssc.bullet             = bulletType;
            ssc.firedBy            = shooter;
            ssc.transform.position = ssc.transform.position + ssc.transform.up * 0.35f;
        }

        if (bulletType.bulletId == 4)  //Chorizo Uzi
        {
            Destroy(spr);
            Destroy(rb);
            Destroy(col);
            UziChorizoController ucc = bulletObject.AddComponent <UziChorizoController>();
            bulletObject.transform.localScale = new Vector2(0.15f, 0.15f);
            ucc.bullet           = bulletType;
            ucc.firedBy          = shooter;
            ucc.transform.parent = shooter.transform;
        }
        if (bulletType.bulletId == 5) //Freshly Toasted Baguette
        {
            Destroy(rb);
            BaguetteController bc = bulletObject.AddComponent <BaguetteController>();
            bulletObject.transform.localScale = new Vector2(0.1f, 0.1f);
            bc.bullet  = bulletType;
            spr.sprite = bulletType.sprite;
            bc.firedBy = shooter;
            bulletObject.transform.parent = shooter.transform;
            //bc.transform.position = new Vector3(shooter.transform.position.x + shooter.transform.forward.x * 2.0f, position.y, shooter.transform.position.z + shooter.transform.forward.z * 2.0f);
            bulletObject.transform.position += bulletObject.transform.forward * 0.8f;
        }
        if (bulletType.bulletId == 6) //Sausage Harpoon Launcher
        {
            SausageHarpoonController shc = bulletObject.AddComponent <SausageHarpoonController>();
            shc.bullet                        = bulletType;
            shc.firedBy                       = shooter;
            shc.transform.position            = shc.transform.position + shc.transform.up;
            bulletObject.transform.localScale = new Vector2(0.15f, 0.15f);
            col.radius                        = 3.0f;
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Horizontal movement A:-1, D: 1 0
        float moveX = Input.GetAxisRaw("Horizontal");

        // Vertical movement W: 1 S:-1 0
        float moveY = Input.GetAxisRaw("Vertical");

        Vector2 moveVector = new Vector2(moveX, moveY);

        if (moveVector.x != 0 || moveVector.y != 0)
        {
            lookDirection = moveVector;
        }
        anim.SetFloat("Look X", lookDirection.x);
        anim.SetFloat("Look Y", lookDirection.y);
        anim.SetFloat("Speed", moveVector.magnitude);

        // ================ movement ================
        Vector2 position = rbody.position;

        position += moveVector * speed * Time.deltaTime;

        rbody.MovePosition(position);

        // ================= INVICIBLE TIMER
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        // ======= press 'J' for attack enemies ==================
        if (Input.GetKeyDown(KeyCode.J) && curBulletCount > 0)
        {
            ChangeBulletCount(-1);
            anim.SetTrigger("Launch");

            audioManager.instance.AudioPlay(launchClip); // lauch sound

            GameObject bullet = Instantiate(bulletPrefab,
                                            rbody.position + Vector2.up * 0.5f,
                                            Quaternion.identity);
            bulletController bc = bullet.GetComponent <bulletController>();
            if (bc != null)
            {
                bc.Move(lookDirection, 300);
            }
        }

        // ============ press 'K' for npc interaction ===============
        if (Input.GetKeyDown(KeyCode.K))
        {
            RaycastHit2D hit = Physics2D.Raycast(rbody.position,
                                                 lookDirection, 2f, LayerMask.GetMask("npc"));
            if (hit.collider != null)
            {
                NPCManager npc = hit.collider.GetComponent <NPCManager>();

                if (npc != null)
                {
                    npc.ShowDialog();
                }
            }
        }
    }