Exemple #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();
            };
        }
Exemple #2
0
        /// <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);
        }