Beispiel #1
0
        /// <summary>
        /// Reflect the bullet by turning the degree.
        /// </summary>
        /// <param name="bullet"> bullet reflecting. </param>
        private void ReflectBullet(JCS_Bullet bullet)
        {
            // if object cannot be reflected, end function call
            if (!bullet.Reflectable)
            {
                return;
            }

            float randDegree = JCS_Random.Range(-mRandomReflectDegree, mRandomReflectDegree);

            Vector3 rotation = bullet.transform.eulerAngles;

            rotation.z += (180 + randDegree);      // plus 180 so it goes other direction.
            bullet.transform.eulerAngles = rotation;

            // apply the force.
            bullet.MoveSpeed += mReflectForce;

            // play sound from sound pool
            mSoundPoolAction.PlayRandomSound();

            // do random teleport effect
            RandomPosEffect(bullet);

            // apply position offset
            bullet.transform.position += mPosOffset;
        }
Beispiel #2
0
        private void RandomPosEffect(JCS_Bullet bullet)
        {
            Vector3 newPos = bullet.transform.position;

            if (mRandPosX)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeX, mRandPosRangeX);
                newPos.x += effectRange;
            }

            if (mRandPosY)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeY, mRandPosRangeY);
                newPos.y += effectRange;
            }

            if (mRandPosZ)
            {
                float effectRange = JCS_Random.Range(-mRandPosRangeZ, mRandPosRangeZ);
                newPos.z += effectRange;
            }

            // apply result
            bullet.transform.position = newPos;
        }
Beispiel #3
0
        private void OnTriggerEnter(Collider other)
        {
            JCS_Bullet bullet = other.GetComponent <JCS_Bullet>();

            if (bullet != null)
            {
                ReflectBullet(bullet);
            }
        }
Beispiel #4
0
        public void ShootWithShootCount(Vector3 pos, Vector3 angle)
        {
            for (int count = 0;
                 count < ShootCount;
                 ++count)
            {
                JCS_Bullet bullet = Shoot();

                if (bullet == null)
                {
                    break;
                }

                bullet.transform.position    = pos;
                bullet.transform.eulerAngles = angle;

                DeviationEffect(bullet.transform);
                RandTransform(bullet.transform.position);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Set Attacker Info, this make all the bullet knows their
 /// attacker object.
 ///
 /// Attacker throw the star, but the star does not know anything
 /// about the attacker itself. Use this function to let them know
 /// the attacker. which i name is "attacker info".
 /// </summary>
 /// <param name="bullet"> bullet we need to set attacker info with </param>
 /// <param name="trans"> transform which is the attacker, usually itself. </param>
 private void SetAttackerInfo(JCS_Bullet bullet, Transform trans)
 {
     bullet.AttackerInfo.Attacker = trans;
 }
Beispiel #6
0
 /// <summary>
 /// Shorthand way to do with own transform. Base function
 /// is under this function.
 /// </summary>
 /// <param name="bullet"> bullet we need to set attacker info with </param>
 private void SetAttackerInfo(JCS_Bullet bullet)
 {
     SetAttackerInfo(bullet, this.transform);
 }
Beispiel #7
0
        /// <summary>
        /// Shoot a bullet.
        /// </summary>
        /// <param name="bulletSpeed"></param>
        /// <param name="pos"></param>
        /// <param name="direction"></param>
        /// <param name="damages"></param>
        /// <param name="index"></param>
        /// <param name="inSequence"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public JCS_Bullet Shoot(float bulletSpeed, Vector3 pos, bool direction, int[] damages, int index = 0, bool inSequence = false, Transform target = null)
        {
            if (mPlayer != null)
            {
                if (mPlayer.CharacterState != JCS_2DCharacterState.NORMAL)
                {
                    return(null);
                }
            }

            int hit = damages.Length;

            Vector3 spawnPos = pos + mSpanwPointOffset;

            spawnPos = RandTransform(spawnPos);

            JCS_Bullet bullet = (JCS_Bullet)JCS_Utility.SpawnGameObject(mBullet, spawnPos, mSpawnPoint.rotation);

            // no object spawns
            if (bullet == null)
            {
                return(null);
            }

            // set the attacker.
            SetAttackerInfo(bullet);

            float tempBulletSpeed = bulletSpeed;

            // default: facing left
            if (!direction)
            {
                tempBulletSpeed = -tempBulletSpeed;
            }

            // set bullet speed
            bullet.MoveSpeed = tempBulletSpeed;

            // Do devication Effect
            DeviationEffect(bullet.transform);

            if (bullet is JCS_2DBullet)
            {
                bullet.GetComponent <JCS_3DGoStraightAction>().MoveSpeed = bulletSpeed;
            }


            if (mTrackSoot &&
                target != null)
            {
                JCS_2DTrackAction ta = bullet.GetComponent <JCS_2DTrackAction>();
                if (ta != null)
                {
                    ta.TargetTransform = target;

                    // set to center
                    float newIndex = index - (hit / 2.0f);

                    // apply effect
                    ta.Index = newIndex;
                }
            }

            if (mAbilityFormat != null)
            {
                JCS_ApplyDamageTextToLiveObjectAction adta = bullet.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                if (adta != null)
                {
                    // set the Ability Format
                    adta.AbilityFormat = mAbilityFormat;
                    adta.Hit           = hit;

                    adta.DamageApplying = damages;

                    // if hit equal to 0,
                    // meaning this bullet is in the sequence
                    if (inSequence)
                    {
                        adta.InSequence = true;
                    }

                    adta.TargetTransform = target;
                }
            }

            // part of the SFX
            mRandomMultiSoundAction.PlayRandomSound();

            return(bullet);
        }