Пример #1
0
        //private static Vector2[] uv = new Vector2[]{new Vector2(1,0), new Vector2(0,0), new Vector2(0,1), new Vector2(1,1)};
        public List<Vertex> GetVertices(OctreeNode node, Block block, Chunk chunk, World world)
        {
            List<Vertex> vertices = new List<Vertex>();

            int x = (int)(chunk.GetWorldLocation().X + node.origin.X),
                y = (int)(chunk.GetWorldLocation().Y + node.origin.Y),
                z = (int)(chunk.GetWorldLocation().Z + node.origin.Z);

            for(int face = 0; face < 6; face++){
                Vector2[] uv = block.GetUV(face);
                Block block2 = world.GetBlock(x + (addsX[face] * node.blockSize), y + (addsX[face + 6] * node.blockSize), z + (addsX[face + 12] * node.blockSize));
                if(!block2.material.solid)
                {
                    int baseCorner = face * 4;
                    for(int corner = 0; corner < 4; corner++){
                        Vertex vertex = new Vertex(corners[quadsOrder[baseCorner + corner]] * node.blockSize);
                        vertex.position += node.origin - new Vector3(node.blockSize / 2f, node.blockSize / 2f, node.blockSize / 2f);
                        vertex.color = block.material.color * brightness[face];
                        vertex.normal.X = node.blockSize;
                        vertex.normal.Y = block.GetSheetX(face);
                        vertex.normal.Z = block.GetSheetY(face);
                        vertex.texCoord = uv[corner];
                        vertices.Add(vertex);
                        triangles += 2;
                    }
                }
            }
            return vertices;
        }
Пример #2
0
 public void CheckBlock(int x, int y, int z, int addX, int addY, int addZ, Block otherblock, World world)
 {
     Block other = world.GetBlock (x + addX, y + addY, z + addZ);
     if (other == Block.empty) {
         world.SetBlockSilent (x + addX, y + addY, z + addZ, Block.water);
         world.AddToUpdateQueue (x + addX, y + addY, z + addZ, x, y, z, otherblock);
     }
 }
Пример #3
0
        public Chunk CreateChunk(int x, int y, int z, World world)
        {
            Chunk chunk = new Chunk(x, y, z, world);
            //if(world.chunkIO.ChunkExists(x, y, z))
            //	chunk = world.chunkIO.LoadChunk(x, y, z, world);
            //else
                chunk = world.generator.GenerateChunk(x, y, z);

            return chunk;
        }
Пример #4
0
 public static void PlaceFeatures(World world, Chunk chunk, int x, int z, int yLow, int yHigh)
 {
     if (ChunkPopulate != null) {
         for (int y = yLow; y <= yHigh; y++)
             ChunkPopulate (x, y, z, chunk);
     }
     if (WorldPopulate != null) {
         for (int y = yLow; y <= yHigh; y++)
             WorldPopulate (x, y, z);
     }
 }
Пример #5
0
 public NearbyUpdate(int x, int y, int z, int oriX, int oriY, int oriZ, Block block, World world)
 {
     this.x = x;
     this.y = y;
     this.z = z;
     this.oriX = oriX;
     this.oriY = oriY;
     this.oriZ = oriZ;
     this.block = block;
     this.world = world;
 }
Пример #6
0
        public override void OnNearbyBlockUpdate(int x, int y, int z, int otherX, int otherY, int otherZ, Block otherblock, World world)
        {
            base.OnNearbyBlockUpdate (x, y, z, otherX, otherY, otherZ, otherblock, world);

            for(int i = 0; i < 5; i++)
            {
                int x1 = checks[i], y1 = checks[i + 5], z1 = checks[i + 10];
                if(otherblock != Block.water || (x1 != otherX && y1 != otherY && z1 != otherZ))
                {
                    CheckBlock(x,y,z,x1,y1,z1, otherblock, world);
                }
            }
        }
Пример #7
0
        public Ball(World world)
        {
            this.world = world;

            location = new Vector3(-2, -2, -2);

            physics = new PhysicsComponent();
            physics.velocity = Vector3.Zero;
            physics.collisionObject.collisionBox = new CollisionBox();
            physics.collisionObject.collisionBox.size = new Vector3(half, half, half);
            physics.collisionObject.collisionBox.offset = new Vector3(0, 0, 0);

            camera = new CameraComponent();

            AddComponent(physics);
            AddComponent(camera);
        }
Пример #8
0
        public override void FirstLoad()
        {
            blockRenderer = new BlockRenderer ();

            sunLight = new Sun();
            sunLight.Setup(1024, 1024);
            sunImg = new Image(){
                texture = Texture2D.FromHandle(sunLight.TextureHandle),
                invertY = true,
                width = 256, height = 256, x = 0, y = 400
            };
            sunImg2 = new Image(){
                texture = new Texture2D(Forgottenvoxels.textureFolder + "sky/sun.png"),// = Texture2D.FromHandle(sunLight.TextureHandle),
                invertY = false,
                width = 256, height = 256, x = 0, y = 656
            };
            sunLight.UpdateSun(new Vector3(0, 0, 0), 0, 5000L);

            projTex = new Texture2D(Forgottenvoxels.textureFolder + "sky/sun.png");

            world = new World (Forgottenvoxels.saveFolder + "world1");
            hud = new GuiIngame ();

            blockTex = new Texture2D();
            blockTex.Image2D(new Bitmap(Forgottenvoxels.textureFolder + "terrain.png"));

            for (int i = 0; i < 32; i++) {
                for (int x = 0; x < i; x++)
                    for (int y = 1; y >= 0; y--)
                        for (int z = 0; z < i; z++)
                            if(!chunksWeWantToLoad.Contains(new Vector3 (x, y, z)))
                                chunksWeWantToLoad.Add (new Vector3 (x, y, z));
            }

            for(int i = 0; i < 16; i++){
                Vector3 vec = chunksWeWantToLoad[loadIndex];
                world.AddToLoadQueue(vec, true);
                loadIndex++;
            }

            //VertexBuffer.Upload(1);

            isLoadedOnce = true;
        }
Пример #9
0
        public Player(World world)
        {
            this.world = world;

            location = new Vector3(-2, -2, -2);

            physics = new PhysicsComponent();
            physics.velocity = Vector3.Zero;
            physics.collisionObject.collisionBox = new CollisionBox();
            physics.collisionObject.collisionBox.size = new Vector3(0.4f, 0.9f, 0.4f);
            physics.collisionObject.collisionBox.offset = new Vector3(0, -0.3f, 0);
            physics.flying = true;

            input = new InputComponent();
            input.Keypress += (e) => {
                Keypress(e.key);
            };
            input.Keydown += (e) => {
                Keydown(e.key);
            };
            input.Keyup += (e) => {
                Keyup(e.key);
            };

            camera = new CameraComponent();
            camera.MakeActive();

            target = new TargetblockComponent();
            target.LinkDependency(camera, out target.camera);

            AddComponent(physics);
            AddComponent(input);
            AddComponent(camera);
            AddComponent(target);
            AddComponent(new WorldloaderComponent());
        }
Пример #10
0
 public Chunk(int chunkX, int chunkY, int chunkZ, Block defaultBlock, World world)
 {
     Init (chunkX, chunkY, chunkZ, defaultBlock, world);
 }
Пример #11
0
 public Chunk(int chunkX, int chunkY, int chunkZ, World world)
 {
     Init (chunkX, chunkY, chunkZ, Block.empty, world);
 }
Пример #12
0
 private void Init(int chunkX, int chunkY, int chunkZ, Block defaultBlock, World world)
 {
     this.world = world;
     storage = new BlockStorage(scale, defaultBlock);
     renderer = new ChunkRenderer(this);
     chunkPos = new Vector3(chunkX, chunkY, chunkZ);
     worldPos = chunkPos * scale;
 }
Пример #13
0
 public virtual void OnNearbyBlockUpdate(int x, int y, int z, int otherX, int otherY, int otherZ, Block otherblock, World world)
 {
 }
Пример #14
0
        public static CollisionObject CollisionCheckWorld(Entity ent, World world, CollisionObject collisionObject)
        {
            List<CollisionObject> objects = new List<CollisionObject>();
            List<CollisionBox> boxes = new List<CollisionBox>();

            //The size of our search
            Vector3 addvec = (Vector3.One * 2);
            for(int x = (int)-addvec.X; x < (int)addvec.X; x++)
            {
                for(int y = (int)-addvec.Y; y < (int)addvec.Y; y++)
                {
                    for(int z = (int)-addvec.X; z < (int)addvec.Z; z++)
                    {
                        Block block = world.GetBlock(collisionObject.prePosition + new Vector3(x,y,z));
                        if(block.collide)
                            boxes.Add(world.GetCollisionBox(collisionObject.prePosition + new Vector3(x,y,z)));
                    }
                }
            }
            foreach(Entity e in EntityManager.instance.GetEntitiesInRadius(ent, collisionObject.prePosition, 2))
            {
                if(e.HasComponentOfType(typeof(PhysicsComponent)))
                {
                    PhysicsComponent physComponent = (PhysicsComponent)e.GetComponentOfType(typeof(PhysicsComponent));
                    CollisionObject collObj = physComponent.collisionObject;
                    objects.Add( collObj );
                }
            }
            return CollisionManager.Collision(collisionObject, objects.ToArray(), boxes.ToArray());
        }
Пример #15
0
 public override void OnNearbyBlockUpdate(int x, int y, int z, int otherX, int otherY, int otherZ, Block otherblock, World world)
 {
     base.OnNearbyBlockUpdate (x, y, z, otherX, otherY, otherZ, otherblock, world);
 }
Пример #16
0
        public WorldGenerator(Int32 seed, World world)
        {
            this.heightNoise = new PerlinNoise(seed);
            this.moistureNoise = new PerlinNoise(seed + 1);
            this.heatNoise = new PerlinNoise(seed + 2);

            this.features = new List<WorldFeature>();

            this.seed = seed;
            this.world = world;

            this.biomes = new List<Biome>();
            biomes.Add(new Biome(6, 3, 4, 3, Block.snow)); //SNOW
            biomes.Add(new Biome(6, 4, 3, 2, Block.dirt)); //TAIGA
            biomes.Add(new Biome(6, 5, 2, 1, Block.grass)); //TEMPERATE RAIN FOREST
            biomes.Add(new Biome(6, 4, 1, 0, Block.stone)); //TROPICAL RAIN FOREST

            biomes.Add(new Biome(3, 2, 4, 3, Block.snow)); //TUNDRA
            biomes.Add(new Biome(4, 2, 3, 2, Block.dirt)); //SHRUBLAND
            biomes.Add(new Biome(5, 3, 2, 1, Block.grass)); //TEMPERATE DECIDOUS FOREST
            biomes.Add(new Biome(4, 2, 1, 0, Block.grass)); //TROPICAL SEASIONAL FOREST

            biomes.Add(new Biome(2, 1, 4, 3, Block.stone)); //BARE
            biomes.Add(new Biome(2, 0, 3, 2, Block.sand)); //TEMPERATE DESERT
            biomes.Add(new Biome(3, 1, 2, 1, Block.grass)); //GRASSLAND
            biomes.Add(new Biome(2, 1, 1, 0, Block.grass)); //GRASSLAND

            biomes.Add(new Biome(1, 0, 2, 1, Block.sand)); //TEMPERATE DESERT
            biomes.Add(new Biome(1, 0, 1, 0, Block.sand)); //SUBTROPICAL DESERT

            //features.Add(new WorldFeature(){props = new WorldFeatureProperties(){MinHeight = 30, MaxHeight = 63, RandomValue = 0.5f, RandomSpread = 0.05f}});
        }
Пример #17
0
 public WorldProvider(World world)
 {
     this.world = world;
     this.empty = new Chunk(0,0,0, Block.stone, world);
 }
Пример #18
0
 public void GenerateFeature(int x, int y, int z, World world, Chunk chunk)
 {
     world.SetBlockSilent(x,y,z,Block.leaf);
 }