Exemple #1
0
        public static IEnumerator _Ghosts(Vector3 ppos)
        {
            /* Using bear ghost creates Warning, when ZMoe ghost does not ...
             * but moe stops moving ?
             */
            //EntityPool EntityPool = new EntityPool("zombieMoeGhost", 20);
            // EntityPool EntityPool = new EntityPool("animalBearGhost", 20);
            // EntityPool EntityPool = new EntityPool("animalChickenGhost", 20);
            EntityPool EntityPool = new EntityPool("animalChickenGhostV2", 20);

            HashSet <Entity> done = new HashSet <Entity>();

            lastExec = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            while (true)
            {
                lastExec = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                Bounds area = new Bounds(ppos, new Vector3(40, 40, 40));
                EntityPool.Update(area);
                foreach (Entity entity in EntityPool.Entities)
                {
                    lastExec = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    if (entity == null)
                    {
                        continue;
                    }
                    if (entity as EntityAlive == null)
                    {
                        continue;
                    }
                    if (_StopGhost)
                    {
                        Attaching.Remove(entity as EntityAlive, currentName);
                        // if (done.Contains(entity)) done.Remove(entity);
                        done.Clear();
                    }
                    else
                    {
                        if (done.Contains(entity))
                        {
                            continue;
                        }
                        Attaching.Apply(entity as EntityAlive, currentName);
                        done.Add(entity);
                    }
                    lastExec = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    yield return(new WaitForEndOfFrame());
                }
                lastExec = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                yield return(new WaitForEndOfFrame());
            }
        }
Exemple #2
0
        public override IEnumerator Regen(EntityPlayer player, Vector3i zchunk, int iniguess)
        {
            Vector3 ppos = player.GetPosition();

            Vector3 where = new Vector3(this.centerx, ppos.y, this.centerz);
            if ((ppos - where).magnitude > 50f)
            {
                Printer.Log(45, "Giant too far ", this.centerx, this.centerz, "from player ", ppos);
                yield break;
            }
            Bounds area = new Bounds(where, new Vector3(20, 20, 20));

            Printer.Log(40, "EntityPool.Update");
            EntityPool.Update(area);
            if (EntityPool.Entities[0] != null)
            {
                EntityAlive giant = (EntityAlive)EntityPool.Entities[0];
                // could be null if not alive ?!
                if (giant == null)
                {
                    Printer.Print("giant is not alive !");
                }
                else
                {
                    Printer.Log(40, "giant buff", giant);
                    if (giant.IsDead())
                    {
                        yield break;
                    }
                    if (!giant.Buffs.HasBuff(opt.OptionEntity.buff))
                    {
                        giant.Buffs.AddBuff(opt.OptionEntity.buff);
                    }
                }
                yield return(new WaitForSeconds(2f));
            }
        }
Exemple #3
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            camera.Update(gameTime);

            heroPool.Update(gameTime, map);
            rotBoxPool.Update(gameTime);

            // This stuff is all example - camera follows random Hero and zooms in when following
            //if (Helper.Random.Next(200) == 0)
            //{
            //    List<Entity> activeHeroes = heroPool.Entities.Where(hero => hero.Active).ToList();
            //    if (activeHeroes.Count > 0) followingHero = (Hero) activeHeroes[Helper.Random.Next(activeHeroes.Count)];
            //}
            //if (Helper.Random.Next(200) == 1 && followingHero != null) followingHero = null;

            //if (followingHero != null && followingHero.Active)
            //{
            //    camera.Target = followingHero.Position;
            //    if (camera.Zoom < 2.5f) camera.Zoom += 0.05f;
            //}
            //else
            //{
            //    camera.Target = new Vector2(ScreenManager.Game.RenderWidth, ScreenManager.Game.RenderHeight)/2f;
            //    if (camera.Zoom > 1f) camera.Zoom -= 0.05f;
            //}
            //////////////////



            particleController.Update(gameTime, map);

            if (Helper.Random.Next(100) == 0)
            {
                heroPool.Spawn(entity =>
                {
                    entity.Position        = new Vector2(Helper.Random.Next(ScreenManager.Game.RenderWidth - 64) + 32, 32);
                    ((Hero)entity).FaceDir = Helper.Random.Next(2) == 0 ? -1 : 1;
                });
            }

            particleController.Add(new Vector2(17, 40),
                                   new Vector2(Helper.RandomFloat(2f), -1.5f),
                                   100, 3000, 1000,
                                   true, true,
                                   new Rectangle(0, 0, 2, 2),
                                   new Color(new Vector3(1f, 0f, 0f) * (0.25f + Helper.RandomFloat(0.5f))),
                                   ParticleFunctions.FadeInOut,
                                   1f, 0f,
                                   1, ParticleBlend.Alpha);

            particleController.Add(new Vector2(150, 176),
                                   new Vector2(-0.05f + Helper.RandomFloat(0.1f), -0.1f),
                                   1000, Helper.Random.NextDouble() * 3000, Helper.Random.NextDouble() * 3000,
                                   false, false,
                                   new Rectangle(0, 0, 16, 16),
                                   new Color(new Vector3(1f) * (0.25f + Helper.RandomFloat(0.5f))),
                                   ParticleFunctions.Smoke,
                                   0.1f, 0f,
                                   1, ParticleBlend.Additive);

            particleController.Add(new Vector2(250, 50),
                                   new Vector2(-1f + Helper.RandomFloat(2f), -1f + Helper.RandomFloat(2f)),
                                   100, 500, 1000,
                                   false, false,
                                   new Rectangle(0, 0, 16, 16),
                                   Color.White,
                                   ParticleFunctions.FadeLight,
                                   Helper.RandomFloat(0.5f), 0f,
                                   1, ParticleBlend.Multiplicative);


            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
Exemple #4
0
 /// <summary>
 /// Called every tick.
 /// </summary>
 internal void Update()
 {
     EntityPool.Update();
 }
Exemple #5
0
        // private int cursor = -1;
        public override void Effect1(EntityPlayer player, Emplacement place, OptionEffect opt)
        {
            Vector3 ppos = player.GetPosition();

            Vector3 where = place.position;
            Bounds area = new Bounds(ppos, new Vector3(40, 40, 40));

            EntityPool.Update(area);

            Vector3 sharedDir = place.direction;

            sharedDir.y = 0.2f;                           // Math.Abs(sharedDir.y); // TODO: constraint in Directions
            EntityMover mover = new EntityMover(3, 0.3f); // .Config(1);
            int         mode  = 0;                        // 0nothing, 1random, 2parralel, 3 player
            float       u     = rand.RandomFloat;

            if (u < 0.4f)
            {
                mode = 3;
            }
            else if (u < 0.6f)
            {
                mode = 2;
            }
            else if (u < 0.8f)
            {
                mode = 1;
            }

            foreach (Entity entity in EntityPool.Entities)
            {
                if (entity == null)
                {
                    continue;
                }
                // if (entity.IsDead()) continue;
                EntityAlive alive = (EntityAlive)entity;
                if (!alive.Buffs.HasBuff(opt.OptionEntity.buff))
                {
                    Printer.Log(40, "MovingGhost buffing", opt.OptionEntity.buff, alive);
                    alive.Buffs.AddBuff(opt.OptionEntity.buff);
                }
                Vector3 toward = Vectors.Float.Zero;
                if (false)
                {
                    if (mode == 3)
                    {
                        toward = (ppos - alive.GetPosition()).normalized;
                        // toward.y = rand.RandomRange(0.05f, 0.2f);
                        toward.y = 0.2f;
                    }
                    else if (u < 0.6)
                    {
                        toward = sharedDir;
                    }
                    else if (u < 0.8)
                    {
                        toward.x = rand.RandomRange(-1f, 1f);
                        toward.z = rand.RandomRange(-1f, 1f);
                        // toward.y = rand.RandomRange(0.05f, 0.2f);
                        toward   = toward.normalized;
                        toward.y = 0.2f;
                    }
                }
                toward = (ppos - alive.GetPosition()).normalized;
                // toward.y = rand.RandomRange(0.05f, 0.2f);
                toward.y = 0.2f;
                if (toward.magnitude > 0)
                {
                    // Can we have a single routine that manages all motions ?
                    Printer.Log(40, "MovingGhost motion", entity, toward);
                    Zombiome.Routines.Start(mover.Move(alive, toward), "MovingGhost");
                }
            }
        }