示例#1
0
 public void GenerateSector(Vector3i Location)
 {
     Sector chunk = new Sector(Realm, Location);
     foreach (WorldGenerator gen in Generators) {
         gen.Generate(chunk);
     }
     Mappings.Add(Location, chunk);
 }
示例#2
0
 public virtual void update(Vector3i Location, Realm world)
 {
     throw new NotImplementedException();
     //if (BlockType.Liquid) {
     //    LiquidUpdated = moveDown(Location - new Vector3i(0, 0, 1), world);
     //    if (Level > 0) {
     //        List<Vector2> Copy = Directions.GetRange(0, Directions.Count);
     //        Copy.Shuffle();
     //        foreach (Vector2 dir in Copy) {
     //            LiquidUpdated |= moveTo(new Vector3i(Location.X + (int)dir.X, Location.Y + (int)dir.Y, Location.Z), world);
     //        }
     //    }
     //} else {
     //    world.RemoveUpdate(Location);
     //}
 }
示例#3
0
        private void GenerateBase(Sector chunk, int ChunkZ)
        {
            Random ran = new Random();

            //Create Terrain
            for (int x = 0; x < Sector.Size.X; x++) {
                for (int y = 0; y < Sector.Size.Y; y++) {
                    for (int z = 0; z < Sector.Size.Z; z++) {
                        Vector3i Location = new Vector3i(x, y, z);
                        if (z + (ChunkZ * Sector.Size.Z) < current_heightmap.GetPixel(x, y).R - 100) {
                            if (z + (ChunkZ * Sector.Size.Z) > current_heightmap.GetPixel(x, y).R - 100 - (int)(5 + ran.Next(3))) {
                                chunk[Location] = new Block(DirtGuid);
                            } else {
                                chunk[Location] = new Block(GraniteGuid);
                            }
                        }

                        if (z + (ChunkZ * Sector.Size.Z) == current_heightmap.GetPixel(x, y).R - 100) {
                            chunk[Location] = new Block(GrassGuid);
                        }
                    }
                }
            }
        }
示例#4
0
        public static void UpdateClient()
        {
            World.Update();

            if (State == GameState.Playing) {
                Self.Update();
            }

            if (State == GameState.Connecting) {
                if (!RequestedPlayer) {
                    RequestedPlayer = true;
                    new RequestMessage(RequestType.NewPlayer).Send();
                }

                if (!RequestedChunks && (Self != null)) {
                    //Make sure we have all nearby chunks
                    for (int x = -3; x <= 3; x++) {
                        for (int y = -3; y <= 3; y++) {
                            for (int z = -3; z <= 3; z++) {
                                Vector3i Loc = new Vector3i(
                                            (int)(Self.xpos + (x * NetworkChunk.Size.X)),
                                            (int)(Self.xpos + (y * NetworkChunk.Size.Y)),
                                            (int)(Self.xpos + (z * NetworkChunk.Size.Z)));
                                if (World[Loc] == null) {
                                    World.Request(Loc);
                                }
                            }
                        }
                    }
                    RequestedChunks = true;
                }

                bool Ready = true;
                Ready &= Package.Ready();
                Ready &= (Self != null);
                Ready &= World.Requester.OutgoingChunkCount() == 0;

                if (Ready) {
                    Game.CenterMouse();
                    State = GameState.Playing;
                    Stopwatch.StartNew();
                }
            }
        }
示例#5
0
 public bool Exists(Vector3i Location)
 {
     return Mappings.ContainsKey(Location);
 }
示例#6
0
        void RemoveBlock()
        {
            float bestDist = 100;
            int bestX = 0;
            int bestY = 0;
            int bestZ = 0;
            bool foundOne = false;

            int CDist = 5;

            Vector3 source = new Vector3();
            source.X = (float)xpos;
            source.Y = (float)ypos;
            source.Z = (float)(zpos + PlayerHeight);

            Vector3 dest = new Vector3();
            dest.X = LookingAtX(CDist);
            dest.Y = LookingAtY(CDist);
            dest.Z = LookingAtZ(CDist);

            for (int x = -CDist; x <= CDist; x++){
                for (int y = -CDist; y <= CDist; y++){
                    for (int z = -CDist; z <= CDist; z++){
                        Block BCDist = Game.World[new Vector3i((int)(xpos + x), (int)(ypos + y), (int)(zpos + z + PlayerHeight))];
                        if (BCDist != null && BCDist.IsSolid()) {
                            Vector3 B1 = new Vector3();
                            B1.X = (int)(xpos+x);
                            B1.Y = (int)(ypos+y);
                            B1.Z = (int)(zpos + z + PlayerHeight);

                            Vector3 B2 = new Vector3();
                            B2.X = B1.X + 1;
                            B2.Y = B1.Y + 1;
                            B2.Z = B1.Z + 1;
                            if (CheckLineBox(B1, B2, source, dest) != NONE){
                                foundOne = true;
                                float length = (float)Math.Sqrt(x*x + y*y + z*z);
                                if (length < bestDist){
                                    bestDist = length;
                                    bestX = (int)(xpos+x);
                                    bestY = (int)(ypos+y);
                                    bestZ = (int)(zpos + z + PlayerHeight);
                                }
                            }
                        }
                    }
                }
            }

            if (foundOne){
                Vector3i Location = new Vector3i(bestX, bestY, bestZ);
                Game.World[Location] = null;
                new BlockRemove(Location).Send();
            }
        }
示例#7
0
 bool CanPlaceBlock(Vector3i Location)
 {
     return Inventory[SelectedItem].CanCombine(Game.World[Location]);
 }
示例#8
0
        void AddBlock()
        {
            float bestDist = 100;
            int bestX = 0;
            int bestY = 0;
            int bestZ = 0;
            bool foundOne = false;

            int CDist = 5;

            int BestSide = NONE;

            Vector3 source = new Vector3();
            source.X = (float)xpos;
            source.Y = (float)ypos;
            source.Z = (float)(zpos + PlayerHeight);

            Vector3 dest = new Vector3();
            dest.X = LookingAtX(CDist);
            dest.Y = LookingAtY(CDist);
            dest.Z = LookingAtZ(CDist);

            for (int x = -CDist; x <= CDist; x++){
                for (int y = -CDist; y <= CDist; y++){
                    for (int z = -CDist; z <= CDist; z++){
                        Block BCDist = Game.World[new Vector3i((int)(xpos + x), (int)(ypos + y), (int)(zpos + z + PlayerHeight))];
                        if (BCDist != null && BCDist.IsSolid()) {
                            Vector3 B1 = new Vector3();
                            B1.X = (int)(xpos+x);
                            B1.Y = (int)(ypos+y);
                            B1.Z = (int)(zpos + z + PlayerHeight);

                            Vector3 B2 = new Vector3();
                            B2.X = B1.X + 1;
                            B2.Y = B1.Y + 1;
                            B2.Z = B1.Z + 1;

                            int clb = CheckLineBox(B1, B2, source, dest);
                            int[] temp = getBlockSide((int)(xpos+x),
                                    (int)(ypos+y),
                                    (int)(zpos + z + PlayerHeight),
                                    clb);
                            if (clb != NONE && clb != INSIDE &&
                                    CanPlaceBlock(new Vector3i(temp[0], temp[1], temp[2]))) {
                                foundOne = true;
                                float length = (float)Math.Sqrt(x*x + y*y + z*z);
                                if (length < bestDist){
                                    bestDist = length;
                                    bestX = (int)(xpos+x);
                                    bestY = (int)(ypos+y);
                                    bestZ = (int)(zpos + z + PlayerHeight);
                                    BestSide = clb;
                                }
                            }
                        }
                    }
                }
            }

            if (foundOne){

                int[] temp = getBlockSide(bestX, bestY, bestZ, BestSide);
                bestX = temp[0];
                bestY = temp[1];
                bestZ = temp[2];

                Guid BlockName = Inventory[SelectedItem].BlockTypeID;

                Block b = new Block(BlockName);

                Vector3i Location = new Vector3i(bestX, bestY, bestZ);
                Game.World[Location] = b;
                BlockAdd msg = new BlockAdd(Location, b);
                msg.Send();
            }
        }