Exemple #1
0
        public Gas(float x, float y)
        {
            initialRadius = MoreRandom.Next(8, 17);
            initialColor  = colors[MoreRandom.Next(0, colors.Length)];

            Circle = new Circle(x, y, initialRadius)
            {
                Color = initialColor
            };
            Circle.ApplyChanges();

            velocity = Vector2Ext.Random() * MoreRandom.Next(25, 120);

            rateOfDecay = (float)MoreRandom.NextDouble(8, 40);
            Lingering   = true;
        }
Exemple #2
0
        public override void Update()
        {
            input.Update();

            float   speed          = 60 * Engine.DeltaTime;
            Vector2 playerVelocity = Vector2.Zero;

            if (input.Pressing("up"))
            {
                playerVelocity = new Vector2(playerVelocity.X, -1);
            }
            if (input.Pressing("down"))
            {
                playerVelocity = new Vector2(playerVelocity.X, 1);
            }
            if (input.Pressing("left"))
            {
                playerVelocity = new Vector2(-1, playerVelocity.Y);
            }
            if (input.Pressing("right"))
            {
                playerVelocity = new Vector2(1, playerVelocity.Y);
            }


            if (playerVelocity == Vector2.Zero)
            {
                // Not Moving
                dtSpeed         = 1000 * Engine.DeltaTime;
                targetAmplitude = 0.2f;
                dt += dtSpeed * 0.75f;
            }
            else
            {
                playerVelocity.Normalize();
                playerVelocity *= speed;

                // sprite.X += playerVelocity.X;
                // sprite.Y += playerVelocity.Y;
                SetPosition(X + playerVelocity.X, Y + playerVelocity.Y);


                // MOving
                dtSpeed         = 200 * Engine.DeltaTime;
                targetAmplitude = 0.1f;
                dt += dtSpeed * 5f;


                if (canStep)
                {
                    SoundManager.PlaySoundEffect("step", 0.4f);
                    canStep = false;
                    stepSoundTracker.Reset();
                    stepSoundTracker.Start();
                }
            }

            if (!canStep)
            {
                stepSoundTracker.Update();

                if (stepSoundTracker.Done)
                {
                    canStep = true;
                }
            }

            if (!(targetAmplitude - 0.01 < amplitude && amplitude < targetAmplitude + 0.01))
            {
                float desired = targetAmplitude - amplitude;
                amplitude += desired * Engine.DeltaTime;
            }

            sprite.Rotation = (float)Math.Sin(dt * 0.01f) * amplitude;
            sprite.Scale    = new Vector2((float)Math.Sin(dt * 0.01f) * 0.1f + 1, 1);

            // FArts
            fartTimer.Update();
            if (fartTimer.Done)
            {
                if (MoreRandom.NextDouble(0, 1) < 0.25)
                {
                    int total = MoreRandom.Next(16, 64);
                    for (int i = 0; i < total; i++)
                    {
                        Vector2 offset = Vector2Ext.Random() * MoreRandom.Next(16, 48 + 1);
                        Farts.Add(new Gas(sprite.X + offset.X, sprite.Y + offset.Y));
                    }


                    if (CanFart)
                    {
                        SoundManager.PlaySoundEffect($"fart_{MoreRandom.Next(0, 3)}", 0.8f);
                        CanFart = false;
                        fartSoundTracker.Reset();
                        fartSoundTracker.Start();
                    }
                }
                fartTimer.Reset();
                fartTimer.Start();
            }

            if (input.Pressing("air"))
            {
                if (airCooldown.Done)
                {
                    airTimer.Update();
                    int total = MoreRandom.Next(4, 8);
                    for (int i = 0; i < total; i++)
                    {
                        Vector2 offset = Vector2Ext.Random() * MoreRandom.Next(8, 16 + 1);
                        Gas     g      = new Gas(sprite.X + offset.X, sprite.Y + offset.Y).Crazy();

                        if (playerVelocity != Vector2.Zero)
                        {
                            g.AddToVelocity(-playerVelocity.X * 100, -playerVelocity.Y * 100);
                        }
                        g.MoreT();
                        Farts.Add(g);
                    }
                    if (airTimer.Done)
                    {
                        airCooldown.Reset();
                        airTimer.Reset();
                        airCooldown.Start();
                        airTimer.Start();
                    }
                }
            }
            else
            {
                airCooldown.Update();
            }

            if (!CanFart)
            {
                fartSoundTracker.Update();

                sprite.Scale = new Vector2((float)Math.Cos(Engine.TotalGameTime.Milliseconds) * 0.25f + 1, (float)Math.Sin(Engine.TotalGameTime.Milliseconds) * 0.25f + 1);

                if (fartSoundTracker.Done)
                {
                    CanFart = true;
                }
            }

            for (int i = Farts.Count - 1; i >= 0; i--)
            {
                Farts[i].Update();

                if (!Farts[i].Lingering)
                {
                    Farts.RemoveAt(i);
                }
            }



            TableCollision();

            DebugManager.GetDebugEntry("playerPos").SetInformation(X, Y);


            if (Bounds.Right < 0)
            {
                SetPosition(WindowManager.PixelWidth * 2 - Width, Y);
            }

            if (Bounds.Left > WindowManager.PixelWidth * 2)
            {
                SetPosition(4, Y);
            }


            if (Bounds.Bottom < 0)
            {
                SetPosition(X, WindowManager.PixelHeight * 2 - Width);
            }

            if (Bounds.Top > WindowManager.PixelHeight * 2)
            {
                SetPosition(X, 4);
            }
        }