Example #1
0
    public void InitializeSpriteMesh()
    {
        playerMaterial.mainTexture = Texturing.playerSpriteSheet;
        meshObject.GetComponent <MeshRenderer>().material = playerMaterial;

        meshObject.GetComponent <MeshFilter>().mesh = MeshControl.InitializePlayerTestMesh();

        MeshControl.LoadDefaultCharacterTexture();
        MeshControl.UpdatePlayerColors();
    }
Example #2
0
    // COMMENTED OUT TO NOT USE THE OLD SYSTEM: PlayerControl in update, Gamecontroller //MapData.CreateBaseLighting();
    public static void CalculateTilesLight(Vec2 position)
    {
        // Clear the temporary list
        tempDynamicLights.Clear();

        // Set the min&maxes
        xMin = position.x - (World.horizontalScreenTiles / 2) - offScreenTiles;
        xMax = position.x + (World.horizontalScreenTiles / 2) + offScreenTiles;
        yMin = position.y - (World.verticalScreenTiles / 2) - offScreenTiles;
        yMax = position.y + (World.verticalScreenTiles / 2) + offScreenTiles;

        if (xMin < 20)
        {
            xMin = 20;
        }
        if (xMax > MapData.totalHorizontalTiles - 20)
        {
            xMax = MapData.totalHorizontalTiles - 20;
        }
        if (yMin < 20)
        {
            yMin = 20;
        }
        if (yMax > MapData.totalVerticalTiles - 20)
        {
            yMax = MapData.totalVerticalTiles - 20;
        }

        // Search in the dynamic lights list and add it to a temporary list

        foreach (LightSource ls in dynamicLights)
        {
            if (ls.position.x >= xMin && ls.position.x <= xMax && ls.position.y >= yMin && ls.position.y <= yMax)
            {
                tempDynamicLights.Add(ls);
            }
        }

        // BIG THING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        // First we reset the brightness to 0. Need to find a way to do it in the same pass.
        for (int x = xMin; x < xMax; x++)
        {
            for (int y = yMin; y < yMax; y++)
            {
                ChangeTileBrightness(x, y, 0, true);
            }
        }

        /*
         * First we calculate ambient light. Run the whole screen + some tiles outside.
         * That's in case there is a light source just outside the screen, which would affect the tiles inside the screen
         * Running horizontally, column by column from bottom up.
         */
        for (int x = xMin; x < xMax; x++)
        {
            for (int y = yMin; y < yMax; y++)
            {
                // First we check if that tile has a dynamic light (player torch, normal torch, etc)
                if (IsTileDynamicLightSource(x, y, out LightSource source))
                {
                    ChangeTileBrightness(x, y, MapData.SunBrightness, false);
                    ApplyDynamicLightMatrix(source);
                    continue; // no need to apply ambient light from that tile
                }

                // if it's an empty tile, with no background (sky tile) or a tree, we count it as an ambient light source
                if (IsTileAmbientLightSource(x, y))
                {
                    // Not sure if I should keep this or not, but it's here in case it's a tree. Not sure if it helps or not.
                    ChangeTileBrightness(x, y, MapData.SunBrightness, false);

                    // if the tile is surrounded by empty tiles, no point in doing it, and we skip it.
                    if (!IsAreaEmpty(x, y))
                    {
                        ApplySunLightMatrix(x, y);
                    }
                }
            }
        }


        // TESTING, TEMPORARY. Slows down a lot
        int gridNumber = World.TileCoordsToGridNumber(position);


        UnityThread.executeInUpdate(() =>
        {
            MeshControl.UpdateGridLight(gridNumber);
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, -1));
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, -1) - 1);
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, -1) + 1);
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, +1));
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, +1) + 1);
            MeshControl.UpdateGridLight(World.GetHorizontalGridNumber(gridNumber, +1) - 1);
            MeshControl.UpdateGridLight(gridNumber + 1);
            MeshControl.UpdateGridLight(gridNumber - 1);
        });
    }
Example #3
0
    public void UpdatePlayerArmor(int slotNr)
    {
        PlayerArmor = 0;

        if (Inventory.armor_slot[0, 0] >= 0)
        {
            PlayerArmor += ItemsDatabase.itemsDB[Inventory.armor_slot[0, 0]].itemArmor;
        }

        if (Inventory.armor_slot[1, 0] >= 0)
        {
            PlayerArmor += ItemsDatabase.itemsDB[Inventory.armor_slot[1, 0]].itemArmor;
        }

        if (Inventory.armor_slot[2, 0] >= 0)
        {
            PlayerArmor += ItemsDatabase.itemsDB[Inventory.armor_slot[2, 0]].itemArmor;
        }

        if (Inventory.armor_slot[slotNr, 0] != -1)
        {
            if (ItemsDatabase.itemsDB[Inventory.armor_slot[slotNr, 0]].itemAttachedArmorSprite != "")
            {
                switch (slotNr)
                {
                case 0:     // helm
                    Inventory.playerHeadTexture = ItemsDatabase.itemsDB[Inventory.armor_slot[slotNr, 0]].itemAttachedArmorSprite;

                    break;

                case 1:     // body
                    Inventory.playerBodyTexture = ItemsDatabase.itemsDB[Inventory.armor_slot[slotNr, 0]].itemAttachedArmorSprite;
                    MeshControl.UpdatePlayerColors();
                    break;

                case 2:     // legs
                    Inventory.playerLegsTexture = ItemsDatabase.itemsDB[Inventory.armor_slot[slotNr, 0]].itemAttachedArmorSprite;
                    MeshControl.UpdatePlayerColors();
                    break;
                }
            }
            else
            {
                switch (slotNr)
                {
                case 0:     // helm
                    Inventory.playerHeadTexture = Inventory.playerEmptyTexture;
                    break;

                case 1:     // body
                    Inventory.playerBodyTexture = Inventory.playerDefaultBodyTexture;
                    MeshControl.UpdatePlayerColors();
                    break;

                case 2:     // legs
                    Inventory.playerLegsTexture = Inventory.playerDefaultLegsTexture;
                    MeshControl.UpdatePlayerColors();
                    break;
                }
            }
        }
        else
        {
            switch (slotNr)
            {
            case 0:     // helm
                Inventory.playerHeadTexture = Inventory.playerEmptyTexture;
                break;

            case 1:     // body
                Inventory.playerBodyTexture = Inventory.playerDefaultBodyTexture;
                MeshControl.UpdatePlayerColors();
                break;

            case 2:     // legs
                Inventory.playerLegsTexture = Inventory.playerDefaultLegsTexture;
                MeshControl.UpdatePlayerColors();
                break;
            }
        }

        // Debug.Log($"Helm: {Inventory.playerHeadTexture}, Body: {Inventory.playerBodyTexture}, legs: {Inventory.playerLegsTexture}");
    }