예제 #1
0
    private void OnMapStart(OnMapCreated data)
    {
        if (deathPanel == null)
        {
            deathPanel = GameObject.FindGameObjectWithTag("DeathPanel");
        }

        deathPanel.SetActive(false);
        winPanel.SetActive(false);
    }
예제 #2
0
    void LoadEntities(OnMapCreated data)
    {
        FXManager.instance.SpawnBackground(Vector2.zero, MapManager.instance.Map.mapWidth, MapManager.instance.Map.mapHeight);
        EntityManager.instance.SpawnPlayer(data.entranceWorldPosition);

        // No enemies on level 0

        if (curLevelPrototype.levelEnemies.Length <= 0)
        {
            // STORY MODE
            MessageLog_Manager.NewMessage("Might be best to go home now before it enters your lungs.", Color.white);
            MessageLog_Manager.NewMessage("But the stench of the Baron lingers in the air still... ", Color.magenta);
            MessageLog_Manager.NewMessage("You vowed to destroy him. Your quest is complete.", Color.white);
            MessageLog_Manager.NewMessage("a necro aristocrat that has dominated your homeland for over 200 years.", Color.white);
            MessageLog_Manager.NewMessage("Before you lies the slaughtered corpse of Baron Rasec", Color.cyan);



            return;
        }
        for (int i = 0; i < curLevelPrototype.levelEnemies.Length; i++)
        {
            // get a position for enemy needed
            Vector2[] enemyPositions = null;
            enemyPositions = mapManager.GetCleanPositions(curLevelPrototype.levelEnemies[i].count);
            Debug.Log(enemyPositions.Length + " returned positions");
            EntityManager.instance.SpawnEnemies(curLevelPrototype.levelEnemies[i].enemyPrototypeName, enemyPositions);
        }

        int itemCount = UnityEngine.Random.Range(0, 4);

        if (itemCount == 0)
        {
            return;
        }
        Vector2[] itemPositions = mapManager.GetCleanPositions(itemCount);
        int       maxItemIndex  = 2;

        if (difficultyLevel >= 2)
        {
            maxItemIndex = 4;
        }
        if (difficultyLevel >= 5)
        {
            maxItemIndex = itemNames.Length - 1;
        }
        for (int i = 0; i < itemPositions.Length; i++)
        {
            EntityManager.instance.SpawnItem(itemNames[UnityEngine.Random.Range(0, maxItemIndex + 1)], itemPositions[i]);
        }
    }
예제 #3
0
 void Start()
 {
     _graph = CreateTestMap();
     DrawMap(_graph);
     OnMapCreated?.Invoke();
 }
예제 #4
0
    public void NewMap(Vector2 mapWorldOrigin, int level, int darknessLevel = 0, int mapWidth = 9, int mapHeight = 9)
    {
        cameraShaker       = CameraShaker.instance;
        this.darknessLevel = darknessLevel;
        this.mapWidth      = mapWidth;
        this.mapHeight     = mapHeight;
        pool = ObjectPool.instance;
        if (tileHolder == null)
        {
            tileHolder      = new GameObject();
            tileHolder.name = "_TILES_";
        }
        tileHolder.transform.position = mapWorldOrigin;

        // Generate the map
        if (Map != null)
        {
            Map.ResetMap();
        }
        else
        {
            Map = new GameMap(mapWidth, mapHeight, mapWorldOrigin, OnTileChange);
        }


        // Make darness map
        darknessMap = new Darkness[mapWidth * mapHeight];
        // Spawn GObjs
        TileGOs = new TileGOData[Map.Tiles.Length];

        Vector2Int exitTilePos     = Vector2Int.zero;
        Vector2Int entranceTilePos = Vector2Int.zero;

        for (int i = 0; i < Map.Tiles.Length; i++)
        {
            if (Map.Tiles[i].tileType == TileType.Empty)
            {
                continue;
            }

            // Spawn tile GO
            GameObject tileGO = pool.GetObjectForType("Tile", true, Map.Tiles[i].WorldPosition);
            if (tileGO == null)
            {
                // Make a new one?
                return;
            }
            tileGO.transform.SetParent(tileHolder.transform);
            TileGOData tileGOData = new TileGOData();
            tileGOData.mainGO   = tileGO;
            tileGOData.renderer = tileGO.GetComponentInChildren <SpriteRenderer>();

            // Set Sprite
            RenderSystem.instance.Render(Map.Tiles[i].tileType.ToString(), tileGOData.renderer);

            darknessMap[i] = new Darkness(Map.Tiles[i].GridPosition.x, Map.Tiles[i].GridPosition.y, 0);


            // Set exit
            if (exitTilePos == Vector2Int.zero)
            {
                if (UnityEngine.Random.Range(1, 50) == 1)
                {
                    exitTilePos = Map.Tiles[i].GridPosition;
                }
                // Set entrance for levels after level 0
                else if (level > 0 && entranceTilePos == Vector2Int.zero)
                {
                    if (UnityEngine.Random.Range(1, 12) == 1)
                    {
                        entranceTilePos = Map.Tiles[i].GridPosition;
                    }
                }
            }

            TileGOs[i] = tileGOData;
        }
        // Clean up array
        TileGOs = TileGOs.Where(go => go.mainGO != null).ToArray();

        // if we still have no exit tile, place it in the center of the room
        if (exitTilePos == Vector2Int.zero)
        {
            exitTilePos = new Vector2Int(mapWidth / 2, mapHeight / 2);
        }
        Map.SetTileType(exitTilePos.x, exitTilePos.y, TileType.Exit);
        if (level > 0)
        {
            Map.SetTileType(entranceTilePos.x, entranceTilePos.y, TileType.Entrance);
        }

        // chance to start with darnkess
        if (darknessLevel > 0)
        {
            SetDarkness();
        }


        Global.OnMapCreated onMapCreated = new OnMapCreated();
        onMapCreated.entranceWorldPosition = entranceTilePos;
        onMapCreated.exitWorldPosition     = exitTilePos;
        onMapCreated.FireEvent();
    }
 public void OnMapLoaded()
 {
     Map.SetOnMapLoadedCallback(null);
     CreateBinding();
     OnMapCreated.Raise(this);
 }
예제 #6
0
 private void OnMapStart(OnMapCreated data)
 {
     canFindTile = true;
 }