Exemple #1
0
        private void SetupMonsterDiedEvent(IEcs ecs, Entity geralt)
        {
            // Get a trigger for Geralt to comment sometimes after a kill.
            var geraltGloats = ecs.GetComponent <Talks>(geralt)
                               .GetSpeaker(Talks.GeraltGetsMoney, 0.2);

            // When Geralt kills a monster
            ecs.EntityRemoveStarted += entity =>
            {
                var type = ecs.GetComponent <IsActor>(entity).Type;

                if (type == ActorType.Monster)
                {
                    Logger.AddLog($" * {ecs.GetComponent<HasName>(entity).Name} has been killed!");
                    ecs.GetComponent <HasMoney>(geralt).AddMoney(5);
                    geraltGloats();
                }

                // For debugging also print a message if Geralt dies
                if (type == ActorType.Witcher)
                {
                    Logger.AddLog($" * * {ecs.GetComponent<HasName>(entity).Name} has been killed! (wait, what?)");
                }
            };
        }
Exemple #2
0
        private Entity CreateGeralt(IEcs ecs)
        {
            // Make a pathfinder for Geralt's AI that knows where the trees are.
            var trees =
                ecs.EntitiesWithComponent <IsActor>()
                .Where(e => ecs.GetComponent <IsActor>(e).Type == ActorType.Tree)
                .Select(e => ecs.GetComponent <HasLocation>(e))
                .Select(l => new Coord(l.X, l.Y));

            var pathFinder = new PathFinder(new Coord(this.boundsX, this.boundsY), trees);

            return
                (ecs.NewEntity()
                 .WithComponent(new HasName("Geralt"))
                 .WithComponent(this.FindSafeLocation(ecs.GetSystem <HasLocation>() as LocationSystem, new Random()))
                 .WithComponent(new Renders('G', ConsoleColor.DarkMagenta))
                 .WithComponent(new IsActor(ActorType.Witcher))
                 .WithComponent(new HasAi(new WitcherAi(pathFinder)))
                 .WithComponent(new Talks(Logger.AddLog).RandomlySay(Talks.GeraltSpeaks, 0.02))
                 .WithComponent <HasMoney>()
                 .Entity);
        }
Exemple #3
0
        private void EnterGameLoop(IEcs ecs, Entity geralt)
        {
            var renderer = new Renderer.Renderer(ecs, this.boundsX, this.boundsY, new RendererCharacters(), Logger, () => ecs.GetComponent <HasMoney>(geralt).Money);

            // Simulation loop - 5 updates a second
            var timer = new Timer(200);

            timer.Elapsed += async(sender, e) =>
            {
                timer.Stop();
                await ecs.UpdateAsync();

                if (ecs.GetSystem <IsActor>().AllComponents().Count(c => c.Type == ActorType.Monster) < 3)
                {
                    this.CreateEntity(ecs, 5, ActorType.Monster);
                }

                renderer.Render();
                timer.Start();
            };
            timer.Start();

            // Press a key to quit
            Console.ReadKey();
        }