Beispiel #1
0
        public static Vec2 GetBulletVecDeg(float degress, float speed = 1f, float speedVariable = 0, float accuracy = 1f)
        {
            var accuracyLossDeg = Rando.Float(180 * (1 - accuracy)).RandomNegative();
            var result          = Maths.AngleToVec(Maths.DegToRad(degress + accuracyLossDeg)) * (speed + Rando.Float(speedVariable).RandomNegative());

            result.y *= -1;
            return(result);
        }
        public static void ThingMoveTo(Thing thing, Vec2 position, float speed = 3, float lerpAmount = -1)
        {
            if (thing == null)
            {
                return;
            }
            if (thing.y < position.y && thing is MaterialThing materialThing)
            {
                IEnumerable <IPlatform> plats = Level.CheckLineAll <IPlatform>(thing.bottomLeft + new Vec2(1f, 1f), thing.bottomRight + new Vec2(-1f, 1f));
                if (plats.FirstOrDefault((IPlatform p) => p is Block) == null)
                {
                    foreach (IPlatform plat in plats)
                    {
                        if (plat is Block)
                        {
                            break;
                        }
                        if (plat is MaterialThing t)
                        {
                            materialThing.clip.Add(t);
                            IPlatform left = Level.CheckPoint <IPlatform>(t.topLeft + new Vec2(-2f, 2f));
                            if (left is not null and MaterialThing and not Block)
                            {
                                materialThing.clip.Add(left as MaterialThing);
                            }
                            IPlatform right = Level.CheckPoint <IPlatform>(t.topRight + new Vec2(2f, 2f));
                            if (right is not null and MaterialThing and not Block)
                            {
                                materialThing.clip.Add(right as MaterialThing);
                            }
                            thing.vSpeed          += 1;
                            thing.y               += 2;
                            materialThing.grounded = false;
                        }
                    }
                }
            }
            Vec2 anglevec = Vec2.Clamp(new Vec2(position.x - thing.x, thing.y - position.y), new Vec2(-speed), new Vec2(speed));
            Vec2 tmp      = Maths.AngleToVec((float)Math.Atan(anglevec.y / anglevec.x)) * speed;

            if (lerpAmount == -1)
            {
                thing.hSpeed = anglevec.x < 0 ? -tmp.x : tmp.x;
                thing.vSpeed = anglevec.x < 0 ? -tmp.y : tmp.y;
            }
            else
            {
                var newHSpeed = anglevec.x < 0 ? -tmp.x : tmp.x;
                var newVSpeed = anglevec.x < 0 ? -tmp.y : tmp.y;
                thing.hSpeed = MathHelper.Lerp(thing.hSpeed, newHSpeed, lerpAmount);
                thing.vSpeed = MathHelper.Lerp(thing.vSpeed, newVSpeed, lerpAmount);
            }

            if (Level.CheckRect <Window>(thing.topLeft, thing.bottomRight) is Window window)
            {
                window.Destroy();
            }
        }
Beispiel #3
0
 public void Draw()
 {
     Graphics.DrawRect(this._upperTorso.position + new Vec2(-1f, -1f), this._upperTorso.position + new Vec2(1f, 1f), Color.LimeGreen * 0.9f, new Depth(0.8f));
     Graphics.DrawLine(this._upperTorso.position, this._upperTorso.position + Maths.AngleToVec(this._upperTorso.orientation) * 4f, Color.Yellow, depth: (new Depth(0.9f)));
     Graphics.DrawRect(this._lowerTorso.position + new Vec2(-1f, -1f), this._lowerTorso.position + new Vec2(1f, 1f), Color.LimeGreen * 0.9f, new Depth(0.8f));
     Graphics.DrawLine(this._lowerTorso.position, this._lowerTorso.position + Maths.AngleToVec(this._lowerTorso.orientation) * 4f, Color.Yellow, depth: (new Depth(0.9f)));
     Graphics.DrawRect(this._head.position + new Vec2(-1f, -1f), this._head.position + new Vec2(1f, 1f), Color.LimeGreen * 0.9f, new Depth(0.8f));
     Graphics.DrawLine(this._head.position, this._head.position + Maths.AngleToVec(this._head.orientation) * 4f, Color.Yellow, depth: (new Depth(0.9f)));
 }
Beispiel #4
0
        public override void Fire()
        {
            SFX.Play(DuckUtils.GetAsset("sounds/pop.wav"));

            Vec2  barrel   = Offset(barrelOffset);
            float radians  = barrelAngle + Rando.Float(-0.1f, 0.1f);
            Vec2  velocity = Maths.AngleToVec(radians) * 10f;

            Frog frog = new Frog(barrel.x, barrel.y, velocity.x > 0);

            Fondle(frog);
            frog.hSpeed = velocity.x;
            frog.vSpeed = velocity.y;
            Level.Add(frog);
        }
Beispiel #5
0
 public override void Update()
 {
     base.Update();
     if (this.ammo == 0)
     {
         this._firing            = false;
         this._barrelFlame.speed = 0.0f;
     }
     if (this._firing && this._barrelFlame.currentAnimation == "idle")
     {
         this._barrelFlame.SetAnimation("puff");
     }
     if (this._firing && this._barrelFlame.currentAnimation == "puff" && this._barrelFlame.finished)
     {
         this._barrelFlame.SetAnimation("flame");
     }
     if (!this._firing && this._barrelFlame.currentAnimation != "idle")
     {
         this._barrelFlame.SetAnimation("puffOut");
     }
     if (this._barrelFlame.currentAnimation == "puffOut" && this._barrelFlame.finished)
     {
         this._barrelFlame.SetAnimation("idle");
     }
     this._sound.lerpVolume = this._firing ? 0.5f : 0.0f;
     if (this.isServerForObject && this._firing && this._barrelFlame.imageIndex > 5)
     {
         this._flameWait -= 0.25f;
         if ((double)this._flameWait > 0.0)
         {
             return;
         }
         Vec2 vec  = Maths.AngleToVec(this.barrelAngle + Rando.Float(-0.5f, 0.5f));
         Vec2 vec2 = new Vec2(vec.x * Rando.Float(2f, 3.5f), vec.y * Rando.Float(2f, 3.5f));
         this.ammo -= 2;
         Level.Add((Thing)SmallFire.New(this.barrelPosition.x, this.barrelPosition.y, vec2.x, vec2.y, firedFrom: ((Thing)this)));
         this._flameWait = 1f;
     }
     else
     {
         this._flameWait = 0.0f;
     }
 }
 public override void OnPressAction()
 {
     if (this.ammo > 0)
     {
         if ((double)this._burnLife <= 0.0)
         {
             SFX.Play("dartStick", 0.5f, Rando.Float(0.2f) - 0.1f);
         }
         else
         {
             --this.ammo;
             SFX.Play("dartGunFire", 0.5f, Rando.Float(0.2f) - 0.1f);
             this.kick = 1f;
             if (this.receivingPress || !this.isServerForObject)
             {
                 return;
             }
             Vec2  vec2    = this.Offset(this.barrelOffset);
             float radians = this.barrelAngle + Rando.Float(-0.1f, 0.1f);
             Dart  dart    = new Dart(vec2.x, vec2.y, this.owner as Duck, -radians);
             this.Fondle((Thing)dart);
             if (this.onFire)
             {
                 Level.Add((Thing)SmallFire.New(0.0f, 0.0f, 0.0f, 0.0f, stick: ((MaterialThing)dart), firedFrom: ((Thing)this)));
                 dart.burning = true;
                 dart.onFire  = true;
             }
             Vec2 vec = Maths.AngleToVec(radians);
             dart.hSpeed = vec.x * 10f;
             dart.vSpeed = vec.y * 10f;
             Level.Add((Thing)dart);
         }
     }
     else
     {
         this.DoAmmoClick();
     }
 }
Beispiel #7
0
 public override void Update()
 {
     base.Update();
     if (this.isServerForObject && this._firing && this.ammo > 0)
     {
         if (this._smoke)
         {
             Vec2 vec  = Maths.AngleToVec(this.barrelAngle + Rando.Float(-0.5f, 0.5f));
             Vec2 vec2 = new Vec2(vec.x * Rando.Float(0.9f, 3f), vec.y * Rando.Float(0.9f, 3f));
             ExtinguisherSmoke extinguisherSmoke = new ExtinguisherSmoke(this.barrelPosition.x, this.barrelPosition.y);
             extinguisherSmoke.hSpeed = vec2.x;
             extinguisherSmoke.vSpeed = vec2.y;
             --this.ammo;
             this._guage.frame = 3 - (int)((double)this.ammo / (double)this._maxAmmo * 4.0);
             Level.Add((Thing)extinguisherSmoke);
         }
         this._smoke = !this._smoke;
     }
     else
     {
         this._smoke = true;
     }
     this._sound.lerpVolume = this._firing ? 0.5f : 0.0f;
 }
 public override void OnPressAction()
 {
     if (this.ammo > 0)
     {
         --this.ammo;
         SFX.Play("netGunFire", 0.5f, Rando.Float(0.2f) - 0.4f);
         this.ApplyKick();
         if (this.receivingPress || !this.isServerForObject)
         {
             return;
         }
         Vec2  vec2  = this.Offset(this.barrelOffset);
         Flare flare = new Flare(vec2.x, vec2.y, this);
         this.Fondle((Thing)flare);
         Vec2 vec = Maths.AngleToVec(this.barrelAngle + Rando.Float(-0.2f, 0.2f));
         flare.hSpeed = vec.x * 14f;
         flare.vSpeed = vec.y * 14f;
         Level.Add((Thing)flare);
     }
     else
     {
         this.DoAmmoClick();
     }
 }
Beispiel #9
0
 public static Vec2 GetBulletVecDeg(float degress, float speed = 1f)
 {
     return(Maths.AngleToVec(Maths.DegToRad(degress)) * speed);
 }
        public override void Update()
        {
            if (this._sprite == null)
            {
                return;
            }
            Vec2 vec2_1 = this.Offset(new Vec2(-6f, -4f));

            if (this._lit && (bool)this._timer)
            {
                Level.Add((Thing)Spark.New(vec2_1.x, vec2_1.y, new Vec2(Rando.Float(-1f, 1f), -0.5f), 0.1f));
            }
            if (this._lit && this._litTimer != null && ((bool)this._litTimer && this._litStartTimer != null) && (bool)this._litStartTimer)
            {
                if (this._sprite.frame == 0)
                {
                    this._sprite.frame = 1;
                }
                if (this.owner == null)
                {
                    this.y -= 6f;
                }
                --this.ammo;
                SFX.Play("netGunFire", 0.5f, Rando.Float(0.2f) - 0.4f);
                this.kick = 1f;
                if (this.isServerForObject)
                {
                    Vec2       vec2_2     = this.Offset(this.barrelOffset);
                    CandleBall candleBall = new CandleBall(vec2_2.x, vec2_2.y, (FlareGun)this, 4);
                    this.Fondle((Thing)candleBall);
                    Vec2 vec = Maths.AngleToVec(this.barrelAngle + Rando.Float(-0.1f, 0.1f));
                    candleBall.hSpeed = vec.x * 14f;
                    candleBall.vSpeed = vec.y * 14f;
                    Level.Add((Thing)candleBall);
                }
                if (this.owner == null)
                {
                    this.hSpeed -= (float)this._flip * Rando.Float(1f, 5f);
                    this.vSpeed -= Rando.Float(1f, 7f);
                    this._flip   = this._flip <= 0 ? 1 : -1;
                }
                this.offDir = (sbyte)this._flip;
            }
            if (this.ammo <= 0)
            {
                this._lit          = false;
                this._sprite.frame = 2;
                if (this._burnSound != null)
                {
                    this._burnSound.Stop();
                    this._burnSound = (Sound)null;
                }
            }
            base.Update();
            if (this.owner != null)
            {
                this._flip = (int)this.owner.offDir;
            }
            else
            {
                this.graphic.flipH = this._flip < 0;
            }
        }