示例#1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("hudfont");

            gameWorld = new World(50,50,1,true);
            gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport);
            cursor = new Cursor();

            this.EnsurePrefabs();
            List<string> pfs = new List<String>(Directory.EnumerateFiles(Path.Combine(Content.RootDirectory, "prefabs/")));
            LoadSave.LoadAnim(ref spawnSprites, Path.Combine(Content.RootDirectory, "spawns.vxs"));

            foreach (string fn in pfs)
            {
                Prefabs.Add(LoadSave.LoadPrefab(fn));
            }

            drawEffect = new BasicEffect(GraphicsDevice)
            {
                World = gameCamera.worldMatrix,
                View = gameCamera.viewMatrix,
                Projection = gameCamera.projectionMatrix,
                VertexColorEnabled = true,
                //LightingEnabled = true // turn on the lighting subsystem.

            };

            cursorEffect = new BasicEffect(GraphicsDevice)
            {
                World = gameCamera.worldMatrix,
                View = gameCamera.viewMatrix,
                Projection = gameCamera.projectionMatrix,
                VertexColorEnabled = true

            };

            saveForm = new SaveForm(gameWorld);

            GC.Collect();
        }
示例#2
0
        public void Update(GameTime gameTime, Camera gameCamera)
        {
            X_SIZE = X_CHUNKS * Chunk.X_SIZE;
            Y_SIZE = Y_CHUNKS * Chunk.Y_SIZE;
            Z_SIZE = Z_CHUNKS * Chunk.Z_SIZE;

            redrawTime += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (redrawTime > REDRAW_INTERVAL)
            {
                redrawTime = 0;
                UpdateWorldMeshes();
            }

            for (int y = 0; y < Y_CHUNKS; y++)
            {
                for (int x = 0; x < X_CHUNKS; x++)
                {
                    Chunk c = Chunks[x, y, 0];
                    if (!gameCamera.boundingFrustum.Intersects(c.boundingSphere.Transform(Matrix.CreateTranslation(gameCamera.Position))))
                    {
                        if (c.Visible)
                        {
                            c.Visible = false;
                            //c.ClearMem();
                        }
                    }
                    else
                    {
                        if (!c.Visible)
                        {
                            c.Visible = true;
                            if (c.Updated) c.UpdateMesh();
                            //c.UpdateMesh();
                        }
                    }
                }
            }
        }