Beispiel #1
0
        private IEnumerator ShotTwo_CircleShot()
        {
            var winds = new WindArea[] { _fullScreeWindArea, _leftWindArea, _rightWindArea };

            while (true)
            {
                if (!_shotTwoShotCircleBullet)
                {
                    yield break;
                }

                float   angle  = Random.Range(0, 360);
                float   rad    = angle * Mathf.Deg2Rad;
                float   speed  = Random.Range(_shotTwoCirMinBulletSpeed, _shotTwoCirMaxBulletSpeed);
                Vector3 vSpeed = new Vector3(Mathf.Cos(rad), Mathf.Sin(rad), 0) * speed;

                var rotation = Quaternion.Euler(0, 0, angle - 90f);
                var bullet   = BulletUtils.GetBullet(
                    _shotTwoCirBullet, null, _falcon.position, rotation);
                bullet.GetComponent <JIBulletController> ()
                .Shot(WindBulletMove.LinearWindMove(bullet.transform, vSpeed, Vector3.zero, winds));

                float interval = Random.Range(_shotTwoCirMinEmitInterval, _shotTwoCirMaxEmitInterval);
                yield return(new WaitForSeconds(interval));
            }
        }
Beispiel #2
0
    private void AttractBullet(Collider2D col)
    {
        var bullet = col.transform.parent?.GetComponent <JIBulletProperty> ();

        if (bullet == null || bullet.IsPlayerBullet)
        {
            return;
        }

        var bulletMove = bullet.GetComponent <JIBulletMovement> ();

        if (bulletMove == null)
        {
            return;
        }

        var attractMoveCtrl = bulletMove.GetComponent <AttractBulletMoveCtrl> ();

        if (attractMoveCtrl == null)
        {
            BulletUtils.ClearAllMoveCtrl(bullet.gameObject);
            attractMoveCtrl = bulletMove.gameObject.AddComponent <AttractBulletMoveCtrl> ();
            attractMoveCtrl.AttractFactor = AttractForceFactor;
            attractMoveCtrl.SmoothFactor  = SmoothFactor;
            attractMoveCtrl.GravityCenter = transform;
        }
    }
Beispiel #3
0
        /// <summary>
        /// Shot the expansion bullet
        /// </summary>
        private IEnumerator Expansion_Shot()
        {
            Vector3 destRight;
            Vector3 destLeft;
            float   timer = 0f;

            for (int i = _expanBulletNum - 1; i >= 0; i--)
            {
                destRight = _falcon.position + Vector3.right * (_expanInitDistance + i * _expanBulletLocaInterval);
                destLeft  = _falcon.position + Vector3.left * (_expanInitDistance + i * _expanBulletLocaInterval);

                var left = BulletUtils.GetBullet(
                    _expanBullet, null, _falcon.position, Quaternion.identity);
                left.GetComponent <JIBulletController> ().Shot(
                    Expansion_BulletMove(left.transform, destLeft));

                var right = BulletUtils.GetBullet(
                    _expanBullet, null, _falcon.position, Quaternion.identity);
                right.GetComponent <JIBulletController> ().Shot(
                    Expansion_BulletMove(right.transform, destRight));

                timer = _expanBulletShotInterval;
                while (timer > 0f)
                {
                    timer -= JITimer.Instance.DeltTime;
                    yield return(null);
                }
            }

            yield return(new WaitForSeconds(_expanBulletPauseTime));

            Expansion_Transition();
        }
Beispiel #4
0
        private IEnumerator SidenWind_Shot()
        {
            var winds = new WindArea[] { _fullScreeWindArea, _leftWindArea, _rightWindArea };

            float timer      = 0f;
            float deltAngle  = _sideWindSecRange / _sideWindNumberPerSector;
            float startAngle = 270f - _sideWindSecRange / 2 + deltAngle / 2;

            for (int i = 0; i < _sideWindSecNumber; i++)
            {
                for (int j = 0; j < _sideWindNumberPerSector; j++)
                {
                    float      angle    = startAngle + deltAngle * j;
                    Quaternion rotation = Quaternion.Euler(0, 0, angle - 90f);

                    float   rad = angle * Mathf.Deg2Rad;
                    Vector3 vec = new Vector3(Mathf.Cos(rad), Mathf.Sin(rad), 0f) * _sideWindBulletVec;

                    var bullet = BulletUtils.GetBullet(
                        _sideWindBullet, null, _falcon.position, Quaternion.identity);
                    bullet.GetComponent <JIBulletController> ().Shot(
                        WindBulletMove.LinearWindMove(bullet.transform, vec, Vector3.zero, winds));
                }

                while (timer < _sideWindShotInterval)
                {
                    timer += JITimer.Instance.DeltTime;
                    yield return(null);
                }

                timer = 0f;
            }

            yield return(new WaitForSeconds(_fullWindWaitTimeWhenEndShot));
        }
Beispiel #5
0
        private void ShotOne_ShotBullet(float emitRad, Vector3 emitPos, WindArea[] winds)
        {
            var bulletRotate = Quaternion.Euler(0, 0, emitRad * Mathf.Rad2Deg);
            var bulletSpeed  = new Vector3(Mathf.Cos(emitRad), Mathf.Sin(emitRad), 0) * _shotOneBulletSpeed;
            var bullet       = BulletUtils.GetBullet(_shotOneBullet, null, emitPos, bulletRotate);

            bullet.GetComponent <JIBulletController> ()
            .Shot(WindBulletMove.LinearWindMove(bullet.transform, bulletSpeed, Vector3.zero, winds));
        }
Beispiel #6
0
 private void Update()
 {
     // todo: get input in same update & distribute event
     if (Input.GetMouseButtonDown(0))
     {
         BulletUtils.ShootBullet(bulletPrefab,
                                 bulletGenPoint,
                                 weaponRotate.Forward,
                                 weaponChange.GetCurrWeapon);
     }
 }
Beispiel #7
0
        // Follow the player and shot
        private void MoveShot_LateUpdate()
        {
            var   playerProperty = _player.GetComponent <PlayerProperty> ();
            float moveSpeed      = playerProperty.GetHMoveSpeed();
            float shotSpeed      = 0.03f;
            float bulletSpeed    = 5;

            _moveShotTarget = _player.position.x;

            _moveShotShotTimer -= JITimer.Instance.DeltTime;

            // Shot bullet
            if (_moveShotShotTimer < 0f)
            {
                _moveShotShotTimer = shotSpeed;

                var left = BulletUtils.GetBullet(
                    _moveShotBullet, null,
                    _falcon.TransformPoint(_moveShotShotPosLeft),
                    Quaternion.identity);
                left.GetComponent <JIBulletController> ().Shot(bulletSpeed, 270f, 0, 0,
                                                               false, null, 0f, 0f,
                                                               false, 0f, 0f,
                                                               false, 0f, 0f);

                var right = BulletUtils.GetBullet(
                    _moveShotBullet, null,
                    _falcon.TransformPoint(_moveShotShotPosRight),
                    Quaternion.identity);
                right.GetComponent <JIBulletController> ().Shot(bulletSpeed, 270f, 0, 0,
                                                                false, null, 0f, 0f,
                                                                false, 0f, 0f,
                                                                false, 0f, 0f);
            }

            // Move
            float distance = _moveShotTarget - _falcon.position.x;

            if (Mathf.Abs(distance) <= moveSpeed * JITimer.Instance.DeltTime)
            {
                _falcon.position = new Vector3(_moveShotTarget, _falcon.position.y, _falcon.position.z);
                if (_moveShotMove)
                {
                    MoveShot_EndMove();
                    _moveShotMove = false;
                }
            }
            else
            {
                _falcon.position += new Vector3(Mathf.Sign(distance), 0, 0) * moveSpeed * JITimer.Instance.DeltTime;
            }
        }
Beispiel #8
0
 protected JIBulletController GetBullet(Vector3 position, Quaternion rotation, bool forceInstantiate = false)
 {
     if (m_bind)
     {
         return(BulletUtils.GetBullet(m_bulletPrefab, m_bindTransform, position,
                                      rotation, forceInstantiate));
     }
     else
     {
         return(BulletUtils.GetBullet(m_bulletPrefab, null, position, rotation,
                                      forceInstantiate));
     }
 }
Beispiel #9
0
        private void MutiShot_Shot()
        {
            float delt = 360 / _mutiShotNumberPerCircle;

            for (int i = 0; i < _mutiShotNumberPerCircle; i++)
            {
                float angle = i * delt;

                var bullet = BulletUtils.GetBullet(
                    _mutiShotBullet, null, _falcon.position, Quaternion.identity);
                bullet.GetComponent <JIBulletController> ().Shot(
                    MutiShot_BulletMove(bullet.transform, angle));
            }
        }
Beispiel #10
0
        private void ShotThree_Shot()
        {
            var winds = new WindArea[] { _fullScreeWindArea, _leftWindArea, _rightWindArea };

            float delt = 360 / _shotThreeNumberPerCircle;

            for (int i = 0; i < _shotThreeNumberPerCircle; i++)
            {
                float   angle = i * delt;
                float   rad   = angle * Mathf.Deg2Rad;
                Vector3 speed = new Vector3(Mathf.Cos(rad), Mathf.Sin(rad), 0f) * _shotThreeInitVec;
                Vector3 accel = new Vector3(Mathf.Cos(rad), Mathf.Sin(rad), 0f) * _shotThreeAccel;

                var bullet = BulletUtils.GetBullet(
                    _shotThreeBullet, null, _falcon.position, Quaternion.identity);
                bullet.GetComponent <JIBulletController> ()
                .Shot(WindBulletMove.LinearWindMove(bullet.transform, speed, accel, winds));
            }
        }
Beispiel #11
0
    private void Shot()
    {
        _shotTimer += JITimer.Instance.DeltTime;

        if (_shotTimer > ShotInterval)
        {
            var bullet = BulletUtils.GetBullet(BulletPrefab, null,
                                               transform.position + (Vector3)_bulletSpawnOffset,
                                               BulletPrefab.transform.rotation)
                         .GetComponent <JIBulletProperty> ();
            bullet.Damage = BulletDamage;

            var moveCtrl = bullet.gameObject.AddComponent <GeneralBulletMoveCtrl> ();
            moveCtrl.Speed = BulletSpeed;
            moveCtrl.Init();

            _shotTimer = 0f;
        }
    }
Beispiel #12
0
    public void NormalShot()
    {
        if (NormalEmitters.Count == 0)
        {
            return;
        }

        foreach (var emitter in NormalEmitters)
        {
            var bullet = BulletUtils.GetBullet(BulletPrefab, null, emitter.position,
                                               emitter.rotation).gameObject;

            float angle = bullet.transform.rotation.eulerAngles.z + 90f;

            var moveController = bullet.AddComponent <GeneralBulletMoveCtrl> ();
            moveController.Angle = angle;
            moveController.Speed = BulletSpeed;
            moveController.Init();
        }
    }
Beispiel #13
0
        private IEnumerator ShotTwo_SecDirShot(float angle)
        {
            var   winds    = new WindArea[] { _fullScreeWindArea, _leftWindArea, _rightWindArea };
            float secRange = 60f;

            for (int i = 0; i < _shotTwoSecBulletNum; i++)
            {
                float   speed       = Random.Range(_shotTwoSecMinBulletSpeed, _shotTwoSecMaxBulletSpeed);
                float   bulletAngle = angle + Random.Range(-secRange / 2, secRange / 2);
                float   bulletRad   = bulletAngle * Mathf.Deg2Rad;
                Vector3 vSpeed      = new Vector3(Mathf.Cos(bulletRad), Mathf.Sin(bulletRad), 0) * speed;

                var rotation = Quaternion.Euler(0, 0, bulletAngle - 90f);
                var bullet   = BulletUtils.GetBullet(
                    _shotTwoSecBullet, null, _falcon.position, rotation);
                bullet.GetComponent <JIBulletController> ().Shot(
                    WindBulletMove.LinearWindMove(bullet.transform, vSpeed, Vector3.zero, winds));

                float interval = Random.Range(_shotTwoSecMinEmitInterval, _shotTwoSecMaxEmitInterval);
                yield return(new WaitForSeconds(interval));
            }
        }
Beispiel #14
0
        public override void Evaluate(int SpreadMax)
        {
            for (int i = 0; i < SpreadMax; i++)
            {
                if (this.CanCreate(i))
                {
                    wheelRadius       = FwheelRadius[0];
                    wheelWidth        = FwheelWidth[0];
                    CUBE_HALF_EXTENTS = FwheelDistance[0];

                    RaycastVehicle vehicle;

                    AbstractRigidShapeDefinition shapedef = this.FShapes[i];
                    ShapeCustomData sc = new ShapeCustomData();
                    sc.ShapeDef = shapedef;


                    CompoundShape compound = new CompoundShape();



                    CollisionShape chassisShape = shapedef.GetShape(sc);
                    Matrix         localTrans   = Matrix.Translation(Vector3.UnitY);
                    compound.AddChildShape(localTrans, chassisShape);

                    float mass = shapedef.Mass;

                    bool isDynamic = (mass != 0.0f);
                    isFrontWheel = true;

                    Vector3 localInertia = Vector3.Zero;
                    if (isDynamic)
                    {
                        chassisShape.CalculateLocalInertia(mass, out localInertia);
                    }

                    Vector3D pos = this.FPosition[i];
                    Vector4D rot = this.FRotation[i];

                    DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w);


                    RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, compound, localInertia);
                    RigidBody carChassis             = new RigidBody(rbInfo);

                    BodyCustomData bd = new BodyCustomData();

                    carChassis.UserObject = bd;
                    bd.Id     = this.FWorld[0].GetNewBodyId();
                    bd.Custom = this.FCustom[i];

                    this.FWorld[0].Register(carChassis);


                    RaycastVehicle.VehicleTuning tuning           = new RaycastVehicle.VehicleTuning();
                    VehicleRaycaster             vehicleRayCaster = new DefaultVehicleRaycaster(this.FWorld[0].World);
                    vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster);



                    carChassis.ActivationState = ActivationState.DisableDeactivation;
                    this.FWorld[0].World.AddAction(vehicle);



                    // choose coordinate system
                    vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex);

                    Vector3   connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius);
                    WheelInfo a = vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    isFrontWheel       = false;
                    connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);


                    for (i = 0; i < vehicle.NumWheels; i++)
                    {
                        WheelInfo wheel = vehicle.GetWheelInfo(i);
                        wheel.SuspensionStiffness     = FsuspensionStiffness[0];
                        wheel.WheelDampingRelaxation  = FDampingRelaxation[0];
                        wheel.WheelDampingCompression = FDampingCompression[0];
                        wheel.FrictionSlip            = FwheelFriction[0];
                        wheel.RollInfluence           = FrollInfluence[0];
                        wheel.MaxSuspensionTravelCm   = FmaxSuspensionTravelCm[0];
                        wheel.MaxSuspensionForce      = FmaxSuspensionForce[0];
                    }

                    FOutVehicle.SliceCount = 1;
                    FOutVehicle[0]         = vehicle;
                }
            }
        }
Beispiel #15
0
    void Start()
    {
        GameObject gameManager = GameObject.FindGameObjectWithTag("GameController");

        bulletUtils = gameManager.GetComponentInChildren <BulletUtils>();
    }
        protected RigidBody CreateBody(int i, out int id)
        {
            if (this.CanCreate(i))
            {
                AbstractRigidShapeDefinition shapedef = this.FShapes[i];

                ShapeCustomData sc = new ShapeCustomData();
                sc.ShapeDef = shapedef;

                Vector3D pos = this.FPosition[i];
                Vector4D rot = this.FRotation[i];

                DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w);

                CollisionShape shape = shapedef.GetShape(sc);


                Vector3 localinertia = Vector3.Zero;
                if (!this.FKinematic[i] && !this.FStatic[i])
                {
                    if (shapedef.Mass > 0.0f)
                    {
                        shape.CalculateLocalInertia(shapedef.Mass, out localinertia);
                    }
                }

                RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(shapedef.Mass,
                                                                                 ms, shape, localinertia);
                rbInfo.Friction    = this.FFriction[i];
                rbInfo.Restitution = this.FRestitution[i];

                RigidBody body = new RigidBody(rbInfo);

                if (!this.FActive[i])
                {
                    body.ActivationState |= ActivationState.DisableSimulation;
                }
                if (!this.FAllowSleep[i])
                {
                    body.ActivationState = ActivationState.DisableDeactivation;
                }


                body.LinearVelocity  = this.FLinearVelocity[i].ToBulletVector();
                body.AngularVelocity = this.FAngularVelocity[i].ToBulletVector();
                body.CollisionFlags  = CollisionFlags.None;

                if (!this.FContactResponse[i])
                {
                    body.CollisionFlags |= CollisionFlags.NoContactResponse;
                }
                if (this.FKinematic[i])
                {
                    body.CollisionFlags |= CollisionFlags.KinematicObject;
                }
                if (this.FStatic[i])
                {
                    body.CollisionFlags |= CollisionFlags.StaticObject;
                }

                BodyCustomData bd = new BodyCustomData();

                body.UserObject = bd;
                bd.Id           = this.FWorld[0].GetNewBodyId();
                bd.Custom       = this.FCustom[i];

                if (this.FCustomObj.PluginIO.IsConnected)
                {
                    bd.CustomObject = (ICloneable)this.FCustomObj[i].Clone();
                }
                else
                {
                    bd.CustomObject = null;
                }

                this.FWorld[0].Register(body);
                id = bd.Id;
                return(body);
            }
            else
            {
                id = -1;
                return(null);
            }
        }