private void runCollisions()
 {
     for (double movement = Math.Sqrt(ball.vel.X * ball.vel.X + ball.vel.Y * ball.vel.Y); movement > 0; movement -= PADDLEHEIGHT)
     {
         ball.limitedMove(PADDLEHEIGHT);
         if (ball.loc.Y > screenHeight - Ball.BALL_RADIUS)
         {
             ball            = newBall(screenWidth, screenHeight);
             paddle          = newPaddle(screenWidth, screenHeight);
             gameState.lives = gameState.lives - 1;
             if (gameState.lives < 0)
             {
                 resetGame();
                 return;
             }
         }
         ball.collideOutside(paddle.getCollisionBox());
         List <Block> removals = new List <Block>();
         foreach (Block block in blocks)
         {
             if (ball.collideOutside(block.getCollisionBox()) && block.isDestroyable)
             {
                 removals.Add(block);
                 gameState.score = gameState.score + POINTS_PER_BLOCK;
                 paddle          = new Block((int)(paddle.width * .99), paddle.height, paddle.loc, paddle.isDestroyable);
             }
         }
         blocks.RemoveAll(i => removals.Contains(i));
         if (blocks.Count == 0)
         {
             blocks = BlockLayer.randomBlocks(screenWidth, screenHeight);
         }
         ball.collideInside(new Rect(0, 0, screenWidth, screenHeight));
     }
 }
Ejemplo n.º 2
0
        public void InitOverlay(
            IDictionary <XBlock, BoolSimulation> simulations,
            IBoolSimulationRenderer cacheRenderer)
        {
            SelectionReset();

            OverlayLayer.EnableSimulationCache = true;
            OverlayLayer.CacheRenderer         = null;

            foreach (var simulation in simulations)
            {
                BlockLayer.Hidden.Add(simulation.Key);
                OverlayLayer.Shapes.Add(simulation.Key);
            }

            EditorLayer.Simulations  = simulations;
            OverlayLayer.Simulations = simulations;

            OverlayLayer.CacheRenderer    = cacheRenderer;
            cacheRenderer.Renderer        = OverlayLayer.Renderer;
            cacheRenderer.NullStateStyle  = OverlayLayer.NullStateStyle;
            cacheRenderer.TrueStateStyle  = OverlayLayer.TrueStateStyle;
            cacheRenderer.FalseStateStyle = OverlayLayer.FalseStateStyle;
            cacheRenderer.Shapes          = OverlayLayer.Shapes;
            cacheRenderer.Simulations     = OverlayLayer.Simulations;

            BlockLayer.InvalidateVisual();
            OverlayLayer.InvalidateVisual();
        }
Ejemplo n.º 3
0
    void update()
    {
        Node           generator    = (Node)GetParent().Get("generator_node");
        List <Vector2> renderChunks = get_render_chunks();

        foreach (Vector2 chunkPos in renderChunks)
        {
            if (oldRenderChunks.Contains(chunkPos))
            {
                oldRenderChunks.Remove(chunkPos);
                continue;
            }

            if (!chunks.ContainsKey(chunkPos))
            {
                generateChunk(chunkPos, generator);
            }

            update_chunk(chunkPos);
        }

        foreach (Vector2 chunk in oldRenderChunks)
        {
            for (int z = 0; z < layer_nodes.Count; z++)
            {
                BlockLayer layer = (BlockLayer)layer_nodes[z];
                layer.clear_chunk(new Rect2(chunk * chunk_size, chunk_size));
            }
        }

        oldRenderChunks = renderChunks;
    }
Ejemplo n.º 4
0
        public void InvalidateLayers()
        {
            if (ShapeLayer.InvalidateVisual != null)
            {
                ShapeLayer.InvalidateVisual();
            }

            if (BlockLayer.InvalidateVisual != null)
            {
                BlockLayer.InvalidateVisual();
            }

            if (PinLayer.InvalidateVisual != null)
            {
                PinLayer.InvalidateVisual();
            }

            if (WireLayer.InvalidateVisual != null)
            {
                WireLayer.InvalidateVisual();
            }

            if (OverlayLayer.InvalidateVisual != null)
            {
                OverlayLayer.InvalidateVisual();
            }
        }
Ejemplo n.º 5
0
        public void ReadFlatOption()
        {
            if (!string.IsNullOrEmpty(this.FlatOptionsString))
            {
                try
                {
                    this.flatOption = new FlatOptions();
                    string[] args = this.FlatOptionsString.Split(';');
                    if (args.Length > 1)
                    {
                        this.flatOption.version = int.Parse(args[0]);

                        string[]    layerData = args[1].Split(',');//support format <2*1:0> or <minecraft:stone:1>
                        BlockLayers layers    = this.flatOption.blockLayers = new BlockLayers();
                        for (int i = 0; i < layerData.Length; ++i)
                        {
                            string[] blockData = layerData[i].Split('*');
                            if (blockData.Length == 2)
                            {
                                int        layerCount = int.Parse(blockData[0]);
                                BlockLayer layer      = new BlockLayer();
                                layer.block  = Block.Get(blockData[1]);
                                layer.height = layerCount;
                                layers.layers.Add(layer);
                            }
                            else if (blockData.Length == 1)
                            {
                                BlockLayer layer = new BlockLayer();
                                layer.block  = Block.Get(blockData[0]);
                                layer.height = 1;
                                layers.layers.Add(layer);
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (layers.layers.Count == 0)
                        {
                            Logger.Notice("FlatOptions Error");
                            this.flatOption = null;
                        }
                    }
                    else
                    {
                        Logger.Notice("FlatOptions Error");
                        this.flatOption = null;
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                    Logger.Notice("FlatOptions Error");
                    this.flatOption = null;
                }
            }
        }
Ejemplo n.º 6
0
    // --- TileMap ---

    public void update_chunk(Vector2 chunkPos)
    {
        for (int z = 0; z < layer_nodes.Count; z++)
        {
            BlockLayer layer = (BlockLayer)layer_nodes[z];
            Rect2      chunk = new Rect2(chunkPos * chunk_size, chunk_size);
            layer.update_chunk(chunk, chunks[chunkPos], z);
        }
    }
Ejemplo n.º 7
0
        public override void GenerationBasicTerrain(Chunk chunk)
        {
            if (this.flatOption != null)
            {
                BlockLayers layers = this.flatOption.blockLayers;
                for (int i = 0; i < 16; ++i)     //X
                {
                    for (int j = 0; j < 16; ++j) //Z
                    {
                        int y = 0;
                        for (int c = 0; c < layers.layers.Count; ++c)
                        {
                            BlockLayer layer = layers.layers[c];
                            for (int k = 0; k < layer.height; ++k)//Y
                            {
                                if (World.MAX_HEIGHT == y)
                                {
                                    Logger.Warn("World MaxHeight 256");
                                    break;
                                }
                                chunk.SetBlock(i, y, j, (byte)layer.block.ID);
                                chunk.SetMetadata(i, y, j, (byte)layer.block.Damage);
                                chunk.SetBiome(i, j, BiomeIDs.Plains);
                                y++;
                            }
                        }
                    }
                }
            }
            else
            {
                SubChunk flat = new SubChunk();
                for (int i = 0; i < 16; ++i)         //X
                {
                    for (int j = 0; j < 16; ++j)     //Z
                    {
                        for (int k = 0; k < 16; ++k) //Y
                        {
                            if (k == 0)
                            {
                                flat.SetBlock(i, k, j, 7);
                            }
                            else if (k == 1 || k == 2)
                            {
                                flat.SetBlock(i, k, j, 3);
                            }
                            else if (k == 3)
                            {
                                flat.SetBlock(i, k, j, 2);
                            }
                        }
                    }
                }

                chunk.SubChunks[0] = flat;
            }
        }
Ejemplo n.º 8
0
    void OnGUI()
    {
        obj = (BlockLayer)EditorGUI.ObjectField(new Rect(3, 6, position.width - 6, 20), "Layer", obj, typeof(BlockLayer), true);

        if (obj != null)
        {
            selectedTileX = EditorGUI.IntField(new Rect(3, 26, position.width - 6, 20), "Selected Tile X", obj.selectedX);
            selectedTileY = EditorGUI.IntField(new Rect(3, 46, position.width - 6, 20), "Selected Tile Y", obj.selectedY);

            EditorGUI.LabelField(new Rect(3, 66, position.width - 6, 20), "Initial X: " + obj.initX);
            EditorGUI.LabelField(new Rect(3, 86, position.width - 6, 20), "Initial Y: " + obj.initY);
            EditorGUI.LabelField(new Rect(3, 106, position.width - 6, 20), "Final X: " + obj.endX);
            EditorGUI.LabelField(new Rect(3, 126, position.width - 6, 20), "Final Y: " + obj.endY);

            if (selectedTileX >= 0 && selectedTileX < obj.width && selectedTileY >= 0 && selectedTileY < obj.height)
            {
                if (obj.map == null)
                {
                    obj.map = new int[obj.width * obj.height];

                    for (int i = 0; i < obj.width; i++)
                    {
                        for (int j = 0; j < obj.height; j++)
                        {
                            obj.map[i + (obj.width * j)] = -1;
                        }
                    }
                }

                if (obj.state == 2)
                {
                    int maxX = Mathf.Max(obj.initX, obj.endX);
                    int maxY = Mathf.Max(obj.initY, obj.endY);

                    string[] blocksTypes = new string[BlockLayer.AllBlocks.Length + 1];

                    blocksTypes[0] = "Empty Block";

                    for (int i = 1; i < blocksTypes.Length; i++)
                    {
                        blocksTypes[i] = BlockLayer.AllBlocks[i - 1].BlockName;
                    }

                    lastBlock = EditorGUI.Popup(new Rect(3, 186, 300, 20), lastBlock, blocksTypes);

                    for (int i = Mathf.Min(obj.initX, obj.endX); i <= maxX; i++)
                    {
                        for (int j = Mathf.Min(obj.initY, obj.endY); j <= maxY; j++)
                        {
                            obj.map[i + (obj.width * j)] = lastBlock - 1;
                        }
                    }
                }
            }
        }
    }
        private void resetGame()
        {
            gameState = new GameState
            {
                score = 0,
                lives = START_LIVES
            };

            blocks = BlockLayer.randomBlocks(screenWidth, screenHeight);
        }
Ejemplo n.º 10
0
        public void ResetOverlay()
        {
            EditorLayer.Simulations    = null;
            OverlayLayer.Simulations   = null;
            OverlayLayer.CacheRenderer = null;

            BlockLayer.Hidden.Clear();
            OverlayLayer.Shapes.Clear();
            BlockLayer.InvalidateVisual();
            OverlayLayer.InvalidateVisual();
        }
Ejemplo n.º 11
0
    public void update_visible_chunks(int z)
    {
        List <Vector2> render_chunks = get_render_chunks();

        foreach (Vector2 chunkPos in render_chunks)
        {
            BlockLayer layer = (BlockLayer)layer_nodes[z];
            Rect2      chunk = new Rect2(chunkPos * chunk_size, chunk_size);
            if (!chunks.ContainsKey(chunkPos))
            {
                continue;
            }
            layer.update_chunk(chunk, chunks[chunkPos], z);
        }
    }
Ejemplo n.º 12
0
        private bool isAppropriateClimateToGrow(IWorldAccessor world, BlockPos pos, AssetLocation blockCode, ClimateCondition climate)
        {
            ICoreServerAPI api       = (ICoreServerAPI)world.Api;
            int            mapheight = api.WorldManager.MapSizeY;

            BlockLayers layers = getBlockLayers(world);
            BlockLayer  bl     = layers.GetBlockLayerForNextGrowthStage(world, blockCode);

            //Check climate conditions to see whether the soil can grow to the next stage
            return(
                climate.Temperature >= bl.MinTemp && climate.Temperature <= bl.MaxTemp &&
                climate.Rainfall >= bl.MinRain && climate.Rainfall <= bl.MaxRain &&
                climate.Fertility >= bl.MinFertility && climate.Fertility <= bl.MaxFertility &&
                (float)pos.Y / mapheight <= bl.MaxY
                );
        }
Ejemplo n.º 13
0
    /// <summary>
    /// Builds the mesh using 4 vertices and 2 triangles per face
    /// </summary>
    private void BuildMesh(Chunk chunk, BlockLayer layer)
    {
        //get this chunks mesh buffer
        MeshBuffer buffer = chunk.GetMeshBuffer(layer);

        // Request the lock, and block until it is obtained.
          	Monitor.Enter(buffer);

        //clear the mesh buffer to store our vertices and triangles
        buffer.Clear();

        for (int x=0; x<chunk.width; x++)
        {
            for (int y=0; y<chunk.height; y++)
            {
                for (int z=0; z<chunk.length; z++)
                {
                    if (chunk[x,y,z] != BlockType.AIR) {

                        if (x + chunk.x == 0 || chunk[x-1, y, z] == BlockType.AIR)
                            buffer.AddFace(FACE.LEFT, x,y,z, chunk[x,y,z]);

                        if (x + chunk.x == chunk.world.width-1 || chunk[x+1, y, z] == BlockType.AIR)
                            buffer.AddFace(FACE.RIGHT, x,y,z, chunk[x,y,z]);

                        if (y + chunk.y == 0 || chunk[x, y-1, z] == BlockType.AIR)
                            buffer.AddFace(FACE.BOTTOM, x,y,z, chunk[x,y,z]);

                        if (y + chunk.y == chunk.world.height-1 || chunk[x, y+1, z] == BlockType.AIR)
                            buffer.AddFace(FACE.TOP, x,y,z, chunk[x,y,z]);

                        if (z + chunk.z == 0 || chunk[x, y, z-1] == BlockType.AIR)
                            buffer.AddFace(FACE.FRONT, x,y,z, chunk[x,y,z]);

                        if (z + chunk.z == chunk.world.length-1 || chunk[x, y, z+1] == BlockType.AIR)
                            buffer.AddFace(FACE.BACK, x,y,z, chunk[x,y,z]);
                    }
                }
            }
        }

        // make sure the chunk knows to assign the mesh data
        buffer.SetGenerated();

        // Ensure that the lock is released.
        Monitor.Exit(buffer);
    }
Ejemplo n.º 14
0
    public async override void _Ready()
    {
        layer = GetParentOrNull <BlockLayer>();
        if (layer == null)
        {
            GD.PushError("BlockFluid node [" + Name + "] is not a child of BlockLayer.");
        }

        await ToSignal(layer.GetParent(), "finished_setup");

        data_node = (BlockData)(layer.GetParent().Get("data_node"));

        ThreadStart threadStart = new ThreadStart(SimThread);

        thread = new System.Threading.Thread(threadStart);
        thread.Start();
    }
Ejemplo n.º 15
0
        protected int getClimateSuitedGrowthStage(IWorldAccessor world, BlockPos pos, ClimateCondition climate)
        {
            if (climate == null)
            {
                return(CurrentStage());                  // Can occasionally be null, e.g. during running /wgen regen command
            }
            ICoreServerAPI api            = (ICoreServerAPI)world.Api;
            int            mapheight      = api.WorldManager.MapSizeY;
            float          transitionSize = blocklayerconfig.blockLayerTransitionSize;

            for (int j = 0; j < blocklayerconfig.Blocklayers.Length; j++)
            {
                BlockLayer bl = blocklayerconfig.Blocklayers[j];

                float tempDist = Math.Abs(climate.Temperature - GameMath.Clamp(climate.Temperature, bl.MinTemp, bl.MaxTemp));
                float rainDist = Math.Abs(climate.WorldgenRainfall - GameMath.Clamp(climate.WorldgenRainfall, bl.MinRain, bl.MaxRain));
                float fertDist = Math.Abs(climate.Fertility - GameMath.Clamp(climate.Fertility, bl.MinFertility, bl.MaxFertility));
                float yDist    = Math.Abs((float)pos.Y / mapheight - GameMath.Min((float)pos.Y / mapheight, bl.MaxY));

                double posRand = (double)GameMath.MurmurHash3(pos.X, 1, pos.Z) / int.MaxValue;
                posRand = (posRand + 1) * transitionSize;

                if (tempDist + rainDist + fertDist + yDist <= posRand)
                {
                    IMapChunk mapchunk = world.BlockAccessor.GetMapChunkAtBlockPos(pos);
                    if (mapchunk == null)
                    {
                        return(0);
                    }

                    int topblockid = mapchunk.TopRockIdMap[(pos.Z % chunksize) * chunksize + (pos.X % chunksize)];
                    int blockId    = bl.GetBlockId(posRand, climate.Temperature, climate.WorldgenRainfall, climate.Fertility, topblockid);

                    Block block = world.Blocks[blockId];
                    if (block is BlockSoil)
                    {
                        return((block as BlockSoil).CurrentStage());
                    }
                }
            }

            return(0);
        }
Ejemplo n.º 16
0
            private void InitBlockLayers(IWorldAccessor world, BlockLayer parentBlockLayer)
            {
                foreach (BlockLayerCodeByMin blockLayerCodeByMin in parentBlockLayer.BlockCodeByMin)
                {
                    BlockLayer layer = new BlockLayer
                    {
                        MinFertility = blockLayerCodeByMin.MinFertility,
                        MaxFertility = blockLayerCodeByMin.MaxFertility,
                        MinRain      = blockLayerCodeByMin.MinRain,
                        MaxRain      = parentBlockLayer.MaxRain,
                        MinTemp      = (int)blockLayerCodeByMin.MinTemp,
                        MaxTemp      = parentBlockLayer.MaxTemp,
                        MaxY         = blockLayerCodeByMin.MaxY,
                        BlockCode    = blockLayerCodeByMin.BlockCode
                    };

                    layers.Add(blockLayerCodeByMin.BlockCode, layer);
                }
            }
Ejemplo n.º 17
0
    public override void _Ready()
    {
        layer_nodes.Clear();
        uint i = 0;

        foreach (Node node in GetParent().GetChildren())
        {
            string     name  = node.Name;
            BlockLayer child = GetParent().GetNodeOrNull <BlockLayer>(name);
            if (child != null)
            {
                layer_nodes.Add(child);
                child.Id = i;
            }
            i++;
        }

        update();
    }
Ejemplo n.º 18
0
    public override void _Process(float delta)
    {
        if (Engine.EditorHint)
        {
            layer_nodes.Clear();
            uint i = 0;
            foreach (Node node in GetParent().GetChildren())
            {
                string     name  = node.Name;
                BlockLayer child = GetParent().GetNodeOrNull <BlockLayer>(name);
                if (child != null)
                {
                    layer_nodes.Add(child);
                    child.Id = i;
                }
                i++;
            }
        }

        update();
    }
Ejemplo n.º 19
0
        //make capcom screen image
        public Bitmap makeScreen(int scrNo, int levelNo, int videoNo, int bigBlockNo, int blockNo, int palleteNo, bool withBorders = true)
        {
            if (scrNo < 0)
            {
                return(VideoHelper.emptyScreen((int)(ConfigScript.getScreenWidth(levelNo) * 32), (int)(ConfigScript.getScreenHeight(levelNo) * 32)));
            }
            var bigBlocks = makeBigBlocks(videoNo, bigBlockNo, blockNo, palleteNo, MapViewType.Tiles, MapViewType.Tiles);

            //var bigBlocks = makeBigBlocks(videoNo, bigBlockNo, blockNo, palleteNo, MapViewType.ObjType,MapViewType.Tiles, withBorders);
            int[] indexes = Globals.getScreen(ConfigScript.screensOffset[levelNo], scrNo);
            int   scrW    = ConfigScript.getScreenWidth(0); //zero as screenNoForLevel
            int   scrH    = ConfigScript.getScreenHeight(0);
            //capcom hardcode

            var blockLayer1 = new BlockLayer()
            {
                screens = new int[1][] { indexes }, showLayer = true, blockWidth = 32, blockHeight = 32
            };

            return(new Bitmap(MapEditor.ScreenToImage(bigBlocks, new BlockLayer[] { blockLayer1 }, 0, 2.0f, false, 0, 0, scrW, scrH)));
        }
Ejemplo n.º 20
0
    public void CustomizePrefab(GameObject prefab)
    {
        prefab.AddComponent <BlockLayer>();

        l = prefab.GetComponent <BlockLayer>();

        TiledMap tm = prefab.GetComponent <TiledMap>();

        BlockLayer.BlockSize = tm.TileHeight;

        l.width  = tm.NumTilesWide;
        l.height = tm.NumTilesHigh;

        l.map = new int[l.width * l.height];

        for (int i = 0; i < l.width; i++)
        {
            for (int j = 0; j < l.height; j++)
            {
                l.map[i + (l.width * j)] = -1;
            }
        }
    }
Ejemplo n.º 21
0
 // condition for when we should draw a face
 // the block is not rendered OR its a transparent block from another render layer
 private static bool ShouldDrawFace(BlockType type, BlockLayer layer)
 {
     return !Block.IsRendered(type) || (!Block.IsOpaque(type) && Block.RenderLayer(type) != layer);
 }
Ejemplo n.º 22
0
 public void Build(List<Chunk> chunks, BlockLayer layer, Action<Chunk> completion)
 {
     //process each chunk seperately
     _processor.Spawn(chunks, BuildMesh, layer, false, completion);
 }
Ejemplo n.º 23
0
    public override void Left(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.XSpeed - l.XSpeed <= 0)
        {
            return;
        }

        float bx = GetX(x, l);

        float cx = contactPoint.position.x;

        float dx = cx - bx;

        target.X -= dx;

        target.BlockedFromRight = true;

        target.XSpeed = 0;
    }
Ejemplo n.º 24
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.XSpeed - l.XSpeed >= 0)
        {
            return;
        }

        float bx = GetX(x, l);

        float cx = contactPoint.position.x;

        float dx = bx + BlockLayer.BlockSize - cx;

        target.X += dx;

        target.BlockedFromLeft = true;

        target.XSpeed = 0;
    }
Ejemplo n.º 25
0
 public BlockLayers(IWorldAccessor world, string blockLayerId)
 {
     blockLayerConfig = BlockLayerConfig.GetInstance((ICoreServerAPI)world.Api);
     blockLayer       = blockLayerConfig.GetBlockLayerById(world, blockLayerId);
     InitBlockLayers(world, blockLayer);
 }
Ejemplo n.º 26
0
    public override void Up(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.YSpeed - l.YSpeed >= 0)
        {
            return;
        }

        float by = GetY(y, l);

        float cy = contactPoint.position.y;

        float dy = cy - (by + BlockLayer.BlockSize);

        target.BlockedFromBelow = true;

        if (!target.BlockedAngleDetector)
        {
            target.Y -= dy;
        }
    }
Ejemplo n.º 27
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (angle <= 0 && target.XSpeed >= 0)
        {
            return;
        }
        if (angle >= 0 && target.XSpeed <= 0)
        {
            return;
        }
        float by       = GetY(y, l);
        float contactY = contactPoint.position.y;

        if (contactY < by + y2)
        {
            base.Right(target, contactPoint, x, y, l);
        }
    }
Ejemplo n.º 28
0
 public override void Down(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
 {
     if (angle != 0)
     {
         return;
     }
     base.Down(target, contactPoint, x, y, l);
 }
Ejemplo n.º 29
0
 public void SetMeshBuffer(BlockLayer layer, MeshBuffer buffer)
 {
     _meshBuffers[(int)layer] = buffer;
 }
Ejemplo n.º 30
0
    public override void Up(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float ny = GetY(y, l) + BlockLayer.BlockSize;

        int b = l.getBlock(contactPoint.position.x, ny);

        if (b >= 0)
        {
            BlockLayer.AllBlocks[b].Up(target, contactPoint, x, l.getYPos(ny), l);
        }
    }
Ejemplo n.º 31
0
        private void LoadBlockLayers(double posRand, float rainRel, float temperature, int unscaledTemp, int posY, int firstBlockId)
        {
            float heightRel    = ((float)posY - TerraGenConfig.seaLevel) / ((float)api.WorldManager.MapSizeY - TerraGenConfig.seaLevel);
            float fertilityRel = TerraGenConfig.GetFertilityFromUnscaledTemp((int)(rainRel * 255), unscaledTemp, heightRel) / 255f;



            float depthf = TerraGenConfig.SoilThickness(rainRel, temperature, posY - TerraGenConfig.seaLevel, 1f);
            int   depth  = (int)depthf;

            depth += (int)((depthf - depth) * rnd.NextDouble());

            BlockLayersIds.Clear();
            for (int j = 0; j < blockLayerConfig.Blocklayers.Length; j++)
            {
                BlockLayer bl = blockLayerConfig.Blocklayers[j];

                float tempDist = Math.Abs(temperature - GameMath.Clamp(temperature, bl.MinTemp, bl.MaxTemp));
                float rainDist = Math.Abs(rainRel - GameMath.Clamp(rainRel, bl.MinRain, bl.MaxRain));
                float fertDist = Math.Abs(fertilityRel - GameMath.Clamp(fertilityRel, bl.MinFertility, bl.MaxFertility));
                float yDist    = Math.Abs((float)posY / mapheight - GameMath.Min((float)posY / mapheight, bl.MaxY));


                if (tempDist + rainDist + fertDist + yDist <= posRand)
                {
                    int blockId = bl.GetBlockId(posRand, temperature, rainRel, fertilityRel, firstBlockId);
                    if (blockId != 0)
                    {
                        BlockLayersIds.Add(blockId);

                        // Would be correct, but doesn't seem to cause noticable problems
                        // so lets not add it for faster chunk gen
                        posY--;
                        temperature = TerraGenConfig.GetScaledAdjustedTemperatureFloat(unscaledTemp, posY - TerraGenConfig.seaLevel);
                        //  rainRel = TerraGenConfig.GetRainFall(unscaledRain, posY) / 255f;
                        heightRel    = ((float)posY - TerraGenConfig.seaLevel) / ((float)api.WorldManager.MapSizeY - TerraGenConfig.seaLevel);
                        fertilityRel = TerraGenConfig.GetFertilityFromUnscaledTemp((int)(rainRel * 255), unscaledTemp, heightRel) / 255f;
                    }
                }

                if (BlockLayersIds.Count >= depth)
                {
                    break;
                }
            }


            layersUnderWater = null;
            for (int j = 0; j < blockLayerConfig.LakeBedLayer.BlockCodeByMin.Length; j++)
            {
                LakeBedBlockCodeByMin lbbc = blockLayerConfig.LakeBedLayer.BlockCodeByMin[j];
                if (lbbc.Suitable(temperature, rainRel, (float)posY / api.WorldManager.MapSizeY, rnd))
                {
                    layersUnderWater = new int[] { lbbc.GetBlockForMotherRock(firstBlockId) };
                    break;
                }
            }
            if (layersUnderWater == null)
            {
                layersUnderWater = new int[0];
            }
        }
Ejemplo n.º 32
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float nx = GetY(x, l) + BlockLayer.BlockSize;

        int b = l.getBlock(nx, contactPoint.position.y);

        if (b >= 0)
        {
            BlockLayer.AllBlocks[b].AngleDetector(target, contactPoint, l.getXPos(nx), y, l);
        }
    }
Ejemplo n.º 33
0
    public override void Up(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.BlockedAngleDetector)
        {
            return;
        }
        float contactX = contactPoint.position.x;
        float contactY = contactPoint.position.y;
        float bx       = GetX(x, l);
        float by       = GetY(y, l);

        if (contactX < bx + x1)
        {
            if (contactY <= by + y1)
            {
                base.Up(target, contactPoint, x, y, l);
            }
        }
        else if (contactX > bx + x2)
        {
            if (contactY <= by + y2)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
    }
Ejemplo n.º 34
0
    public override void AngleDetector(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float contactX = contactPoint.position.x;
        float contactY = contactPoint.position.y;
        float bx       = GetX(x, l);
        float by       = GetY(y, l);

        if (contactX < bx + x1)
        {
            if (contactY <= by + y1)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
        else if (contactX > bx + x2)
        {
            if (contactY <= by + y2)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
        else
        {
            float dy = m * (contactX - (bx + x1)) + (by + y1) - contactY;

            if (dy > 0 || target.GuidedByTerrain)
            {
                target.Y += dy;
                target.BlockedAngleDetector = true;
                target.TerrainAngle         = angle;
                target.BlockedFromBelow     = true;
            }
        }
    }
Ejemplo n.º 35
0
 public MeshBuffer GetMeshBuffer(BlockLayer layer)
 {
     return _meshBuffers[(int)layer];
 }