Пример #1
0
    public override bool PlantOn(IntVector3 blockPos)
    {
        Tuple <IntVector3, byte>[] treeBlocks = new Tuple <IntVector3, byte> [48];
        for (int i = 0; i < 48; i++)
        {
            treeBlocks[i] = Tuple.Create(blockPos + treeBlockVectors[i].Item1, treeBlockVectors[i].Item2);
        }

        if (!CanGrowOn(blockPos))
        {
            return(false);
        }

        terrain.SetBlocks(treeBlocks);
        plantBlocks.Add(blockPos);
        Tuple <int, int> gridPos = Tuple.Create(blockPos.x / GRID_SIZE, blockPos.z / GRID_SIZE);

        if (!grid.ContainsKey(gridPos))
        {
            grid[gridPos] = new List <IntVector3>();
        }
        grid[gridPos].Add(blockPos);

        CollisionShape collisionShape = new CollisionShape();
        BoxShape       b = new BoxShape();

        b.SetExtents(new Vector3(Block.SIZE * 3.0f, 4.0f * Block.SIZE, Block.SIZE * 3.0f)); //trees are 8ish blocks tall
        collisionShape.SetShape(b);

        PhysicsBody physicsBody = new StaticBody();

        physicsBody.AddToGroup("plants");
        physicsBody.AddToGroup("alive");


        //Don't collide with player
        physicsBody.SetCollisionLayerBit(0, false);
        physicsBody.SetCollisionMaskBit(0, false);

        //But still collide with giants
        physicsBody.SetCollisionLayerBit(2, true);

        //And still get picked up by the giant areas
        physicsBody.SetCollisionMaskBit(31, true);

        Vector3 position = (blockPos + new Vector3(0, 5, 0)) * Block.SIZE + new Vector3(0, 5, 0); //the plus 5 to make it actually seen

        physicsBody.SetTranslation(position);

        physicsBody.AddChild(collisionShape);

        physicsBodies[blockPos] = physicsBody;
        plants.AddChild(physicsBody);

        return(true);
    }
Пример #2
0
        public Chunk(int x, int y)
        {
            _x = x; _y = y;

            mi = new MeshInstance();
            AddChild(mi);
            cs  = new CollisionShape();
            ccs = new ConcavePolygonShape();
            cs.SetShape(ccs);
            AddChild(cs);
        }