Esempio n. 1
0
        public override void Fire()
        {
            if (!loaded)
            {
                return;
            }
            firedBullets.Clear();
            if (ammo > 0 && _wait == 0)
            {
                ApplyKick();
                for (int index = 0; index < _numBulletsPerFire; ++index)
                {
                    float num = _ammoType.accuracy;
                    _ammoType.accuracy   *= 1f - _accuracyLost;
                    _ammoType.bulletColor = _bulletColor;
                    float angle = offDir >= 0 ? angleDegrees + _ammoType.barrelAngleDegrees : angleDegrees + 180f - _ammoType.barrelAngleDegrees;
                    if (!receivingPress)
                    {
                        Vec2 vec = barrelVector * Rando.Float(1f, 3f);

                        if (barrelVector.x > 0f)
                        {
                            vec.y += _aimAngle - 4f;
                            vec.x += _ammoType.bulletSpeed;
                        }
                        else
                        {
                            vec.y += -(_aimAngle + 4f);
                            vec.x += -(_ammoType.bulletSpeed);
                        }

                        //addded the following code
                        g = new TunnelGrenade(this.x, this.y);
                        Level.Add(g);

                        g.bouncy   = 0.6f;
                        g._pin     = false;
                        teleported = false;

                        // Bullet bullet = _ammoType.FireBullet(Offset(barrelOffset), owner, angle, this);
                        g.ApplyForce(vec);

                        /*if (Network.isActive && isServerForObject)
                         * {
                         * firedBullets.Add(bullet);
                         * if (duck != null && duck.profile.connection != null)
                         * bullet.connection = duck.profile.connection;
                         * }*/
                    }
                    ++bulletFireIndex;
                    _ammoType.accuracy = num;
                }
                loaded = false;
                if (!_manualLoad)
                {
                    Reload(true);
                }
                firing = true;
                _wait  = _fireWait;
                PlayFireSound();
                if (owner == null)
                {
                    Vec2 vec2 = barrelVector * Rando.Float(1f, 3f);
                    vec2.y += Rando.Float(2f);
                    hSpeed -= vec2.x;
                    vSpeed -= vec2.y;
                }
                _accuracyLost += loseAccuracy;
                if (_accuracyLost <= maxAccuracyLost)
                {
                    return;
                }
                _accuracyLost = maxAccuracyLost;
            }
            else
            {
                if (ammo > 0 || _wait != 0f)
                {
                    return;
                }
                _wait = _fireWait;
            }
        }
Esempio n. 2
0
        public override void Update()
        {
            base.Update();

            //Animations
            if (ammo >= 3)
            {
                sprite.SetAnimation("3");
            }
            else if (ammo == 2)
            {
                sprite.SetAnimation("2");
            }
            else if (ammo == 1)
            {
                sprite.SetAnimation("1");
            }
            else
            {
                sprite.SetAnimation("0");
            }


            if (tempX != 0f && tempY != 0f)
            {
                d = new DuckPlaceHolder(tempX, tempY);
                Level.Add(new DuckPlaceHolder(tempX, tempY));
            }

            if (g != null && g._timer <= 0.1f && teleported == false)
            {
                tempX      = g.position.x;
                tempY      = g.position.y - 10f;
                teleported = true;
            }

            if (duck != null)
            {
                if (g != null && teleported == false && duck != null)
                {
                    if (g._timer <= 0.1f)
                    {
                        tempX      = g.position.x;
                        tempY      = g.position.y - 10f;
                        teleported = true;
                    }
                }

                if (g != null && tempX != 0f && tempY != 0f && teleported == true)
                {
                    if (g._destroyed == true)
                    {
                        teleTimer = teleTimer - 0.01f;
                        if (teleTimer <= 0.03f)
                        {
                            Level.Add(SmallSmoke.New(duck.position.x, duck.position.y));
                            if (duck.ragdoll != null)
                            {
                                duck.ragdoll.position.x = tempX;
                                duck.ragdoll.position.y = tempY;
                            }
                            else
                            {
                                duck.position.x = tempX;
                                duck.position.y = tempY;
                            }
                            Level.Add(SmallSmoke.New(duck.position.x, duck.position.y));
                            duck.vSpeed = -0.5f;

                            g          = null;
                            teleported = false;
                            tempX      = 0f;
                            tempY      = 0f;
                            teleTimer  = 0.06f;
                            SFX.Play(GetPath("/sfx/teleport"), 1f, 0f, 0f, false);
                            Level.Remove(d);
                            level.RemoveThing(d);
                            d = null;
                        }
                    }
                }
            }



            if (_aiming && _aimWait <= 0f && _fireAngle < 80f)
            {
                _ammoType.bulletSpeed += 0.3f;
                _fireAngle            += 7f;
            }
            if (_aimWait > 0.0)
            {
                _aimWait -= 0.9f;
            }
            if (_cooldown > 0.0)
            {
                _cooldown -= 0.1f;
            }
            else
            {
                _cooldown = 0f;
            }
            if (owner != null)
            {
                _aimAngle = -Maths.DegToRad(_fireAngle);
                if (offDir < 0)
                {
                    _aimAngle = -_aimAngle;
                }
            }
            else
            {
                _aimWait   = 0f;
                _aiming    = false;
                _aimAngle  = 0f;
                _fireAngle = 0f;
            }
            if (!_raised)
            {
                return;
            }
            _aimAngle = 0.0f;
        }