Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        #region Lanes
        if (lastSelectTime + SELECT_COOLDOWN < Time.time && currentMissile == null)
        {
            float laneDir = player.GetAxis("Lane Horizontal");
            lastSelectTime = Time.time;

            //Move lane depending on player input
            if (player.id == 0) //player 1
            {
                if (laneDir < 0)
                {
                    lane++;
                }
                else if (laneDir > 0)
                {
                    lane--;
                }
            }
            else //player 2
            {
                if (laneDir > 0)
                {
                    lane++;
                }
                else if (laneDir < 0)
                {
                    lane--;
                }
            }
            if (laneDir != 0)
            {
                audioManager.SelectLaneSound();
            }

            //Set player position in lane
            transform.position = (player.id == 0) ? new Vector3(-8.5f, .01f, zAxis[Mathf.Abs(lane % 3)]) : new Vector3(8f, .01f, zAxis[Mathf.Abs(lane % 3)]);
        }
        #endregion

        #region Minions
        if (player.GetButtonDown("Spawn Minion"))
        {
            if (lastMinionTime + MINION_COOLDOWN < Time.time || currentMinion == null)
            {
                SpawnMinion("Packet");
            }
        }
        else if (currentMinion != null)
        {
            if (player.GetButton("Spawn Minion"))
            {
                if (minionChargeTime >= MINION_CHARGE_MAX && !isPayload)
                {
                    //swap minions
                    SpawnMinion("Payload");
                    isPayload = true;
                }
                else
                {
                    //charge packet into payload
                    minionChargeTime += Time.deltaTime;
                }
            }
            else if (player.GetButtonUp("Spawn Minion"))
            {
                audioManager.MinionSpawnSound();
                currentMinion.Fire();
                currentMinion    = null; //be free
                isPayload        = false;
                minionChargeTime = 0;
            }
        }
        #endregion

        #region Missiles
        if (player.GetButtonDown("Spawn Missile"))
        {
            if (lastMissileTime + MISSILE_COOLDOWN < Time.time || currentMissile == null)
            {
                //spawn initial missile
                SpawnMissile("Ping");
            }
        }
        else if (currentMissile != null)
        {
            if (player.GetButton("Spawn Missile"))
            {
                if (missileChargeTime >= MISSILE_CHARGE_MAX && !isWorm)
                {
                    //swap missiles
                    Destroy(currentMissile);
                    SpawnMissile("Worm");
                    isWorm = true;
                }
                else
                {
                    //charge ping into worm
                    missileChargeTime += Time.deltaTime;
                }
            }
            else if (player.GetButtonUp("Spawn Missile") && currentMissile.launched == false)
            {
                currentMissile.MissileDestroyed += OnMissileDestroyed;

                if (isWorm)
                {
                    //swap control maps to missile controls
                    player.controllers.maps.SetMapsEnabled(false, "Default");
                    player.controllers.maps.SetMapsEnabled(true, "Missile");
                }

                currentMissile.Fire();
                audioManager.MissileSpawnSound();

                isWorm            = false;
                missileChargeTime = 0;
            }
        }
        #endregion
    }
Esempio n. 2
0
    public override void Fire()
    {
        if (_isCooledDown)
        {
            //check if storage has it
            GameObject o        = null;
            Missile    missile  = null;
            Item       ammoItem = null;

            ammoItem = ParentShip.Storage.TakeAmmo(AmmoID, 1, this.AmmoType, _isNPC);
            if (ammoItem != null)
            {
                //just in case the ammo type has changed during take ammo, we always assign the item's id to ammoid
                AmmoID  = ammoItem.ID;
                o       = GameObject.Instantiate(Resources.Load(ammoItem.GetStringAttribute("Weapon Prefab ID"))) as GameObject;
                missile = o.GetComponent <Missile>();
                Damage damage = new Damage();
                damage.DamageType   = (DamageType)Enum.Parse(typeof(DamageType), ammoItem.GetStringAttribute("Damage Type"));
                damage.ShieldAmount = ammoItem.GetFloatAttribute("Shield Damage");
                damage.HullAmount   = ammoItem.GetFloatAttribute("Hull Damage");
                missile.Damage      = damage;
            }
            else
            {
                return;
            }



            if (missile != null)
            {
                Audio.PlayOneShot(GameManager.Inst.SoundManager.GetClip("MissileFire"));

                ShipBase target = null;
                if (ParentShip == GameManager.Inst.PlayerControl.PlayerShip)
                {
                    if (GameManager.Inst.PlayerControl.TargetShip != null)
                    {
                        target = GameManager.Inst.PlayerControl.TargetShip;
                        GameManager.Inst.PlayerControl.TargetShip.IncomingMissiles.Add(missile.gameObject);
                    }
                }
                else
                {
                    ShipBase currentTarget = (ShipBase)ParentShip.MyAI.Whiteboard.Parameters["TargetEnemy"];
                    if (currentTarget != null)
                    {
                        target = currentTarget;
                        currentTarget.IncomingMissiles.Add(missile.gameObject);
                    }
                }

                missile.Initialize(target, ammoItem);
                missile.Attacker           = this.ParentShip;
                missile.transform.position = Barrel.transform.position + Barrel.transform.forward * 2f;
                Vector3 lookTarget = Barrel.transform.position + Barrel.transform.forward * 100;
                missile.transform.LookAt(lookTarget);
                missile.Fire(this.ParentShip, missile.transform.forward * 9f + ParentShip.RB.velocity);

                _isCooledDown  = false;
                _coolDownTimer = 0;
            }
        }
    }
 public ActionResult Fire()
 {
     Missile.Fire(Datetime.Now);
 }