Example #1
0
    private GameObject CreateWall(Sprite sprite, Vector3 position, Transform parent, Vector2Int gridPos)
    {
        // Create block
        GameObject block = new GameObject();

        block.transform.parent = parent;
        // Create Sprite
        SpriteRenderer sr = block.AddComponent <SpriteRenderer>();

        sr.sprite = sprite;
        wallSprites.Add(sr);
        // Scale and position
        block.transform.localScale = useSquare ? new Vector3(0.2f, 0.2f, 1) : new Vector3(0.1f, 0.1f, 1);
        block.transform.position   = new Vector3(position.x, position.y, 0);

        block.AddComponent <BoxCollider2D>();
        BlockDebug debug = block.AddComponent <BlockDebug>();

        debug.SetPos(gridPos);

        return(block);
    }
Example #2
0
    private void PlaceBlock(int x, int y, Vector3 position, Transform parent, int[,] mapArray)
    {
        switch (mapArray[x, y])
        {
        case 1:
            // Outside Corner
            HandleCorner(CreateWall(outCorner, position, parent, new Vector2Int(x, y)), new Vector2Int(x, y));
            break;

        case 2:
            // Outside Wall
            HandleStraight(CreateWall(outWall, position, parent, new Vector2Int(x, y)), new Vector2Int(x, y));
            break;

        case 3:
            // Inside Corner
            HandleCorner(CreateWall(inCorner, position, parent, new Vector2Int(x, y)), new Vector2Int(x, y));
            break;

        case 4:
            // Inside Wall
            HandleStraight(CreateWall(inWall, position, parent, new Vector2Int(x, y)), new Vector2Int(x, y));
            break;

        case 5:
            // Normal Pellet
            GameObject newPellet = Instantiate(pellet, position, new Quaternion(), levelParent);
            newPellet.transform.localScale = new Vector3(0.1f, 0.1f, 1);

            // Debug
            newPellet.AddComponent <BoxCollider2D>();
            BlockDebug debug = newPellet.AddComponent <BlockDebug>();
            debug.SetPos(new Vector2Int(x, y));

            // Add pellets to list
            if (!allPellets.ContainsKey(new Vector2Int(x, y)))
            {
                allPellets.Add(new Vector2Int(x, y), newPellet);
            }
            break;

        case 6:
            // Power Pellet
            GameObject newPPellet = Instantiate(pellet, position, new Quaternion(), levelParent);
            newPPellet.transform.localScale = new Vector3(0.1f, 0.1f, 1);
            Pellet pelletScript = newPPellet.GetComponent <Pellet>();
            pelletScript.ConvertToPowerPellet();

            // Debug
            newPPellet.AddComponent <BoxCollider2D>();
            BlockDebug pdebug = newPPellet.AddComponent <BlockDebug>();
            pdebug.SetPos(new Vector2Int(x, y));
            break;

        case 7:
            // T Junction
            CreateWall(tJunction, position, parent, new Vector2Int(x, y));
            break;

        default:
            //Nothing
            break;
        }
    }