Exemple #1
0
    /// <summary>
    /// Awake()でコントローラーのインスタンス生成
    /// </summary>
    private void Awake()
    {
        if (!AllController)
        {
            AllController = gameObject.AddComponent <GamePadController>();
        }
        if (!Controller1)
        {
            Controller1 = gameObject.AddComponent <GamePadController>();
        }
        if (!Controller2)
        {
            Controller2 = gameObject.AddComponent <GamePadController>();
        }
        if (!Controller3)
        {
            Controller3 = gameObject.AddComponent <GamePadController>();
        }
        if (!Controller4)
        {
            Controller4 = gameObject.AddComponent <GamePadController>();
        }

        AllController.SetParameter(gamePad_dead);
        Controller1.SetParameter(gamePad_dead);
        Controller2.SetParameter(gamePad_dead);
        Controller3.SetParameter(gamePad_dead);
        Controller4.SetParameter(gamePad_dead);

        AllController.Controller = GamePad.Index.ALL;
        Controller1.Controller   = GamePad.Index.One;
        Controller2.Controller   = GamePad.Index.Two;
        Controller3.Controller   = GamePad.Index.Three;
        Controller4.Controller   = GamePad.Index.Four;
    }
Exemple #2
0
 public GamePadButtonInfo(GamePadController controller, GamePadButton button, bool pressed, bool prevPressed)
 {
     this.controller  = controller;
     this.button      = button;
     this.pressed     = pressed;
     this.prevPressed = prevPressed;
 }
Exemple #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //KeyboardController c1 = new KeyboardController();
            GamePadController c1 = new GamePadController(PlayerIndex.One);

            player1 = new Player(graphics.GraphicsDevice, c1, 20,
                                 graphics.GraphicsDevice.Viewport.Height / 2, Color.Red);

            KeyboardController c2 = new KeyboardController();

            c2.up    = Keys.W;
            c2.down  = Keys.S;
            c2.right = Keys.D;
            c2.left  = Keys.A;
            c2.fire  = Keys.Space;
            //player2 = new Player(graphics.GraphicsDevice, k2, graphics.GraphicsDevice.Viewport.Width - 60,
            //                                                            graphics.GraphicsDevice.Viewport.Height / 2, Color.Blue);
            player2 = new CirclePlayer(graphics.GraphicsDevice, c2, graphics.GraphicsDevice.Viewport.Width - 60,
                                       graphics.GraphicsDevice.Viewport.Height / 2, Color.Blue);

            // TODO: use this.Content to load your game content here
        }
Exemple #4
0
 public GamePadTriggerInfo(GamePadController controller, GamePadTrigger trigger, float value, bool pressed, bool prevPressed)
 {
     this.controller  = controller;
     this.trigger     = trigger;
     this.value       = value;
     this.pressed     = pressed;
     this.prevPressed = prevPressed;
 }
Exemple #5
0
 public GamePadAxisInfo(GamePadController controller, GamePadAxis axis, Vector2f value, bool pressed, bool prevPressed)
 {
     this.controller  = controller;
     this.axis        = axis;
     this.value       = value;
     this.pressed     = pressed;
     this.prevPressed = prevPressed;
 }
Exemple #6
0
        public override Vector2f GetGamePadAxis(GamePadAxis axis, GamePadController controller, bool rawValue)
        {
            if (controller == GamePadController.None || axis == GamePadAxis.None)
            {
                return(Vector2f.zero);
            }

            string xAxisName       = "";
            string yAxisName       = "";
            int    controllerIndex = (int)controller;

            if (controller == GamePadController.Any)
            {
                controllerIndex = 0;
            }

            switch (axis)
            {
            case GamePadAxis.Dir_Pad:
                xAxisName = "DPad_XAxis_" + controllerIndex;
                yAxisName = "DPad_YAxis_" + controllerIndex;
                break;

            case GamePadAxis.L_Stick:
                xAxisName = "L_XAxis_" + controllerIndex;
                yAxisName = "L_YAxis_" + controllerIndex;
                break;

            case GamePadAxis.R_Stick:
                xAxisName = "R_XAxis_" + controllerIndex;
                yAxisName = "R_YAxis_" + controllerIndex;
                break;
            }

            Vector2f axisValue = Vector2f.zero;

            try
            {
                if (!rawValue)
                {
                    axisValue.x = UnityEngine.Input.GetAxis(xAxisName);
                    axisValue.y = -UnityEngine.Input.GetAxis(yAxisName);
                }
                else
                {
                    axisValue.x = UnityEngine.Input.GetAxisRaw(xAxisName);
                    axisValue.y = -UnityEngine.Input.GetAxisRaw(yAxisName);
                }
            }
            catch (System.Exception e)
            {
                Core.debug.Error(e.Message);
            }

            return(axisValue);
        }
Exemple #7
0
    void Start()
    {
        DontDestroyOnLoad(gameObject);
        rg = GetComponent <Rigidbody2D>();

        hover   = new Hover(1f, rg);
        dash    = new Dash(transform, 0.35f, 3.0f);
        minigun = new Minigun(20, 1.5f, transform, proiettile);

        StartCoroutine(GamePadController.SetColorePs4(coloreBase));
    }
    // Resize UI Panel's height when a new line is added
    override protected void NewLineUIPanelResizing()
    {
        base.NewLineUIPanelResizing();
        float UIPanelHeightAugmentation = hiddenTextRect.rect.height * lineHeightFactor * text_text.lineSpacing;
        float controllerTranslation     = UIPanelHeightAugmentation / 2;

        UIPanelRect.sizeDelta = UIPanelRect.sizeDelta + new Vector2(0, UIPanelHeightAugmentation);
        if (panelVAlignment == VERTICAL_ALIGNMENT.UPPER_ALIGNMENT)
        {
            UIPanelRect.anchoredPosition = UIPanelRect.anchoredPosition + new Vector2(0, UIPanelHeightAugmentation / 2.0f);
            controllerTranslation        = UIPanelHeightAugmentation;
        }
        else if (panelVAlignment == VERTICAL_ALIGNMENT.LOWER_ALIGNMENT)
        {
            UIPanelRect.anchoredPosition = UIPanelRect.anchoredPosition - new Vector2(0, UIPanelHeightAugmentation / 2.0f);
            controllerTranslation        = 0;
        }

        // Move controller on Y axis
        if (automaticControllerPosition && linkWithController)
        {
            if (GamePadController != null && GamePadController.isActive)
            {
                GamePadController.TranslatePositionY(controllerTranslation);
            }
            if (KeyboardController != null && KeyboardController.isActive)
            {
                KeyboardController.TranslatePositionY(controllerTranslation);
            }
            if (MouseController != null && MouseController.isActive)
            {
                MouseController.TranslatePositionY(controllerTranslation);
            }
        }

        for (int i = 0; i < textList.Count; i++)
        {
            if (linesCount != i)
            {
                if (textList [i] != null)
                {
                    textList [i].GetComponent <Text> ().text = textList [i].GetComponent <Text> ().text + '\n';
                }
            }
            // Reposition texts GameObject when origin Y position is not 0
            if (originTextYPosition != 0)
            {
                if (textList [i] != null)
                {
                    textList [i].GetComponent <RectTransform> ().anchoredPosition = textList [i].GetComponent <RectTransform> ().anchoredPosition + new Vector2(0, originTextYPosition / 2.0f);
                }
            }
        }
    }
Exemple #9
0
        internal Mage(string name, PlayerIndex input, Color targetColor, Color tint)
            : base(name, new Actor(name.Contains("1")?Animations:Animations2))
        {
            if (GamePad.GetState(input).IsConnected)
            {
                controller = new GamePadController(input);
            }
            else
            {
                controller = new KeyboardController();
            }
            currentTargetAlignment = TargetAlignment.None;
            This.Game.LoadingLevel.AddAnimation(new Animation("target.anim"));
            target         = new Sprite("target", new Actor(new Animation("target.anim")));
            target.Visible = false;
            target.Static  = true;
            target.mColor  = targetColor;
            mColor         = tint;
            target.Scale   = 1.5f;
            sortType       = new DistanceSort(this);

            UpdateBehavior         = mUpdate;
            CollidesWithBackground = true;

            This.Game.AudioManager.AddSoundEffect("Effects/Sword_Attack");
            This.Game.AudioManager.AddSoundEffect("Effects/Lightning_Strike");
            This.Game.AudioManager.AddSoundEffect("Effects/Earthquake");
            This.Game.AudioManager.AddSoundEffect("Effects/RockShower");
            This.Game.AudioManager.AddSoundEffect("Effects/Lightning_T1");
            This.Game.AudioManager.AddSoundEffect("Effects/Water_T1");
            This.Game.AudioManager.AddSoundEffect("Effects/Water_T2");
            This.Game.AudioManager.AddSoundEffect("Effects/Water_T3");
            This.Game.AudioManager.AddSoundEffect("Effects/Fire_T1");
            This.Game.AudioManager.AddSoundEffect("Effects/Fire_T2");
            This.Game.AudioManager.AddSoundEffect("Effects/Fire_T3");
            This.Game.AudioManager.AddSoundEffect("Effects/Earth_T1");


            This.Cheats.AddCheat("SpeedUp_" + Name, new SpeedUpCheat(this, Speed * 2));

            CollisionList = 3;

            Effect    particleEffect = This.Game.CurrentLevel.GetEffect("ParticleSystem");
            Texture2D bloodParticle  = This.Game.CurrentLevel.GetTexture("blood");
            Texture2D sparkball      = This.Game.CurrentLevel.GetTexture("sparkball");

            blood     = new ParticleEmitter(200, particleEffect, bloodParticle);
            spellCast = new ParticleEmitter(1000, particleEffect, sparkball);

            isDieEffectEnabled = true;
        }
Exemple #10
0
        protected override void Initialize()
        {
            Controllers = new Collection <IController>();
            WorldLoader.InitializeLists();
            GamePadController  gamepad  = new GamePadController(this);
            KeyboardController keyboard = new KeyboardController(this);

            keyboard.RegisterKeys(this);
            gamepad.RegisterButtons(this);
            Controllers.Add(gamepad);
            Controllers.Add(keyboard);
            Camera.SetViewportAndOrigin(GraphicsDevice.Viewport);
            base.Initialize();
        }
Exemple #11
0
        public override float GetGamePadTrigger(GamePadTrigger trigger, GamePadController controller, bool rawValue)
        {
            if (controller == GamePadController.None || trigger == GamePadTrigger.None)
            {
                return(0f);
            }

            string triggerName     = "";
            int    controllerIndex = (int)controller;

            if (controller == GamePadController.Any)
            {
                controllerIndex = 0;
            }

            switch (trigger)
            {
            case GamePadTrigger.Left:
                triggerName = "TriggersL_" + controllerIndex;
                break;

            case GamePadTrigger.Right:
                triggerName = "TriggersR_" + controllerIndex;
                break;
            }

            float triggerValue = 0f;

            try
            {
                if (!rawValue)
                {
                    triggerValue = UnityEngine.Input.GetAxis(triggerName);
                }
                else
                {
                    triggerValue = UnityEngine.Input.GetAxisRaw(triggerName);
                }
            }
            catch (System.Exception e)
            {
                Core.debug.Error(e.Message);
            }

            return(triggerValue);
        }
Exemple #12
0
        public void AddGamePadAxis(Identifier action, GamePadAxis axis, GamePadController controller = GamePadController.Any, PlayerId player = PlayerId.Player1)
        {
            var actionId        = new InputActionId(action, player);
            var gamePadAxisInfo = new GamePadAxisInfo(controller, axis, Vector2f.zero, false, false);

            if (gamePadAxisBindings.ContainsKey(actionId))
            {
                gamePadAxisBindings[actionId].Add(gamePadAxisInfo);
            }
            else
            {
                var newList = new List <GamePadAxisInfo>()
                {
                    gamePadAxisInfo
                };
                gamePadAxisBindings.Add(actionId, newList);
            }
        }
Exemple #13
0
        public void AddGamePadTrigger(Identifier action, GamePadTrigger trigger, GamePadController controller = GamePadController.Any, PlayerId player = PlayerId.Player1)
        {
            var actionId           = new InputActionId(action, player);
            var gamePadTriggerInfo = new GamePadTriggerInfo(controller, trigger, 0f, false, false);

            if (gamePadTriggerBindings.ContainsKey(actionId))
            {
                gamePadTriggerBindings[actionId].Add(gamePadTriggerInfo);
            }
            else
            {
                var newList = new List <GamePadTriggerInfo>()
                {
                    gamePadTriggerInfo
                };
                gamePadTriggerBindings.Add(actionId, newList);
            }
        }
Exemple #14
0
    /// <summary>
    /// 更新
    /// </summary>
    public void PlayerUpdate()
    {
        //コントローラー
        gamePad = MyInputManager.GetController(useControllerIndex);



        //攻撃
        //Attack();
        AttackTrgOn();
        AttackUpdate();

        //回転
        Turn();

        //移動
        Move();
    }
Exemple #15
0
        public UI()
        {
            InitializeComponent();

            ClientSize = new Size(GameWidth * 2, GameHeight * 2);

            FindRenderers();
            SetRenderer(availableRenderers.Last());

            var joysticks = GamePadController.GetJoysticks();

            if (joysticks.Count != 0)
            {
                controller = new GamePadController(joysticks[0].InstanceGuid);
            }
            else
            {
                controller = new KeyboardController();
            }
        }
Exemple #16
0
        protected override void Initialize()
        {
            Quit       = () => { this.Exit(); };
            LevelReset = () => { if (State == GameState.InGame)
                                 {
                                     GameWorld = WorldLoader.LoadWorld(Selector.CurrentLevel, this);
                                 }
            };
            MenuReset = () => { State = GameState.WorldSelector; };

            InputActions.LoadInputActions(this);
            controllers = new List <IController>();
            KeyboardController keyboard = new KeyboardController(this);
            GamePadController  gamepad  = new GamePadController(this);

            controllers.Add(keyboard);
            controllers.Add(gamepad);

            Selector = new LevelSelector(this);
            State    = GameState.WorldSelector;

            base.Initialize();
        }
Exemple #17
0
        public Player(Game game, PlayerIndex playerIndex, Vector2 PlayerPosition)
            : base(game)
        {
            guns = new List<Gun>(new Gun[]{
                new GrenadeLauncher(Game),
                new HandGun(Game)}
            );
            this.playerIndex = playerIndex;
            Position = PlayerPosition;
            relativeBounds = new Rectangle(-10, -10, 20, 20);
            Speed = 200;
            reticule = new Sprite(Game, "reticule_new");
            controller = new GamePadController(playerIndex);

            //Kenneth: Hardkoder inn spillernavn,health, life, deaths, kills. ønsker som parameter senere
            PlayerName = "Godzilla!";
            Health = 100;
            Life = 5;
            Deaths = 0;
            Kills = 0;
            //la til keyboard
            oldKeyboardState = Keyboard.GetState();
        }
Exemple #18
0
    /// <summary>
    /// 初期化
    /// </summary>
    public void Initialize()
    {
        //  移動可能フラグ
        isMove = true;

        //  回転可能フラグ
        isRotation = true;

        //  攻撃可能フラグ
        isAttack = false;

        //  無敵フラグ
        isInvisible = false;

        //  初期位置の記憶
        resetPos = modelObject.transform.position;

        //  ポイント
        point = 0;

        //  コントローラーの設定
        gamePad = MyInputManager.GetController(useControllerIndex);

        //  アウトラインマテリアルの設定
        SetOutlineColor();

        //  蹴り
        KickEvent inst = modelObject.AddComponent <KickEvent>();

        inst.Init(animator);

        //  キック時の攻撃トリガーを入れる関数
        Action kickStartFunc = () =>
        {
            //  攻撃のトリガー
            isAttack = true;
            #region DEBUG
            #if UNITY_EDITOR
            //  デバッグ用
            isDrawAttackTrigger = true;
            #endif
            #endregion
        };

        inst.SetKickStartFunc(kickStartFunc);

        //  キック時の攻撃トリガーを切る関数
        Action kickEndFunc = () =>
        {
            AttackTrgOff();
        };

        inst.SetKickEndFunc(kickEndFunc);

        //  攻撃時に発生するボイス
        Action kickVoiceFunc = () =>
        {
            KickVoice();
        };

        inst.SetKickVoiceFunc(kickVoiceFunc);

        //  注視処理
        Vector3 targetPos = Camera.main.transform.position;

        lookAtTargetIK.SetTargetPosition(targetPos);
        lookAtTargetIK.SetLookAtWeight(1.0f, 0.0f, 0.45f, 0.0f, 0.5f);
    }
Exemple #19
0
 public abstract bool IsGamePadButtonReleased(GamePadButton button, GamePadController controller = GamePadController.Any);
Exemple #20
0
 private void Awake()
 {
     instance = this;
 }
Exemple #21
0
 public abstract Vector2f GetGamePadAxis(GamePadAxis axis, GamePadController controller          = GamePadController.Any, bool rawValue = false);
Exemple #22
0
        private int GetGamePadKeyCode(GamePadController controller, GamePadButton button)
        {
            int index;

            switch (controller)
            {
            case GamePadController.Any:
                index = (int)GamePadButtonInternal.Any_1;
                break;

            case GamePadController.Controller_1:
                index = (int)GamePadButtonInternal.C1_1;
                break;

            case GamePadController.Controller_2:
                index = (int)GamePadButtonInternal.C2_1;
                break;

            case GamePadController.Controller_3:
                index = (int)GamePadButtonInternal.C3_1;
                break;

            case GamePadController.Controller_4:
                index = (int)GamePadButtonInternal.C4_1;
                break;

            case GamePadController.Controller_5:
                index = (int)GamePadButtonInternal.C5_1;
                break;

            case GamePadController.Controller_6:
                index = (int)GamePadButtonInternal.C6_1;
                break;

            case GamePadController.Controller_7:
                index = (int)GamePadButtonInternal.C7_1;
                break;

            case GamePadController.Controller_8:
                index = (int)GamePadButtonInternal.C8_1;
                break;

            default:
                index = (int)GamePadButtonInternal.None;
                break;
            }

            if (controller != GamePadController.None)
            {
                if (button != GamePadButton.None)
                {
                    index += (int)button - 1;
                }
                else
                {
                    index = (int)GamePadButtonInternal.None;
                }
            }

            return(index);
        }
Exemple #23
0
 public abstract float GetGamePadTrigger(GamePadTrigger trigger, GamePadController controller    = GamePadController.Any, bool rawValue = false);
Exemple #24
0
 void Start()
 {
     // !!!!!!!!!!!!!
     // This would probably be better implemented using a prefab, check Scripts/PlayerBehaviour.cs
     controller = GameObject.FindGameObjectWithTag("GamePad").GetComponent <GamePadController>();
 }
 public void Danneggia()
 {
     AggiornaVita(-1);
     GamePadController.Vibra(0.5f, 0.75f, 0.75f);
 }
Exemple #26
0
 public override bool IsGamePadButtonReleased(GamePadButton button, GamePadController controller)
 {
     return(UnityEngine.Input.GetKeyUp((UnityEngine.KeyCode)GetGamePadKeyCode(controller, button)));
 }
        public static void GameOverReset(this GameMario game)
        {
            Physics.Reset();
            EventManager.Ins.Reset();
            Camera.Ins.Reset();
            Scene.Ins.Reset();
            Scene.Ins.Active(Constants.DEFAULT_SCENE);
            Scene.Ins.ResetActive();

            Coins.Ins.Reset();
            Score.Ins.Reset();
            Lives.Ins.Reset();
            Timer.Ins.Reset();
            HUD.Ins.Reset();

            game.State = new GameMarioStateNormal(game);

            EventManager.Ins.Subscribe(EventEnum.GameOver, () => game.State.TriggerGameOver());

            EventManager.Ins.Subscribe(EventEnum.Win, () => game.State.TriggerGameWin());

            EventManager.Ins.Subscribe(EventEnum.KeyDown, (s, e) =>
            {
                switch ((e as KeyDownEventArgs).key)
                {
                case Keys.Q:
                    game.Exit();
                    break;

                case Keys.R:
                    game.State.TriggerReset();
                    break;

                case Keys.Escape:
                    game.State.Pause();
                    break;

                case Keys.M:
                    if (AudioManager.Ins.IsMuted)
                    {
                        AudioManager.Ins.Unmute();
                    }
                    else
                    {
                        AudioManager.Ins.Mute();
                    }
                    break;
                }
            });

            game.Controllers.Clear();
            var keyboardController = new GameKeyboardController();

            keyboardController.SetKeyMapping(Keys.LeftShift, Keys.X);
            keyboardController.SetKeyMapping(Keys.RightShift, Keys.X);
            keyboardController.SetKeyMapping(Keys.Space, Keys.Up);
            keyboardController.SetKeyMapping(Keys.Z, Keys.Up);
            keyboardController.SetKeyMapping(Keys.W, Keys.Up);
            keyboardController.SetKeyMapping(Keys.S, Keys.Down);
            keyboardController.SetKeyMapping(Keys.A, Keys.Left);
            keyboardController.SetKeyMapping(Keys.D, Keys.Right);
            keyboardController.EnableKeyEvent(InputState.Down, Keys.Q, Keys.R, Keys.Escape, Keys.M);
            keyboardController.EnableKeyEvent(InputState.Down, Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.X);
            keyboardController.EnableKeyEvent(InputState.Up, Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.X);
            keyboardController.EnableKeyEvent(InputState.Hold, Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.X);
            keyboardController.EnableKeyEvent(InputState.Down, Keys.Y, Keys.U, Keys.I, Keys.O, Keys.P);
            game.Controllers.Add(keyboardController);

            var gamePadController = new GamePadController();

            gamePadController.EnableButtonEvent(InputState.Down, Buttons.Start);
            gamePadController.EnableButtonEvent(InputState.Down,
                                                Buttons.LeftThumbstickDown,
                                                Buttons.LeftThumbstickLeft,
                                                Buttons.LeftThumbstickRight,
                                                Buttons.A,
                                                Buttons.B
                                                );
            gamePadController.EnableButtonEvent(InputState.Hold,
                                                Buttons.LeftThumbstickDown,
                                                Buttons.LeftThumbstickLeft,
                                                Buttons.LeftThumbstickRight,
                                                Buttons.A,
                                                Buttons.B
                                                );
            gamePadController.EnableButtonEvent(InputState.Up,
                                                Buttons.LeftThumbstickDown,
                                                Buttons.LeftThumbstickLeft,
                                                Buttons.LeftThumbstickRight,
                                                Buttons.A,
                                                Buttons.B
                                                );
            game.Controllers.Add(gamePadController);
        }
Exemple #28
0
 /// <summary>
 /// 使用するコントローラーの設定
 /// </summary>
 /// <param name="index"></param>
 public void SetControllerIndex(GamePadInput.GamePad.Index index)
 {
     useControllerIndex = index;
     gamePad            = MyInputManager.GetController(useControllerIndex);
 }