Beispiel #1
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Coords   = new Coords(bytes, 0);
                    Velocity = new Vector3(BitConverter.ToSingle(bytes, sizeof(float) * 5),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 6),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 7));
                    BlockType    = (Block.BlockType)BitConverter.ToUInt16(bytes, Coords.SIZE + Vector3.SizeInBytes);
                    GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort));
                }
            }

            //add the new block item to the chunk game items (note: constructor adds the item to the collection)
            var newBlockItem = new BlockItem(ref Coords, BlockType, Velocity, GameObjectId);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id)
                    {
                        ConnectedPlayer = player
                    }.Send();
                }
            }
        }
Beispiel #2
0
    public IEnumerator Flow(Block b, Block.BlockType bt, int strength, int maxSize)
    {
        // Reduce the strength of the fluid block with each new block created
        if (maxSize <= 0)
        {
            yield break;
        }
        if (b == null)
        {
            yield break;
        }
        if (strength <= 0)
        {
            yield break;
        }
        if (b.bType != Block.BlockType.AIR)
        {
            yield break;
        }

        b.SetType(bt, false);
        b.CurHealth = strength;
        b.Owner.Redraw();
        yield return(new WaitForSeconds(1));

        int x = (int)b.Pos.x;
        int y = (int)b.Pos.y;
        int z = (int)b.Pos.z;

        // Flow down if air block is underneath
        Block below = b.GetBlock(x, y - 1, z);

        if (below != null && below.bType == Block.BlockType.AIR)
        {
            World.Queue.Run(Flow(b.GetBlock(x, y - 1, z), bt, strength, --maxSize));
            yield break;
        }
        // Flow outward
        else
        {
            --strength;
            --maxSize;

            // Flow left
            World.Queue.Run(Flow(b.GetBlock(x - 1, y, z), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow right
            World.Queue.Run(Flow(b.GetBlock(x + 1, y, z), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow forward
            World.Queue.Run(Flow(b.GetBlock(x, y, z + 1), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow backward
            World.Queue.Run(Flow(b.GetBlock(x, y, z - 1), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));
        }
    }
Beispiel #3
0
    public IEnumerator Flow(Block block, Block.BlockType blockType, int strength, int maxSize)
    {
        // strength: how many times the function will run recursively before stopping
        // maxSize: how far down water will flow before stopping

        if (maxSize <= 0)
        {
            yield break;
        }
        if (block == null)
        {
            yield break;
        }
        if (strength <= 0)
        {
            yield break;
        }
        if (block.bType != Block.BlockType.AIR)
        {
            yield break;
        }

        block.SetType(blockType);
        block.currentHealth = strength;
        block.owner.RedrawChunk();
        yield return(new WaitForSeconds(1));

        int x = (int)block.blockPosition.x;
        int y = (int)block.blockPosition.y;
        int z = (int)block.blockPosition.z;

        Block blockBelow = block.GetBlock(x, y - 1, z);

        if (blockBelow != null && blockBelow.bType == Block.BlockType.AIR)
        {
            StartCoroutine(Flow(block.GetBlock(x, y - 1, z), blockType, strength, --maxSize));
            yield break;
        }
        else
        {
            --strength;
            --maxSize;

            // flow left
            World.coroutineQueue.Run(Flow(block.GetBlock(x - 1, y, z), blockType, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // flow right
            World.coroutineQueue.Run(Flow(block.GetBlock(x + 1, y, z), blockType, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // flow backward
            World.coroutineQueue.Run(Flow(block.GetBlock(x, y, z - 1), blockType, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // flow forward
            World.coroutineQueue.Run(Flow(block.GetBlock(x, y, z + 1), blockType, strength, maxSize));
            yield return(new WaitForSeconds(1));
        }
    }
Beispiel #4
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Position = new Position(bytes, 0);
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Position.SIZE);
                }
            }

            WorldData.PlaceBlock(Position, BlockType);

            if (Config.IsServer)
            {
                //bm: this has to wait until the server can manage who's in creative mode
                //if (ConnectedPlayer.Inventory[(int)BlockType] <= 0) return;
                //ConnectedPlayer.Inventory[(int)BlockType] -= 1;

                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddBlock(ref Position, BlockType) { ConnectedPlayer = player }.Send();
                }
            }
        }
Beispiel #5
0
 public AddBlock(ref Position position, Block.BlockType blockType)
     : this()
 {
     if (blockType == Block.BlockType.Air) throw new Exception("You can't place air, use RemoveBlock");
     Position = position;
     BlockType = blockType;
 }
Beispiel #6
0
    public Chunk(Block[,] inputBlocks, int height, int width)
    {
        MaxWorldHeight = height;
        MaxWorldWidth  = width;
        Blocks         = inputBlocks;

        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
            {
                Block.BlockType type = Blocks[x, y].Type;

                switch (type)
                {
                case Block.BlockType.NULL:
                    OpenBlocks.Add(Blocks[x, y]);
                    break;

                case Block.BlockType.Indescructible:
                    IndestructibleBlocks.Add(Blocks[x, y]);
                    break;

                case Block.BlockType.Destructible:
                    DestuctibleBlocks.Add(Blocks[x, y]);
                    break;

                default:
                    break;
                }
            }
        }
        Type = ChunkType.Empty;
    }
Beispiel #7
0
 public AddCuboid(Position position1, Position position2, Block.BlockType blockType)
     : this()
 {
     Position1 = position1;
     Position2 = position2;
     BlockType = blockType;
 }
Beispiel #8
0
        public static Color BlockHighlightOne(Block.BlockType type)
        {
            switch (type)
            {
            case Block.BlockType.OneHit:
                return(new Color(255, 255, 153, 255));

            case Block.BlockType.TwoHits:
                return(new Color(255, 210, 153, 255));

            case Block.BlockType.ThreeHits:
                return(new Color(255, 130, 180, 255));

            case Block.BlockType.FourHits:
                return(new Color(191, 145, 255, 255));

            case Block.BlockType.FiveHits:
                return(new Color(130, 255, 192, 255));

            case Block.BlockType.Indestructible:
                return(new Color(40, 40, 40, 255));

            default:
                return(Color.Black);
            }
        }
Beispiel #9
0
    void BuildGhostChunk(Vector3 blockPosition, Block.BlockType blockType)
    {
        Block ghostBlock = new Block(blockType, blockPosition, this);

        ghostBlock.CreateGhostBlock();
        CombineQuads();
    }
Beispiel #10
0
        /// <summary>Processes raw data to populate the resource</summary>
        /// <param name="raw">Raw byte data</param>
        /// <param name="containsHeader">Whether or not <i>raw</i> contains the resource Header information</param>
        /// <exception cref="ArgumentException">Header-defined <see cref="Type"/> is not <see cref="Resource.ResourceType.Film"/></exception>
        public override void DecodeResource(byte[] raw, bool containsHeader)
        {
            //System.Diagnostics.Debug.WriteLine("Decode FILM");
            _decodeResource(raw, containsHeader);
            if (_type != ResourceType.Film)
            {
                throw new ArgumentException("Raw header is not for a Film resource");
            }
            _numberOfFrames = BitConverter.ToInt16(_rawData, 2);
            _blocks         = new Block[BitConverter.ToInt16(_rawData, 4) + 1];
            int offset = 6;

            for (int i = 0; i < _blocks.Length; i++)
            {
                //System.Diagnostics.Debug.WriteLine("Block " + (i + 1) + " of " + _blocks.Length);
                Block.BlockType type = (Block.BlockType)BitConverter.ToInt32(_rawData, offset + TypeOffset);
                string          name = ArrayFunctions.ReadStringFromArray(_rawData, offset + NameOffset, 8);
                int             len  = BitConverter.ToInt32(_rawData, offset + LengthOffset);
                //System.Diagnostics.Debug.WriteLine(type + name + ", " + len);
                short[] block = new short[(len - 0x12) / 2];
                //System.Diagnostics.Debug.WriteLine("block len: " + block.Length);
                //System.Diagnostics.Debug.WriteLine("copying raw...");
                ArrayFunctions.TrimArray(_rawData, offset + 0x12, block);
                //for (int i = 0; i < block.Length; i++) block[i] = BitConverter.ToInt16(_rawData, offset + HeaderLength + 2 + i * 2);
                //System.Diagnostics.Debug.WriteLine("copied, creating block...");
                _blocks[i] = new Block(type, name, block);
                offset    += len;
            }
        }
Beispiel #11
0
        public void AddOrRemoveBlock(Block.BlockType blockType)
        {
            if (!BlockCursorHost.Position.IsValidBlockLocation)
            {
                Game.UiHost.AddChatMessage(new ChatMessage(ChatMessageType.Error, "Invalid block location."));
                return;
            }

            var blockAtCursor = BlockCursorHost.Position.GetBlock();

            if (!Config.CreativeMode && blockAtCursor.Type == Block.BlockType.Water)
            {
                if (!blockAtCursor.IsDirty)
                {
                    Game.UiHost.AddChatMessage(new ChatMessage(ChatMessageType.Error, "Only player-made water may be removed."));
                    return;
                }
                if (blockType == Block.BlockType.Air)
                {
                    Game.UiHost.AddChatMessage(new ChatMessage(ChatMessageType.Error, "Water must be removed by building on it."));
                    return;
                }
            }
            NetworkClient.SendAddOrRemoveBlock(blockType == Block.BlockType.Air || (blockType != Block.BlockType.Water && blockAtCursor.Type == Block.BlockType.Water) ? BlockCursorHost.Position : BlockCursorHost.PositionAdd, blockType);
        }
Beispiel #12
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Coords   = new Coords(bytes, 0);
                    Velocity = new Vector3(BitConverter.ToSingle(bytes, Coords.SIZE),
                                           BitConverter.ToSingle(bytes, Coords.SIZE + sizeof(float)),
                                           BitConverter.ToSingle(bytes, Coords.SIZE + sizeof(float) * 2));
                    BlockType    = (Block.BlockType)BitConverter.ToUInt16(bytes, Coords.SIZE + Vector3.SizeInBytes);
                    AllowBounce  = BitConverter.ToBoolean(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort));
                    GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort) + sizeof(bool));
                }
            }

            var newProjectile = new Projectile(ref Coords, BlockType, AllowBounce, Velocity, GameObjectId);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddProjectile(ref newProjectile.Coords, ref newProjectile.Velocity, newProjectile.BlockType, newProjectile.AllowBounce, newProjectile.Id)
                    {
                        ConnectedPlayer = player
                    }.Send();
                }
            }
        }
Beispiel #13
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Coords = new Coords(bytes, 0);
                    Velocity = new Vector3(BitConverter.ToSingle(bytes, sizeof(float) * 5),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 6),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 7));
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Coords.SIZE + Vector3.SizeInBytes);
                    GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort));
                }
            }

            //add the new block item to the chunk game items (note: constructor adds the item to the collection)
            var newBlockItem = new BlockItem(ref Coords, BlockType, Velocity, GameObjectId);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id) { ConnectedPlayer = player }.Send();
                }
            }
        }
Beispiel #14
0
        internal Projectile(ref Coords coords, Block.BlockType blockType, bool allowBounce, Vector3?velocity = null, int id = -1) : base(ref coords, GameItemType.Projectile, allowBounce, velocity, id)
        {
            BlockType = blockType;

            //Stop += OnItemStop;
            Decay += OnItemDecay;
        }
Beispiel #15
0
 public AddBlockItem(ref Coords coords, ref Vector3 velocity, Block.BlockType blockType, int gameObjectId = -1) : this()
 {
     Coords       = coords;
     Velocity     = velocity;
     BlockType    = blockType;
     GameObjectId = gameObjectId;
 }
Beispiel #16
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Position  = new Position(bytes, 0);
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Position.SIZE);
                }
            }

            WorldData.PlaceBlock(Position, BlockType);

            if (Config.IsServer)
            {
                //bm: this has to wait until the server can manage who's in creative mode
                //if (ConnectedPlayer.Inventory[(int)BlockType] <= 0) return;
                //ConnectedPlayer.Inventory[(int)BlockType] -= 1;

                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddBlock(ref Position, BlockType)
                    {
                        ConnectedPlayer = player
                    }.Send();
                }
            }
        }
Beispiel #17
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Coords = new Coords(bytes, 0);
                    Velocity = new Vector3(BitConverter.ToSingle(bytes, Coords.SIZE),
                                           BitConverter.ToSingle(bytes, Coords.SIZE + sizeof(float)),
                                           BitConverter.ToSingle(bytes, Coords.SIZE + sizeof(float) * 2));
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Coords.SIZE + Vector3.SizeInBytes);
                    AllowBounce = BitConverter.ToBoolean(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort));
                    GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort) + sizeof(bool));
                }
            }

            var newProjectile = new Projectile(ref Coords, BlockType, AllowBounce, Velocity, GameObjectId);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddProjectile(ref newProjectile.Coords, ref newProjectile.Velocity, newProjectile.BlockType, newProjectile.AllowBounce, newProjectile.Id) { ConnectedPlayer = player }.Send();
                }
            }
        }
Beispiel #18
0
        public static Color BlockHighlightTwo(Block.BlockType type)
        {
            switch (type)
            {
            case Block.BlockType.OneHit:
                return(new Color(255, 255, 216, 255));

            case Block.BlockType.TwoHits:
                return(new Color(255, 237, 214, 255));

            case Block.BlockType.ThreeHits:
                return(new Color(255, 204, 224, 255));

            case Block.BlockType.FourHits:
                return(new Color(225, 204, 255, 255));

            case Block.BlockType.FiveHits:
                return(new Color(216, 255, 235, 255));

            case Block.BlockType.Indestructible:
                return(new Color(30, 30, 30, 255));

            default:
                return(Color.Black);
            }
        }
Beispiel #19
0
        public static Color BlockShadowOne(Block.BlockType type)
        {
            switch (type)
            {
            case Block.BlockType.OneHit:
                return(new Color(137, 137, 78, 255));

            case Block.BlockType.TwoHits:
                return(new Color(142, 109, 65, 255));

            case Block.BlockType.ThreeHits:
                return(new Color(112, 68, 85, 255));

            case Block.BlockType.FourHits:
                return(new Color(88, 65, 119, 255));

            case Block.BlockType.FiveHits:
                return(new Color(56, 99, 78, 255));

            case Block.BlockType.Indestructible:
                return(new Color(10, 10, 10, 255));

            default:
                return(Color.Black);
            }
        }
Beispiel #20
0
    public static PalleteType GetPallete(Block.BlockType blockType)
    {
        switch (blockType)
        {
        case Block.BlockType.appendage:
            return(PalleteType.green);

        case Block.BlockType.background:
            return(PalleteType.sand);

        case Block.BlockType.collectible:
            return(PalleteType.blue);

        case Block.BlockType.goal:
            return(PalleteType.teal);

        case Block.BlockType.hazard:
            return(PalleteType.red);

        case Block.BlockType.player:
            return(PalleteType.green);

        case Block.BlockType.solid:
            return(PalleteType.grey);

        default:
            return(PalleteType.sand);
        }
    }
Beispiel #21
0
        public static Color BlockShadowTwo(Block.BlockType type)
        {
            switch (type)
            {
            case Block.BlockType.OneHit:
                return(new Color(181, 181, 74, 255));

            case Block.BlockType.TwoHits:
                return(new Color(193, 145, 81, 255));

            case Block.BlockType.ThreeHits:
                return(new Color(160, 97, 123, 255));

            case Block.BlockType.FourHits:
                return(new Color(124, 92, 168, 255));

            case Block.BlockType.FiveHits:
                return(new Color(88, 155, 122, 255));

            case Block.BlockType.Indestructible:
                return(new Color(0, 0, 0, 255));

            default:
                return(Color.Black);
            }
        }
Beispiel #22
0
        public static Color BlockMain(Block.BlockType type)
        {
            switch (type)
            {
            case Block.BlockType.OneHit:
                return(new Color(255, 255, 89, 255));

            case Block.BlockType.TwoHits:
                return(new Color(255, 175, 71, 255));

            case Block.BlockType.ThreeHits:
                return(new Color(255, 56, 135, 255));

            case Block.BlockType.FourHits:
                return(new Color(149, 73, 255, 255));

            case Block.BlockType.FiveHits:
                return(new Color(73, 255, 164, 255));

            case Block.BlockType.Indestructible:
                return(new Color(20, 20, 20, 255));

            default:
                return(Color.Black);
            }
        }
Beispiel #23
0
    public IEnumerator Drop(Block b, Block.BlockType bt, int maxdrop)
    {
        Block thisBlock = b;
        Block prevBlock = null;

        for (int i = 0; i < maxdrop; i++)
        {
            Block.BlockType previousType = thisBlock.bType;

            if (previousType != bt)
            {
                thisBlock.SetType(bt);
            }
            if (prevBlock != null)
            {
                prevBlock.SetType(previousType);
            }

            prevBlock = thisBlock;
            b.owner.Redraw();

            yield return(new WaitForSeconds(0.2f));

            Vector3 pos = thisBlock.position;

            thisBlock = thisBlock.GetBlock((int)pos.x, (int)pos.y - 1, (int)pos.z);
            if (thisBlock.isSolid)
            {
                yield break;
            }
        }
    }
Beispiel #24
0
    public IEnumerator Flow(Block b, Block.BlockType bt, int strength, int maxsize)
    {
        //reduce strength of the fluid block
        //with each new block created

        if (maxsize <= 0)
        {
            yield break;
        }
        if (b == null)
        {
            yield break;
        }
        if (strength <= 0)
        {
            yield break;
        }
        if (b.bType != Block.BlockType.AIR)
        {
            yield break;
        }
        b.SetType(bt);
        b.currentHealth = strength;
        b.owner.Redraw();
        yield return(new WaitForSeconds(0.5f));

        int x = (int)b.position.x;
        int y = (int)b.position.y;
        int z = (int)b.position.z;

        //flow down if air block beneath
        Block below = b.GetBlock(x, y - 1, z);

        if (below != null && below.bType == Block.BlockType.AIR)
        {
            StartCoroutine(Flow(b.GetBlock(x, y - 1, z), bt, strength, --maxsize));
            yield break;
        }
        else
        {
            --strength;
            --maxsize;
            //flow left
            World.queue.Run(Flow(b.GetBlock(x - 1, y, z), bt, strength, maxsize));
            yield return(new WaitForSeconds(0.5f));

            //flow right
            World.queue.Run(Flow(b.GetBlock(x + 1, y, z), bt, strength, maxsize));
            yield return(new WaitForSeconds(0.5f));

            //flow forward
            World.queue.Run(Flow(b.GetBlock(x, y, z + 1), bt, strength, maxsize));
            yield return(new WaitForSeconds(0.5f));

            //flow backward
            World.queue.Run(Flow(b.GetBlock(x, y, z - 1), bt, strength, maxsize));
            yield return(new WaitForSeconds(0.5f));
        }
    }
Beispiel #25
0
        internal Projectile(ref Coords coords, Block.BlockType blockType, bool allowBounce, Vector3? velocity = null, int id = -1)
            : base(ref coords, GameItemType.Projectile, allowBounce, velocity, id)
        {
            BlockType = blockType;

            //Stop += OnItemStop;
            Decay += OnItemDecay;
        }
Beispiel #26
0
 public AddProjectile(ref Coords coords, ref Vector3 velocity, Block.BlockType blockType, bool allowBounce, int gameObjectId = -1) : this()
 {
     Coords       = coords;
     Velocity     = velocity;
     BlockType    = blockType;
     AllowBounce  = allowBounce;
     GameObjectId = gameObjectId;
 }
 private bool IsBlock(int x, int y, Block.BlockType b)
 {
     if ((b == Block.BlockType.goal) && GetBlock(x, y).isAlsoGoal)
     {
         return(true);
     }
     return(GetBlock(x, y).getType() == b);
 }
Beispiel #28
0
 public AddBlockItem(ref Coords coords, ref Vector3 velocity, Block.BlockType blockType, int gameObjectId = -1)
     : this()
 {
     Coords = coords;
     Velocity = velocity;
     BlockType = blockType;
     GameObjectId = gameObjectId;
 }
Beispiel #29
0
    public void SetCurrentBlockBasic()
    {
        _currentBlockType = Block.BlockType.Basic;
        Color color = _basicMaterial.color;

        color.a = _hoverBlockMaterial.color.a;
        _hoverBlockMaterial.color        = color;
        _activeBorder.transform.position = _basicBlock.transform.position;
    }
Beispiel #30
0
    public void SetCurrentBlockGrass()
    {
        _currentBlockType = Block.BlockType.Grass;
        Color color = _grassMaterial.color;

        color.a = _hoverBlockMaterial.color.a;
        _hoverBlockMaterial.color        = color;
        _activeBorder.transform.position = _grassBlock.transform.position;
    }
Beispiel #31
0
 public AddProjectile(ref Coords coords, ref Vector3 velocity, Block.BlockType blockType, bool allowBounce, int gameObjectId = -1)
     : this()
 {
     Coords = coords;
     Velocity = velocity;
     BlockType = blockType;
     AllowBounce = allowBounce;
     GameObjectId = gameObjectId;
 }
Beispiel #32
0
 public AddBlock(ref Position position, Block.BlockType blockType) : this()
 {
     if (blockType == Block.BlockType.Air)
     {
         throw new Exception("You can't place air, use RemoveBlock");
     }
     Position  = position;
     BlockType = blockType;
 }
Beispiel #33
0
    /// <summary>
    /// Coroutine to allow a fluid Block to fall down and spreadout.
    /// </summary>
    /// <param name="b"></param>
    /// <param name="bt"></param>
    /// <param name="strength"></param>
    /// <param name="maxSize"></param>
    /// <returns></returns>
    public IEnumerator Flow(Block b, Block.BlockType bt, int strength, int maxSize)
    {
        // Reduce the strenth of the fluid block with each new block created (avoid infinite and exponentially growing number of fluid blocks)
        if (maxSize <= 0)
        {
            yield break;
        }
        if (b == null)
        {
            yield break;
        }
        if (strength <= 0)
        {
            yield break;
        }
        if (b.blockType != Block.BlockType.AIR)
        {
            yield break;
        }
        b.SetType(bt);
        b.currentHealth = strength;
        b.owner.Redraw();
        yield return(new WaitForSeconds(1));

        int x = (int)b.position.x;
        int y = (int)b.position.y;
        int z = (int)b.position.z;

        // Flow down if air block is beneath
        Block below = b.GetBlock(x, y - 1, z);

        if (below != null && below.blockType == Block.BlockType.AIR)
        {
            StartCoroutine(Flow(b.GetBlock(x, y - 1, z), bt, strength, --maxSize));
            yield break;
        }
        else         // Flow outward
        {
            --strength;
            --maxSize;
            // Flow left
            World.queue.Run(Flow(b.GetBlock(x - 1, y, z), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow right
            World.queue.Run(Flow(b.GetBlock(x + 1, y, z), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow forward
            World.queue.Run(Flow(b.GetBlock(x, y, z + 1), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));

            // Flow back
            World.queue.Run(Flow(b.GetBlock(x, y, z - 1), bt, strength, maxSize));
            yield return(new WaitForSeconds(1));
        }
    }
Beispiel #34
0
    public void SetCurrentBlockWood()
    {
        _currentBlockType = Block.BlockType.Wood;
        Color color = _woodMaterial.color;

        color.a = _hoverBlockMaterial.color.a;
        _hoverBlockMaterial.color        = color;
        _activeBorder.transform.position = _woodBlock.transform.position;
    }
    /// <summary>
    /// Creates a button for selecting a tile of the given type, in the tile selection menu (blockButtonPanel)
    /// </summary>
    private void CreateNewBlockButton(Block.BlockType type)
    {
        ButtonManager newButton = Instantiate(buttonPrefab) as ButtonManager;

        newButton.transform.SetParent(blockButtonPanel.transform);
        newButton.image.sprite = Block.GetSprite(type);
        newButton.text.text    = "";
        newButton.button.onClick.AddListener(() => SetType(type));
    }
Beispiel #36
0
 /// <summary>
 /// Applies proper checks before looking at Block.
 /// </summary>
 /// <returns>Returns 1 if block is around it of correct type</returns>
 /// <param name="temp"> The Block being looked at.</param>
 /// <param name="compare"> Checking if the temp Block is of type compare.</param>
 private int getBlockType(Block temp, Block.BlockType compare)
 {
     if (temp != null)
     {
         if (temp.Type == compare)
         {
             return(1);
         }
     }
     return(0);
 }
Beispiel #37
0
 // the only public function, generic getter for uvs for any blockType and any direction quad
 public static Vector2[] GetUVs(Block.BlockType blockType, Vector3 direction)
 {
     if (blockType == Block.BlockType.GRASS)
     {
         return(GetGrassUVsByDirection(direction));
     }
     else
     {
         return(GetUniformBlockUVs(blockType));
     }
 }
Beispiel #38
0
    public IEnumerator Flow(Block block, Block.BlockType blockType, int strength, int maxsize)
    {
        if (maxsize <= 0)
        {
            yield break;
        }
        if (block == null)
        {
            yield break;
        }
        if (strength <= 0)
        {
            yield break;
        }
        if (block.blockType != Block.BlockType.air)
        {
            yield break;
        }

        block.SetType(blockType);
        block.currHealth = strength;
        block.owner.ReDraw();

        yield return(new WaitForSeconds(1));

        int x = (int)block.position.x;
        int y = (int)block.position.y;
        int z = (int)block.position.z;

        Block below = block.GetBlock(x, y - 1, z);

        if (below != null && below.blockType == Block.BlockType.air)
        {
            StartCoroutine(Flow(below, blockType, strength, --maxsize));
            yield break;
        }
        else
        {
            --strength;
            --maxsize;

            World.coroutineQueue.Run(Flow(block.GetBlock(x - 1, y, z), blockType, strength, maxsize));
            yield return(new WaitForSeconds(1));

            World.coroutineQueue.Run(Flow(block.GetBlock(x + 1, y, z), blockType, strength, maxsize));
            yield return(new WaitForSeconds(1));

            World.coroutineQueue.Run(Flow(block.GetBlock(x, y, z - 1), blockType, strength, maxsize));
            yield return(new WaitForSeconds(1));

            World.coroutineQueue.Run(Flow(block.GetBlock(x, y, z + 1), blockType, strength, maxsize));
            yield return(new WaitForSeconds(1));
        }
    }
Beispiel #39
0
        internal BlockItem(ref Coords coords, Block.BlockType blockType, Vector3? velocity = null, int id = -1)
            : base(ref coords, GameItemType.BlockItem, true, velocity, id)
        {
            Coords.Xf = (float)Math.Floor(Coords.Xf) + Constants.HALF_BLOCK_SIZE; //spawn in the middle of the block
            Coords.Yf += Constants.HALF_BLOCK_SIZE;
            Coords.Zf = (float)Math.Floor(Coords.Zf) + Constants.HALF_BLOCK_SIZE;
            if (!Coords.IsValidItemLocation) throw new Exception(string.Format("Invalid BlockItem location: {0}", Coords));

            switch (blockType)
            {
                case Block.BlockType.Grass:
                case Block.BlockType.Snow:
                    BlockType = Block.BlockType.Dirt;
                    break;
                default:
                    BlockType = blockType;
                    break;
            }
        }
Beispiel #40
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Position1 = new Position(bytes, 0);
                    Position2 = new Position(bytes, Position.SIZE);
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Position.SIZE * 2);
                }
            }

            WorldData.PlaceCuboid(Position1, Position2, BlockType);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddCuboid(Position1, Position2, BlockType) { ConnectedPlayer = player }.Send();
                }
            }
            else
            {
                //play the sound relative to the closer of the 2 diagonal corners (accurate enough for cuboids, otherwise we would have to check around the entire perimeter)
                var playerPosition = Game.Player.Coords.ToPosition();
                if (Position1.GetDistanceExact(ref playerPosition) < Position2.GetDistanceExact(ref playerPosition))
                {
                    Sounds.Audio.PlaySound(Sounds.SoundType.AddBlock, ref Position1);
                }
                else
                {
                    Sounds.Audio.PlaySound(Sounds.SoundType.AddBlock, ref Position2);
                }
            }
        }
Beispiel #41
0
 internal BlockItem(XmlNode xmlNode)
     : base(xmlNode)
 {
     if (xmlNode.Attributes == null) throw new Exception("Node attributes is null.");
     BlockType = (Block.BlockType)int.Parse(xmlNode.Attributes["BT"].Value);
 }