public WorldManager(int seed, int worldSize, int chunkSize, double scale, int tileSize, CollisionManager collisionManager, Point curretChunk)
        {
            if (man == null)
            {
                man = this;
            }
            else
            {
                throw new SingletonException(this);
            }

            worldSizeX      = worldSize;
            worldSizeY      = worldSize;
            chunkSizeX      = chunkSize;
            chunkSizeY      = chunkSize;
            currentChunkPos = curretChunk;
            currentChunk    = new Chunk(chunkSize, currentChunkPos.X, currentChunkPos.Y);

            this.tileSize = tileSize;
            this.scale    = scale;

            wGen          = new WorldGen.WorldGenerator(seed, worldSize, chunkSize, scale, tileSize, collisionManager);
            worldFileLoc += seed.ToString() + "/";
            worldCache    = new Dictionary <Point, Chunk>();
            LoadChunk();
        }
예제 #2
0
        /// <summary>
        /// Initializes the context object.
        /// </summary>
        /// <returns>THe context object.</returns>
        public static Context InitContext()
        {
            int worldSeed = 915434125;

            ConditionCompiler <BaseGlobalVariables> processor =
                new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables()
            {
                World = new World(),
            });
            Definitions  definitions = DefinitionSerializer.DeserializeFromDirectory(processor, "Definitions");
            ThingFactory factory     = new ThingFactory(definitions);

            HistoryGenerator history = new HistoryGenerator(factory, definitions);

            WorldGen.WorldGenerator worldGen = new WorldGen.WorldGenerator(worldSeed, factory);
            int   width  = 200;
            int   height = 200;
            World world  = worldGen.GenerateWorld(width, height);

            processor.UpdateGlobalVariables(g => g.World = world);

            Random rdm = new Random(worldSeed);

            for (int i = 0; i < 100; i++)
            {
                int  x        = rdm.Next(0, width - 1);
                int  y        = rdm.Next(0, height - 1);
                Site cityInst = factory.CreateSite(rdm, x, y, "City");
                world.Grid.AddThing(cityInst);
            }

            foreach (var thing in world.Grid.AllGridEntries.SelectMany(x => x.Square.GetThings()))
            {
                thing.FinalizeConstruction(new Random());
            }

            Context.Instance.Attach(history, world, processor);

            return(Context.Instance);
        }
예제 #3
0
        public void Init(GraphicsDevice device, ContentManager content)
        {
            GameModel.ModelGeometryCompiler.ModelBaseDir = "Scenes\\GameplayAssets\\Models\\";
            GameObject.IO.MagicFileReader mr      = new GameObject.IO.MagicFileReader();
            List <CharacterTemplate>      classes = mr.ReadClassFile();
            List <ModularAbility>         skills  = mr.ReadAbilityFile();

            abilities = skills;
            RotateMap = true;
            World     = new World(device, 100)
            {
                Player = new GameObject.MapEntities.Actors.Player(classes[0], skills)
            };
            World.Terrain.RenderDistance = 3;
            Generator = new WorldGen.WorldGenerator(World.Terrain.BlockSize, World, 4);
            World.Terrain.WaterHeight       = Generator.WaterHeight;
            World.Player.WorldSpawn         = World;
            World.Player.Abilities[0].Level = 1;
            World.Player.Abilities[1].Level = 2;
            World.Player.Abilities[2].Level = 5;
            if (OverheadMapTex == null)
            {
                OverheadMapTex = new RenderTarget2D(device, 256, 256, false, device.PresentationParameters.BackBufferFormat, device.PresentationParameters.DepthStencilFormat);
            }
            b = new SpriteBatch(device);


            #region load game textures
            Textures = new Dictionary <string, Texture2D>();
            Textures["grass_overworld"] = LoadTex2D(device, "graphics\\terraintiles.png");
            Textures["waterbump"]       = LoadTex2D(device, "graphics\\waterbump.jpg");
            Textures["rock"]            = LoadTex2D(device, "graphics\\rock.jpg");
            Textures["sand"]            = LoadTex2D(device, "graphics\\sand.png");
            Textures["point_sphere"]    = LoadTex2D(device, "graphics\\sphere.png");
            Textures["ray"]             = LoadTex2D(device, "graphics\\ray.png");
            Textures["mapsprites"]      = LoadTex2D(device, "graphics\\mapsprites.png");
            Textures["mapnavring"]      = LoadTex2D(device, "graphics\\mapnavring.png");
            Textures["mapoverlay"]      = LoadTex2D(device, "graphics\\mapoverlay.png");
            Textures["equipdoll"]       = LoadTex2D(device, "graphics\\vitruvian.png");
            Textures["dummy"]           = LoadTex2D(device, "graphics\\gray.png");
            Fonts          = new Dictionary <string, SpriteFont>();
            Fonts["font1"] = content.Load <SpriteFont>("font1");
            Fonts["font1"].DefaultCharacter = '#';
            Fonts["fontN"] = content.Load <SpriteFont>("LargeFontX");
            Fonts["fontN"].DefaultCharacter = '#';
            Fonts["FX"] = content.Load <SpriteFont>("FX");
            GameModel.Model.TexturePool = Textures;
            #endregion

            GameModel.ModelPart.Textures = Textures;
            TerrainEffect = content.Load <Effect>("legacy");
            World.Terrain.TerrainEffect = TerrainEffect;
            World.ModelEffect           = TerrainEffect;
            World.Camera          = World.Player.GetTheCamera();
            World.Player.Position = new Vector3(0, 0, 0);
            World.Terrain.QThread = new Thread(new ThreadStart(ProcessQ));
            World.Terrain.QThread.Start();


            #region GUI - onlybasics
            GUIRenderer                   = new GUI.Renderer(device);
            GUIRenderer.WindowSkin        = Texture2D.FromStream(device, new System.IO.FileStream("graphics\\winskin.png", System.IO.FileMode.Open));
            GUIRenderer.InventoryPartsMap = Texture2D.FromStream(device, new System.IO.FileStream("graphics\\itemparts.png", System.IO.FileMode.Open));
            GUIRenderer.AbilityMap        = Texture2D.FromStream(device, new System.IO.FileStream("graphics\\icons.png", System.IO.FileMode.Open));
            GUIRenderer.GUIEffect         = content.Load <Effect>("GUI");
            GUIRenderer.UIFont            = Fonts["font1"];
            GUIRenderer.FloatFont         = Fonts["fontN"];
            WindowManager                 = new GUI.WindowManager();
            WindowManager.Renderer        = GUIRenderer;
            wlist            = new Dictionary <string, GUI.Window>();
            wlist["console"] = new GameplayAssets.ConsoleWindow(WindowManager, this);
            WindowManager.Add(wlist["console"]);


            Terrain.Console.WriteCallback      = new Action <string>(ConsoleWrite);
            _3DGame.Console.WriteCallback      = new Action <string>(ConsoleWrite);
            _3DGame.Console.WriteCallbackEx    = new Action <string, List <Action> >(ConsoleWriteEx);
            GameObject.Console.WriteCallback   = new Action <string>(ConsoleWrite);
            GameObject.Console.WriteCallbackEx = new Action <string, List <Action> >(ConsoleWriteEx);
            GUI.Console.WriteCallback          = new Action <string>(ConsoleWrite);
            #endregion


            GameObject.Items.Material.MaterialTemplates.Load();

            //GameObject.AbilityLogic.AbilityLoader l = new GameObject.AbilityLogic.AbilityLoader("Mage");
            //World.Player.Abilities = l.LoadAbilities();


            #region GUI - the rest of it
            wlist["status"] = new GameplayAssets.StatusWindow(WindowManager, World.Player);
            WindowManager.Add(wlist["status"]);
            wlist["nav"] = new GameplayAssets.Windows.NavWindow(World.Player, OverheadMapTex);
            WindowManager.Add(wlist["nav"]);
            wlist["target"] = new GameplayAssets.Windows.TargetWindow(WindowManager, World.Player);
            WindowManager.Add(wlist["target"]);
            wlist["inventory"] = new GameplayAssets.Windows.InventoryWindow(WindowManager, World.Player);
            WindowManager.Add(wlist["inventory"]);
            wlist["equipment"] = new GameplayAssets.Windows.EquipWindow(WindowManager, World.Player);
            WindowManager.Add(wlist["equipment"]);
            wlist["skills"] = new GameplayAssets.Windows.SkillTreeWindow(WindowManager, World.Player, abilities);
            WindowManager.Add(wlist["skills"]);
            wlist["fbinds"] = new GameplayAssets.Windows.FBindWindow(WindowManager, World.Player);
            WindowManager.Add(wlist["fbinds"]);

            ScreenResized(device);
            #endregion

            /*WorldGen.ObjectPopulator p = new WorldGen.ObjectPopulator(new Random(1));
             * List<MapEntity> elist = p.GenerateObjectsTest(3);
             * foreach(MapEntity me in elist)
             * {
             *  me.WorldSpawn = World;
             *  World.Entities.Add(me);
             * }
             * //*/
        }