Esempio n. 1
0
 public static bool IsTileSetType(PATile tile, TileSetType tst)
 {
     if (tile == null)
     {
         return(false);
     }
     else
     {
         return(tile.tileSetType == tst);
     }
 }
Esempio n. 2
0
    /// <summary>
    /// Instantiates all the tiles.
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void InstantiateTiles(TileType[,] map, int dividerLevel, Dictionary <TileSetType, TileLevel> availiableTile, List <Vector2> spawnPoints)
    {
        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx];
                if (type != TileType.None && type != TileType.Lava)
                {
                    TileSetType level = ydx > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

                    GameObject obj  = availiableTile[level].GetTileType(type);
                    var        tile = (GameObject)Instantiate(obj, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());

                    Debug.Log(tile);
                    NetworkServer.Spawn(tile);
                }
                else if (type == TileType.Lava)
                {
                    GameObject obj  = availiableTile[TileSetType.lava].GetTileType(TileType.Top);
                    var        tile = (GameObject)Instantiate(obj, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());
                    tile.name = "Lava";
                    Debug.Log(tile);
                    NetworkServer.Spawn(tile);
                }

                //GameObject bck = availiableTile[TileSetType.background].GetTileType(TileType.Filler);
                //var backt = (GameObject)Instantiate(bck, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());
                //backt.name = "background";
                //Debug.Log(backt);
                //NetworkServer.Spawn(backt);
            }
        }

        foreach (Vector2 point in spawnPoints)
        {
            var spawn = (GameObject)Instantiate(SpawnPrefab, new Vector3(point.x * Tilesize, point.y * Tilesize), new Quaternion());
            spawn.name = "spawnPoint";
            Debug.Log(spawn);
            NetworkServer.Spawn(spawn);
        }

        //GameObject back = backgroundPrefab;

        var backobj           = (GameObject)Instantiate(backgroundPrefab, new Vector3(0, 0, -1.5f), new Quaternion());
        BackgroundScript move = backobj.GetComponent(typeof(BackgroundScript)) as BackgroundScript;

        move.MapSize      = new Vector2(WidthSize * Tilesize, HeightSize * Tilesize);
        move.DividerLevel = dividerLevel;
        Debug.Log(backobj);
        NetworkServer.Spawn(backobj);
    }
        /// <summary>
        /// Starts a new game.
        /// </summary>
        /// <param name="gameParams">Parameters of the game.</param>
        public void StartGame(GameParameters gameParams)
        {
            // Init the game
            CurrentGameState.Params             = gameParams;
            CurrentGameState.CurrentPlayerIndex = -1;
            CurrentGameState.CurrentPhase       = GamePhase.BEFORE_START;

            _TileSetType = gameParams.TileSet;

            // Set correct tile supplier
            switch (_TileSetType)
            {
            case TileSetType.STANDARD:
                CurrentGameState.TileSupplier = new StandardTileSetSupplier();
                break;

            case TileSetType.PASSIVE:
                CurrentGameState.TileSupplier = new PassiveTileSupplier();
                break;

            case TileSetType.STANDARD_PASSIVE:
                CurrentGameState.TileSupplier = new StandardPassiveTileSetSupplier();
                break;
            }

            // Add score records
            foreach (PlayerColor color in gameParams.PlayerOrder)
            {
                CurrentGameState.Scores.Add(color, 0);
            }

            // Notify that game has been started
            GameStartedEvent.Invoke(gameParams);

            if (_TileSetType != TileSetType.PASSIVE && _TileSetType != TileSetType.STANDARD_PASSIVE)
            {
                // Place the initial tile
                PlaceTile(PlayerColor.NONE, CurrentGameState.TileSupplier.GetFirst(), new Coords(0, 0), TileOrientation.N);
            }

            // Start next move
            StartNextMove();
        }
        /// <summary>
        /// Changes tile set type.
        /// </summary>
        /// <param name="tileSet">New type of tile set.</param>
        /// <exception cref="InvalidOperationException">When tile set cannot be changed.</exception>
        public void ChangeTileSetType(TileSetType tileSet)
        {
            switch (tileSet) // If change is correct, use return; else break.
            {
            case TileSetType.STANDARD:
                if (_TileSetType == TileSetType.STANDARD_PASSIVE)
                {
                    _TileSetType = TileSetType.STANDARD;
                    return;
                }
                break;

            case TileSetType.PASSIVE:
                _TileSetType = TileSetType.PASSIVE;
                CurrentGameState.TileSupplier = new PassiveTileSupplier();
                return;
            }

            throw new InvalidOperationException($"Cannot change tile set type from {_TileSetType} to {tileSet}.");
        }
Esempio n. 5
0
        public static Rectangle GetSourceRectangle(TileSetType p_type, int p_index)
        {
            Rectangle __sourceRect = new Rectangle(0, 0, 16, 16);

            if (p_type == TileSetType.PLAYER)
            {
                __sourceRect.X = (p_index % (GraphicAssets.playerTileset.Width / 16)) * 16;
                __sourceRect.Y = (p_index / (GraphicAssets.playerTileset.Height / 16)) * 16;
            }
            else if (p_type == TileSetType.PROJECTILES)
            {
                __sourceRect.X = (p_index % (GraphicAssets.projectilesTileset.Width / 16)) * 16;
                __sourceRect.Y = (p_index / (GraphicAssets.projectilesTileset.Height / 16)) * 16;
            }

            else if (p_type == TileSetType.ENEMIES)
            {
                __sourceRect.X = (p_index % (GraphicAssets.enemiesTileset.Width / 16)) * 16;
                __sourceRect.Y = (p_index / (GraphicAssets.enemiesTileset.Height / 16)) * 16;
                if (p_index >= 48)
                {
                    __sourceRect.X      = ((48 + ((p_index - 48) * 2)) % (GraphicAssets.enemiesTileset.Width / 16)) * 16;
                    __sourceRect.Y      = ((48 + ((p_index - 48) * 2)) / (GraphicAssets.enemiesTileset.Height / 16)) * 16;
                    __sourceRect.Width  = 32;
                    __sourceRect.Height = 32;
                }
            }
            else if (p_type == TileSetType.INVENTORY)
            {
                __sourceRect.X = (p_index % (GraphicAssets.inventoryTileset.Width / 16)) * 16;
                __sourceRect.Y = (p_index / (GraphicAssets.inventoryTileset.Height / 16)) * 16;
            }
            else if (p_type == TileSetType.ITEMS)
            {
                __sourceRect.X = (p_index % (GraphicAssets.itemsTileset.Width / 16)) * 16;
                __sourceRect.Y = (p_index / (GraphicAssets.itemsTileset.Height / 16)) * 16;
            }
            return(__sourceRect);
        }
Esempio n. 6
0
 public static Texture2D GetTileSet(TileSetType p_tileType)
 {
     if (p_tileType == TileSetType.ITEMS)
     {
         return(GraphicAssets.itemsTileset);
     }
     else if (p_tileType == TileSetType.ENEMIES)
     {
         return(GraphicAssets.enemiesTileset);
     }
     else if (p_tileType == TileSetType.PLAYER)
     {
         return(GraphicAssets.playerTileset);
     }
     else if (p_tileType == TileSetType.PROJECTILES)
     {
         return(GraphicAssets.projectilesTileset);
     }
     else if (p_tileType == TileSetType.INVENTORY)
     {
         return(GraphicAssets.inventoryTileset);
     }
     return(GraphicAssets.itemsTileset);
 }
Esempio n. 7
0
    public void PaintATileDecal(PATile tile)
    {
        if (tile == null || tile.decalTilesetIndex != -1)
        {
            return;
        }

        //融合处不能贴花
        if (!tile.IsElementFull())
        {
            return;
        }

        PATile[] nTiles          = GetNeighboringTilesNxN(tile, 1);
        PATile   leftTile        = nTiles[1];
        PATile   topTile         = nTiles[3];
        PATile   rightTile       = nTiles[5];
        PATile   rightBottomTile = nTiles[6];
        PATile   bottomTile      = nTiles[7];

        foreach (var config in ConfigDataBase.instance.DecalConfigAsset.configs)
        {
            if (tile.decalTilesetIndex != -1)
            {
                return;
            }
            if (config.elementType != (int)tile.element.GetDecalSuitTileType())
            {
                continue;
            }
            if (!config.elementValue.Contains(tile.element.GetMaxElementValue()))
            {
                continue;
            }
            TileSetType tileSetType = (TileSetType)config.tileSetType;
            if (tile.tileSetType != tileSetType)
            {
                continue;
            }
            //float rate = (config.maxRate - tile.distance * config.atten);
            int rate        = config.rate;
            int randomValue = RandomManager.instance.Range(0, 1000);
            if (20 < randomValue)
            {
                continue;
            }
            //int randomRotate = RandomManager.instance.Range(0,4);
            //UVRotateType rotateType = (UVRotateType)randomRotate;
            UVRotateType rotateType = UVRotateType._90;
            if (config.decalType == (int)TileDecalType.Decal_2)
            {
                if (config.tileSetIndex.Count != 2)
                {
                    Debug.LogError("config.tileSetIndex.Count != 2");
                    continue;
                }
                if (rotateType == UVRotateType._90)
                {
                    if (rightTile == null || rightTile.decalTilesetIndex != -1 || !rightTile.IsElementFull())
                    {
                        continue;
                    }
                    if (rightTile.tileSetType != tileSetType)
                    {
                        continue;
                    }

                    tile.decalTilesetIndex      = config.tileSetIndex[0];
                    rightTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(rightTile, rotateType);
                }
                else if (rotateType == UVRotateType.None)
                {
                    if (topTile == null || topTile.decalTilesetIndex != -1 || !topTile.IsElementFull())
                    {
                        continue;
                    }
                    if (topTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex    = config.tileSetIndex[0];
                    topTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(topTile, rotateType);
                }
                else if (rotateType == UVRotateType._180)
                {
                    if (bottomTile == null || bottomTile.decalTilesetIndex != -1 || !bottomTile.IsElementFull())
                    {
                        continue;
                    }
                    if (bottomTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex       = config.tileSetIndex[0];
                    bottomTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(bottomTile, rotateType);
                }
                else if (rotateType == UVRotateType._270)
                {
                    if (leftTile == null || leftTile.decalTilesetIndex != -1)
                    {
                        continue;
                    }
                    if (leftTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex     = config.tileSetIndex[0];
                    leftTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(leftTile, rotateType);
                }
                PaintTileDecal(tile, rotateType);
            }
            else if (config.decalType == (int)TileDecalType.Decal_4)
            {
                if (rightTile == null || rightTile.decalTilesetIndex != -1 || !rightTile.IsElementFull() ||
                    rightBottomTile == null || rightBottomTile.decalTilesetIndex != -1 || !rightBottomTile.IsElementFull() ||
                    bottomTile == null || bottomTile.decalTilesetIndex != -1 || !bottomTile.IsElementFull())
                {
                    continue;
                }
                if (rightTile.tileSetType != tileSetType)
                {
                    continue;
                }
                if (rightBottomTile.tileSetType != tileSetType)
                {
                    continue;
                }
                if (bottomTile.tileSetType != tileSetType)
                {
                    continue;
                }

                if (config.tileSetIndex.Count != 4)
                {
                    Debug.LogError("config.tileSetIndex.Count != 4");
                    continue;
                }

                if (rotateType == UVRotateType._90)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[0];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[1];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[2];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[3];
                }
                else if (rotateType == UVRotateType.None)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[1];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[3];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[0];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[2];
                }
                else if (rotateType == UVRotateType._270)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[3];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[2];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[1];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[0];
                }
                else if (rotateType == UVRotateType._180)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[2];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[0];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[3];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[1];
                }
                PaintTileDecal(tile, rotateType);
                PaintTileDecal(rightTile, rotateType);
                PaintTileDecal(bottomTile, rotateType);
                PaintTileDecal(rightBottomTile, rotateType);
            }
            else
            {
                if (config.tileSetIndex.Count != 1)
                {
                    Debug.LogError("config.tileSetIndex.Count != 1");
                    continue;
                }
                tile.decalTilesetIndex = config.tileSetIndex[0];
                PaintTileDecal(tile, rotateType);
            }
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Creates an instantites the tiles.
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary <TileSetType, TileLevel> availiableTile)
    {
        List <Vector2> leftEnds  = new List <Vector2>();
        List <Vector2> rightEnds = new List <Vector2>();

        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx];

                if (type == TileType.LeftEnd)
                {
                    leftEnds.Add(new Vector2(xdx, ydx));
                }
                else if (type == TileType.RightEnd)
                {
                    rightEnds.Add(new Vector2(xdx, ydx));
                }
            }
        }

        DualStore <Vector2, Vector2> veritcal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int xdx = (int)vec.x + 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (Vector2 vec in leftEnds)
        {
            int xdx = (int)vec.x - 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in veritcal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.updown;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

        DualStore <Vector2, Vector2> horizontal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int ydx = (int)vec.y;

            for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx));
                    xdx = map.GetLength(0);
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in horizontal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.leftright;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }
    }
Esempio n. 9
0
    /// <summary>
    /// Gets all tiles of a specific set type.
    /// </summary>
    /// <param name="allTiles"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    protected virtual DualStore <TileDetails, GameObject> GetTileSetType(DualStore <TileDetails, GameObject> allTiles, TileSetType type)
    {
        DualStore <TileDetails, GameObject> thisTileset = new DualStore <TileDetails, GameObject>();

        foreach (KeyValuePair <TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.Type == type)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return(thisTileset);
    }
Esempio n. 10
0
    /// <summary>
    /// Gets all tiles of a specific set type. 
    /// </summary>
    /// <param name="allTiles"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    protected virtual DualStore<TileDetails, GameObject> GetTileSetType (DualStore<TileDetails, GameObject> allTiles, TileSetType type)
    {
        DualStore<TileDetails, GameObject> thisTileset = new DualStore<TileDetails, GameObject>();

        foreach (KeyValuePair<TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.Type == type)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return thisTileset;
    }