Fire() public abstract method

Inherited from the concrete Weapon types.
public abstract Fire ( GameObject ammo, GameObject origin ) : void
ammo GameObject The ammo we are firing that could affect the rate of fire.
origin GameObject The origin we are firing from. (Player Ship)
return void
コード例 #1
0
    void Update()
    {
        if (paused)
        {
            return;
        }

        timeSinceLastFire += Time.deltaTime;
        // Control main weapon
        float   h          = Input.GetAxis("Horizontal2");
        float   v          = Input.GetAxis("Vertical2");
        Vector2 weaponAxis = new Vector2(h, v);

        if (weaponAxis.magnitude > deadzone)
        {
            weapon.SetFireHeld(true);
            if (weapon.Fire(timeSinceLastFire, weaponAxis, transform))
            {
                timeSinceLastFire = 0;
            }
        }
        else
        {
            weapon.SetFireHeld(false);
        }
    }
コード例 #2
0
    public void HandleAction(AgentAction action)
    {
        if (action.IsFailed())
        {
            return;
        }

        if (action is AgentActionAttack)
        {
            AttackAction = action as AgentActionAttack;

            WeaponBase weapon = Weapons[CurrentWeapon];

            weapon.Fire(AttackAction.AttackDir);

            if (weapon.ClipAmmo == 0)
            {
                Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, false);
            }
        }
        else if (action is AgentActionReload)
        {
            WeaponBase weapon = Weapons[CurrentWeapon];
            weapon.Reload();
            Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, true);
        }
    }
コード例 #3
0
    public override void ExecuteCommand(Command command, bool resetState)
    {
        base.ExecuteCommand(command, resetState);

        if (entity.isOwner)
        {
            IPlayerMoveCommandInput cmd = (IPlayerMoveCommandInput)command;

            state.isFacingRight = cmd.velocity.x >= 0;

            rigidbody2D.AddForce(cmd.velocity);
            if (rigidbody2D.velocity.magnitude > topSpeed)
            {
                rigidbody2D.velocity = rigidbody2D.velocity.normalized * topSpeed;
            }

            if (cmd.jump && isGrounded)
            {
                rigidbody2D.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
            }

            if (cmd.fire)
            {
                if (currentWeapon != null)
                {
                    currentWeapon.Fire();
                }
            }
        }
    }
コード例 #4
0
        void Start()
        {
            input = GetComponent <PlayerInput>();
            Vector2 direction = Vector2.zero;

            weapon = GetComponentInChildren <WeaponBase>();

            input.MoveHorizontalStream
            .Subscribe(x => {
                direction.x = x;
                Move(direction);
            }).AddTo(gameObject);
            input.MoveVerticalStream
            .Subscribe(y => {
                direction.y = y;
                Move(direction);
            }).AddTo(gameObject);

            Transform shotPos = GameObject.Find("Muzzle").transform;

            input.ShotStream
            .ThrottleFirst(TimeSpan.FromSeconds(weapon.WeaponInfo.ShotInterval))
            .Subscribe(_ => {
                weapon.Fire(shotPos);
            }).AddTo(gameObject);
        }
コード例 #5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         CurrentWeapon.Fire();
     }
     if (Input.GetButtonDown("Reload"))
     {
         Debug.Log("reload");
         CurrentWeapon.Reload();
     }
     if (Input.GetButtonDown("Num1"))
     {
         SwitchWeapon(WeaponType.pistol);
     }
     if (Input.GetButtonDown("Num2"))
     {
         SwitchWeapon(WeaponType.shotgun);
     }
     if (Input.GetButtonDown("Num3"))
     {
         SwitchWeapon(WeaponType.grenadeLauncher);
     }
     if (Input.GetButtonDown("Print"))
     {
         CurrentWeapon.PrintCurrentAmmoCounts();
     }
 }
コード例 #6
0
    public void HandleAction(AgentAction action)
    {
        if (action.IsFailed())
        {
            return;
        }

        if (action is AgentActionAttack)
        {
            AgentActionAttack a      = action as AgentActionAttack;
            WeaponBase        weapon = Weapons[CurrentWeapon];

            weapon.Fire(a.FromPos, a.AttackDir);

            PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(Owner.NetworkView.owner);
            if (ppi != null)
            {
                ppi.AddWeaponUse(CurrentWeapon);
            }
        }
        else if (action is AgentActionReload)
        {
            WeaponBase weapon = Weapons[CurrentWeapon];
            weapon.Reload();
            //            Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, true);
        }
    }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        weapons = this.GetComponents<WeaponBase>();
        currentWeapon = weapons[weaponIndex];
        var clickStream = UpdateAsObservable ()
            .Where (_ => currentWeapon.FireTrigger());

        var rightclickStream = UpdateAsObservable ()
            .Where (_ => Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.R));

        var weaponChangeStreamQ = UpdateAsObservable ()
            .Where (_ => Input.GetKeyDown (KeyCode.Q));
        var weaponChangeStreamE = UpdateAsObservable ()
            .Where (_ => Input.GetKeyDown (KeyCode.E));

        clickStream.TimeInterval().Where(l=>{
            interval += l.Interval.TotalMilliseconds;
            return interval  > currentWeapon.FireRatePerMilliSec;} ).Subscribe (_ =>
        {
            interval = 0;
            if (currentWeapon.CanFire)
            {
                currentWeapon.Fire(camera);
            }
            else if (!currentWeapon.IsReloading)
            {
                currentWeapon.Reload();
            }
        }).AddTo(this);

        rightclickStream.Subscribe (_ =>
                                    {
            if (!currentWeapon.IsReloading)
            {
                currentWeapon.Reload();
            }
        }).AddTo(this);

        weaponChangeStreamQ.Subscribe (_ =>{
            weaponIndex--;
            if (weaponIndex < 0)
                weaponIndex = weapons.Length -1;
            currentWeapon = weapons[weaponIndex];
        }).AddTo(this);
        weaponChangeStreamE.Subscribe (_ =>{
            weaponIndex++;
            if (weaponIndex >= weapons.Length)
                weaponIndex = 0;
            currentWeapon = weapons[weaponIndex];
        }).AddTo(this);

        guardTarget.ObserveEveryValueChanged (x => x.currentHelth)
                .Subscribe (helth => {
                Debug.Log("helth: "+helth);
                    if (helth <= 0)
                        Application.LoadLevel(Application.loadedLevelName);
        }).AddTo(this);
    }
コード例 #8
0
 private void HandleCurrentWeapon()
 {
     if (_currentWeapon is null)
     {
         return;
     }
     _currentWeapon.Reload();
     _currentWeapon.Fire();
 }
コード例 #9
0
    private void GetFireInput(int playerID)
    {
        string fire = "Fire" + playerID;

        if (Input.GetButton(fire) && _CurrentWeapon != null)
        {
            _CurrentWeapon.Fire();
        }
    }
コード例 #10
0
ファイル: Enemy.cs プロジェクト: kanizabuza/2DShooter_UniRx
        private void Start()
        {
            weapon = GetComponentInChildren <WeaponBase>();
            Move(transform.up * -1);
            if (!CanShot)
            {
                return;
            }

            Observable.Interval(TimeSpan.FromSeconds(weapon.WeaponInfo.ShotInterval))
            .Subscribe(_ => {
                for (int i = 0; i < transform.childCount; i++)
                {
                    Transform shotPosition = transform.GetChild(i);
                    weapon.Fire(shotPosition);
                }
            }).AddTo(this);
        }
コード例 #11
0
    void Update()
    {
        if (paused)
        {
            return;
        }

        if (player != null)
        {
            currentStageTime += Time.deltaTime;
            if (moving)
            {
                Vector2 direction = player.transform.position - transform.position;
                // Add some randomization to enemy movement
                direction = RandomizeDirection(direction);
                body.AddForce(direction.normalized * forceScalar * Time.deltaTime);

                if (currentStageTime >= movementTime)
                {
                    currentStageTime = 0;
                    moving           = false;
                    body.velocity    = Vector2.zero;
                }
            }
            else
            {
                if (currentStageTime >= stopTime)
                {
                    currentStageTime = 0;
                    moving           = true;
                    // fire interval and direction don't matter
                    //TODO this could be bad...
                    weapon.Fire(weapon.minFireInterval + 1, Vector2.zero, transform);
                }
            }
        }
        else
        {
            this.enabled = false;
        }
    }
コード例 #12
0
    void Update()
    {
        if (paused)
        {
            return;
        }

        if (player != null)
        {
            currentFireDelay += Time.deltaTime;
            if (currentFireDelay >= weapon.minFireInterval)
            {
                Vector2 direction = player.transform.position - transform.position;
                weapon.Fire(currentFireDelay, direction, transform);
                currentFireDelay = 0;
            }
        }
        else
        {
            this.enabled = false;
        }
    }
コード例 #13
0
    IEnumerator Think()
    {
        bool wasFireDown = false;

        while (true)
        {
            if (GameManager.Instance.GameState != GameManager.State.Playing)
            {
                yield return(null);

                continue;
            }

            bool leftDown  = Input.GetMouseButton(0);
            bool rightDown = Input.GetMouseButton(1);
            bool bothDown  = leftDown && rightDown;
            bool doFire    = false;

            if (!bothDown)
            {
                // First show the correct weapon if not already shown
                if (leftDown && Weapon.Type != WeaponTypeLeft && WeaponTypeLeft != WeaponType.None)
                {
                    SetWeapon(WeaponTypeLeft);
                }

                if (rightDown && Weapon.Type != WeaponTypeRight && WeaponTypeRight != WeaponType.None)
                {
                    SetWeapon(WeaponTypeRight);
                }

                doFire = leftDown || rightDown;
            }

            if (!doFire && wasFireDown)
            {
                // Stop firing
                isShooting_ = false;
                Weapon.StopFire();
                moveSpeedModifier_ = 1.0f;
            }
            else if (doFire && Weapon.GetCdLeft() <= 0.0f)
            {
                isShooting_        = true;
                moveSpeedModifier_ = Weapon.MoveSpeedModifier;
                wasFireDown        = true;
                float recoil;
                Weapon.Fire(weaponTransform_, lookDir_, GameManager.Instance.SortLayerTopEffects, out recoil);
                AddForce(lookDir_ * -recoil);
                const float RecoilScreenShakeFactor = 4.0f;
                GameManager.Instance.ShakeCamera(recoil * RecoilScreenShakeFactor);

                if (Weapon.Type == WeaponType.Grenade)
                {
                    grenadeScript_.Throw(trans_.position, LookAt);
                }
                else if (Weapon.Type == WeaponType.Mine)
                {
                    var newMine = Instantiate <GameObject>(MineProto).GetComponent <MineScript>();
                    newMine.Throw(trans_.position, LookAt);
                }
            }

            if (!isMoving_)
            {
                animationController_.Tick(Time.deltaTime, renderer_, GameManager.Instance.SelectedHero.PlayerIdleSprites);
            }
            else
            {
                animationController_.Tick(Time.deltaTime, renderer_, GameManager.Instance.SelectedHero.PlayerRunSprites);
            }
            yield return(null);
        }
    }
コード例 #14
0
 public void Shoot()
 {
     _weapon.Fire((int)_geometryUtilities.DirectionToObject(gameObject, _target.gameObject));
     Task.current.Complete(true);
 }
コード例 #15
0
 void Fire()
 {
     myWeapon.Fire(this);
 }