static void ActivatePlayer() { // Activate player only once. if (player != null) { player.Gui.IsInventoryOpen = false; player.Gui.IsMenuOpen = false; return; } // Activate camera movement cameraControl = new FreeCameraControl(-10f, camera); // Configure the camera to receive user input. Input.RootGroup.AddListener(cameraControl); // Create particle entity. ParticleEntity = new AnonymousEntity(mat4.Identity); world.AddEntity(ParticleEntity, Network.GCManager.CurrentUserID); // Create the Player EntityScript and add it to the world. // For now, place him 30 meters above the ground and let him drop to the ground. player = new Player(camera); world.AddEntity(player, mat4.Translate(new vec3(0, 50f, 0)), Network.GCManager.CurrentUserID); // Register the update callback that updates the camera position. Scripting.RegisterUpdateFunction(Update, 1 / 60f, 3 / 60f); // Register save callback Savegame.OnSave += s => { player.Save(); UpvoidMinerWorldGenerator.SaveEntities(); }; }
/// <summary> /// Initializes the terrain materials and settings. /// </summary> public static void init(World world) { Instance = new UpvoidMinerWorldGenerator(); Instance.world = world; // Register all terrain resources (and thus terrain materials). TerrainResource.RegisterResources(world.Terrain); // Get handle to dirt for generation. Instance.terrainDirt = TerrainResource.FromName("Dirt"); Instance.terrainRock = TerrainResource.FromName("Stone.09"); Instance.terrainDesert = TerrainResource.FromName("Desert"); // load entities LoadEntities(); // init terrain world.SetTerrainGenerator(new TerrainGenerator()); world.TerrainGenerator.SetCsgNode(Instance.createTerrain()); }
/// <summary> /// Updates the camera position. /// </summary> public static void Update(float _elapsedSeconds) { if (NoclipEnabled && cameraControl != null) { // Bezier Path if (PathPlaying && PathPositions.Count >= 2) { PathCurrPos += _elapsedSeconds; while (PathCurrPos > PathPositions.Count) { PathCurrPos -= PathPositions.Count; } vec3 pos = bezierOf(PathPositions, PathTmps, PathCurrPos / (float)PathPositions.Count); vec3 dir = bezierOf(PathDirections, PathTmps, PathCurrPos / (float)PathPositions.Count); camera.Position = pos; camera.SetTarget(pos + dir, vec3.UnitY); } cameraControl.Update(_elapsedSeconds); } if (player != null) { player.Update(_elapsedSeconds); } UpdateResourceDownloadProgress(); if ((DateTime.Now - lastSave).TotalSeconds > 60) { lastSave = DateTime.Now; if (player != null) { player.Save(); } UpvoidMinerWorldGenerator.SaveEntities(); } UpvoidMinerWorldGenerator.UpdateTrees(camera.Position); }
/// <summary> /// Starts /// </summary> public static void Startup(IntPtr _unmanagedModule) { // Get and save the resource domain of the mod, needed for loading resources. UpvoidMiner.Mod = Module.FromHandle(_unmanagedModule); UpvoidMiner.ModDomain = UpvoidMiner.Mod.ResourceDomain; // Create the world. Multiple worlds could be created here, but we only want one. // Use the UpvoidMinerWorldGenerator, which will create a simple terrain with some vegetation. World world = Universe.CreateWorld("UpvoidMinerWorld"); UpvoidMinerWorldGenerator.init(world); world.Start(); for (int i = 0; i < 3; ++i) { TerrainResource mat = TerrainResource.FromName("Stone." + (i + 1).ToString("00")); Debug.Assert(mat != null, "Invalid material"); MaterialItem testItem = new MaterialItem(mat, MaterialShape.Cube, new vec3(1), 1); world.AddEntity(new ItemEntity(testItem), mat4.Translate(new vec3(5f, i * 2f, ((i % 3) * 2f)))); } }