Ejemplo n.º 1
0
        public override bool GenerateBullet(Vector2 position, float direction, float bonusAccuracy)
        {
            bool bulletGenerated = base.GenerateBullet(position, direction, bonusAccuracy);
            ShotgunBullet bullet;
            float currentDirection;

            if (bulletGenerated)
            {
                for (int i = 0; i < numberOfBullets; i++)
                {
                    currentDirection = (float)(direction + (accuracy + bonusAccuracy) * (random.NextDouble() - 0.5));

                    bullet = new ShotgunBullet(position, (float)(bulletSpeed * (1 - 0.1*random.NextDouble())),
                        currentDirection, (float)(maxDistance * (1 - 0.1 * random.NextDouble())));

                    bullet.CurrentImages.Add(new Image(texture));
                    bullet.CurrentImages[0].OriginX = bullet.CurrentImages[0].Width / 2;
                    bullet.CurrentImages[0].OriginY = bullet.CurrentImages[0].Height / 2;
                    bullet.CurrentImages[0].Angle = currentDirection;
                    bullet.AddCollisionMask(baseMask.Clone());

                    OGE.CurrentWorld.AddEntity(bullet);
                }

                PlaySound("shotgun");
                OGE.WorldCamera.ShackCamera(5, 0.2f);
            }

            return bulletGenerated;
        }
Ejemplo n.º 2
0
    /// <summary>
    /// shoots the gun that just propels the character away from the pointer
    /// </summary>
    void ShootBigRecoil()
    {
        if (hasBigRecoil && GameStats.Instance.isPaused == false)
        {
            if (numBigRecoilShots < 1)// no big recoil shots if there are no bullets left
            {
                return;
            }

            if (!grounded)
            {
                numBigRecoilShots -= 1; //decrement the number of big recoil shots remaining
            }
            else
            {
                subtractBigRecoil = true;
                StartCoroutine(removeBigRecoilFired());
            }

            if (velocityZeroing)
            {
                rb.velocity = Vector2.zero;
            }

            //get the mouse position in world coordinates
            Vector3 mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
            //get the vector from mouse position to object position
            Vector2 direction = new Vector2(gameObject.transform.position.x - mousePos.x, gameObject.transform.position.y - mousePos.y).normalized;

            rb.AddForce(direction * recoilForce);

            float firingAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

            //Startup the shooting animation
            StartShootAnim(firingAngle, 0);

            GameObject shooting = null;
            if (shotgunEffect != null)
            {
                shooting = Instantiate(shotgunEffect);
                shooting.transform.position = GetFiringPoint(firingAngle, true);
                shooting.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(-direction.y, -direction.x) * Mathf.Rad2Deg);
            }

            firingAngle -= 5;
            for (int i = 0; i < 4; i++)
            {
                firingAngle += Random.Range(1.5f, 2.5f);
                ShotgunBullet bullet = Instantiate(shotgunBullet).GetComponent <ShotgunBullet>();
                bullet.transform.position = shooting.transform.position;
                bullet.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(-direction.y, -direction.x) * Mathf.Rad2Deg);
                bullet.Init(new Vector2(-Mathf.Cos(firingAngle * Mathf.Deg2Rad), -Mathf.Sin(firingAngle * Mathf.Deg2Rad)).normalized);
            }

            // Audio code
            AudioManager.Instance.PlayOneShot(shotgunShootingEvent);
        }
    }
Ejemplo n.º 3
0
    public static ShotgunBullet Create(Vector3 position, Vector3 direction)
    {
        Transform bulletTransform = Instantiate(GameAssets.instance.shotgunBullet, position, Quaternion.identity);

        ShotgunBullet bullet = bulletTransform.GetComponent <ShotgunBullet>();

        bullet.Setup(direction);

        return(bullet);
    }
Ejemplo n.º 4
0
        public override AGameObject[] CreateBullets(Vector2 direction)
        {
            var bullets = new AGameObject[8];

            for (int i = 0; i < 8; i++)
            {
                bullets[i] = new ShotgunBullet(
                    Owner,
                    Guid.NewGuid(),
                    Vector2.Transform(direction, Matrix.CreateRotationZ((float)(-Math.PI / 6f + _rand.NextDouble() * Math.PI / 3f))));
            }

            return(bullets);
        }
Ejemplo n.º 5
0
 private void HandleShooting()
 {
     if (timeBtwLastShot <= 0)
     {
         ShotgunBullet.Create(transform.position, new Vector3(1, 0, 0));
         ShotgunBullet.Create(transform.position, new Vector3(0, 1, 0));
         ShotgunBullet.Create(transform.position, new Vector3(-1, 0, 0));
         ShotgunBullet.Create(transform.position, new Vector3(0, -1, 0));
         timeBtwLastShot = timeBtwShot;
     }
     else
     {
         timeBtwLastShot -= Time.deltaTime;
     }
 }
Ejemplo n.º 6
0
    public override void Fire()
    {
        GameObject tempFirePoint = new GameObject();

        tempFirePoint.transform.position = FirePoint.position;
        tempFirePoint.transform.rotation = Quaternion.Euler((FirePoint.rotation.eulerAngles - new Vector3(0, 10, 0)));
        for (int i = 0; i < 3; i++)
        {
            GameObject    curBullet     = Instantiate(Bullet, tempFirePoint.transform.position, tempFirePoint.transform.rotation);
            ShotgunBullet shotgunBullet = curBullet.GetComponent <ShotgunBullet>();
            shotgunBullet.Account            = this.Account;
            shotgunBullet.Speed              = this.Speed;
            shotgunBullet.Damage             = this.Damage;
            tempFirePoint.transform.rotation = Quaternion.Euler((tempFirePoint.transform.rotation.eulerAngles + new Vector3(0, 10, 0)));
        }
    }
Ejemplo n.º 7
0
    public override bool Shoot(bool isVampire = false, bool isQuick = false)
    {
        if (ammo > 0 && Time.time > nextFire)
        {
            // Increase the power each time we shoot.
            power += powerPerShot;
            if (power > maxPower)
            {
                power = maxPower;
            }

            // Increase the bullet number taking in count the power.
            int amount = bulletsPerShot + (int)(power * 0.1f);

            // Create some bullets.
            for (int i = 0; i < amount; i++)
            {
                ShotgunBullet bulletClone = Instantiate(bullet, spawnPoint.position, transform.rotation) as ShotgunBullet;
                bulletClone.SetDamage(baseDamage, isVampire);
                bulletClone.OnTargetReached = HealPlayer;   // Register the vampibot delegate.
                Vector3 euler = bulletClone.transform.localRotation.eulerAngles;
                euler.x += Random.Range(-10.0f + accuracyCapacity * 4.0f, 10.0f - accuracyCapacity * 4.0f);
                euler.y += Random.Range(-10.0f + accuracyCapacity * 4.0f, 10.0f - accuracyCapacity * 4.0f);
                bulletClone.transform.localRotation = Quaternion.Euler(euler);
            }

            if (isQuick)
            {
                nextFire = Time.time + fireRate * 0.5f;
            }
            else
            {
                nextFire = Time.time + fireRate;
            }

            ammo--;
            nextDischarge = Time.time + dischargeRate;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 8
0
        private void ShootTimer_timeout()
        {
            GetNode <Timer>("ShootTimer").Stop();
            ShotgunBullet bullet = (ShotgunBullet)_bulletScene.Instance();

            bullet.Speed     = 140;
            bullet.Position  = Position;
            bullet.Rotation  = (_player.Position - GlobalPosition).Angle();
            bullet.Direction = new Vector2(_player.Position.x - Position.x, _player.Position.y - Position.y).Normalized();
            GetParent().AddChild(bullet);
            if (++_shots == 3)
            {
                _shots = 0;
                GetNode <Timer>("ShootTimer").WaitTime = (float)(_random.NextDouble() * (1.5 - .95) + .95);
                GetNode <Timer>("ShootTimer").Start();
            }
            else
            {
                GetNode <Timer>("ShootTimer").WaitTime = (float)(_random.NextDouble() * (.7 - .3) + .3);
                GetNode <Timer>("ShootTimer").Start();
            }
        }
Ejemplo n.º 9
0
    void Update()
    {
        if (active)//if gun is picked up by player
        {
            //Update UI
            UI.ammoCapacity = maxClip;
            UI.ammo         = clip;

            //update mouse position
            tempVector.x = Input.mousePosition.x;
            tempVector.y = Input.mousePosition.y;
            tempVector.z = Mathf.Abs(cam.transform.position.z);//depth of camera
            mousePos     = cam.ScreenToWorldPoint(tempVector);

            //update gun position
            tempVector         = player.transform.position;
            tempVector.z       = 0;     //gun in front of player
            tempVector.y      += -0.4f; //offsets gun higher
            transform.position = tempVector;

            //update gun orientation
            tempVector.x = 0;
            tempVector.y = 0;
            tempVector.z = Mathf.Atan2(mousePos.y - transform.position.y, mousePos.x - transform.position.x) * Mathf.Rad2Deg; //angle of gun in degrees
            scale        = transform.localScale;
            if (Mathf.Abs(tempVector.z) > 90)                                                                                 //if gun is facing other way, flip gun
            {
                scale.y = -1 * Mathf.Abs(scale.y);
            }
            else
            {
                scale.y = Mathf.Abs(scale.y);
            }
            transform.localScale = scale;
            transform.rotation   = Quaternion.AngleAxis(tempVector.z, Vector3.forward);//rotate gun

            //decrement reloading and fire delay
            reloadingDelay--;
            fireDelay--;

            //done reloading
            if (reloadingDelay % 50 == 0 && reloadingDelay > 0)//every 50 frames, load 1 shot
            {
                clip++;
                audioSource.PlayOneShot(loadSFX, 1F);
            }

            if (reloadingDelay == 0)//done loading all clips
            {
                fireDelay = 65;
                audioSource.PlayOneShot(cockSFX, 1F);
            }

            //fire while reloading: permitted but requires cocking shotgun first
            if (Input.GetMouseButton(0) && reloadingDelay > 0 && clip > 0)
            {
                fireDelay = 65;
                audioSource.PlayOneShot(cockSFX, 1F);
                reloadingDelay = -1;
            }

            //fire
            if (Input.GetMouseButton(0) && reloadingDelay < 0 && fireDelay <= 0)//if left click clicked (can be held) and not reloading
            {
                fireDelay = 65;
                audioSource.PlayOneShot(fireSFX, 0.6F);
                clip--;//decrement clip

                float   finalRotation;
                Vector3 finalDirection;
                for (int i = 0; i < 10; i++)
                {
                    finalRotation = tempVector.z + Random.Range(-spread, spread);
                    GameObject    g = Instantiate(bullet, transform.position, Quaternion.identity); //instantiate bullet prefab
                    ShotgunBullet p = g.GetComponent <ShotgunBullet>();                             //cache bullet
                    finalDirection       = (mousePos - transform.position).normalized;
                    finalDirection.x    += Mathf.Cos(Mathf.Deg2Rad * finalRotation);                //change spread angle into directional vector
                    finalDirection.y    += Mathf.Sin(Mathf.Deg2Rad * finalRotation);                //change spread angle into directional vector
                    p.direction          = finalDirection;                                          //direction bullet is travelling
                    p.transform.rotation = Quaternion.AngleAxis(finalRotation, Vector3.forward);    //rotate bullet
                }

                if (clip == 0)//if clip is empty, reload automatically
                {
                    fireDelay      = 50;
                    reloadingDelay = (maxClip - clip) * 50 + 65;//time it take to fully reload all shells
                }
            }

            //manual reload (if not already reloading)
            if (Input.GetKeyDown("r") && reloadingDelay < 0)
            {
                reloadingDelay = (maxClip - clip) * 50 + 45;//time it take to fully reload all shells
            }
        }
    }