Exemple #1
0
    private void OnSceneGUI()
    {
        FieldOfViewSystem fow = (FieldOfViewSystem)target;

        Handles.color = Color.white;
        Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius);

        Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false);
        Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false);

        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius);
        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius);


        Handles.color = Color.red;
        foreach (Transform visibleTarget in fow.visibleTargets)
        {
            Handles.DrawLine(fow.transform.position, visibleTarget.position);
        }
    }
Exemple #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>();
    }