예제 #1
0
        /// <summary>
        /// TO BE COMPLETED
        /// </summary>
        /// <param name="deltaT"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public override bool Update(Single deltaT, Game game)
        {
            if (IsSpawning)
            {
                if (timeSinceSpawnStart < spawningDelay)
                {
                    timeSinceSpawnStart++;
                    float spawningPercentage = (float)timeSinceSpawnStart / spawningDelay;
                    int   size = (int)(enemyMaxSize * spawningPercentage);
                    RandomColor(colorInt, spawningPercentage);
                    enemyCurrentSize = size;
                    setEnemyPoints();
                    Speed = speed * spawningPercentage / 2;
                }
                else
                {
                    IsSpawning = false;
                    RandomColor(colorInt, 1);
                    enemyCurrentSize = enemyMaxSize;
                    setEnemyPoints();
                    Speed = speed;
                }
            }
            Bounce();
            if (Speed < 10 + speed)
            {
                DetermineAngle();
            }
            else
            {
                if (rotatesClockwise)
                {
                    Angle += rnd.Next(28, 35);
                }
                else
                {
                    Angle -= rnd.Next(28, 35);
                }
            }

            Speed += 0.02f;
            Advance(Speed);
            if (Game.Stopwatch.ElapsedMilliseconds > smokeParticleLastCreated.TotalMilliseconds + 50)
            {
                smokeParticleLastCreated = Game.Stopwatch.Elapsed;
                SmokeParticle smokeParticle = new SmokeParticle(Type, Position.X, Position.Y, 4, Speed / 2, false, 35, enemyMaxSize / 2, 0.2f, colorInt, 1);
                smokeParticle.Angle = rnd.Next(-7, 8);
                game.smokeParticles.Add(smokeParticle);
            }
            if (Speed > 11 + speed)
            {
                Projectile projectile = new Projectile(Type, Position.X, Position.Y, 8, 21, 8, colorInt)
                {
                    Angle = (float)(Math.Atan2(game.hero.Position.Y - Position.Y, game.hero.Position.X - Position.X) * 180 / Math.PI)
                };
                game.projectiles.Add(projectile);
                IsAlive = false;
            }
            return(base.Update(deltaT, game));
        }
예제 #2
0
        public static void Start()
        {
            Clear();

            IsActive     = true;
            startTime    = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            ambientSound = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind,
                                            MyCamera.Position + MyCamera.ForwardVector * MaxSoundDistance, Vector3.Forward,
                                            Vector3.Up, Vector3.Zero, 0);


            sphereCenter = MyCamera.Position + MyCamera.ForwardVector * 400;


            for (int i = 0; i < SmokeCount; i++)
            {
                Vector3 pos = sphereCenter +
                              MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, SmokeSphereRadius);
                var smokePart = new SmokeParticle
                {
                    Angle           = MyMwcUtils.GetRandomRadian(),
                    Color           = Vector4.Zero,
                    AngularVelocity = MyMwcUtils.GetRandomFloat(-0.15f, 0.15f),
                    Pos             = pos,
                    Velocity        =
                        MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 30f)
                };
                smokeParticles.Add(smokePart);
            }
        }
예제 #3
0
        public override void Update()
        {
            if (active)
            {
                // Emit new particles if needed.
                float dt = Time.GameTimeFrameSeconds;
                dt = MathHelper.Clamp(dt, 0.0f, 1.0f);  // Limit to reasonable values.

                if (emitting)
                {
                    partial += dt * emissionRate;

                    // Emit as many particles as needed this
                    // frame to keep up with the emission rate.
                    while (partial >= 1.0f)
                    {
                        // Pick a random position somewhere along the path covered this frame.
                        Vector3       pos      = position + (float)rnd.NextDouble() * dt * velocity;
                        float         lifetime = minLifetime + (float)rnd.NextDouble() * (maxLifetime - minLifetime);
                        SmokeParticle particle = new SmokeParticle(pos, lifetime, color);
                        particleList.Add(particle);

                        partial -= 1.0f;
                    }
                }

                // Update any existing particles.  For more heavyweight particles we could
                // have an Update call per particle.  These are lightweight enough that we
                // can just update them directly.
                for (int i = 0; i < particleList.Count;)
                {
                    SmokeParticle particle = (SmokeParticle)particleList[i];

                    particle.age += dt;

                    Debug.Assert(particle.age >= 0.0f);

                    float t = particle.age / particle.lifetime;
                    if (t > 1.0f)
                    {
                        // Dead particle.
                        particleList.RemoveAt(i);
                    }
                    else
                    {
                        particle.radius = MyMath.Lerp(startRadius, endRadius, t) * scale;
                        particle.alpha  = MyMath.Lerp(startAlpha, endAlpha, t) * scale;
                        particle.alpha *= particle.alpha;

                        i++;
                    }
                }
            } // end of if active
        }     // end of SmokeEmitter3D Update()
예제 #4
0
파일: Wolf.cs 프로젝트: Jorch72/CS-MiNET
        public override void DoInteraction(int actionId, Player player)
        {
            if (IsTamed)
            {
                if (Owner == player)
                {
                    IsSitting = !IsSitting;
                    BroadcastSetEntityData();
                }
                else
                {
                    // Hmm?
                }
            }
            else
            {
                if (player.Inventory.GetItemInHand() is ItemBone)
                {
                    Log.Debug($"Wolf taming attempt by {player.Username}");

                    player.Inventory.RemoveItems(new ItemBone().Id, 1);

                    var random = new Random();
                    if (random.Next(3) == 0)
                    {
                        Owner        = player;
                        IsTamed      = true;
                        IsSitting    = true;
                        IsAngry      = false;
                        AttackDamage = 4;
                        BroadcastSetEntityData();

                        for (int i = 0; i < 7; ++i)
                        {
                            Particle particle = new HeartParticle(Level, random.Next(3));
                            particle.Position = KnownPosition + new Vector3(0, (float)(Height + 0.85d), 0);
                            particle.Spawn();
                        }


                        Log.Debug($"Wolf is now tamed by {player.Username}");
                    }
                    else
                    {
                        for (int i = 0; i < 7; ++i)
                        {
                            Particle particle = new SmokeParticle(Level);
                            particle.Position = KnownPosition + new Vector3(0, (float)(Height + 0.85d), 0);
                            particle.Spawn();
                        }
                    }
                }
            }
        }
예제 #5
0
        }     // end of SmokeEmitter3D Update()

        public override void Render(Camera camera)
        {
            if (active)
            {
                Sphere sphere = Sphere.GetInstance();

                // Get the effect we need.
                Effect effect = manager.Effect3d;

                // Set up common rendering values.
                effect.CurrentTechnique = manager.Technique(ParticleSystemManager.EffectTech3d.PremultAlphaGlowColorPass);

                manager.Parameter(ParticleSystemManager.EffectParams3d.DiffuseColor).SetValue(color.ToVector4());

                // Set up world matrix.
                Matrix worldMatrix = Matrix.Identity;

                manager.Parameter(ParticleSystemManager.EffectParams3d.GlowFactor).SetValue(0.5f);

                for (int i = 0; i < particleList.Count; i++)
                {
                    SmokeParticle particle = (SmokeParticle)particleList[i];

                    // Set translation and radius.
                    worldMatrix.Translation = particle.position;
                    Matrix worldViewProjMatrix = worldMatrix * camera.ViewProjectionMatrix;

                    manager.Parameter(ParticleSystemManager.EffectParams3d.Radius).SetValue(particle.radius);

                    // Set alpha.
                    manager.Parameter(ParticleSystemManager.EffectParams3d.Alpha).SetValue(particle.alpha);

                    // Set color
                    manager.Parameter(ParticleSystemManager.EffectParams3d.DiffuseColor).SetValue(particle.color.ToVector4());

                    sphere.Render(camera, ref worldMatrix, effect);
                }
            } // end of if active
        }     // end of Emitter Render()
예제 #6
0
 public void CreateMovingParticles()
 {
     if (!IsJumping)
     {
         if (Math.Abs(Velocity.X) < .1f)
             return;
         if (_movementParticlesTimer.TimeElapsedInMilliSeconds > 500 / Math.Abs(Velocity.X))
         {
             _movementParticlesTimer.Reset();
             var par = new SmokeParticle(CollRectangle.Center.X, CollRectangle.Bottom,
                 new Vector2(0, (float)(GameWorld.RandGen.Next(-5, 5) / 10f)));
             GameWorld.ParticleSystem.Add(par);
         }
     }
 }
예제 #7
0
        public void OnJumpAction(Player.Player player)
        {
            if (!player.IsJumping)
            {
                player.Sounds.Get("jump").Play();
                player.IsJumping = true;
                player.SetVelY(JumpAcc);
                player.ChangePosBy(0, -1);
                player.AddAnimationToQueue("jump");
                player.CollidedWithTileBelow += OnTouchGround;

                for (int i = 0; i < 10; i++)
                {
                    SmokeParticle par = new SmokeParticle(CalcHelper.GetRandomX(player.GetCollRectangle()),player.GetCollRectangle().Bottom,new Vector2(GameWorld.RandGen.Next((int)player.GetVelocity().X - 1,(int)player.GetVelocity().X + 1)/10f,-GameWorld.RandGen.Next(1,10)/10f));
                    GameWorld.ParticleSystem.Add(par);
                }

            }

            if (_airTimer.TimeElapsedInMilliSeconds < 1000)
            {
                player.GravityStrength = Main.Gravity * .75f;
            }
            else
            {
                player.GravityStrength = Main.Gravity;
            }
        }
예제 #8
0
        /// <summary>
        /// Adds a new particle to the shared emitter.
        /// </summary>
        /// <returns>true on success, false on failure (max particle count exceeded)</returns>
        public bool AddParticle(ref SmokeParticle p)
        {
            bool result = false;

            if (numActiveParticles < maxParticles)
            {
                int index = (firstParticle + numActiveParticles) % maxParticles;

                particleDeathTimeList[index] = p.lifetime + (float)Time.GameTimeTotalSeconds;

                if (firstNewParticleIndex == -1)
                {
                    firstNewParticleIndex = index;
                }
                lastNewParticleIndex = index;

                float initialRotation = MathHelper.TwoPi * (float)BokuGame.bokuGame.rnd.NextDouble();

                float birth = (float)Time.GameTimeTotalSeconds;
                index *= 4;
                for (int i = 0; i < 4; i++)
                {
                    localVertices[index + i].position     = p.position;
                    localVertices[index + i].velocity     = p.velocity;
                    localVertices[index + i].acceleration = p.acceleration;
                    localVertices[index + i].radius.X     = p.startRadius;
                    localVertices[index + i].radius.Y     = p.endRadius;
                    localVertices[index + i].times.X      = birth;
                    localVertices[index + i].times.Y      = p.lifetime + birth;
                    if (p.flash.Y > 0)
                    {
                        float scale = 1.0f / p.flash.Y;
                        localVertices[index + i].flash.X = scale;
                        localVertices[index + i].flash.Y = -p.flash.X * scale;
                    }
                    else
                    {
                        localVertices[index + i].flash.X = 0;
                        localVertices[index + i].flash.Y = 1.0f;
                    }
                    if (p.flash.Z > 0)
                    {
                        float scale = 1.0f / p.flash.Z;
                        localVertices[index + i].flash.Z = scale;
                    }
                    else
                    {
                        localVertices[index + i].flash.Z = 0;
                    }
                    localVertices[index + i].rotation.X = initialRotation;
                    localVertices[index + i].rotation.Y = p.rotationRate;
                    localVertices[index + i].color      = p.color;
                }

                ++numActiveParticles;
                newParticles = true;

                result = true;
            }

            return(result);
        }   // end of SharedSmokeEmitter AddParticle()