Exemplo n.º 1
0
    public void OnPlayerMove()
    {
        Vector2 playerPos = FindObjectOfType <Player>().transform.position;
        Vector2 roomPos   = new Vector2(((int)playerPos.x + 6) / 12, ((int)playerPos.y + 6) / 12);

        UI.instance.map.texture = MapTextureGenerator.Generate(map, roomPos);
    }
Exemplo n.º 2
0
    public void Generate()
    {
        map = new bool[mapWidth, mapHeight];
        CheckRoom(3, 3, 0, Vector2.zero, true);
        InstantiateRooms();
        FindObjectOfType <Player>().transform.position = firstRoomPos * 12;

        UI.instance.map.texture = MapTextureGenerator.Generate(map, firstRoomPos);
    }
Exemplo n.º 3
0
    public void BuildMap()
    {
        spawnWaves = SpawnWavesFromMapTexture(mapTexture);

        for (int i = 0; i < spawnWaves.Length; i++)
        {
            RandomizeArray(spawnWaves[i].spawnings, random);
        }

        mapObject       = new GameObject("Map", typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider));
        mapObject.layer = LayerMask.NameToLayer("Ground");

        grid = new Grid(map);

        mapMesh = map.BuildMesh();
        mapObject.GetComponent <MeshFilter>().mesh = mapMesh;

        var material = new Material(LevelBootstrap.mapMaterial);

        mapObject.GetComponent <MeshRenderer>().material = material;

        mapTexture           = MapTextureGenerator.Generate(map, 2048);
        material.mainTexture = mapTexture;

        var collider = mapObject.GetComponent <MeshCollider>();

        collider.inflateMesh = true;
        collider.sharedMesh  = mapMesh;

        SpawnBreakables(TileType.WeakWall, LevelBootstrap.brickBlockPrefab);
        SpawnBreakables(TileType.StrongWall, LevelBootstrap.concreteBlockPrefab);

        SpawnProps(TileType.Water, LevelBootstrap.waterPrefab);
        SpawnRandomProps(TileType.Woods, LevelBootstrap.RandomTree);

        enemySpawnPoints = map.EnemySpawnPoints();
        RandomizeArray(enemySpawnPoints, random);

        var basePosition = map.BasePosition();

        enemyController.playerBasePosition = basePosition;
        playerBaseBreakable =
            Object.Instantiate(LevelBootstrap.playerBasePrefab, basePosition, Quaternion.identity, mapObject.transform);
        playerBaseBreakable.OnBreak += defeatCallback;

        // Tank base colour
        float       hue        = (float)random.NextDouble() % 1f;
        const float saturation = 0.7f;
        const float value      = 0.7f;

        enemyController.tankBaseColor = new ColorHSV(hue, saturation, value);

        BuildCollidersOnEdges();


        // Set Background color and create same coloured plane on ground to hide tanks spawning underneath map
        var backgroundColor = LevelBootstrap.RandomSkyColor(random);

        Camera.main.backgroundColor = backgroundColor;
        RenderSettings.ambientLight = backgroundColor;

        var hideBelowGroundObject = GameObject.CreatePrimitive(PrimitiveType.Plane);

        hideBelowGroundObject.name = "Hide Below Ground";
        hideBelowGroundObject.transform.position   = new Vector3(map.size / 2f, -0.0001f, map.size / 2f);
        hideBelowGroundObject.transform.localScale = Vector3.one * 2 * map.size;
        hideBelowGroundObject.transform.parent     = mapObject.transform;

        var hideBelowMaterial = new Material(Shader.Find("Unlit/Color"));

        hideBelowMaterial.color = backgroundColor;
        hideBelowGroundObject.GetComponent <Renderer>().material = hideBelowMaterial;
    }     // build map