Пример #1
0
        public void Run()
        {
            GhostConfigComponent ghostConfig = _ghostConfig.Components1[0];
            WorldComponent       world       = _world.Components1[0];

            if (_enableEvents.EntitiesCount > 0)
            {
                foreach (int i in _ghosts)
                {
                    GameObject ghost       = _ghosts.Components2[i].Transform.gameObject;
                    int        ghostEntity = _ghosts.Entities[i];

                    bool isNew;
                    _ecsWorld
                    .EnsureComponent <GhostInFearStateComponent>(ghostEntity, out isNew)
                    .EstimateTime = ghostConfig.FearStateInSec;

                    if (isNew)
                    {
                        ghost.GetComponent <MeshRenderer>().material.color = ghostConfig.FearState;
                    }
                }
            }

            foreach (int i in _fearStateGhosts)
            {
                GhostComponent            ghostComponent = _fearStateGhosts.Components1[i];
                GhostInFearStateComponent fearState      = _fearStateGhosts.Components2[i];
                GameObject ghost       = _fearStateGhosts.Components3[i].Transform.gameObject;
                int        ghostEntity = _fearStateGhosts.Entities[i];

                fearState.EstimateTime -= Time.deltaTime;
                if (fearState.EstimateTime <= 0)
                {
                    _ecsWorld.RemoveComponent <GhostInFearStateComponent>(ghostEntity);

                    var material = ghost.GetComponent <MeshRenderer>().material;
                    switch (ghostComponent.GhostType)
                    {
                    case GhostTypes.BLINKY:
                        material.color = ghostConfig.Blinky;
                        break;

                    case GhostTypes.PINKY:
                        material.color = ghostConfig.Pinky;
                        break;

                    case GhostTypes.INKY:
                        material.color = ghostConfig.Inky;
                        break;

                    case GhostTypes.CLYDE:
                        material.color = ghostConfig.Clyde;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    return;
                }

                Vector2Int currentPosition = _ecsWorld.GetComponent <PositionComponent>(ghostEntity).Position;
                foreach (int entity in world.WorldField[currentPosition.x][currentPosition.y])
                {
                    var player = _ecsWorld.GetComponent <PlayerComponent>(entity);
                    if (player == null)
                    {
                        continue;
                    }

                    player.Scores += ghostConfig.ScoresPerGhost;
                    _ecsWorld.CreateEntityWith <UpdateScoreTableEvent>();
                    _ecsWorld.AddComponent <DestroyedWorldObjectComponent>(ghostEntity);
                }
            }
        }
Пример #2
0
        public void Run()
        {
            GhostDefinition ghostDefinition = _gameDefinitions.ghostDefinition;

            if (!_enableEvents.IsEmpty())
            {
                foreach (int i in _ghosts)
                {
                    GhostComponent ghost       = _ghosts.Get1[i];
                    EcsEntity      ghostEntity = _ghosts.Entities[i];

                    ghostEntity.Set <GhostInFearStateComponent>().EstimateTime = ghostDefinition.FearStateInSec;
                    ghost.Renderer.material.color = ghostDefinition.FearState;
                }
            }

            foreach (int i in _fearStateGhosts)
            {
                GhostComponent            ghostComponent = _fearStateGhosts.Get1[i];
                GhostInFearStateComponent fearState      = _fearStateGhosts.Get2[i];
                EcsEntity ghostEntity = _fearStateGhosts.Entities[i];

                fearState.EstimateTime -= Time.deltaTime;
                if (fearState.EstimateTime <= 0)
                {
                    ghostEntity.Unset <GhostInFearStateComponent>();
                    switch (ghostComponent.GhostType)
                    {
                    case GhostTypes.Blinky:
                        ghostComponent.Renderer.material.color = ghostDefinition.Blinky;
                        break;

                    case GhostTypes.Pinky:
                        ghostComponent.Renderer.material.color = ghostDefinition.Pinky;
                        break;

                    case GhostTypes.Inky:
                        ghostComponent.Renderer.material.color = ghostDefinition.Inky;
                        break;

                    case GhostTypes.Clyde:
                        ghostComponent.Renderer.material.color = ghostDefinition.Clyde;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    return;
                }

                Vector2Int currentPosition = ghostEntity.Set <PositionComponent>().Position;
                foreach (EcsEntity entity in _worldService.WorldField[currentPosition.x][currentPosition.y])
                {
                    var player = entity.Get <PlayerComponent>();
                    if (player == null)
                    {
                        continue;
                    }

                    player.Scores += ghostDefinition.ScoresPerGhost;
                    ghostEntity.Set <DestroyedWorldObjectComponent>();
                    _ecsWorld.NewEntityWith(out UpdateScoreTableEvent _);
                }
            }
        }