Esempio n. 1
0
        public InputManager()
        {
            ks[ cur ] = Keyboard.GetState();
            gs1[ cur ] = GamePad.GetState(PlayerIndex.One);
            gs2[ cur ] = GamePad.GetState(PlayerIndex.Two);

            for (int i = 0; i < cpu.Length; i++)
            {
                cpu[i] = new CPUInputState();
            }

            if ( gs1[ cur ].IsConnected ) connectn++;
            if ( gs2[ cur ].IsConnected ) connectn++;
        }
Esempio n. 2
0
        void cpuInput(GameTime gameTime)
        {
            cpuTime += gameTime.ElapsedGameTime;

            if (player.id == 0) enemy = scene.Character2P;
            if (player.id == 1) enemy = scene.Character1P;

            CPUInputState state = new CPUInputState();

            Vector2 myPos = RecVisible.Center;
            Vector2 hisPos = enemy.RecVisible.Center;
            Vector2 v = -myPos + hisPos;

            if (myPos.X < cpuMinX)
            {
                state.stick.X = 1;
                if (jumpFlg <= 0)
                {
                    state.stick.Y = 1;
                    state.button[(int)BUTTON.LB] = true;
                }
                else
                {
                    if (CheckFloat(gameTime) && velocity.Y < 0)
                    {
                        state.stick.Y = 1;
                        state.button[(int)BUTTON.LB] = true;
                    }
                }
            }
            else if (myPos.X > cpuMaxX)
            {
                state.stick.X = -1;
                if (jumpFlg <= 0)
                {
                    state.stick.Y = 1;
                    state.button[(int)BUTTON.LB] = true;
                }
                else
                {
                    if (CheckFloat(gameTime) && velocity.Y < 0)
                    {
                        state.stick.Y = 1;
                        state.button[(int)BUTTON.LB] = true;
                    }
                }
            }
            else
            {
                if (v.X > 0)
                {
                    state.stick.X = 1;
                }
                else
                {
                    state.stick.X = -1;
                }

                if (v.Y > 0.5)
                {
                    if (jumpFlg <= 0)
                    {
                        state.stick.Y = 1;
                        state.button[(int)BUTTON.LB] = true;
                    }
                    else
                    {
                        if (CheckFloat(gameTime) && velocity.Y < 0)
                        {
                            state.stick.Y = 1;
                            state.button[(int)BUTTON.LB] = true;
                        }
                    }
                }
            }

            if (v.Length() < 2.0f || cpuTime >= TimeSpan.FromSeconds(cpuNextTime))
            {
                if (cpuNextTime >= 2.0 && input.PrevCPU.button[(int)BUTTON.B] == false)
                {
                    state.button[(int)BUTTON.B] = true;
                }
                else if (input.PrevCPU.button[(int)BUTTON.A] == false)
                {
                    state.button[(int)BUTTON.A] = true;
                }
                cpuTime = TimeSpan.Zero;
                cpuNextTime = rand.NextDouble() * 3;
            }

            input.CurCPU = state;
        }