public Gate(Vector2 position, OpenCondition condition = OpenCondition.KEYS) : base(position, new Box(position, new Vector2(16, 16))) { InitState("Closed"); AddComponent(new TopDownPhysics(0, 0)); List <string> newTags = tags; newTags.Add("gate"); _openCondition = condition; mapIndex = util.CorrespondingMapIndex(transform.position); switch (condition) { case OpenCondition.KEYS: openedCondition = () => { return(keysLeft <= 0); }; keysLeft = 1; break; case OpenCondition.NO_ENEMIES: openedCondition = () => { var enemies = GameObjectManager.FindObjectsWithTag("enemy"); currentEnemyCount = 0; foreach (var e in enemies) { if (mapIndex == util.CorrespondingMapIndex(e.transform.position)) { currentEnemyCount += 1; } } return(currentEnemyCount <= 0); }; newTags.Add("nonpersistent"); break; default: openedCondition = () => { return(keysLeft <= 0); }; keysLeft = 1; break; } tags = newTags; }
public override void Update(GameTime gameTime) { var pi = GameObjectManager.playerInstance; if (pi == null) { return; } Vector2 nextIndex = util.CorrespondingMapIndex(pi.collisionBox.middle); if (currentIndex.X != nextIndex.X || currentIndex.Y != nextIndex.Y) { Debug.Log($"Got into map index ( {nextIndex.X}, {nextIndex.Y} )"); if (toDestroy != null) { foreach (var obj in toDestroy) { obj.done = true; } toDestroy = null; } currentIndex = nextIndex; toDestroy = GameObjectManager.FindObjectsWithTag("nonpersistent"); if (toDestroy != null) { foreach (var obj in toDestroy) { obj.isPaused = true; TaskScheduler.AddTask(() => { obj.done = true; Debug.Log($"{obj.GetType().FullName} is done"); }, 0.5, 0.5, this.id); } } TaskScheduler.AddTask(() => toDestroy = null, 0.5, 0.5, this.id); InstantiateEntities(currentIndex); } }