コード例 #1
0
ファイル: FPSInput.cs プロジェクト: tammukul/Lemma
        private void enableLook()
        {
            this.Mouse.Value = this.lastMouseLook;
            FPSInput.RecenterMouse();
            MouseState oldState = this.main.MouseState;

            this.lastMouseNonLook      = new Vector2(oldState.X, oldState.Y);
            this.main.MouseState.Value = new MouseState(FPSInput.MouseCenter.X, FPSInput.MouseCenter.Y, oldState.ScrollWheelValue, oldState.LeftButton, oldState.MiddleButton, oldState.RightButton, oldState.XButton1, oldState.XButton2);
        }
コード例 #2
0
        void IUpdateableComponent.Update(float dt)
        {
            if (this.main.IsActive && this.EnableMouse)
            {
                MouseState realMouseState = this.main.MouseState;
#if VR
                Point lastMousePos = new Point();
                if (this.main.VR)
                {
                    lastMousePos     = this.mousePos;
                    this.mousePos.X += realMouseState.X - FPSInput.MouseCenter.X;
                    this.mousePos.Y += realMouseState.Y - FPSInput.MouseCenter.Y;
                    FPSInput.RecenterMouse();
                    realMouseState = new MouseState
                                     (
                        this.mousePos.X,
                        this.mousePos.Y,
                        realMouseState.ScrollWheelValue,
                        realMouseState.LeftButton,
                        realMouseState.MiddleButton,
                        realMouseState.RightButton,
                        realMouseState.XButton1,
                        realMouseState.XButton2
                                     );
                }
#endif
                MouseState current = this.MouseFilter(realMouseState), last = this.lastMouseState;

#if VR
                if (this.main.VR)
                {
                    Point size = this.RenderTargetSize;
                    if (current.X > size.X)
                    {
                        this.mousePos.X = Math.Min(this.mousePos.X, lastMousePos.X);
                    }
                    if (current.X < 0)
                    {
                        this.mousePos.X = Math.Max(this.mousePos.X, lastMousePos.X);
                    }
                    if (current.Y > size.Y)
                    {
                        this.mousePos.Y = Math.Min(this.mousePos.Y, lastMousePos.Y);
                    }
                    if (current.Y < 0)
                    {
                        this.mousePos.Y = Math.Max(this.mousePos.Y, lastMousePos.Y);
                    }
                }
#endif

                if (this.GeeUI != null)
                {
                    this.GeeUI.Update(dt, this.main.KeyboardState, current);
                }

                this.Mouse.Value = new Vector2(current.X, current.Y);
                if (current.LeftButton != last.LeftButton ||
                    current.RightButton != last.RightButton ||
                    current.MiddleButton != last.MiddleButton ||
                    current.ScrollWheelValue != last.ScrollWheelValue ||
                    realMouseState.X != this.lastRealMouseState.X ||
                    realMouseState.Y != this.lastRealMouseState.Y ||
                    current.XButton1 != last.XButton1 ||
                    current.XButton2 != last.XButton2)
                {
                    if (this.Root.HandleMouse(current, last, Matrix.Identity, true))
                    {
                        this.SwallowMouseEvents.Execute();
                    }
                    this.lastMouseState     = current;
                    this.lastRealMouseState = realMouseState;
                }
            }
        }
コード例 #3
0
ファイル: Spawner.cs プロジェクト: Educational-Repos/Lemma
        public void Update(float dt)
        {
            // Spawn an editor or a player if needed
            if (this.main.EditorEnabled)
            {
                this.main.Renderer.InternalGamma.Value = 0.0f;
                this.main.Renderer.Brightness.Value    = 0.0f;
                if (this.editor == null || !this.editor.Active)
                {
                    this.editor = Factory.Get <EditorFactory>().CreateAndBind(this.main);
                    FPSInput.RecenterMouse();
                    this.editor.Get <Editor>().Position.Value = this.lastEditorPosition;
                    this.editor.Get <FPSInput>().Mouse.Value  = this.lastEditorMouse;
                    this.StartSpawnPoint.Value     = this.lastEditorSpawnPoint;
                    this.StartSpawnPointGUID.Value = this.lastEditorSpawnPointGUID;
                    this.main.Add(this.editor);
                }
                else
                {
                    this.lastEditorPosition = this.editor.Get <Editor>().Position;
                    this.lastEditorMouse    = this.editor.Get <FPSInput>().Mouse;
                }
            }
            else
            {
                if (this.main.MapFile.Value == null || !this.CanSpawn || CameraStop.CinematicActive)
                {
                    return;
                }

                this.editor = null;

                bool createPlayer = PlayerFactory.Instance == null;

                if (this.mapJustLoaded)
                {
                    if (!createPlayer)
                    {
                        // We just loaded a save game
                        this.main.Renderer.InternalGamma.Value = 0.0f;
                        this.main.Renderer.Brightness.Value    = 0.0f;
                        this.PlayerSpawned.Execute();
                        this.respawnTimer = 0;
                    }
                }
                else if (createPlayer)
                {
                    if (this.respawnTimer == 0)
                    {
                        this.main.AddComponent(new Animation(this.FlashAnimation()));
                    }

                    if (this.respawnTimer > this.RespawnInterval)
                    {
                        bool spawnFound = false;

                        RespawnLocation foundSpawnLocation         = default(RespawnLocation);
                        Vector3         foundSpawnAbsolutePosition = Vector3.Zero;

                        if (string.IsNullOrEmpty(this.StartSpawnPoint) && this.StartSpawnPointGUID == 0)
                        {
                            // Look for an autosaved spawn point
                            Entity playerData = PlayerDataFactory.Instance;
                            if (playerData != null)
                            {
                                ListProperty <RespawnLocation> respawnLocations = playerData.Get <PlayerData>().RespawnLocations;
                                int   supportedLocations = 0;
                                float lowerLimit         = Factory.Get <LowerLimitFactory>().GetLowerLimit();
                                while (respawnLocations.Length > 0)
                                {
                                    RespawnLocation respawnLocation  = respawnLocations[respawnLocations.Length - 1];
                                    Entity          respawnMapEntity = respawnLocation.Map.Target;
                                    if (respawnMapEntity != null && respawnMapEntity.Active)
                                    {
                                        Voxel   respawnMap  = respawnMapEntity.Get <Voxel>();
                                        Vector3 absolutePos = respawnMap.GetAbsolutePosition(respawnLocation.Coordinate);
                                        if (respawnMap.Active &&
                                            absolutePos.Y > lowerLimit &&
                                            respawnMap.GetAbsoluteVector(respawnMap.GetRelativeDirection(Direction.PositiveY).GetVector()).Y > 0.5f &&
                                            Agent.Query(absolutePos, 0.0f, 20.0f) == null &&
                                            Rift.Query(absolutePos) == null &&
                                            Zone.CanSpawnAt(absolutePos))
                                        {
                                            Voxel.State state = respawnMap[respawnLocation.Coordinate];
                                            if (state != Voxel.States.Empty && state != Voxel.States.Infected && state != Voxel.States.HardInfected && state != Voxel.States.Floater)
                                            {
                                                supportedLocations++;
                                                DynamicVoxel dynamicMap = respawnMap as DynamicVoxel;
                                                if (dynamicMap == null || absolutePos.Y > respawnLocation.OriginalPosition.Y - 1.0f)
                                                {
                                                    Voxel.GlobalRaycastResult hit = Voxel.GlobalRaycast(absolutePos + new Vector3(0, 1, 0), Vector3.Up, 2);
                                                    if (hit.Voxel == null)
                                                    {
                                                        // We can spawn here
                                                        spawnFound                 = true;
                                                        foundSpawnLocation         = respawnLocation;
                                                        foundSpawnAbsolutePosition = absolutePos;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (supportedLocations >= 40 || (spawnFound && (foundSpawnAbsolutePosition - this.lastPlayerPosition).Length() > this.RespawnDistance))
                                    {
                                        if (supportedLocations > 3)                                         // We should try to spawn the player back at least a few steps
                                        {
                                            break;
                                        }
                                    }

                                    respawnLocations.RemoveAt(respawnLocations.Length - 1);
                                }
                            }
                        }

                        if (spawnFound)
                        {
                            // Spawn at an autosaved location
                            if (createPlayer)
                            {
                                this.spawn();
                            }
                            Vector3 absolutePos = foundSpawnLocation.Map.Target.Get <Voxel>().GetAbsolutePosition(foundSpawnLocation.Coordinate);
                            PlayerFactory.Instance.Get <Transform>().Position.Value = this.main.Camera.Position.Value = absolutePos + new Vector3(0, spawnHeightOffset, 0);

                            FPSInput.RecenterMouse();
                            PlayerFactory.Instance.Get <FPSInput>().Mouse.Value = new Vector2(foundSpawnLocation.Rotation, 0);
                        }
                        else
                        {
                            // Spawn at a spawn point
                            PlayerSpawn spawn       = null;
                            Entity      spawnEntity = null;
                            if (this.StartSpawnPointGUID != 0)
                            {
                                spawnEntity = this.main.GetByGUID(this.StartSpawnPointGUID);
                                if (spawnEntity != null)
                                {
                                    spawn = spawnEntity.Get <PlayerSpawn>();
                                }
                                this.lastEditorSpawnPointGUID  = this.StartSpawnPointGUID;
                                this.StartSpawnPointGUID.Value = 0;
                            }
                            else if (!string.IsNullOrEmpty(this.StartSpawnPoint.Value))
                            {
                                spawnEntity = this.main.GetByID(this.StartSpawnPoint);
                                if (spawnEntity != null)
                                {
                                    spawn = spawnEntity.Get <PlayerSpawn>();
                                }
                                this.lastEditorSpawnPoint  = this.StartSpawnPoint;
                                this.StartSpawnPoint.Value = null;
                            }

                            if (spawnEntity == null)
                            {
                                spawn       = PlayerSpawn.FirstActive();
                                spawnEntity = spawn == null ? null : spawn.Entity;
                            }

                            if (spawnEntity != null)
                            {
                                Vector3 pos = spawnEntity.Get <Transform>().Position;
                                main.Camera.Position.Value = pos;
                                WorldFactory.Instance.Get <World>().UpdateZones();
                                Voxel.GlobalRaycastResult hit = Voxel.GlobalRaycast(pos + new Vector3(0, 2, 0), Vector3.Down, 8, null, false, true);
                                if (hit.Voxel == null)
                                {
                                    // There is nowhere to spawn. Reload the map.
                                    this.respawnTimer = 0;
                                    IO.MapLoader.Load(this.main, this.main.MapFile);
                                    return;
                                }
                                else
                                {
                                    if (createPlayer)
                                    {
                                        this.spawn();
                                    }
                                    pos = hit.Position + new Vector3(0, spawnHeightOffset, 0);
                                    PlayerFactory.Instance.Get <Transform>().Position.Value = this.main.Camera.Position.Value = pos;

                                    if (spawn != null)
                                    {
                                        spawn.IsActivated.Value = true;
                                        FPSInput.RecenterMouse();
                                        PlayerFactory.Instance.Get <FPSInput>().Mouse.Value = new Vector2(spawn.Rotation, 0);
                                        spawn.OnSpawn.Execute();
                                    }
                                }
                            }
                        }

                        // When the player teleports to a new map, show the number of orbs and notes on that map
                        // If mapJustLoaded is true, we just loaded a save game
                        if (this.main.TotalTime < Spawner.DefaultRespawnInterval * 2 && !this.mapJustLoaded)
                        {
                            WorldFactory.Instance.Add(new Animation
                                                      (
                                                          new Animation.Delay(1.5f),
                                                          new Animation.Execute(delegate()
                            {
                                int notes = Note.UncollectedCount;
                                if (notes > 0)
                                {
                                    this.main.Menu.HideMessage(WorldFactory.Instance, this.main.Menu.ShowMessageFormat(WorldFactory.Instance, notes == 1 ? "\\one note" : "\\note count", notes), 3.0f);
                                }

                                int orbs = Collectible.ActiveCount;
                                if (orbs > 0)
                                {
                                    this.main.Menu.HideMessage(WorldFactory.Instance, this.main.Menu.ShowMessageFormat(WorldFactory.Instance, orbs == 1 ? "\\one orb" : "\\orb count", orbs), 3.0f);
                                }
                            })
                                                      ));
                        }

                        WorldFactory.Instance.Add(new Animation(this.EndFlashAnimation()));
                        this.respawnTimer = 0;

                        this.PlayerSpawned.Execute();

                        this.RespawnInterval = Spawner.DefaultRespawnInterval;
                        this.RespawnDistance = Spawner.DefaultRespawnDistance;
                    }
                    else
                    {
                        this.respawnTimer += dt;
                    }
                }
                else
                {
                    this.lastPlayerPosition = PlayerFactory.Instance.Get <Transform>().Position;
                }
            }
            this.mapJustLoaded = false;
        }
コード例 #4
0
ファイル: FPSInput.cs プロジェクト: tammukul/Lemma
        protected override void handleMouse()
        {
            if (this.EnableLook)
            {
                if (this.main.IsActive && this.main.LastActive)
                {
                    MouseState mouse = this.main.MouseState;

                    Vector2 mouseMovement = new Vector2(FPSInput.MouseCenter.X - mouse.X, mouse.Y - FPSInput.MouseCenter.Y) * this.MouseSensitivity * FPSInput.sensitivityMultiplier;

                    GamePadState gamePad = this.main.GamePadState;
                    if (gamePad.IsConnected)
                    {
                        mouseMovement += gamePad.ThumbSticks.Right * this.MouseSensitivity * FPSInput.gamePadSensitivityMultiplier * this.main.ElapsedTime;
                    }

                    if (this.InvertMouseX)
                    {
                        mouseMovement.X *= -1;
                    }
                    if (this.InvertMouseY)
                    {
                        mouseMovement.Y *= -1;
                    }

                    if (mouseMovement.LengthSquared() > 0.0f)
                    {
                        Vector2 newValue = this.Mouse.Value + mouseMovement;

                        newValue.X = newValue.X.ToAngleRange();
                        newValue.Y = newValue.Y.ToAngleRange();

                        float minX = this.MinX, maxX = this.MaxX, minY = this.MinY, maxY = this.MaxY;

                        const float pi = (float)Math.PI;

                        if (!(minX == 0 && maxX == 0))
                        {
                            float tempX = minX;
                            minX = Math.Min(minX, maxX);
                            maxX = Math.Max(tempX, maxX);

                            if (Math.Abs(minX + pi) + Math.Abs(maxX - pi) < Math.Abs(minX) + Math.Abs(maxX))
                            {
                                if (newValue.X < 0 && newValue.X > minX)
                                {
                                    newValue.X = minX;
                                }
                                if (newValue.X > 0 && newValue.X < maxX)
                                {
                                    newValue.X = maxX;
                                }
                            }
                            else
                            {
                                newValue.X = Math.Min(maxX, Math.Max(minX, newValue.X));
                            }
                        }

                        float tempY = minY;
                        minY = Math.Min(minY, maxY);
                        maxY = Math.Max(tempY, maxY);

                        if (minY < 0 && maxY > 0 && Math.Abs(minY + pi) + Math.Abs(maxY - pi) < Math.Abs(minY) + Math.Abs(maxY))
                        {
                            if (newValue.Y < 0 && newValue.Y > minY)
                            {
                                newValue.Y = minY;
                            }
                            if (newValue.Y > 0 && newValue.Y < maxY)
                            {
                                newValue.Y = maxY;
                            }
                        }
                        else
                        {
                            newValue.Y = Math.Min(maxY, Math.Max(minY, newValue.Y));
                        }

                        this.Mouse.Value = newValue;
                    }
                }
                FPSInput.RecenterMouse();
            }
            else
            {
                base.handleMouse();
            }
        }
コード例 #5
0
        public override void Awake()
        {
            base.Awake();
            this.Add(new CommandBinding(this.Enable, delegate()
            {
                FPSInput.RecenterMouse();
            }));
            this.Add(new CommandBinding(this.Disable, delegate()
            {
                if (!this.Movement.Value.Equals(Vector2.Zero))
                {
                    this.Movement.Value = Vector2.Zero;
                }
            }));
            this.Add(new ChangeBinding <bool>(this.EnableLook, delegate(bool old, bool value)
            {
                if (value && !old)
                {
                    this.Mouse.Value = this.lastMouseLook;
                    FPSInput.RecenterMouse();
                    MouseState oldState        = this.main.MouseState;
                    this.lastMouseNonLook      = new Vector2(oldState.X, oldState.Y);
                    this.main.MouseState.Value = new MouseState(FPSInput.MouseCenter.X, FPSInput.MouseCenter.Y, oldState.ScrollWheelValue, oldState.LeftButton, oldState.MiddleButton, oldState.RightButton, oldState.XButton1, oldState.XButton2);
                }
                else if (!value && old)
                {
                    this.lastMouseLook = this.Mouse;
                    Microsoft.Xna.Framework.Input.Mouse.SetPosition((int)this.lastMouseNonLook.X, (int)this.lastMouseNonLook.Y);
                    if (this.EnableMouse)
                    {
                        this.Mouse.Value = this.lastMouseNonLook;
                    }
                }
            }));

            this.Add(new SetBinding <float>(this.MinX, delegate(float value)
            {
                float v = value.ToAngleRange();
                if (v != value)
                {
                    this.MinX.Value = v;
                }
            }));

            this.Add(new SetBinding <float>(this.MaxX, delegate(float value)
            {
                float v = value.ToAngleRange();
                if (v != value)
                {
                    this.MaxX.Value = v;
                }
            }));
            this.Add(new SetBinding <float>(this.MinY, delegate(float value)
            {
                float v = value.ToAngleRange();
                if (v != value)
                {
                    this.MinY.Value = v;
                }
            }));
            this.Add(new SetBinding <float>(this.MaxY, delegate(float value)
            {
                float v = value.ToAngleRange();
                if (v != value)
                {
                    this.MaxY.Value = v;
                }
            }));
        }