示例#1
0
    public void dig(GamePosition pos)
    {
        if (!isServer)
        {
            return;
        }

        MapCoords mapCoords = pos.toMapCoords();

        Tile tile = mapData.getTile(mapCoords);

        if (tile.GetType().Equals(typeof(Wall)))
        {
            spawnManager.SpawnItemFromTile(new RockItem(), 1, mapCoords.toGamePosition());
            spawnManager.SpawnItemFromTile(new DirtItem(), 1, mapCoords.toGamePosition());

            if (Random.Range(1, 100) <= 25)
            {
                spawnManager.SpawnItemFromTile(new GrubItem(), 1, mapCoords.toGamePosition());
            }

            if (Random.Range(1, 100) <= 50)
            {
                spawnManager.SpawnItemFromTile(new WormItem(), 1, mapCoords.toGamePosition());
            }
        }

        RpcDig(pos.toStruct());
    }
示例#2
0
    public Tile getTileFromGamePosition(GamePosition pos)
    {
        MapCoords coords = pos.toMapCoords();

        if (mapData == null)
        {
            return(new Wall(ConnectableVariant.All_Way));
        }
        return(mapData.getTile(coords));
    }
示例#3
0
    public void RpcDig(GamePosStruct posStruct)
    {
        GamePosition pos       = GamePosition.ParseStruct(posStruct);
        MapCoords    mapCoords = pos.toMapCoords();


        Tile tile = mapData.getTile(mapCoords);

        bool redraw = false;

        if (tile.GetType().Equals(typeof(Wall)))
        {
            redraw = mapData.smartSet(mapCoords, new Dirt());
        }
        else if (tile.GetType().Equals(typeof(Dirt)))
        {
            MapCoords lowerCoords = mapCoords.add(depth: 1);
            Tile      lowTile     = mapData.getTile(lowerCoords);
            if (lowTile != null && lowTile.GetType().Equals(typeof(Wall)))
            {
                bool redrawLower = mapData.smartSet(lowerCoords, new Dirt());

                if (redrawLower)
                {
                    redrawNonaTile(lowerCoords);
                }
            }

            if (lowTile != null)
            {
                redraw = mapData.smartSet(mapCoords, new Air(ConnectableVariant.None));
            }
        }

        if (redraw)
        {
            redrawNonaTile(mapCoords);
        }
    }
示例#4
0
    private void applyGravity(GamePosition pos)
    {
        Tile  currentTile = map.getTileFromGamePosition(pos);
        float floorDepth  = Mathf.Ceil(pos.depth);

        if (currentTile.GetType().Equals(typeof(Air)))
        {
            fall(pos);
        }
        else
        {
            if (pos.toMapCoords().depth - pos.depth > 0.0)
            {
                fall(pos);
            }

            if (pos.depth > floorDepth)
            {
                pos.depth = floorDepth;
            }
        }
    }
示例#5
0
    void Update()
    {
        if (!firstSync)
        {
            InitializeObject();
            firstSync = true;
        }


        trans.position = gamePos.getRenderingPosition();

        if (rend != null)
        {
            rend.sortingOrder = (map.mapDepth - gamePos.toMapCoords().depth - 1) * 10 + 5;
        }

        if (!isLocalPlayer)
        {
            GamePosition syncGamePos = GamePosition.ParseStruct(syncPos);
            gamePos.planePosition = Vector2.Lerp(gamePos.planePosition, syncGamePos.planePosition, Time.deltaTime * lerpRate);
            gamePos.depth         = syncGamePos.depth;

            if (rend.sortingOrder > MoleController.localPlayer.GetComponent <MoleController> ().rend.sortingOrder)
            {
                rend.color = new Color(1, 1, 1, 0);
            }
            else
            {
                rend.color = new Color(1, 1, 1, 1);
            }
        }
        else
        {
            CmdTransmitPosition(gamePos.toStruct());
        }

        GameUpdate();
    }
示例#6
0
    public void RpcPlace(GamePosStruct posStruct)
    {
        GamePosition pos       = GamePosition.ParseStruct(posStruct);
        MapCoords    mapCoords = pos.toMapCoords();


        Tile tile = mapData.getTile(mapCoords);

        bool redraw = false;

        switch (tile.GetType().Name)
        {
        case "Wall":
            Wall wall = (Wall)tile;

            if (wall.getSpriteIndex() == 26)
            {
                MapCoords upperTileCoords = mapCoords.add(0, 1, -1);
                if (upperTileCoords.depth < 0)
                {
                    return;
                }
                bool wasChange = mapData.smartSet(upperTileCoords, new Air(ConnectableVariant.None));
                if (wasChange)
                {
                    redrawNonaTile(upperTileCoords);
                }

                mapData.smartSet(mapCoords.add(y: 1), new Ladder());
                redrawNonaTile(mapCoords);
            }

            break;

        case "Dirt":
            mapData.smartSet(mapCoords, new Wall(ConnectableVariant.None));
            redrawNonaTile(mapCoords);

            MapCoords upperCoord = mapCoords.add(depth: -1);
            Tile      upperTile  = getNonaTile(upperCoord) [1, 1];
            if (upperTile == null)
            {
                return;
            }
            if (upperTile.GetType().Equals(typeof(Air)))
            {
                mapData.smartSet(upperCoord, new Dirt());
                redrawNonaTile(upperCoord);
            }

            break;

        case "Air":
            mapData.smartSet(mapCoords, new Dirt());
            redrawNonaTile(mapCoords);
            break;

        case "Ladder":
            mapData.smartSet(mapCoords, new Dirt());
            redrawNonaTile(mapCoords);
            break;

        default:
            return;
        }
    }