protected void UpdateSmokes(float tpf)
        {
            NewtonianMovementControl control = asteroid.GetControlOfType <NewtonianMovementControl>();

            if (control == null)
            {
                return;
            }

            double speed = control.RealSpeed / tpf;

            if (speed < 80 && smokeEmmitors.Count > 0)
            {
                foreach (ParticleEmmitor e in smokeEmmitors)
                {
                    e.DelayedStop();
                }

                smokeEmmitors.Clear();
                return;
            }

            int maxSmoke = GetMaxSmoke();

            if (smokeEmmitors.Count == maxSmoke)
            {
                return;
            }

            int num = (int)((speed - 80) / 20);

            if (num > maxSmoke)
            {
                num = maxSmoke;
            }

            int diff = num - smokeEmmitors.Count;

            if (diff == 0)
            {
                return;
            }

            if (diff < 0)
            {
                for (int i = 1; i <= diff; i++)
                {
                    smokeEmmitors[smokeEmmitors.Count - i].DelayedStop();
                    smokeEmmitors.RemoveAt(smokeEmmitors.Count - i);
                }
            }
            else
            {
                for (int i = 0; i < diff; i++)
                {
                    smokeEmmitors.Add(CreateAndAddSmokeEmmitor(smokeEmmitors.Count));
                }
            }
        }
Ejemplo n.º 2
0
        public void SpawnAsteroid()
        {
            if (AsteroidSpawned)
            {
                return;
            }

            AsteroidSpawned = true;
            me.RemoveControlsOfType <HighlightingControl>();

            Asteroid ast = new Asteroid(me.SceneMgr, IdMgr.GetNewId(me.SceneMgr.GetCurrentPlayer().GetId()));

            ast.Gold      = 0;
            ast.Radius    = 20;
            ast.Position  = new Vector(me.Position.X - ast.Radius, me.Position.Y - ast.Radius);
            ast.Direction = (me as IMovable).Direction;

            ast.AsteroidType = AsteroidType.NORMAL;
            ast.TextureId    = me.SceneMgr.GetRandomGenerator().Next(1, 18);

            SphereCollisionShape cs = new SphereCollisionShape();

            cs.Center          = ast.Center;
            cs.Radius          = ast.Radius;
            ast.CollisionShape = cs;

            ast.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(ast));

            me.SceneMgr.DelayedAttachToScene(ast);

            collided.Add(ast.Id);

            ast.AddControl(new StickySphereCollisionShapeControl());

            NewtonianMovementControl nmc = new NewtonianMovementControl();

            nmc.Speed = me.SceneMgr.GetCurrentPlayer().Data.MineFallingSpeed;
            ast.AddControl(nmc);

            NetOutgoingMessage msg = me.SceneMgr.CreateNetMessage();

            ast.WriteObject(msg);

            me.SceneMgr.SendMessage(msg);
        }
        private void CreateSpark()
        {
            ParticleNode node = new ParticleNode(me.SceneMgr, IdMgr.GetNewId(me.SceneMgr.GetCurrentPlayer().GetId()));

            // TODO spawn in a whole volume
            bool left = me.SceneMgr.GetRandomGenerator().Next(2) == 0 ? false : true;

            if (left)
            {
                Vector position = (meNode.Center - (meNode.Direction.Rotate(Math.PI / 4) * (asteroid.Radius)));
                position      += meNode.Direction * (asteroid.Radius * 1.5);
                node.Position  = position;
                node.Direction = meNode.Direction.Rotate(FastMath.DegToRad(-10));
            }
            else
            {
                Vector position = (meNode.Center - (meNode.Direction.Rotate(-Math.PI / 4) * (asteroid.Radius)));
                position      += meNode.Direction * (asteroid.Radius * 1.5);
                node.Position  = position;
                node.Direction = meNode.Direction.Rotate(FastMath.DegToRad(10));
            }

            float minSize = (float)FastMath.LinearInterpolate(0.2, 0.5, me.SceneMgr.GetRandomGenerator().NextDouble());
            float maxSize = minSize * 1.2f;

            ParticleEmmitor smokeEmmitor = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(80, 0, 0, 0));

            smokeEmmitor.Amount      = 20;
            smokeEmmitor.MinLife     = 0.3f;
            smokeEmmitor.MaxLife     = 0.4f;
            smokeEmmitor.MinSize     = minSize * 1.3f;
            smokeEmmitor.MaxSize     = maxSize * 1.3f;
            smokeEmmitor.SpawnRadius = 4f;
            smokeEmmitor.Infinite    = true;

            ParticleEmmitor fireEmmitor = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(150, 255, 100, 0));

            fireEmmitor.Amount   = 20;
            fireEmmitor.MinLife  = 0.1f;
            fireEmmitor.MaxLife  = 0.2f;
            fireEmmitor.MinSize  = minSize * 1.1f;
            fireEmmitor.MaxSize  = maxSize * 1.1f;
            fireEmmitor.Infinite = true;

            ParticleEmmitor fireEmmitor2 = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(200, 255, 200, 0));

            fireEmmitor2.Amount   = 20;
            fireEmmitor2.MinLife  = 0.1f;
            fireEmmitor2.MaxLife  = 0.1f;
            fireEmmitor2.MinSize  = minSize;
            fireEmmitor2.MaxSize  = maxSize;
            fireEmmitor2.Infinite = true;

            EmmitorGroup grp = new EmmitorGroup();

            grp.Add(smokeEmmitor);
            grp.Add(fireEmmitor);
            grp.Add(fireEmmitor2);

            node.AddEmmitorGroup(grp, new Vector(), false);

            NewtonianMovementControl nmc = new NewtonianMovementControl();

            nmc.Speed = (asteroid.GetControlOfType <IMovementControl>().RealSpeed / tpf) * 0.75f;
            node.AddControl(nmc);
            node.AddControl(new LimitedLifeControl((float)FastMath.LinearInterpolate(0.5, 2, me.SceneMgr.GetRandomGenerator().NextDouble())));

            me.SceneMgr.DelayedAttachToScene(node);
        }