Esempio n. 1
0
    ActionResult ProcessTurn()
    {
        var actionResult = new ActionResult();
        var actor        = _actors.ElementAt(_currentActorId);
        var action       = actor.GetAction(_entityMap, _groundMap);
        var actionToTake = action;

        if (action == null)
        {
            return(new ActionResult());
        }

        do
        {
            var mapData = new MapDTO {
                EntityMap = _entityMap, EntityFloorMap = _entityMapBackground, GroundMap = _groundMap
            };
            actionResult = actionToTake.PerformAction(mapData);

            // Cleanup to handle after player potentially changes position
            var adjustment =
                Camera.main.transform.position = new Vector3(_player.position.x + CalculateCameraAdjustment(), _player.position.y, Camera.main.transform.position.z);

            if (actionResult.Success)
            {
                TransitionFrom(_gameState);
                TransitionTo(actionResult.TransitionToStateOnSuccess);
            }

            actionToTake = actionResult.NextAction;
        }while (actionResult.NextAction != null);


        if (actionResult.Success)
        {
            _currentActorId = (_currentActorId + 1) % _actors.Count();
            if (actor.entity == _player)
            {
                fovSystem.Run(new Vector2Int(_player.position.x, _player.position.y), playerViewDistance);
                _groundMap.UpdateTiles();
            }
        }

        ProcessNewState();

        return(actionResult);
    }
Esempio n. 2
0
    void Start()
    {
        roomSizeRange     = IntRange.CreateInstance <IntRange>();
        roomSizeRange.min = 6;
        roomSizeRange.max = 10;

        Application.targetFrameRate = 120;
        QualitySettings.vSyncCount  = 0;

        var groundTileMap = GameObject.Find(TileMapType.GroundMap.Name()).GetComponent <Tilemap>();
        var levelBuilder  = new LevelBuilder();

        _groundMap = levelBuilder.MakeMap(maxRooms, roomSizeRange, mapWidth, mapHeight, groundTileMap);
        var startLocation = levelBuilder.GetStartPosition();

        var entityTileMap = GameObject.Find(TileMapType.EntityMap.Name()).GetComponent <Tilemap>();

        _entityMap = ScriptableObject.CreateInstance <EntityMap>().Init(entityTileMap, _groundMap);

        var entityBackgroundTileMap = GameObject.Find(TileMapType.EntityMap_Background.Name()).GetComponent <Tilemap>();

        _entityMapBackground = ScriptableObject.CreateInstance <EntityMap>().Init(entityBackgroundTileMap, _groundMap);

        _actors = new List <Actor>();

        // Build Player
        _player = Entity.CreateEntity().Init(startLocation.Clone(), spriteType: SpriteType.Soldier_Sword, color: Color.green, name: "player");
        _player.gameObject.AddComponent <Player>().owner = _player;
        _player.gameObject.AddComponent <Fighter>().Init(30, 2, 5).owner       = _player;
        _player.gameObject.AddComponent <Inventory>().Init(capacity: 10).owner = _player;
        _actors.Add(new Actor(_player));

        SetDesiredScreenSize();
        Camera.main.transform.position = new Vector3(_player.position.x + CalculateCameraAdjustment(), _player.position.y, Camera.main.transform.position.z);

        // Build Enemies
        var newEntities = levelBuilder.FillRoomsWithEntityActors(_entityMap.GetEntities(), maxEnemiesInRoom, maxItemsInRoom);

        foreach (var enemy in newEntities)
        {
            _actors.Add(new Actor(enemy));
            _entityMap.AddEntity(enemy);
        }

        var passiveEntities = levelBuilder.FillRoomsWithPassiveEntities(_entityMapBackground.GetEntities(), maxEnemiesInRoom, maxItemsInRoom);

        foreach (var passiveEntity in passiveEntities)
        {
            _entityMapBackground.AddEntity(passiveEntity);
        }

        _entityMap.AddEntity(_player);

        // Setup Systems
        fovSystem = new FieldOfViewSystem(_groundMap);
        fovSystem.Run(new Vector2Int(_player.position.x, _player.position.y), playerViewDistance);

        RunVisibilitySystem();

        // Final Setup
        _groundMap.UpdateTiles();

        statText.SetPlayer(_player);
        inventoryInterface.SetInventory(_player.GetComponent <Inventory>());
        _gameState = GameState.Global_LevelScene;

        _log = FindObjectOfType <MessageLog>();
    }