Пример #1
0
        private void Initialize()
        {
            // Spawn intial entities and register each
            foreach (
                KeyValuePair <Spawns.Kind, List <PhysicalVector2> > pair in
                map.spawns.spawnPositions
                )
            {
                Spawns.Kind kind = pair.Key;
                if (!ShouldSpawn(kind))
                {
                    continue;
                }

                List <PhysicalVector2> positions = pair.Value;

                foreach (PhysicalVector2 position in positions)
                {
                    Entity entity = Spawn(kind, position);

                    var respawnable = new Respawnable {
                        entityOpt    = entity.Some(),
                        spawnKind    = kind,
                        position     = position,
                        respawnDelay = ToTicks(GetDelay(kind))
                    };

                    if (IsRespawnable(kind))
                    {
                        Register(respawnable);
                    }
                }
            }
        }
Пример #2
0
        public void Update()
        {
            for (int i = 0; i < data.Count; i++)
            {
                Respawnable respawnable = data[i];
                switch (respawnable.entityOpt.Update(registry))
                {
                case EntityOption.State.JustRemoved:
                    respawnable.despawnStartTime = Global.tick;
                    break;

                case EntityOption.State.Removed:
                    Tick elapsed = Global.tick - respawnable.despawnStartTime;
                    if (elapsed > respawnable.respawnDelay)
                    {
                        respawnable.entityOpt = Spawn(
                            respawnable.spawnKind,
                            respawnable.position
                            ).Some();
                    }
                    break;
                }
            }
        }
Пример #3
0
 public void Register(Respawnable respawnable)
 {
     data.Add(respawnable);
 }