Esempio n. 1
0
    /// <summary>
    /// 子弹进入准备阶段前, 检测初始的碰撞和阻挡, 从而决定子弹究竟进入何种状态.
    /// </summary>
    private BulletState readyCheck()
    {
        BulletState state = BulletState.Ready;

        // 如果开火者的位置, 不在子弹的飞行方向上, 这样检测会不准确.
        // 检测开火者的位置到子弹起始点之间的阻挡.
        Vector3 farthest = Vector3.zero;

        if (Scene.TestLineBlock(mFirerAttr.AttackerPosition, StartPosition,
                                true, CheckLowBlockOnFlying, out farthest))
        {
            // 存在阻挡, 目标点截断至farthest.
            // 表示子弹产生就会出现阻挡, 因此子弹不会产生, 直接爆炸.
            state = BulletState.Arrived;
        }

        // 检测开火者的位置到子弹起始点之间的碰撞.
        // (如果开火者的位置, 不在子弹的飞行方向上, 这样检测会不准确)
        if (CheckFlyHit && FlyHit(mFirerAttr.AttackerPosition, farthest))
        {
            state = BulletState.Arrived;
        }

        // 如果没有延迟时间, 那么直接进入飞行状态.
        if (state != BulletState.Arrived && mCreateDelay == 0)
        {
            state = BulletState.Flying;
        }

        return(state);
    }
Esempio n. 2
0
    //进入场景后
    public override void OnEnterScene(BaseScene scene, uint instanceid)
    {
        base.OnEnterScene(scene, instanceid);

        try
        {
            mFlyController     = initFlyController();
            mExplodeController = initExplodeController();
        }
        catch (System.Exception exception)
        {
            switch2State(BulletState.Invalid);
            GameDebug.LogError(exception);
            return;
        }

        // 检查从开火者位置到枪口的碰撞等.
        BulletState newState = readyCheck();

        // 根据子弹的飞行控制器, 确定目标点.
        if (newState != BulletState.Arrived)
        {
            verifyRange(mBulletParam);
        }

        //
        switch2State(newState);

        //
        mFlyController.Launch();
    }
Esempio n. 3
0
    public void SyncBullet(string[] cmds)
    {
        for (var i = 1; (i + 2) < cmds.Length; i += 2)
        {
            var id = System.Convert.ToInt32(cmds[i]);
            var px = System.Convert.ToInt32(cmds[i + 1]);
            var py = System.Convert.ToInt32(cmds[i + 2]);
            if (allBullet.ContainsKey(id))
            {
            }
            else
            {
                var BulletS = new BulletState();
                BulletS.id = id;

                GameObject go = MainUI.Instance.bullet;

                var copyQizi = (GameObject)GameObject.Instantiate(go);
                copyQizi.transform.parent        = go.transform.parent;
                copyQizi.transform.localScale    = Vector3.one;
                copyQizi.transform.localPosition = Vector3.zero;
                BulletS.go = copyQizi;
                allBullet.Add(id, BulletS);
            }
            var qizi2  = allBullet[id].go;
            var curPos = MainUI.Instance.GetPos(px, py);
            qizi2.transform.localPosition = new Vector3(curPos.x, curPos.y, 0);
            qizi2.SetActive(true);
        }
        //TODO : 删除死亡子弹
    }
    public override void Deserialize(NetworkReader reader)
    {
        var locals   = new Dictionary <int, LocalState>();
        var numLocal = reader.ReadInt32();

        for (var i = 0; i < numLocal; i++)
        {
            var id    = reader.ReadInt32();
            var state = new LocalState();
            state.Deserialize(reader);
            locals[id] = state;
        }

        var bullets   = new Dictionary <string, BulletState>();
        var numBullet = reader.ReadInt32();

        for (var i = 0; i < numBullet; i++)
        {
            var id    = reader.ReadString();
            var state = new BulletState();
            state.Deserialize(reader);
            bullets[id] = state;
        }

        LocalStates  = locals;
        BulletStates = bullets;
    }
Esempio n. 5
0
 public void OnStart()
 {
     rb = GetComponent <Rigidbody2D>();
     gameObject.SetActive(false);
     bulletState             = BulletState.Waiting;
     transform.localPosition = Vector3.zero;
 }
Esempio n. 6
0
 // Use this for initialization
 void Start()
 {
     m_material           = gameObject.GetComponent <MeshRenderer>().material;
     m_state              = BulletState.HIDE_COMPLETE;
     transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);
     m_material.SetFloat("_Sat", -1);
 }
Esempio n. 7
0
 public void OnCollisionItem(Item item) //when the player picks up an item
 {
     if (item is HealthItem)
     {
         life++;                           //increases health by 1
     }
     if (item is StrightBulletPowerUpItem) //power up stright bullet
     {
         strightBulletPowerUpCounter++;
         bulletState = BulletState.Stright; //tells the computer to use stright bullets
         spreadBulletPowerUpCounter  = 0;   //resets power ups in other bullet types
         missileBulletPowerUpCounter = 0;
     }
     if (item is SpreadBulletPowerUpItem)
     {
         spreadBulletPowerUpCounter++;
         bulletState = BulletState.Spread;
         strightBulletPowerUpCounter = 0;
         missileBulletPowerUpCounter = 0;
     }
     if (item is MissileBulletPowerUpItem)
     {
         missileBulletPowerUpCounter++;
         bulletState = BulletState.missile;
         strightBulletPowerUpCounter = 0;
         spreadBulletPowerUpCounter  = 0;
     }
 }
Esempio n. 8
0
    public void Fire()
    {
        state = BulletState.FIRE;

        (new EventCreateEffect(60010010, gameObject, transform.position, 1.0f)).Send();
        //60010010
    }
    public override void Deserialize(NetworkReader reader)
    {
        Vector2?position       = null;
        var     hasNewPosition = reader.ReadBoolean();

        if (hasNewPosition)
        {
            position = reader.ReadVector2();
        }
        Direction?orientation       = null;
        var       hasNewOrientation = reader.ReadBoolean();

        if (hasNewOrientation)
        {
            orientation = DirectionIO.readDirectionFromBuffer(reader);
        }
        var bullets   = new HashSet <BulletState>();
        var numBullet = reader.ReadInt32();

        for (var i = 0; i < numBullet; i++)
        {
            var bullet = new BulletState();
            bullet.Deserialize(reader);
            bullets.Add(bullet);
        }
        NewPosition    = position;
        NewOrientation = orientation;
        BulletsCreated = bullets;
    }
Esempio n. 10
0
        public Bullet(SpriteInfo info, int vel) : base()
        {
            m_State           = BulletState.Flying;
            Position          = info.Position;
            m_InitialPosition = Position;
            //maybe this should just be a random rotation
            RotationAngle  = info.Rotation;
            m_Heading      = new Vector2((float)Math.Cos(RotationAngle), (float)Math.Sin(RotationAngle));
            Velocity       = vel;
            playerVelocity = info.PlayerVelocity;
            textures       = new string[8];
            intervals      = new float[8];
            textures[0]    = "plasmaShot\\plasmaShot1test";
            textures[1]    = "plasmaShot\\plasmaShot2test";
            textures[2]    = "plasmaShot\\plasmaShot3test";
            textures[3]    = "plasmaShot\\plasmaShot4test";
            textures[4]    = "plasmaShot\\plasmaShot5test";
            textures[5]    = "plasmaShot\\plasmaShot4test";
            textures[6]    = "plasmaShot\\plasmaShot3test";
            textures[7]    = "plasmaShot\\plasmaShot2test";

            intervals[0] = 20;
            intervals[1] = 20;
            intervals[2] = 20;
            intervals[3] = 20;
            intervals[4] = 20;
            intervals[5] = 20;
            intervals[6] = 20;
            intervals[7] = 20;
        }
Esempio n. 11
0
 public void Shoot(Vector3 vec)
 {
     gameObject.SetActive(true);
     vel = vec.normalized * speed;
     transform.parent = null;
     bulletState      = BulletState.Shooting;
 }
Esempio n. 12
0
    public void StartBullet()
    {
        onCourse       = true;
        mFlipDirection = (BulletFlipDirection)Random.Range(0, 2);
        anim           = GetComponent <Animator>();

        if (transform.tag == "Player Bullet" && GameManager.instance != null)
        {
            if (GameManager.instance.player.GetComponent <Player>().m_Gunz == Gunz.BasicGun)
            {
                m_State = BulletState.NormalBullet;
            }
            else if (GameManager.instance.player.GetComponent <Player>().m_Gunz == Gunz.SecondGun)
            {
                m_State = BulletState.SecondBullet;
            }
            else
            {
                m_State = BulletState.ThirdBullet;
            }
        }

        if (transform.tag == "Enemy Bullet")
        {
            GetComponent <Animator>().enabled      = false;
            GetComponent <SpriteRenderer>().sprite = GameManager.instance.enemyBulletSprite;
            GetComponent <Renderer>().sortingOrder = 7;
            transform.rotation = Quaternion.Euler(0, 0, 180);
        }

        if (m_State == BulletState.ThirdBullet)
        {
            limitRotations = Quaternion.Euler(0, 0, Random.Range(-20, 20));
        }
    }
Esempio n. 13
0
        public override void Update(GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (currentBulletState)
            {
            case BulletState.comTempo:
            {
                if (timeCounter <= bulletTime)
                {
                    timeCounter += dt;
                }
                else
                {
                    currentBulletState = BulletState.semTempo;
                }
            }
            break;

            case BulletState.semTempo:
            {
                Game1.entities.Remove(this);
            }
            break;
            }
            base.Update(gameTime);
        }
Esempio n. 14
0
        public void Update()
        {
            switch (state)
            {
            case BulletState.spawning:
                activeTime += Time.DeltaB;
                // move towards start position by double speed
                position += (position - startPos).GetAsNormal() * (direction.Length * 2f) * Time.DeltaB;
                if (BMath.NearlyEqual(position, startPos, 0.1f))
                {
                    state = BulletState.active;
                }
                break;

            case BulletState.active:
                activeTime += Time.DeltaB;
                // move in set direction
                position += direction.ToVector2() * Time.DeltaB;
                break;

            case BulletState.destroying:
                activeTime += Time.DeltaB;
                break;

            default: Debug.ErrorLog("We shouldn't be here"); break;
            }
        }
Esempio n. 15
0
 public Player(float x, float y, Game game, Mouse mouse)
 {
     this.x      = x;
     this.y      = y;
     this.game   = game;
     this.mouse  = mouse;
     bulletState = BulletState.Stright;
 }
Esempio n. 16
0
 public void SetupTracing(Vector3 targetPosition, float steerCoef, float steerCoefAcc, bool passBy = false)
 {
     this._state            = BulletState.TracePosition;
     this._targetPosition   = targetPosition;
     this._traceLerpCoef    = steerCoef;
     this._traceLerpCoefAcc = steerCoefAcc;
     this._passBy           = passBy;
 }
    public void ReplaceBulletState(BulletState newState)
    {
        var index     = GameComponentsLookup.BulletState;
        var component = (BulletStateComponent)CreateComponent(index, typeof(BulletStateComponent));

        component.state = newState;
        ReplaceComponent(index, component);
    }
Esempio n. 18
0
 void Timer()
 {
     if (timer > timeLimit)
     {
         bulletState = BulletState.Hided;
         gameObject.SetActive(false);
     }
     timer += Time.deltaTime;
 }
 void Start()
 {
     //bullet's player reference
     player = GameObject.Find("Player");
     //bullet's rigid body reference
     rb2d = GetComponent <Rigidbody2D>();
     //when bullet is created, set state to JUST ACTIVE
     myBulletState = BulletState.JUSTACTIVE;
 }
 /// <summary>
 /// 弾道移動の終了
 /// </summary>
 public void BulletMoveEnter()
 {
     if (selectBullet)
     {
         state = BulletState.rotate;
         //selectBullet.SetDefaultPosition();
         selectBullet.SetBulletObjEnabled(true);
     }
 }
Esempio n. 21
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            other.GetComponent <Rigidbody>().velocity = direction * bulletForce;
        }


        CurrentBulletState = BulletState.InPool;
    }
Esempio n. 22
0
    [HideInInspector] public bool isTimer;                          // 일정 시간이 지난 뒤 재조준 체크

    private void Start()
    {
        bulletState    = GetComponent <BulletState>();
        bulletMove     = GetComponent <BulletMove>();
        playerPosition = GameObject.Find("CHARACTER").transform.Find("Player");

        changeCount = 0;

        StartCoroutine(Reaiming());
    }
Esempio n. 23
0
        public override BulletView Create(BulletData data, Vector3 position, Quaternion rotation)
        {
            var state  = new BulletState(data);
            var bullet = _container.InstantiatePrefabForComponent <BulletView>(data.BulletPrefab, position, rotation, _transform, new List <object>()
            {
                state
            });

            bullet.SetForce(bullet.transform.up * data.Speed);
            bullet.SetTransform(bullet.transform);
            return(bullet);
        }
Esempio n. 24
0
    protected void switch2State(BulletState newState)
    {
        if (mState != newState)
        {
            mState = newState;

            if (mState == BulletState.Flying)
            {
                onStartFlying();
            }
        }
    }
Esempio n. 25
0
 public bool CheckCollision(GameObject ob)
 {
     if (Bounds.Intersects(ob.Bounds) && m_State == BulletState.Flying)
     {
         PlasmaHitAnimationTimer = new AnimationTimer(hitIntervals, m_HitAnimation, HandlePlasmaHitAnimation, false);
         Texture = TextureBank.GetTexture(hitTextures[0]);
         //play the bullet explosion animation here, make sure to remove bounds, it should be fast enough that nothing clips
         m_State = BulletState.Contact;
         return(true);
     }
     return(false);
 }
Esempio n. 26
0
    public override object GetState()
    {
        BulletState s = new BulletState
        {
            Position = transform.position,
            Rotation = transform.rotation,
            TargetId = _enemy.GlobalId,
            Damage = _damage,
            Speed = _speed
        };

        return s;
    }
Esempio n. 27
0
    public override bool Fire(BasicMove player, float angle)
    {
        if(m_chamber == BulletState.Live && m_slideState == SlideState.Forward){
            AudioManager.PlaySFX(m_gunsfx);
            m_chamber = BulletState.Fired;

            for(int i = 0; i < m_pelletCount; i++){
                SpawnBullet(m_bulletPrefab, m_bulletSpeed, player, angle -m_pelletSpread/2 + m_pelletSpread * i / (m_pelletCount-1));
            }
            return true;
        }
        return false;
    }
Esempio n. 28
0
 public void SetupPositioning(Vector3 originalPosition, Vector3 targetPosition, float duration, float resumeSpeed, float steerCoef, float steerCoefAcc, Vector3 tracingPosition, bool passBy = false)
 {
     this._state        = BulletState.Placing;
     this._placingTimer = new EntityTimer(duration);
     this._placingTimer.Reset(true);
     this._originalPosition = originalPosition;
     this._placingPosition  = targetPosition;
     this._resumeSpeed      = resumeSpeed;
     this._traceLerpCoef    = steerCoef;
     this._traceLerpCoefAcc = steerCoefAcc;
     this._targetPosition   = tracingPosition;
     this._passBy           = passBy;
 }
Esempio n. 29
0
        private void Start()
        {
            _bulletColider = GetComponent <SphereCollider>();

            if (_bullet == null)
            {
                _bullet = GetComponent <Rigidbody>();
            }

            GameManger.instance.SoundManger.PlayOutSideSFX("bulletHum", gameObject);

            _currentState = BulletState.MOVING;
        }
Esempio n. 30
0
 protected override void Start()
 {
     base.Start();
     this._rigidbody.velocity = (Vector3)(((base.transform.forward * this.speed) + this.speedAdd) * this.BulletTimeScale);
     if (this._state == BulletState.None)
     {
         this._state = BulletState.Linear;
     }
     if (this._aliveDuration > 0f)
     {
         this._aliveTimer.Reset(true);
     }
 }
Esempio n. 31
0
 public void Fire(float rot)
 {
     if (bullets == 0)
     {
         bState = BulletState.empty;
     }
     else
     {
         bState   = BulletState.justFired;
         rotation = rot;
         bullets--;
     }
 }
Esempio n. 32
0
    public void Display(CylinderState state, BulletState[] chambers, int currentChamber)
    {
        cylinder.transform.localPosition = state == CylinderState.Closed ? closedOffset : openOffset;

        for(int i = 0; i < bullets.Length; i++){
            var chamberState = chambers[(currentChamber + i) % chambers.Length];
            if(chamberState == BulletState.Empty){
                bullets[i].SetActive(false);
            }
            else{
                bullets[i].SetActive(true);
                bullets[i].renderer.material.color = chamberState == BulletState.Fired ? deadBulletColor : liveBulletColor;
            }
        }
    }
Esempio n. 33
0
    public void Display(BoltState state, BulletState[] magazine, bool partialLoad)
    {
        boltClosed.SetActive(state == BoltState.Closed);
        boltUp.SetActive(state == BoltState.Up);
        boltOpen.SetActive(state == BoltState.Open);

        for(int i = 0; i < magazine.Length; i++){
            bullets[i].SetActive(magazine[i] != BulletState.Empty);
        }
        if(state != BoltState.Open && magazine[0] != BulletState.Empty){
            bullets[0].SetActive(false);
            chamberedBullet.SetActive(true);
            chamberedBullet.renderer.material.color = magazine[0] == BulletState.Fired ? deadBulletColor : liveBulletColor;
        }
        else{
            chamberedBullet.SetActive(false);
            bullets[0].renderer.material.color = magazine[0] == BulletState.Fired ? deadBulletColor : liveBulletColor;
        }
        partialLoadBullet.SetActive(partialLoad);
    }
Esempio n. 34
0
	public void SetState(BulletState state)
	{
		if (currentState == state)
		{
			return;
		}

		if (BeforeEffect != null)
			BeforeEffect.SetActive(false);
		if (NormalEffect != null)
			NormalEffect.SetActive(false);
		if (AfterEffect != null)
			AfterEffect.SetActive(false);

		switch(state)
		{
			case BulletState.Before:
			{
				if (BeforeEffect != null)
					BeforeEffect.SetActive(true);
				break;
			}
			case BulletState.Normal:
			{
				if (NormalEffect != null)
					NormalEffect.SetActive(true);
				break;
			}
			case BulletState.After:
			{
				if (AfterEffect != null)
					AfterEffect.SetActive(true);
				StartCoroutine(DelayDestroy());
				break;
			}
		}
		currentState = state;
	}
Esempio n. 35
0
    public void Display(SlideState state, BulletState[] magazine, BulletState chamber, bool partialLoad)
    {
        slideForward.SetActive(state == SlideState.Forward);
        slideBack.SetActive(state == SlideState.Back);

        for(int i = 0; i < shells.Length; i++){
            shells[i].SetActive(magazine[i] != BulletState.Empty);
        }
        if(chamber == BulletState.Empty || state == SlideState.Back){
            chamberedForward.SetActive (false);
        }
        else{
            chamberedForward.SetActive (true);
            chamberedForward.renderer.material.color = chamber == BulletState.Fired ? deadBulletColor : liveBulletColor;
        }
        if(chamber == BulletState.Empty || state == SlideState.Forward){
            chamberedBack.SetActive(false);
        }
        else{
            chamberedBack.SetActive (true);
            chamberedBack.renderer.material.color = chamber == BulletState.Fired ? deadBulletColor : liveBulletColor;
        }
        partialLoadShell.SetActive(partialLoad);
    }
Esempio n. 36
0
        public Bullet(Game1 g, ParticleSystem explosionParticles, ParticleSystem explosionSmokeParticles,
            ParticleSystem projectileTrailParticles, Vector3 origin, Vector3 initialVelocity, SoundEffect Explosion)
            : base(g)
        {
            game = g;
            bulletState = BulletState.Unexploded;

            this.position = origin;
            this.velocity = initialVelocity;

            game.physicsEngine.AddPhysicsObject(this);

            this.explosionParticles = explosionParticles;
            this.explosionSmokeParticles = explosionSmokeParticles;

            this.explosionAge = float.NaN;
            this.explosionLifetime = (float)explosionParticles.Settings.Duration.TotalSeconds + explosionParticles.Settings.DurationRandomness;

            // Use the particle emitter helper to output our trail particles.
            trailEmitter = new ParticleEmitter(projectileTrailParticles,
                                               trailParticlesPerSecond, position);

            explosion = Explosion;
        }
Esempio n. 37
0
 public override void ManipulateLeft()
 {
     if(m_slideState == SlideState.Forward){
         m_partialReload = false;
         m_slideState = SlideState.Back;
         m_chamber = m_magazine[0];
         RemoveTopRound();
     }
 }
Esempio n. 38
0
        public void StartExplosion()
        {
            switch (bulletState)
            {
                case BulletState.Unexploded:

                    bulletState = BulletState.Exploding;
                    explosionAge = 0.0f;
                    explosionLocation = this.position;

                    Vector3 explosionVelocity = 0.25f * new Vector3(velocity.X, 5.0f, velocity.Z);

                    explosion.Play();

                    for (int i = 0; i < numExplosionParticles; i++)
                        explosionParticles.AddParticle(position, explosionVelocity);

                    for (int i = 0; i < numExplosionSmokeParticles; i++)
                        explosionSmokeParticles.AddParticle(position, explosionVelocity);

                    break;
                case BulletState.Exploding:
                    break;
                case BulletState.Dead:
                    break;
                default:
                    break;
            }
        }
Esempio n. 39
0
    // Update is called once per frame
    void Update()
    {
        switch (St_currentBulletState)
        {
            //The bullet is in the player's hands.
            case BulletState.Held:
            {
                //Make charge and aura follow player
                charge.transform.position = T_bulletTransform.position;
                chargeAura.transform.position = T_bulletTransform.position;
                //Disable the trail renderer
                TR_trail.enabled = false;
                //Get the target's position relative to the bullet
                if (Input.GetMouseButton(0))
                {
                    //Calculate the bullet's trajectory vector
                    v2_trajectory = (Vector2)T_targetTransform.position - new Vector2(T_bulletTransform.position.x, T_bulletTransform.position.y);
                    //Normalize the vector to allow for proper scaling
                    v2_trajectory.Normalize();
                    //Show direction and intensity of throw
                    Debug.DrawRay(T_bulletTransform.position, v2_trajectory * (15 / f_bulletMaxSpeed) * f_bulletSpeed, Color.red);
                }
                //Move the bullet with the player
                T_bulletTransform.position = (T_playerTransform.position + this.player.BulletOffset);
                //Tween the bullet speed between the default value and the max value
                f_bulletSpeed = iTween.FloatUpdate(f_bulletSpeed, f_bulletMaxSpeed, f_chargeSpeed);
                //Debug.Log(f_bulletSpeed);

                //Scale the power bar based on the bullet charge
                go_powerBar.transform.localScale = new Vector3(1, 1, ((15 / f_bulletMaxSpeed) * f_bulletSpeed));

                //Create an explosion on the power bar to indicate power shot timing
                if (f_bulletSpeed >= 2f && f_bulletSpeed <= 2.15f)
                {
                    GameObject explosion = (GameObject)Instantiate(go_explosion, go_powerBar.transform.position + (new Vector3(0f, 13f)), Quaternion.identity);
                    //Destroy the explosion after a set time
                    Destroy(explosion, .5f);
                }

                //Destroy the bullet if held too long
                if (f_bulletSpeed > f_bulletMaxSpeed - .0005f)
                {
                    Destroy(gameObject);
                    //Destroy the charge effect
                    Destroy(charge);
                    //Destroy the charge aura
                    Destroy(chargeAura);
                    //reset power bar scale
                    go_powerBar.transform.localScale = new Vector3(1, 1, 0);
                }
                //On mouse release, change to Fired state
                if (Input.GetMouseButtonUp(0))
                {
                    //Check bulletspeed within a certian range for a power shot
                    if (f_bulletSpeed >= 2f && f_bulletSpeed <= 2.25f)
                    {
                        St_currentBulletState = BulletState.PowerShot;
                        //b_powerShot = true;

                    }
                    //Else change to b_beatFired state to release the bullet
                    else
                    {
                        //Change to b_beatFired state to release the bullet
                        St_currentBulletState = BulletState.Fired;
                    }
                    //reset power bar scale
                    go_powerBar.transform.localScale = new Vector3(1, 1, 0);
                }
            }
            break;
            //The bullet is released and flying
            case BulletState.Fired:
            {
                //Destroy charge
                Destroy(charge);
                //Destroy the charge aura
                Destroy(chargeAura);

                //Vertical speed
                float speedY = 0;
                //Add gravity over time
                speedY -= (f_gravity * Time.deltaTime);
                //Adjust the vertical speed of the trajectory
                v2_trajectory = new Vector2(v2_trajectory.x, v2_trajectory.y += speedY);
                //Move the bullet
                T_bulletTransform.Translate(v2_trajectory * f_bulletSpeed);
                //enable the trail renderer
                TR_trail.enabled = true;

                //Delete object when max bounces reached
                if (i_bounceCount > i_maxBounceCount)
                {
                    DestroyBullet();
                }
                //Delete object when it goes above or below a certain cameraHeight
                else if (T_bulletTransform.position.y > 50f || T_bulletTransform.position.y < -5f)
                {
                    Destroy(gameObject);
                }
            }
            break;
            case BulletState.PowerShot:
            {
                //Destroy charge
                Destroy(charge);
                //Destroy the charge aura
                Destroy(chargeAura);

                //Vertical speed
                float speedY = 0;
                //Add gravity over time
                speedY -= (f_gravity * 1.5f * Time.deltaTime);
                //Adjust the vertical speed of the trajectory
                v2_trajectory = new Vector2(v2_trajectory.x, v2_trajectory.y += speedY);
                //Move the bullet
                T_bulletTransform.Translate(v2_trajectory * f_bulletSpeed * 2f);
                //enable the trail renderer
                TR_trail.enabled = true;

                //Change bullet and trail color
                TR_trail.material.color = Color.blue;
                renderer.material.color = Color.blue;
                go_explosion.particleSystem.startColor = Color.blue;

                //Create explosions only when the bullet renderer is enabled
                if (renderer.enabled)
                {
                    //Debug.Log("adding explosions");
                    GameObject explosion = ((GameObject)Instantiate(go_explosion, T_bulletTransform.position, Quaternion.identity));
                    //Destroy the explosion after a set time
                    Destroy(explosion, .5f);
                }

                //Delete object when max bounces + 1 reached
                if (i_bounceCount > (i_maxBounceCount + 1))
                {
                    DestroyBullet();
                }
                //Delete object when it goes above or below a certain cameraHeight
                else if (T_bulletTransform.position.y > 50f || T_bulletTransform.position.y < -5f)
                {
                    Destroy(gameObject);
                }
            }
            break;
            default:
                break;
        }
    }
Esempio n. 40
0
    void Start()
    {
        thisTransform = transform;
        passDroneRef = new List<Drone>();
        bulletState = gameObject.GetComponent<BulletState>();

        if(WeaponManager.Instance.abilities.Contains(WeaponManager.Instance.chainScr))
        {
            (collider as SphereCollider).radius = 3f;
        }
    }
Esempio n. 41
0
        public override void Update(GameTime gameTime)
        {
            switch (game.gameState)
            {
                case GameState.Play:

                    float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

                    switch (bulletState)
                    {
                        case BulletState.Unexploded:

                            age += elapsedTime;

                            // Update the particle emitter, which will create our particle trail.
                            trailEmitter.Update(gameTime, position);

                            // Perform collision detection with any tanks present in the game.
                            foreach (Tank tank in game.tanks)
                            {
                                if (tank.boundingBox.Intersects(this.GetBoundingBox()))
                                {
                                    tank.GetHit(this);
                                    this.StartExplosion();
                                    break;
                                }
                            }

                            // Check if we're outside the bounds of the terrain. (Note that collision
                            // detection with the terrain is handled in the HandleCollisionWithTerrain()
                            // method below).
                            if (!game.terrain.heightMapInfo.IsOnHeightmap(position))
                            {
                                StartExplosion();
                                break;
                            }

                            break;

                        case BulletState.Exploding:
                            if (this == game.bulletManager.ActiveBullet)
                            {
                                //game.worldCamera.CurrentBehavior = game.previousBehavior;

                            }
                            explosionAge += elapsedTime;
                            if (explosionAge >= explosionLifetime)
                            {
                                game.bulletManager.RemoveBullet(this);
                                bulletState = BulletState.Dead;
                                // Switch tanks
                                game.switchCurrentTank();
                            }

                            break;

                        case BulletState.Dead:
                            break;

                        default:
                            break;
                    }

                    break;

                default:
                    break;
            }

            base.Update(gameTime);
        }
Esempio n. 42
0
 void OnEnable()
 {
     ui.gameObject.SetActive (true);
     m_slideState = SlideState.Forward;
     m_magazine = new BulletState[4];
     for(int i = 0; i < m_magazine.Length; i++){
         m_magazine[i] = BulletState.Live;
     }
     m_chamber = BulletState.Live;
     m_partialReload = false;
     Update();
 }