Beispiel #1
0
        public TextPopup(AbstractScene scene, Texture2D texture, Vector2 position, float scale = 1, float timeout = 0) : base(scene.LayerManager.TutorialLayer, null, position)
        {
            input = new UserInputController();

            if (timeout == 0)
            {
                Scene.LayerManager.PauseForUserInput();

                Timer.TriggerAfter(1000, () =>
                {
                    input.RegisterKeyPressAction(Keys.Space, (thumbstickPos) =>
                    {
                        Scene.LayerManager.Continue();
                        Destroy();
                    });
                });
            }
            else
            {
                Timer.TriggerAfter(timeout, () => {
                    Destroy();
                });
            }

            Sprite s = new Sprite(this, texture, new Rectangle(0, 0, texture.Width, texture.Height));

            s.Scale = scale;
            AddComponent(s);

            Active  = true;
            Visible = true;
        }
    void InitializeGame()
    {
        //инициализируем пулл объектов
        Instantiate(ObjectPoolSetup);

        //инициализируем звездное небо
        Instantiate(StarsGenerator);
        //инициализируем игрока
        _player = Instantiate(PlayerPrefab) as GameObject;
        _playerMovementModel = new PlayerMovementModel(_player, RotationSpeed, MovingSpeed);

        //инициализируем стрельбу и урон
        _shotModel        = new ShootModel(_player);
        _damageController = new DamageController();
        Instantiate(StrongWeaponController);

        //инициализируем пользовательский ввод
        _inputController = new UserInputController(_playerMovementModel, _shotModel);
        _userInput       = _inputController.GetUserInputView();

        //инициализируем UI
        _playerPannel = new PlayerPannelController(PlayerPannel);
        _uiController = new UIController();
        _gameEventSystem.UpdateStrongBulletValueLaunch(MaxSrongBulletsCount);
        _scoreController = new ScoreController(ScoreDisplay);

        //инициализируем спавн астероидов
        Instantiate(AwaitingControllerPrefab);
        _spawnModel = new ObjectSpawnModel(AsteroidsSpawnPointsObject);
        _asteroidsSpawnController = new AsteroidsSpawnController(_spawnModel);
        _ufoSpawnController       = new UFOSpawnController(_spawnModel);

        _isGameInitialized = true;
    }
    void Start()
    {
        healthManager      = GetComponent <HealthManager>();
        inputController    = GetComponent <UserInputController>();
        rotationController = GetComponent <UserRotationController>();

        if (healthManager != null)
        {
            healthManager.OnDeath += healthManager_OnDeath;
        }
    }
Beispiel #4
0
    //public override void OnHitBoxUpdated(string newHitBoxValue)
    //{
    //    MExperimentController.m_instance.taskInfo.HitBox = string.IsNullOrEmpty(newHitBoxValue) ? 0f : float.Parse(newHitBoxValue);
    //}

    public void InputSelectorHandler(int selection)
    {
        // Shut down and inactivate current controller.
        inputController.gameObject.SetActive(false); // OnDisable will be called.

        if (inputController is PupilRayController)
        {
            // PupilRayController prc = (PupilRayController)inputController;
            PupilCalibration prc = (PupilCalibration)inputController;
            prc.OnCalibrationStarted   -= WisconsinExperimentController.m_instance.HideTargets;
            prc.OnCalibrationSucceeded -= WisconsinExperimentController.m_instance.ShowTargets;
        }


        UserInputController.EDevice inputDevice = (UserInputController.EDevice)selection;
        // CameraCheck(inputDevice); // Information about VR or NoVR
        switch (inputDevice)
        {
        case UserInputController.EDevice.Pupil:

            inputController = Resources.FindObjectsOfTypeAll <PupilCalibration>()[0];
            PupilCalibration prc = (PupilCalibration)inputController;
            prc.OnCalibrationStarted   -= WisconsinExperimentController.m_instance.HideTargets;
            prc.OnCalibrationSucceeded -= WisconsinExperimentController.m_instance.ShowTargets;

            break;

        case UserInputController.EDevice.HMD:
            inputController = Resources.FindObjectsOfTypeAll <HMDRayController>()[0];
            break;

        case UserInputController.EDevice.MotionController:
            inputController = Resources.FindObjectsOfTypeAll <ViveInputController>()[0];
            break;

        case UserInputController.EDevice.Keyboard:
            inputController = Resources.FindObjectsOfTypeAll <KeyboardController>()[0];
            break;

        case UserInputController.EDevice.Mouse:
            inputController = Resources.FindObjectsOfTypeAll <MouseController>()[0];
            break;

        case UserInputController.EDevice.Null:
            inputController = Resources.FindObjectsOfTypeAll <NullInputController>()[0];
            break;

        default:
            Debug.Log("Something went wrong.");
            break;
        }
        inputController.gameObject.SetActive(true);  // OnEnable will be called.
    }
Beispiel #5
0
        public Game()
        {
            Resolution = new Sfs.Vector2u(1280, 720);
#if DEBUG
            _window = new Sfg.RenderWindow(new Sfw.VideoMode(Resolution.X, Resolution.Y), new string(Strings.GameName));
#else
            _window = new Sfg.RenderWindow(new Sfw.VideoMode(1280, 720), new string(Strings.GameName), Sfw.Styles.Fullscreen);
#endif
            var cameraView = _window.DefaultView;
            cameraView.Center = new Sfs.Vector2f(300f, 200f);
            _window.SetView(cameraView);

            var gameplayState = new GameplayState();
            _userInputController = new UserInputController {
                ActualState = gameplayState, ActualViewContainer = new GameplayStateView(gameplayState)
            };
        }
Beispiel #6
0
        public void Update(Level level, Player player)
        {
            #region i need to change this, this is very ugly
            if (UserInputController.KeyPressed(Keys.Up))
            {
                this.Shoot(level, player, Direction.Up);
            }
            else if (UserInputController.KeyPressed(Keys.Down))
            {
                this.Shoot(level, player, Direction.Down);
            }
            else if (UserInputController.KeyPressed(Keys.Left))
            {
                this.Shoot(level, player, Direction.Left);
            }
            else if (UserInputController.KeyPressed(Keys.Right))
            {
                this.Shoot(level, player, Direction.Right);
            }
            #endregion

            this.Update(60);

            ShootCoolDown();

            List <GameObject> objectsToDelete = new List <GameObject>();

            foreach (var item in this.GetChildrens())
            {
                if (!item.Visible)
                {
                    objectsToDelete.Add(item);
                }
            }

            foreach (var item in objectsToDelete)
            {
                this.RemoveChild(item);
            }
        }
 private void Start()
 {
     userInputController = gameObject.AddComponent <UserInputController>();
 }
Beispiel #8
0
 private void Awake()
 {
     instance = instance ? instance : this;
     DontDestroyOnLoad(instance);
 }
Beispiel #9
0
        private void SetupController()
        {
            UserInput = new UserInputController();

            UserInput.RegisterKeyPressAction(Keys.D, (Vector2 thumbStickPosition) =>
            {
                VelocityX += MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
            });

            UserInput.RegisterKeyPressAction(Keys.A, Buttons.LeftThumbstickLeft, (Vector2 thumbStickPosition) =>
            {
                VelocityX -= MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
            });

            UserInput.RegisterKeyPressAction(Keys.W, (Vector2 thumbStickPosition) =>
            {
                if (jumpCount < 2 && currentJump < MAX_JUMP)
                {
                    VelocityY   -= JUMP_FORCE;
                    currentJump += JUMP_FORCE;
                    VelocityY   -= JUMP_FORCE;
                    FallSpeed    = 0;
                    AudioEngine.Play("HeroJump", true);
                    //jumpCount++;
                }
            });

            UserInput.RegisterKeyReleaseAction(Keys.W, () =>
            {
                //if (jumpCount < 2)
                {
                    currentJump = 0;
                    jumpCount++;
                }
                if (IsOnGround)
                {
                    //jumpCount = 0;
                }
            });

            UserInput.LeftClickPressedAction = (mousePosition) =>
            {
                if (CurrentWeapon != null && !CurrentWeapon.IsEmpty() && !IsKicking)
                {
                    CurrentWeapon.TriggerPulled(Scene.Camera.ScreenToWorldSpace(mousePosition));
                }
            };

            UserInput.LeftClickUpAction = (mousePosition) =>
            {
                if (CurrentWeapon != null && !CurrentWeapon.IsEmpty() && !IsKicking)
                {
                    CurrentWeapon.TriggerReleased(Scene.Camera.ScreenToWorldSpace(mousePosition));
                }
            };


            UserInput.RightClickDownAction = (mousePosition) =>
            {
                if (CurrentFaceDirection == Direction.WEST)
                {
                    if (flying)
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickJetpackLeft");
                    }
                    else
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickLeft");
                    }
                }
                else
                {
                    if (flying)
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickJetpackRight");
                    }
                    else
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickRight");
                    }
                }
            };


            /*UserInput.RegisterKeyPressAction(Keys.Down, Buttons.LeftThumbstickLeft, (Vector2 thumbStickPosition) =>
             * {
             *  VelocityY += MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
             * });*/

            UserInput.RegisterKeyPressAction(Keys.Space, (Vector2 thumbStickPosition) =>
            {
                if (Fuel > 0)
                {
                    //AudioEngine.Play("Jetpack");
                    VelocityY -= JETPACK_SPEED;
                    Fuel      -= JETPACK_SPEED;
                    flying     = true;
                    if (Fuel < 0)
                    {
                        Fuel = 0;
                    }
                }
                else
                {
                    flying = false;
                }
            });

            UserInput.RegisterKeyReleaseAction(Keys.Space, () =>
            {
                flying = false;
                //AudioEngine.Stop("Jetpack");
            });

            UserInput.RegisterMouseActions(
                () =>
            {
                NextWeapon();

                /*Timer.Repeat(300, (elapsedTime) =>
                 * {
                 *  Scene.Camera.Zoom += 0.002f * elapsedTime;
                 * });*/
            },
                () =>
            {
                PreviousWeapon();

                /*Timer.Repeat(300, (elapsedTime) =>
                 * {
                 *  Scene.Camera.Zoom -= 0.002f * elapsedTime;
                 * });*/
            }
                , 100);

            /*UserInput.RegisterKeyPressAction(Keys.Space, (Vector2 thumbStickPosition) =>
             * {
             *  if (CurrentWeapon != null && !CurrentWeapon.IsEmpty())
             *  {
             *      CurrentWeapon.TriggerPulled();
             *  }
             *
             * });
             *
             * UserInput.RegisterKeyReleaseAction(Keys.Space, () =>
             * {
             *  if (CurrentWeapon != null && !CurrentWeapon.IsEmpty())
             *  {
             *      CurrentWeapon.TriggerReleased();
             *  }
             *
             * });*/

            UserInput.RegisterKeyPressAction(Keys.D1, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Handgun(Scene, this);
            }, true);

            UserInput.RegisterKeyPressAction(Keys.D2, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Machinegun(Scene, this);
            }, true);

            UserInput.RegisterKeyPressAction(Keys.D3, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Shotgun(Scene, this);
            }, true);

            UserInput.MouseMovedAction = (prevMousePos, currentMousePos) => {
                Vector2 worldPos = Scene.Camera.ScreenToWorldSpace(currentMousePos);
                if (Transform.Position.X < worldPos.X)
                {
                    if (!IsKicking)
                    {
                        CurrentFaceDirection = Direction.EAST;
                    }
                }
                else
                {
                    if (!IsKicking)
                    {
                        CurrentFaceDirection = Direction.WEST;
                    }
                }
                CurrentWeapon?.SetDirection(CurrentFaceDirection);
                CurrentWeapon?.FollowMouse(worldPos);
            };

            /*UserInput.RegisterKeyPressAction(Keys.Escape, (Vector2 thumbstickPosition) =>
             * {
             *  Config.ExitAction.Invoke();
             * });*/
        }
Beispiel #10
0
 private void CanvasForm_KeyUp(object sender, KeyEventArgs e)
 {
     UserInputController.ChangeState(e.KeyCode, false);
 }
Beispiel #11
0
        public override void Update(float currentFps)
        {
            Engine.Point previousPosition = LocalPosition;

            if (UserInputController.KeyPressed(Keys.D))
            {
                this.MoveRight();
            }
            if (UserInputController.KeyPressed(Keys.A))
            {
                this.MoveLeft();
            }
            if (UserInputController.KeyPressed(Keys.W))
            {
                this.MoveUp();
            }
            if (UserInputController.KeyPressed(Keys.S))
            {
                this.MoveDown();
            }

            foreach (var item in level.GetChildrens())
            {
                if (item is FallowingEnemy)
                {
                    if (this.BoundingBox.IntersectsWith(item.Rectangle))
                    {
                        this.Die();
                    }
                }

                if (item is Tile)
                {
                    if (this.velocity.X > 0 && Collision.IsTouchingLeft(this.velocity, this.BoundingBox, item))
                    {
                        this.velocity.X = 0;
                    }

                    if (this.velocity.X < 0 && Collision.IsTouchingRight(this.velocity, this.BoundingBox, item))
                    {
                        this.velocity.X = 0;
                    }

                    if (this.velocity.Y < 0 && Collision.IsTouchingBottom(this.velocity, this.BoundingBox, item))
                    {
                        this.velocity.Y = 0;
                    }

                    if (this.velocity.Y > 0 && Collision.IsTouchingTop(this.velocity, this.BoundingBox, item))
                    {
                        this.velocity.Y = 0;
                    }
                }
            }

            base.Update(currentFps);

            if (IsAlive)
            {
                LocalPosition += (velocity * walkingSpeed) * (1 / currentFps);
                velocity       = Engine.Point.Zero;

                this.gun.Update(this.level, this);
            }
        }
 public UserInputView(UserInputController inputController)
 {
     _inputController = inputController;
 }