Example #1
0
        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 local part of the mod.
        /// </summary>
        public static void Startup(IntPtr _unmanagedModule)
        {
            if (!Scripting.IsHost)
            {
                Universe.CreateWorld("UpvoidMinerWorld", new UpvoidMinerNetworkWorldReceiver());
            }

            // Create a simple camera that allows free movement.
            Camera = new GenericCamera ();
            Camera.FarClippingPlane = 3500.0;
            CameraControl = new FreeCameraControl (-10f, Camera);

            // Get the world (created by the host script)
            World world = Universe.GetWorldByName ("UpvoidMinerWorld");

            // Place the camera in the world
            world.AttachCamera (Camera);
            if (Rendering.ActiveMainPipeline != null)
                Rendering.ActiveMainPipeline.SetCamera (Camera);

            GC.KeepAlive (Camera);

            if (!Scripting.IsHost) {
                ivec3 refPos = new ivec3 (0, 0, 0);
                float activeRadius = 10;
                float sleepingRadius = 20;
                float minLODRange = 10;
                float falloff = 5;
                world.AddActiveRegion (refPos, activeRadius, sleepingRadius, minLODRange, falloff);
            }

            // Configure the camera to receive user input
            Input.RootGroup.AddListener (CameraControl);

            // Registers the update callback that updates the camera position.
            Scripting.RegisterUpdateFunction(Update, 1 / 60.0f, 3 / 60.0f);
        }