Exemple #1
0
        public void render(Game game)
        {
            GL.BindTexture(TextureTarget.Texture2D, game.textureMapID);

            foreach(Chunk chunk in loadedChunks.Values){
                chunk.render(game, this);
            }
        }
Exemple #2
0
        public World(Game game)
        {
            Directory.CreateDirectory(directory);

            this.game = game;

            chunksToLoad = new List<Vector3i>();
            chunksToUnload = new List<Vector3i>();
            loadedChunks = new Dictionary<Vector3i, Chunk>();
        }
Exemple #3
0
        public Chunk(Vector3i pos, World world, Game game)
        {
            this.chunkPosition = new Vector3i(pos.x, pos.y, pos.z);
            vbo = new VboGroup(game);

            fileName = world.directory + "\\chunk_" + chunkPosition.getSafeString()+".chunk";

            bool loaded = false;

            if (File.Exists(fileName)) {
                loaded = load();
            }

            if (!loaded) {
                generate(game, world);
                save();
                Console.WriteLine("Generate Chunk");
            } else {
                Console.WriteLine("Loaded Chunk");
            }

            this.world = world;
        }
Exemple #4
0
 public void render(Game game, World world)
 {
     vbo.render(game);
 }
Exemple #5
0
 private void generate(Game game, World world)
 {
     setBlock(0, 0, 0, Block.stone);
 }
Exemple #6
0
 internal void update(Game game, World world)
 {
     if (needsVboReset) {
         needsVboReset = false;
         resetVbo(world);
     }
 }
Exemple #7
0
 static void Main(string[] args)
 {
     Game game = new Game();
 }
Exemple #8
0
        public void update(Game game)
        {
            KeyboardState k = Keyboard.GetState();
            MouseState m = Mouse.GetCursorState();

            if (m.IsButtonDown(MouseButton.Left)) {
                game.world.setBlock(new Vector3i(position), Block.stone, true);
            }

            if (m.IsButtonDown(MouseButton.Right)) {
                game.world.setBlock(new Vector3i(position), Block.air, true);
            }

            Vector3 moveDif = new Vector3();

            float sin = (float)Math.Sin(radians180 - rotation.Y);
            float cos = (float)Math.Cos(radians180 - rotation.Y);

            if (k.IsKeyDown(Key.Space)) {
                moveDif.Y -= moveSpeed;
            }
            if (k.IsKeyDown(Key.LShift)) {
                moveDif.Y += moveSpeed;
            }

            if (k.IsKeyDown(Key.W)) {
                moveDif.X += sin * -moveSpeed;
                moveDif.Z += cos * -moveSpeed;
            }
            if (k.IsKeyDown(Key.S)) {
                moveDif.X += sin * moveSpeed;
                moveDif.Z += cos * moveSpeed;
            }

            sin = (float)Math.Sin(radians270 - rotation.Y);
            cos = (float)Math.Cos(radians270 - rotation.Y);

            if (k.IsKeyDown(Key.A)) {
                moveDif.X += sin * -moveSpeed;
                moveDif.Z += cos * -moveSpeed;
            }
            if (k.IsKeyDown(Key.D)) {
                moveDif.X += sin * moveSpeed;
                moveDif.Z += cos * moveSpeed;
            }

            if(!k.IsKeyDown(Key.Enter)){
                position += moveDif;
            }else{
                position += attemtToMove(moveDif);
            }

            if (game.Focused) {

                int x = ((Mouse.GetCursorState().X - game.Bounds.X - game.Bounds.Width / 2));
                int y = ((Mouse.GetCursorState().Y - game.Bounds.Y - game.Bounds.Height / 2));

                rotation.Y += x * rotationSpeed;
                rotation.X -= y * rotationSpeed;

                if (rotation.X < -radians90) {
                    rotation.X = -radians90;
                }
                if (rotation.X > radians90) {
                    rotation.X = radians90;
                }

                //Console.WriteLine("Mouse: " + x + ", " + y);

                Mouse.SetPosition(game.Bounds.X + game.Bounds.Width / 2, game.Bounds.Y + game.Bounds.Height / 2);
            }

            camera.position = position+eyeOffset;
            camera.rotation = rotation;
        }
Exemple #9
0
 public Player(Game game)
 {
     this.game = game;
     camera = new Camera();
 }
Exemple #10
0
        public void update(Game game)
        {
            int x = (int)game.player.position.X/Chunk.chunkSize.x;
            int y = (int)game.player.position.Y/Chunk.chunkSize.y;
            int z = (int)game.player.position.Z/Chunk.chunkSize.z;

            addToLoadedIfNeeded(new Vector3i(x, y, z));

            for (int i = -game.renderDistance; i <= game.renderDistance; i++) {
                for (int j = -game.renderDistance; j <= game.renderDistance; j++) {
                    for (int k = -game.renderDistance; k <= game.renderDistance; k++) {
                        addToLoadedIfNeeded(new Vector3i(i + x, j + y, k + z));
                    }
                }
            }

            if (chunksToLoad.Count > 0) {
                loadChunk(chunksToLoad[0]);
                chunksToLoad.RemoveAt(0);
            }

            if (chunksToUnload.Count > 0) {
                unloadChunk(chunksToUnload[0]);
                chunksToUnload.RemoveAt(0);
            }

            bool a = true;

            foreach (Chunk chunk in loadedChunks.Values) {
                chunk.update(game, this);
                if(a){
                    if(outOfView(chunk.chunkPosition, x, y, z, game)){
                        chunksToUnload.Add(chunk.chunkPosition);
                        a = false;
                    }
                }
            }
        }
Exemple #11
0
 private bool outOfView(Vector3i p, int x, int y, int z, Game game)
 {
     return
         (p.x < x - game.renderDistance) ||
         (p.y < y - game.renderDistance) ||
         (p.z < z - game.renderDistance) ||
         (p.x > x + game.renderDistance) ||
         (p.y > y + game.renderDistance) ||
         (p.z > z + game.renderDistance);
 }