public static void UpdateGamepad()
        {
            try{
            gamepadData = GamePad.GetData(0);

            AnalogLeftX = gamepadData.AnalogLeftX;
            AnalogLeftY = gamepadData.AnalogLeftY;
            AnalogRightX = gamepadData.AnalogRightX;
            AnalogRightY = gamepadData.AnalogRightY;

            #if ANALOG_RIGHT_EMU
                if(ButtonsAreDown(GamePadButtons.Left))AnalogRightX = -1;
                else if (ButtonsAreDown(GamePadButtons.Right))AnalogRightX = 1;

                if(ButtonsAreDown(GamePadButtons.Up))AnalogRightY = -1;
                else if (ButtonsAreDown(GamePadButtons.Down))AnalogRightY = 1;
            #elif ANALOG_LEFT_EMU
                if(ButtonsAreDown(GamePadButtons.Left))AnalogLeftX = -1;
                else if (ButtonsAreDown(GamePadButtons.Right))AnalogLeftX = 1;

                if(ButtonsAreDown(GamePadButtons.Up))AnalogLeftY = -1;
                else if (ButtonsAreDown(GamePadButtons.Down))AnalogLeftY = 1;
            #endif

            }catch(Exception){}
        }
        public override void Tick(float dt)
        {
            base.Tick(dt);

            GamePadData data = GamePad.GetData(0);

            float analogX = 0.0f;
            float analogY = 0.0f;


            //d-pad movement,emulating analog movement of the sticks
            if (Input2.GamePad0.Right.Down)
            {
                analogX = 1.0f;
            }
            else if (Input2.GamePad0.Left.Down)
            {
                analogX = -1.0f;
            }
            if (Input2.GamePad0.Up.Down)
            {
                analogY = -1.0f;
            }
            else if (Input2.GamePad0.Down.Down)
            {
                analogY = 1.0f;
            }


            //if the left stick is moving,then use values read from the stick
            if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f)
            {
                analogX = data.AnalogLeftX;
                analogY = data.AnalogLeftY;
            }


            //calculate the position
            Position = new Vector2(Position.X + analogX / 10f, Position.Y - analogY / 10f);


            //rotate according to the right analog stick, or if it's not moving, then according the the left stick
            // so basically if you are not pointing the player in any direction with the right stick he is going to point in the walking direction
            //or if both sticks are not moving,then use the analogX and analogY values(d-pad movement)
            if (data.AnalogRightX > 0.2f || data.AnalogRightX < -0.2f || data.AnalogRightY > 0.2f || data.AnalogRightY < -0.2f)
            {
                var angleInRadians = FMath.Atan2(-data.AnalogRightX, -data.AnalogRightY);
                Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f)
            {
                var angleInRadians = FMath.Atan2(-data.AnalogLeftX, -data.AnalogLeftY);
                Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (analogX != 0.0f || analogY != 0.0f)
            {
                var angleInRadians = FMath.Atan2(-analogX, -analogY);
                Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
        }
        /// アップデート
        public bool Update()
        {
            GamePadData gamePadData = GamePad.GetData(trgDevIdx);

            /// ボタン入力の保管
            setInputState(ref inputScan, gamePadData.Buttons);                  /// 押されているボタン
            setInputState(ref inputTrig, gamePadData.ButtonsDown);              /// 今回押したボタン
            setInputState(ref inputFree, gamePadData.ButtonsUp);                /// 今回離したボタン

            /// アナログ入力の保管
            inputAnalogLeftX  = gamePadData.AnalogLeftX;
            inputAnalogLeftY  = gamePadData.AnalogLeftY;
            inputAnalogRightX = gamePadData.AnalogRightX;
            inputAnalogRightY = gamePadData.AnalogRightY;

            /// 連続入力の情報更新
            updateInputRepeat();

/*
 *              /// アナログ入力
 *              if( gamePadButtons.AnalogLeftX != 0.0f || gamePadButtons.AnalogLeftY != 0.0f ){
 *                      inputState |= InputGamePadState.AnalogLeft;
 *              }
 *              if( gamePadButtons.AnalogRightX != 0.0f || gamePadButtons.AnalogRightY != 0.0f ){
 *                      inputState |= InputGamePadState.AnalogRight;
 *              }
 */
            //Console.WriteLine( " rep : " + inputRepeat + "<"+repeatStartWaitFrameCnt+", "+repeatEveryWaitFrameCnt+">" + "( "+inputScan+", "+inputRepeatTmp+" )" );



            return(true);
        }
Exemple #4
0
    public override bool PollJoystick(int port, float[] joyx, float[] joyy, float[] joyz, bool[] buttons)
    {
        if (port != 0)
        {
            return(false);
        }

        GamePadData gd = GamePad.GetData(port);

        joyx[0] = gd.AnalogLeftX;
        joyy[0] = -gd.AnalogLeftY;

        joyx[1] = gd.AnalogRightX;
        joyy[1] = -gd.AnalogRightY;

        GamePadButtons down = gd.ButtonsDown;

        buttons[0]  = (down & GamePadButtons.Cross) != 0;
        buttons[1]  = (down & GamePadButtons.Circle) != 0;
        buttons[2]  = (down & GamePadButtons.Square) != 0;
        buttons[3]  = (down & GamePadButtons.Triangle) != 0;
        buttons[4]  = (down & GamePadButtons.L) != 0;
        buttons[5]  = (down & GamePadButtons.R) != 0;
        buttons[6]  = (down & GamePadButtons.Back) != 0;
        buttons[7]  = (down & GamePadButtons.Start) != 0;
        buttons[8]  = (down & GamePadButtons.Left) != 0;
        buttons[9]  = (down & GamePadButtons.Up) != 0;
        buttons[10] = (down & GamePadButtons.Right) != 0;
        buttons[11] = (down & GamePadButtons.Down) != 0;

        return(true);
    }
Exemple #5
0
        public static void UpdateMenu(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            if ((pressedButtons & GamePadButtons.Square) == GamePadButtons.Square)
            {
                InitializeInstructions();
            }
            if ((pressedButtons & GamePadButtons.Triangle) == GamePadButtons.Triangle)
            {
                InitializeCredits();
            }
            if ((pressedButtons & GamePadButtons.Circle) == GamePadButtons.Circle)
            {
                InitializeHighScore();
            }
            if ((pressedButtons & GamePadButtons.Select) == GamePadButtons.Select)
            {
                EndGame();
            }
            if ((pressedButtons & GamePadButtons.Cross) == GamePadButtons.Cross)
            {
                InitializeNewGame();
            }
        }
Exemple #6
0
 private void checkKeys(GamePadData gamePadData)
 {
     if ((gamePadData.Buttons & GamePadButtons.Left) != 0)
     {
         left.toggle(true);
     }
     else
     {
         left.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Up) != 0)
     {
         up.toggle(true);
     }
     else
     {
         up.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Right) != 0)
     {
         right.toggle(true);
     }
     else
     {
         right.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Down) != 0)
     {
         down.toggle(true);
     }
     else
     {
         down.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Cross) != 0)
     {
         fire.toggle(true);
     }
     else
     {
         fire.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Circle) != 0)
     {
         exit.toggle(true);
     }
     else
     {
         exit.toggle(false);
     }
     if ((gamePadData.Buttons & GamePadButtons.Start) != 0)
     {
         pause.toggle(true);
     }
     else
     {
         pause.toggle(false);
     }
 }
Exemple #7
0
 public void tick(GamePadData gamePadData)
 {
     for (int i = 0; i < keys.Count; i++)
     {
         keys[i].tick();
         checkKeys(gamePadData);
     }
 }
Exemple #8
0
        public static void UpdateCredits(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            if ((pressedButtons & GamePadButtons.Start) == GamePadButtons.Start)
            {
                InitializeMenu();
            }
        }
Exemple #9
0
        public void Update(GamePadData gamePadData)
        {
            if (hitPoints <= 0)
            {
                isAlive = false;
            }

            Move(gamePadData);
        }
Exemple #10
0
 internal static void Initialize()
 {
     //Init devices
     Keyboard = new KeyboardData();
     Mouse = new MouseData();
     GamePads = new GamePadData[4];
     for (int i = 0; i < 4; i++)
         GamePads[i] = new GamePadData((PlayerIndex)i);
     VirtualInputs = new List<VirtualInput>();
 }
Exemple #11
0
 /// <summary>
 /// 静的コンストラクタ
 /// </summary>
 static Peripheral()
 {
     _padData = GamePad.GetData(0);
     TouchDataList = new List<TouchData>();
     _holdDic = new Dictionary<GamePadButtons, float>();
     foreach (GamePadButtons btnType in Enum.GetValues(typeof (GamePadButtons)))
     {
         _holdDic.Add(btnType, 0);
     }
 }
Exemple #12
0
        public static void UpdateHighScore(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            if ((pressedButtons & GamePadButtons.Start) == GamePadButtons.Start)
            {
                InitializeMenu();
            }
            topScoreHUD.Update(gamePadData);
        }
Exemple #13
0
        public void Update(GamePadData gamePadData)
        {
            //Checks for keypresses and adjusts the ship accordingly
            rot = Rotation;
            if ((gamePadData.Buttons & GamePadButtons.Left) != 0)
            {
                if (s.Position.X - speed >= 0)
                {
                    s.Position.X -= speed;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Right) != 0)
            {
                if (s.Position.X + s.Width + speed < graphics.Screen.Rectangle.Width)
                {
                    s.Position.X += speed;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Up) != 0)
            {
                if (s.Position.Y - speed >= 0)
                {
                    s.Position.Y -= speed;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Down) != 0)
            {
                if (s.Position.Y + s.Height + speed <= graphics.Screen.Height)
                {
                    s.Position.Y += speed;
                }
            }
            if ((gamePadData.Buttons & GamePadButtons.Square) != 0)
            {
                rot -= .05f;
            }
            if ((gamePadData.Buttons & GamePadButtons.Circle) != 0)
            {
                rot += .05f;
            }

            //If cross is held, then the player will slow down
            if ((gamePadData.Buttons & GamePadButtons.Cross) != 0)
            {
                speed = 2;
            }
            else
            {
                speed = 4;
            }
        }
Exemple #14
0
        static public void Initialize()
        {
            Keyboard = new KeyboardData();
            Mouse    = new MouseData();

            GamePads = new GamePadData[4];
            for (int i = 0; i < 4; i++)
            {
                GamePads[i] = new GamePadData((PlayerIndex)i);
            }
        }
Exemple #15
0
 static internal void Initialize()
 {
     //Init devices
     Keyboard = new KeyboardData();
     Mouse    = new MouseData();
     GamePads = new GamePadData[4];
     for (int i = 0; i < 4; i++)
     {
         GamePads[i] = new GamePadData((PlayerIndex)i);
     }
     VirtualInputs = new List <VirtualInput>();
 }
Exemple #16
0
        public void Update()
        {
            pad = GamePad.GetData(0);

            if (state != State.VIEW)
            {
                BrowseInput();
            }
            else if (state == State.VIEW)
            {
                ReadModeInput();
            }
        }
Exemple #17
0
        public static void UpdatePaused(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            if ((pressedButtons & GamePadButtons.Start) == GamePadButtons.Start)
            {
                currentState = GameState.Playing;
            }
            if ((pressedButtons & GamePadButtons.Select) == GamePadButtons.Select)
            {
                InitializeMenu();
            }
        }
Exemple #18
0
        private void SpawnPlayer(GamePadData gamepad, int index)
        {
            Vector2 spawnLocation = _spawnLocations.DistributeSpawn();
            var     spawnX        = (int)spawnLocation.X;
            var     spawnY        = (int)spawnLocation.Y;
            var     player        = scene.addEntity(new Player(Characters.All().randomItem(), spawnX, spawnY, index));

            player.addComponent(new PlayerController(gamepad));

            _connectedPlayers.Add(player);

            _playerSpawnedThisFrame = true;
        }
Exemple #19
0
        public void Update(GamePadData gamePadData, float dt)
        {
            //Handle player controls
            Vector2 tempPosition =  sprite.Position;

            tempPosition.X += gamePadData.AnalogLeftX * ananlogScale;
            tempPosition.Y += - gamePadData.AnalogLeftY * ananlogScale;

            tempPosition.X += gamePadData.AnalogRightX * ananlogScale;
            tempPosition.Y += - gamePadData.AnalogRightY * ananlogScale;

            sprite.Position = tempPosition;

            // handle gravity well controls

            Vector2 touchPosition = new Vector2(0,0);
            List<TouchData> touch_data_list = Touch.GetData(0);

            if(touch_data_list.Count > 0)
            {
                TouchData touchData = touch_data_list[0];

                touchPosition.X =  touchData.X * 960f ;
                touchPosition.Y = - touchData.Y * 544f ;
                /*
                System.Console.WriteLine( "X: {0:G}", touchPosition.X );
                System.Console.WriteLine( "Y: {0:G}", touchPosition.Y );
                */
                if (touchData.X != 0 && touchData.Y != 0)
                {
                    gravitywell_1.sprite.Position = touchPosition + new Vector2(480,272); //shift for Vita's coordinate system
                }

            }

            //handle buttons

            //firing

            if( gamePadData.Buttons == GamePadButtons.L || gamePadData.Buttons == GamePadButtons.R)
            {
                gravityWeapon.FireWeapon(sprite.Position, dt);
            }

            //update gravity inlfuences
            gravitywell_1.ApplyGravityToObjectArray( gravityWeapon.bulletsArray);

            //update players's objects, ex; weapons
            gravityWeapon.Update(dt);
        }
Exemple #20
0
 public void Update(GamePadData gamePadData)
 {
     /* cube自身のupdate */
     for (int i = 0; i < gameSize; i++)
     {
         for (int j = 0; j < gameSize; j++)
         {
             for (int k = 0; k < gameSize; k++)
             {
                 cubes[i, j, k].Update(gamePadData);
             }
         }
     }
 }
Exemple #21
0
        public static void UpdateGameOver(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            topScoreHUD.Update(gamePadData);

            if ((pressedButtons & GamePadButtons.Start) == GamePadButtons.Start)
            {
                scoreList[4].PlayerInitials = topScoreHUD.PlayersInitials;
                scoreList[4].PlayerScore    = topScoreHUD.PlayersScore;
                Array.Sort(scoreList);
                Array.Reverse(scoreList);
                InitializeMenu();
            }
        }
Exemple #22
0
        public void Update(GamePadData gamePadData, long deltaTime)
        {
            elapsedTime += deltaTime;

            if (activeFrame != 0 && (waitTime < elapsedTime - saveTime))
            {
                activeFrame = 0;
            }

            move(gamePadData);

            setDirection();

            tSpeed = 1f;
        }
Exemple #23
0
        public override void Fire(GamePadData gamepaddata, long elapsed)
        {
            Recoil += elapsed;
            if((gamepaddata.ButtonsDown & GamePadButtons.Down)!=0 && Mag>Spent)
            {
                if (Recoil >= FireRate * 1000f) {
                    Shoot ();
                    Spent++;
                    Recoil = 0;
                }

                else{}
            }
            if (Mag<=Spent){
                Reload(elapsed);
            }
            else{}
        }
        public void Update(GamePadData gamePadData)
        {
            scale = 1.0f;

            if ((gamePadData.Buttons & GamePadButtons.Circle) != 0)
            {
                if (selectStatus == CubeSelectStatus.Circle)
                {
                    scale = GameParameters.CubeScale;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Cross) != 0)
            {
                if (selectStatus == CubeSelectStatus.Cross)
                {
                    scale = GameParameters.CubeScale;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Square) != 0)
            {
                if (selectStatus == CubeSelectStatus.Square)
                {
                    scale = GameParameters.CubeScale;
                }
            }

            if ((gamePadData.Buttons & GamePadButtons.Triangle) != 0)
            {
                if (selectStatus == CubeSelectStatus.Triangle)
                {
                    scale = GameParameters.CubeScale;
                }
            }


            front.Update();
            left.Update();
            back.Update();
            right.Update();
            top.Update();
            bottom.Update();
        }
Exemple #25
0
        private void Move(GamePadData gamePadData)
        {
            var pressedButtons = gamePadData.ButtonsDown;

            velocityFwd = new Vector3((float)Math.Cos(sprite.Rotation) * speed, (float)Math.Sin(sprite.Rotation) * speed, 0);

            if ((gamePadData.Buttons & GamePadButtons.Up) != 0)
            {
                sprite.Position += velocityFwd;
            }
            if ((gamePadData.Buttons & GamePadButtons.Down) != 0)
            {
                sprite.Position -= velocityFwd;
            }
            if ((gamePadData.Buttons & GamePadButtons.Left) != 0)
            {
                sprite.Rotation -= .05f;
            }
            if ((gamePadData.Buttons & GamePadButtons.Right) != 0)
            {
                sprite.Rotation += .05f;
            }

            // creating some max movements here.
            maxRight = graphics.Screen.Rectangle.Width;
            maxDown  = graphics.Screen.Rectangle.Height;
            if (sprite.Position.X < 0)
            {
                sprite.Position.X = 0;
            }
            else if (sprite.Position.X > maxRight)
            {
                sprite.Position.X = maxRight;
            }
            else if (sprite.Position.Y < 0)
            {
                sprite.Position.Y = 0;
            }
            else if (sprite.Position.Y > maxDown)
            {
                sprite.Position.Y = maxDown;
            }
        }
Exemple #26
0
        private static void HandlePickupWeapon(GamePadData gp)
        {
            var gamePadData    = gp;
            var pressedButtons = gamePadData.ButtonsDown;

            //pickup weapon
            if ((pressedButtons & GamePadButtons.Cross) == GamePadButtons.Cross)
            {
                for (int i = weaponScaterList.Count - 1; i >= 0; i--)
                {
                    float dist = Vector3.DistanceSquared(playership.Position, weaponScaterList[i].Pos);
                    if (dist < 400)
                    {
                        if (weaponScaterList[i].UniqueID == 1)
                        {
                            texture = new Texture2D(gunTexFile, false);
                            weaponPlayerList.Add(new Guns(graphics, texture, playership, 1));
                            weaponScaterList.RemoveAt(i);
                            break;
                        }
                        if (weaponScaterList[i].UniqueID == 2)
                        {
                            texture = new Texture2D(missleTexFile, false);
                            weaponPlayerList.Add(new Missle(graphics, texture, playership, 2));
                            weaponScaterList.RemoveAt(i);
                            break;
                        }
                        if (weaponScaterList[i].UniqueID == 3)
                        {
                            texture = new Texture2D(DropOffTexFile, false);
                            weaponPlayerList.Add(new DropOff(graphics, texture, playership, 3));
                            weaponScaterList.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
Exemple #27
0
        private static void changeWeapons(GamePadData gamePadData)
        {
            if ((gamePadData.Buttons & GamePadButtons.L) != 0 &&
                gameTime - currentChangeWeaponTime > CHANGE_WEAPON_BUFFER)
            {
                currentChangeWeaponTime = gameTime;

                if (wpn is WeaponBasic)
                {
                    if (gotFlame == true)
                    {
                        wpn = new WeaponFlame(graphics, wpn.X, wpn.Y, wpnFTex);
                    }
                    else
                    if (gotLazer == true)
                    {
                        wpn = new WeaponLazer(graphics, wpn.X, wpn.Y, wpnLTex);
                    }
                }
                else
                if (wpn is WeaponFlame)
                {
                    if (gotLazer == true)
                    {
                        wpn = new WeaponLazer(graphics, wpn.X, wpn.Y, wpnLTex);
                    }
                    else
                    {
                        wpn = new WeaponBasic(graphics, wpn.X, wpn.Y, wpnBTex);
                    }
                }
                else
                if (wpn is WeaponLazer)
                {
                    wpn = new WeaponBasic(graphics, wpn.X, wpn.Y, wpnBTex);
                }
            }
        }
Exemple #28
0
        public void Update(GamePadData gamePadData)
        {
            if((gamePadData.Buttons& GamePadButtons.Left )!=0 ){
                // Boundary left limit.
                if(Hero.Position.X -Speed >= 0) Hero.Position.X -= Speed;

            }
            if((gamePadData.Buttons& GamePadButtons.Right )!=0 ){
                // Boundary right limit.
                if(Hero.Position.X + Hero.Width +Speed < graphics.Screen.Rectangle.Width * .85f)
                    Hero.Position.X += Speed;
            }
            if((gamePadData.Buttons& GamePadButtons.Up )!=0 ){
                // Boundary up limit.
                if(Hero.Position.Y -Speed >= 0) Hero.Position.Y -= Speed;

            }
            if((gamePadData.Buttons& GamePadButtons.Down )!=0 ){
                // Boundary down limit.
                if(Hero.Position.Y + Hero.Height +Speed < graphics.Screen.Rectangle.Height)
                    Hero.Position.Y += Speed;
            }
        }
        public GameScene()
        {
            Scheduler.Instance.ScheduleUpdateForTarget(this, 1, false);                 // Tells the director that this "node" requires to be updated
            var         touches = Touch.GetData(0);
            GamePadData data    = GamePad.GetData(0);

            scenePaused = false;
            swapScene   = false;;

            backgroundLoader = new BackgroundLoader("Background2");
            this.AddChild(backgroundLoader.Sprite);

            enemy    = new Entity[8];
            enemy[0] = new Enemy(new Vector2(100f, 0f), "WeakEnemy4");
            this.AddChild(enemy[0].Sprite);
            enemy[1] = new Enemy(new Vector2(300f, 0f), "WeakEnemy4");
            this.AddChild(enemy[1].Sprite);
            enemy[2] = new Enemy(new Vector2(500f, 0f), "WeakEnemy4");
            this.AddChild(enemy[2].Sprite);
            enemy[3] = new Enemy(new Vector2(700f, 0f), "WeakEnemy4");
            this.AddChild(enemy[3].Sprite);
            enemy[4] = new Enemy(new Vector2(400, 0f), "WeakEnemy3");
            this.AddChild(enemy[4].Sprite);
            enemy[5] = new Enemy(new Vector2(400, 0f), "WeakEnemy3");
            this.AddChild(enemy[5].Sprite);
            enemy[6] = new Enemy(new Vector2(600, 0f), "WeakEnemy3");
            this.AddChild(enemy[6].Sprite);
            enemy[7] = new Enemy(new Vector2(600, 0f), "WeakEnemy3");
            this.AddChild(enemy[7].Sprite);

            player = new Player();
            this.AddChild(player.Sprite);

            loadMenu = new LoadMenu("MenuScreen");
            this.AddChild(loadMenu.Sprite);
        }
Exemple #30
0
        public virtual void Update(float datX, float datY, int dir, GamePadData gamePadData, long timeDelta)
        {
            direction = (Dir)dir;               //Assume direction is the way dat is moving

            elapsedTime += timeDelta;

            //If you aren't cooling down your weapon, allows you to shoot with arrow keys in 8 directions
            //MakeShot tells AppMain to create a projectile
            if (!shotsFired)
            {
                if ((gamePadData.Buttons & GamePadButtons.Left) != 0)
                {
                    shotDirection  = Dir.west;
                    isWest         = true;
                    currentTime    = elapsedTime;
                    shotsFired     = true;
                    makeProjectile = true;
                }
                if ((gamePadData.Buttons & GamePadButtons.Right) != 0)
                {
                    shotDirection  = Dir.east;
                    isEast         = true;
                    currentTime    = elapsedTime;
                    shotsFired     = true;
                    makeProjectile = true;
                }
                if ((gamePadData.Buttons & GamePadButtons.Up) != 0)
                {
                    shotDirection  = Dir.north;
                    currentTime    = elapsedTime;
                    shotsFired     = true;
                    makeProjectile = true;
                    if (isWest)
                    {
                        shotDirection  = Dir.northwest;
                        currentTime    = elapsedTime;
                        shotsFired     = true;
                        makeProjectile = true;
                    }
                    else
                    if (isEast)
                    {
                        shotDirection  = Dir.northeast;
                        currentTime    = elapsedTime;
                        shotsFired     = true;
                        makeProjectile = true;
                    }
                }
                if ((gamePadData.Buttons & GamePadButtons.Down) != 0)
                {
                    shotDirection  = Dir.south;
                    currentTime    = elapsedTime;
                    shotsFired     = true;
                    makeProjectile = true;
                    if (isWest)
                    {
                        shotDirection  = Dir.southwest;
                        currentTime    = elapsedTime;
                        shotsFired     = true;
                        makeProjectile = true;
                    }
                    else
                    if (isEast)
                    {
                        shotDirection  = Dir.southeast;
                        currentTime    = elapsedTime;
                        shotsFired     = true;
                        makeProjectile = true;
                    }
                }

                isEast = false;
                isWest = false;
            }
            else
            {
                //Holds weapon in the direction that the player last shot for 1 extra frame
                direction = shotDirection;

                //Limits projectiles per shot interval
                if (shotsFired && !(currentTime + shotInterval > elapsedTime))
                {
                    shotsFired = false;
                }
            }

            if (shotsFired)
            {
                //Holds weapon in the direction that the player last shot
                direction = shotDirection;
            }

            setWeaponDirection(datX, datY);
        }
        //===========================================================================
        // Update
        //===========================================================================
        static void Update()
        {
            //
            gamePadData = GamePad.GetData( 0 );
            if( ( ( goalPos[0] == player[0].position && goalPos[1] == player[1].position ) ||	//goal: to next stage
               ( goalPos[1] == player[0].position && goalPos[0] == player[1].position ) ) &&
               player[0].mode >= StateId.lookingUp && player[1].mode >= StateId.lookingUp )
            {
                bCleared = true;
            //				soundPlayerClear.Play();
            }

            if( bCleared )
            {
                foreach( var touchData in Touch.GetData( 0 ) )
                {
                    if( touchData.Status == TouchStatus.Down )
                    {
            //						soundPlayerClear.Stop();

                        // RESET TEST
                        NewStage();
                        player[0].mode = StateId.lookingDown;
                        player[1].mode = StateId.lookingDown;

                        if( nStageNum < 22 ) // 数値固定よくないね yoshi
                        {
                            // NEXT STAGE
                            nStageNum++;
                            NewStage();
                        }
                        else
                        {
                            // ALL STAGE CLEARED
                            menuCtrl.MoveSq( MenuCtrl.SqGameClear );
                            nGameStatID = 1;
                            nStageNum = 0;
                        }
                   }
                }
            }

            // スタートボタン処理
            if( ( gamePadData.Buttons & GamePadButtons.Start ) != 0 )
            {
                // RESET
                NewStage();
                player[0].mode = StateId.lookingDown;
                player[1].mode = StateId.lookingDown;
                Countdown = 60;
            }

            // セレクトボタン処理
            if( ( gamePadData.Buttons & GamePadButtons.Select ) != 0 )
            {
                // to STAGE SELECT
                player[0].mode = StateId.lookingDown;
                player[1].mode = StateId.lookingDown;
                menuCtrl.MoveSq( MenuCtrl.SqStageSelect );
                nGameStatID = 1;
            }

            // ゲームパッド処理
            if( bCleared == false )
            {
                // for player 1
                // for player 2
                changeMode();
            }

            // to move

            rBlock.frame();
            float fMoveSpeed = 0.25f; // スピード調整したいんだけどなあ.. yoshi
            for(int i=0; i<2; i++){
                MovePlayer(i,fMoveSpeed);	//移動
                if(0 < player[i].position.X && player[i].position.X < stage.GetLength(1)-1 &&
                   0 < player[i].position.Y && player[i].position.Y < stage.GetLength(0)-1)
                {
                    WarpCol(i);					//ワープ判定
                    WallCol(i);					//壁とのあたり判定
                    RBlock(i);
            //					RBlockCol(i);				//回転ブロック(実装中)
                }
            //					if(0 < player[i].position.X && player[i].position.X < stage.GetLength(1) &&
            //					   0 < player[i].position.Y && player[i].position.Y < stage.GetLength(0))
                WarpNoWall(i);
            }
            PlayerAndPlayerCol(0,1);	//プレイヤー同士のあたり判定

            #if ( false )
            // to see stagedata
            for( int i=0; i<stage.GetLength(1); i++ )
            {
                for( int j=0; j<stage.GetLength(0); j++ )
                {
                    Console.Write( stage[ j, i ] );
                    Console.Write( "," );
                }
                Console.WriteLine();
            }
            #endif
        }
Exemple #32
0
 public bool GameKeyBool()
 {
     gamePadData = GamePad.GetData(0);
     return(Convert.ToBoolean(gamePadData.Buttons));
 }
Exemple #33
0
    static void Main(string[] args)
    {
        Log.SetToConsole();

                #if EASY_SETUP
        // initialize GameEngine2D's singletons
        Director.Initialize();
                #else // #if EASY_SETUP
        // create our own context
        Sce.Pss.Core.Graphics.GraphicsContext context = new Sce.Pss.Core.Graphics.GraphicsContext();

        // maximum number of sprites you intend to use (not including particles)
        uint sprites_capacity = 500;

        // maximum number of vertices that can be used in debug draws
        uint draw_helpers_capacity = 400;

        // initialize GameEngine2D's singletons, passing context from outside
        Director.Initialize(sprites_capacity, draw_helpers_capacity, context);
                #endif // #if EASY_SETUP

        Director.Instance.GL.Context.SetClearColor(Colors.Grey20);

        // set debug flags that display rulers to debug coordinates
//		Director.Instance.DebugFlags |= DebugFlags.DrawGrid;
        // set the camera navigation debug flag (press left alt + mouse to navigate in 2d space)
        Director.Instance.DebugFlags |= DebugFlags.Navigate;

        // create a new scene
        var scene = new Scene();

        // set the camera so that the part of the word we see on screen matches in screen coordinates
        scene.Camera.SetViewFromViewport();

        // create a new TextureInfo object, used by sprite primitives
        var texture_info = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/HelloSprite/king_water_drop.png", false));

        // create a new sprite
        var sprite = new SpriteUV()
        {
            TextureInfo = texture_info
        };

        // make the texture 1:1 on screen
        sprite.Quad.S = texture_info.TextureSizef;

        // center the sprite around its own .Position
        // (by default .Position is the lower left bit of the sprite)
        sprite.CenterSprite();

        // put the sprite at the center of the screen
        sprite.Position = scene.Camera.CalcBounds().Center;
        //sprite.Scale = Vector2.One * 0.9f;
        // our scene only has 2 nodes: scene->sprite
        scene.AddChild(sprite);

                #if EASY_SETUP
        Director.Instance.RunWithScene(scene);
                #else // #if EASY_SETUP
        // handle the loop ourself

        Director.Instance.RunWithScene(scene, true);

        while (!Input2.GamePad0.Cross.Press)
        {
            Sce.Pss.Core.Environment.SystemEvents.CheckEvents();

                        #if EXTERNAL_INPUT
            // it is not needed but you can set external input data if you want

            List <TouchData> touch_data_list = Touch.GetData(0);
            Input2.Touch.SetData(0, touch_data_list);

            GamePadData pad_data = GamePad.GetData(0);
            Input2.GamePad.SetData(0, pad_data);
                        #endif // #if EXTERNAL_INPUT

            Director.Instance.Update();
//			Debug.WriteLine("===============>" + Director.Instance.SpriteRenderer);
            Director.Instance.Render();

            Director.Instance.GL.Context.SwapBuffers();
            Director.Instance.PostSwap();             // you must call this after SwapBuffers

//			System.Console.WriteLine( "Director.Instance.DebugStats.DrawArraysCount " + Director.Instance.GL.DebugStats.DrawArraysCount );
        }
                #endif // #if EASY_SETUP

        Director.Terminate();

        System.Console.WriteLine("Bye!");
    }
Exemple #34
0
        /// <summary>
        /// シーン更新処理
        /// </summary>
        public void Update()
        {
            key = GamePad.GetData( 0 );
            touches = Touch.GetData( 0 );

            switch( sq )
            {
                case SqTitle:
                    DoSqTitle();
                    break;
                case SqTitleUserInput:
                    DoSqTitleUserInput();
                    break;
                case SqCredit:
                    DoSqCredit();
                    break;
                case SqCreditUserInput:
                    DoSqCreditUserInput();
                    break;
                case SqStory:
                    DoSqStory();
                    break;
                case SqStoryUserInput:
                    DoSqStoryUserInput();
                    break;
                case SqStageSelect:
                    DoSqStageSelect();
                    break;
                case SqStageSelectUserInput:
                    DoSqStageSelectUserInput();
                    break;
                case SqClearStroy:
                    DoSqClearStroy();
                    break;
                case SqClearStroyUserInput:
                    DoSqClearStroyUserInput();
                    break;
                case SqGameClear:
                    DoSqGameClear();
                    break;
                case SqGameClearUserInput:
                    DoSqGameClearUserInput();
                    break;
            }
        }
Exemple #35
0
 public string GameKey()
 {
     gamePadData = GamePad.GetData(0);
     return(Convert.ToString(gamePadData.Buttons));
 }
Exemple #36
0
        public void TickGame(float dt)
        {
            TickCounter++;
            int speed=4;
            gamePadData = GamePad.GetData(0);
            var Player_Position = Player.Position;
            var Bat_Position = Bat.Position;
            //Board.Tick(dt);
            Console.WriteLine(gamePadData.Buttons);

            //Bat.RunAction(FlyAnimation);

            //注意 画面左下原点を取る、X方向右向き、Y方向上向きの座標系
            if((gamePadData.Buttons & GamePadButtons.Left) != 0)
                {
                //	Player.Position.X -= speed;
                    Player.Position -= new Vector2(speed,0);
                if(Player.Position.X < Player.TextureInfo.TextureSizei.X/2.0f)
                        Player.Position=new Vector2(Player.TextureInfo.TextureSizei.X/2.0f,Player_Position.Y);

                //Player.TextureInfo.TextureSizei.X
                }
                if((gamePadData.Buttons & GamePadButtons.Right) != 0)
                {
                    Player.Position += new Vector2(speed,0);
                    if(Player.Position.X> screen_size.X - Player.TextureInfo.TextureSizei.X/2.0f) {
                        Player.Position=new Vector2(screen_size.X - Player.TextureInfo.TextureSizei.X/2.0f,Player_Position.Y);
                }
                }
                if((gamePadData.Buttons & GamePadButtons.Up) != 0)
                {
                    Player.Position += new Vector2(0,speed);
                    if(Player.Position.Y > screen_size.Y - Player.TextureInfo.TextureSizei.Y/2.0f) {

                        Player.Position=new Vector2(Player_Position.X,screen_size.Y - Player.TextureInfo.TextureSizei.Y/2.0f);
                }

                }
                if((gamePadData.Buttons & GamePadButtons.Down) != 0)
                {
                    Player.Position -= new Vector2(0,speed);
                    if(Player.Position.Y < Player.TextureInfo.TextureSizei.Y/2.0f) {
                        Player.Position=new Vector2( Player_Position.X, Player.TextureInfo.TextureSizei.Y/2.0f);
                }
                }

                if((gamePadData.ButtonsDown & (GamePadButtons.Circle | GamePadButtons.Cross)) != 0)
                {
                    //gs.soundPlayerBullet.Play();
                //	gs.Root.Search("bulletManager").AddChild(new Bullet(gs, "bullet", gs.textureBullet,
                //		new Vector3(this.Sprite.Position.X, this.Sprite.Position.Y, 0.4f)));

                }

            // 毎フレーム呼び出す。
               		 float period_in_seconds = 0.2f;
                float wave = ( (  FMath.Sin( (float)Director.Instance.CurrentScene.SceneTime
                    * Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Pi / period_in_seconds ) ) * 4.0f );

            //Console.WriteLine(wave);
            if(Bat.Position.X < Bat.TextureInfo.TextureSizei.X) move_direction = 1;
            if(Bat.Position.X > screen_size.X - Bat.TextureInfo.TextureSizei.X) move_direction = -1;

            Bat.Position = Bat_Position + new Vector2(move_direction * 4,wave);
            ///Console.WriteLine(Bat.Position);
            //コメントを外して挙動を確認してください
              //  Bat.Rotation = Vector2.Rotation( Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.Pi  * 2.0f * wave );
               //Bat.Scale = new Vector2( 1.0f + 2.0f * wave );
        }
Exemple #37
0
        public void ControllerConnected(GamePadData gamepad)
        {
            var index = _connectedPlayers.Count + 1;

            SpawnPlayer(gamepad, index);
        }
Exemple #38
0
 //        public virtual void Spawn()
 //        {
 //        Random rand1 = new Random();
 //        Vector3 spawn = new Vector3 (rand1.Next(60, 901), rand1.Next (44,500), 0);
 //            
 //        }
 public virtual void Update(Player player, long elapsed, GamePadData gamepaddata)
 {
     s.Position = player.s.Position;
     s.Rotation = player.s.Rotation;
     Fire (gamepaddata, elapsed);
 }
Exemple #39
0
        public virtual void Fire(GamePadData gamepaddata, long elapsed)
        {
            recoil += elapsed;
            if((gamepaddata.Buttons & GamePadButtons.Down)!=0 && mag>=spent)
            {
                if (recoil >= fireRate * 1000f) {
                    Shoot ();
                    spent++;
                    recoil = 0;
                }

                else{}
            }
            else if (mag<=spent){
                Reload(elapsed);
            }
            else{}
        }
        public void Update()
        {
            // Query gamepad for current state
            gamePadData = GamePad.GetData (0);

            if((gamePadData.Buttons & GamePadButtons.Cross) != 0)
            {
                data.cross = true;
            }
            else
            {
                data.cross = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Circle) != 0)
            {
                data.circle = true;
            }
            else
            {
                data.circle = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Square) != 0)
            {
                data.square = true;
            }
            else
            {
                data.square = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Square) != 0)
            {
                data.square = true;
            }
            else
            {
                data.square = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Triangle) != 0)
            {
                data.triangle = true;
            }
            else
            {
                data.triangle = false;
            }

            if((gamePadData.Buttons & GamePadButtons.L) != 0)
            {
                data.leftShoulder = true;
            }
            else
            {
                data.leftShoulder = false;
            }

            if((gamePadData.Buttons & GamePadButtons.R) != 0)
            {
                data.rightShoulder = true;
            }
            else
            {
                data.rightShoulder = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Start) != 0)
            {
                data.start = true;
            }
            else
            {
                data.start = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Select) != 0)
            {
                data.select = true;
            }
            else
            {
                data.select = false;
            }

            // DPad Buttons
            if((gamePadData.Buttons & GamePadButtons.Up) != 0)
            {
                data.dPadUp = true;
            }
            else
            {
                data.dPadUp = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Right) != 0)
            {
                data.dPadRight = true;
            }
            else
            {
                data.dPadRight = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Down) != 0)
            {
                data.dPadDown = true;
            }
            else
            {
                data.dPadDown = false;
            }

            if((gamePadData.Buttons & GamePadButtons.Left) != 0)
            {
                data.dPadLeft = true;
            }
            else
            {
                data.dPadLeft = false;
            }

            //Analogue Joystick
            data.analogLeftX = gamePadData.AnalogLeftX;
            data.analogLeftY = gamePadData.AnalogLeftY;
            data.analogRightX = gamePadData.AnalogRightX;
            data.analogRightY = gamePadData.AnalogRightY;
        }
Exemple #41
0
 private void RefreshInputData()
 {
     if (CollectGamePadData)
         GamePadData = GamePad.GetData(0);
     if (CollectTouchData)
         TouchData = Touch.GetData(0);
 }
        public GamePadData GetData()
        {
            ReadDataFromChannel();

            GamePadData gpd = new GamePadData();

            gpd.AnalogLeftX = BitConverter.ToSingle(IncomingDataBuffer, 4);
            gpd.AnalogLeftY = BitConverter.ToSingle(IncomingDataBuffer, 8);
            gpd.AnalogRightX = BitConverter.ToSingle(IncomingDataBuffer, 12);
            gpd.AnalogRightY = BitConverter.ToSingle(IncomingDataBuffer, 16);

            RawButtonData = BitConverter.ToUInt32(IncomingDataBuffer, 20);

            //The order of button decoding is important here.
            switch(ControllerType)
            {
            case ControllerTypes.SonySixaxis:
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Triangle;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Circle;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Cross;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Square;
                if(ReadNextRawButtonValue())
                {
                    //L2, do nothing.
                }
                if(ReadNextRawButtonValue())
                {
                    //R2, do nothing.
                }
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.L;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.R;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Start;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Select;
                if(ReadNextRawButtonValue())
                {
                    //L3, do nothing.
                }
                if(ReadNextRawButtonValue())
                {
                    //R3, do nothing.
                }
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Left;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Right;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Up;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Down;
                break;

            case ControllerTypes.MotionInJoy:
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Triangle;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Circle;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Cross;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Square;
                if(ReadNextRawButtonValue())
                {
                    //L2, do nothing.
                }
                if(ReadNextRawButtonValue())
                {
                    //R2, do nothing.
                }
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.L;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.R;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Select;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Start;
                if(ReadNextRawButtonValue())
                {
                    //L3, do nothing.
                }
                if(ReadNextRawButtonValue())
                {
                    //R3, do nothing.
                }
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Left;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Right;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Up;
                if(ReadNextRawButtonValue())
                    gpd.Buttons = gpd.Buttons | GamePadButtons.Down;
                break;

            default:
                throw new InvalidProgramException("Unknown controller type.");
            }

            return gpd;
        }
Exemple #43
0
        /// <summary>
        /// 更新処理
        /// </summary>
        /// <remarks>(※1フレームに一度だけ呼び出すこと)</remarks>
        public static void Update(float dt)
        {
            // タッチ情報取得
            TouchDataList = Touch.GetData(0);

            // パッド情報取得
            _padData = GamePad.GetData(0);

            // アナログ
            AnalogLeft = new Vector2(_padData.AnalogLeftX, _padData.AnalogLeftY);
            AnalogRight = new Vector2(_padData.AnalogRightX, _padData.AnalogRightY);

            // 押したままの時間を計測
            foreach (GamePadButtons btnType in Enum.GetValues(typeof (GamePadButtons)))
            {
                if (Down(btnType))
                {
                    // 押したままのボタンがある場合は、経過時間を保存
                    _holdDic[btnType] += dt;
                }
                else
                {
                    // 上記以外のボタンについては0クリア
                    _holdDic[btnType] = 0;
                }
            }
        }
 public virtual void Input()
 {
     gamePadData = GamePad.GetData(0);
 }
Exemple #45
0
        public void Update(GamePadData gamepaddata, long elapsed)
        {
            time += elapsed;

            if(wlist.Count > 0)
            {
                if((gamepaddata.ButtonsDown & GamePadButtons.Left)!=0){
                    Console.WriteLine(wepsel);
                    if(wepsel==0){
                        wepsel=wlist.Count-1;
                    }
                        else{wepsel--;}
                }
                if((gamepaddata.ButtonsDown & GamePadButtons.Right)!=0){
                    Console.WriteLine(wepsel);
                    if(wepsel==wlist.Count-1){
                        wepsel=0;
                    }
                    else{wepsel++;}
                }
                wlist[wepsel].Update(this, elapsed, gamepaddata);
            }
            if((gamepaddata.Buttons & GamePadButtons.Triangle)!=0){
                s.Position.X += (float)Math.Sin (s.Rotation) * movementSpeed;
                s.Position.Y -= (float)Math.Cos (s.Rotation) * movementSpeed;
            }
            if((gamepaddata.Buttons & GamePadButtons.Cross)!=0){
                s.Position.X -= (float)Math.Sin (s.Rotation) * movementSpeed;
                s.Position.Y += (float)Math.Cos (s.Rotation) * movementSpeed;
            }
            if((gamepaddata.Buttons & GamePadButtons.Square)!=0){
                s.Rotation-=rotSpeed;
            }
            if((gamepaddata.Buttons & GamePadButtons.Circle)!=0){
                s.Rotation+=rotSpeed;
            }
            if((gamepaddata.Buttons & GamePadButtons.L)!=0){
                s.Position.X -= (float)Math.Sin (s.Rotation+(float)Math.PI/2f) * movementSpeed;
                s.Position.Y += (float)Math.Cos (s.Rotation+(float)Math.PI/2f) * movementSpeed;
            }
            if((gamepaddata.Buttons & GamePadButtons.R)!=0){
                s.Position.X += (float)Math.Sin (s.Rotation+(float)Math.PI/2f) * movementSpeed;
                s.Position.Y -= (float)Math.Cos (s.Rotation+(float)Math.PI/2f) * movementSpeed;
            }

            if(time>=duration){
                if(active<(frames-1)){
                    active++;
                }
                else{
                    active=0;
                }
                time=0;
            }
            else{}
        }
Exemple #46
0
        public override void Tick(float dt)
        {
            base.Tick(dt);

            GamePadData data = GamePad.GetData(0);

            float analogX = 0.0f;
            float analogY = 0.0f;


            //d-pad movement,emulating analog movement of the sticks
            if (Input2.GamePad0.Right.Down)
            {
                analogX = 1.0f;
            }
            else if (Input2.GamePad0.Left.Down)
            {
                analogX = -1.0f;
            }
            if (Input2.GamePad0.Up.Down)
            {
                analogY = -1.0f;
            }
            else if (Input2.GamePad0.Down.Down)
            {
                analogY = 1.0f;
            }


            //if the left stick is moving,then use values read from the stick
            if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f)
            {
                analogX = data.AnalogLeftX;
                analogY = data.AnalogLeftY;
            }


            //calculate the position


            /*if(analogX>0)
             * {
             *      Position = new Vector2 (Position.X + 0.1f, Position.Y);
             * }else if(analogX<0)
             * {
             *      Position = new Vector2 (Position.X - 0.1f, Position.Y);
             * }
             *
             * if(analogY>0)
             * {
             *      Position = new Vector2 (Position.X + Position.Y- 0.1f);
             * }else if(analogY<0)
             * {
             *      Position = new Vector2 (Position.X, Position.Y + 0.1f);
             * }*/
            Vector2 proposedChange;

            if (analogX != 0.0f)
            {
                proposedChange = new Vector2(analogX / 10f, 0.0f);
                if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange))
                {
                    Position += proposedChange;
                }
            }
            if (analogY != 0.0f)
            {
                proposedChange = new Vector2(0.0f, -analogY / 10f);
                if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange))
                {
                    Position += proposedChange;
                }
            }



            //rotate according to the right analog stick, or if it's not moving, then according the the left stick
            // so basically if you are not pointing the player in any direction with the right stick he is going to point in the walking direction
            //or if both sticks are not moving,then use the analogX and analogY values(d-pad movement)
            // OR do autoaim if enabled
            if (data.AnalogRightX > 0.2f || data.AnalogRightX < -0.2f || data.AnalogRightY > 0.2f || data.AnalogRightY < -0.2f)
            {
                var angleInRadians = FMath.Atan2(-data.AnalogRightX, -data.AnalogRightY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (!Game.autoAim && (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f))
            {
                var angleInRadians = FMath.Atan2(-data.AnalogLeftX, -data.AnalogLeftY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (!Game.autoAim && (analogX != 0.0f || analogY != 0.0f))
            {
                var angleInRadians = FMath.Atan2(-analogX, -analogY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (Game.autoAim)
            {
                GameEntity e;
                if (Collisions.findNearestEnemy(Player.Instance, 8.0f, out e))
                {
                    Vector2 distance       = (Player.Instance.Position - e.Position).Normalize();
                    var     angleInRadians = FMath.Atan2(distance.X, -distance.Y);
                    playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
                }
                else
                {
                    var angleInRadians = FMath.Atan2(-analogX, -analogY);
                    playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
                }
            }
        }
 protected void Input()
 {
     gamePadData = GamePad.GetData(0);
 }
Exemple #48
0
 public Boolean isButtonDown(GamePadData gpd, GamePadButtons button)
 {
     return((gpd.Buttons & button) != 0);
 }