コード例 #1
0
        private void UpdateControlState(EntityRegistry registry)
        {
            int count = mPlayersSlice.Player.Count;

            for (int i = 0; i < count; ++i)
            {
                int          playerIndex = mPlayersSlice.Player[i].Index;
                GamePadState state       = GamePad.GetState(playerIndex);

                FrogControlState controlState = new FrogControlState();
                controlState.JumpSignal         = state.IsButtonDown(Buttons.A);
                controlState.ToungueSignalState = state.IsButtonDown(Buttons.X);
                Vector2 direction    = state.ThumbSticks.Left;
                float   rawMagnitude = direction.Length();
                if (rawMagnitude >= kMinMagnitude)
                {
                    direction.Normalize();
                }
                else
                {
                    direction = Vector2.Zero;
                }
                controlState.InputDirection = direction;

                Entity controlledFrog = mPlayersSlice.ControlledEntity[i].Entity;
                registry.SetComponent(controlledFrog, controlState);
            }
        }
コード例 #2
0
        private void UpdateControlState(EntityRegistry registry)
        {
            int count = mPlayersSlice.Player.Count;

            for (int i = 0; i < count; ++i)
            {
                int              playerIndex  = mPlayersSlice.Player[i].Index;
                GamePadState     state        = GamePad.GetState(playerIndex);
                FrogControlState controlState = new FrogControlState();
                Vector2          direction    = Vector2.Zero;
                if (state.IsConnected)
                {
                    controlState.JumpSignal         = state.IsButtonDown(Buttons.A);
                    controlState.ToungueSignalState = state.IsButtonDown(Buttons.X);
                    direction = state.ThumbSticks.Left;
                }
                else
                {
                    KeyboardState keyboardState = Keyboard.GetState();
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        direction.X -= 1.0f;
                    }
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        direction.X += 1.0f;
                    }
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        direction.Y -= 1.0f;
                    }
                    if (keyboardState.IsKeyDown(Keys.Up))
                    {
                        direction.Y += 1.0f;
                    }
                    controlState.JumpSignal         = keyboardState.IsKeyDown(Keys.LeftControl);
                    controlState.ToungueSignalState = keyboardState.IsKeyDown(Keys.Space);
                }
                float rawMagnitude = direction.Length();
                if (rawMagnitude >= kMinMagnitude)
                {
                    direction.Normalize();
                }
                else
                {
                    direction = Vector2.Zero;
                }
                controlState.InputDirection = direction;

                Entity controlledFrog = mPlayersSlice.ControlledEntity[i].Entity;
                registry.SetComponent(controlledFrog, controlState);
            }
        }
コード例 #3
0
        public Entity MakeFrog(int index, EntityRegistry registry)
        {
            Entity frogEntity = registry.Create();

            //Controller state
            FrogControlState controlState = new FrogControlState();

            registry.AddComponent(frogEntity, controlState);

            //Position Component
            int      spawnIndex    = index % mPondData.FrogSpawns.Length;
            float    spawnX        = mPondData.FrogSpawns[spawnIndex];
            float    spawnY        = mPondData.Height + mFrogData.Height;
            Vector2  positionValue = new Vector2(spawnX, spawnY);
            Position spawnPosition = new Position(positionValue);

            registry.AddComponent(frogEntity, spawnPosition);

            //Facing
            Facing facing = new Facing();

            registry.AddComponent(frogEntity, facing);

            //Velocity
            Velocity velocity = new Velocity();

            registry.AddComponent(frogEntity, velocity);

            //Shape
            RectShape rectShape = new RectShape(mFrogData.Width, mFrogData.Height);

            registry.AddComponent(frogEntity, rectShape);

            //Rect - Added automatically by the RectUpkeepSystem, but I don't want to worry about the first frame this being missing
            Rect rect = new Rect(spawnPosition.Value, rectShape.Width, rectShape.Height);

            //Gravity - Spawned in the air!
            Gravity gravity = new Gravity();

            registry.AddComponent(frogEntity, gravity);

            //Animation
            AnimationState animation = new AnimationState();

            registry.AddComponent(frogEntity, animation);

            return(frogEntity);
        }
コード例 #4
0
        private void UpdateNoToungueFrogs(EntityRegistry registry)
        {
            int count = mNoToungueFrogs.Frogs.Count;

            for (int i = 0; i < count; ++i)
            {
                FrogControlState controlState = mNoToungueFrogs.ControlState[i];
                if (controlState.InputDirection.X != 0)
                {
                    Facing facing = mNoToungueFrogs.Facing[i];
                    int    sign   = Math.Sign(controlState.InputDirection.X);
                    if (sign != facing.CurrentFacing)
                    {
                        registry.SetComponent(mNoToungueFrogs.Frogs[i], new Facing(sign));
                    }
                }
            }
        }
コード例 #5
0
        private void UpdateLandedFrogs(EntityRegistry registry)
        {
            int count = mLandedFrogs.Frogs.Count;

            for (int i = 0; i < count; ++i)
            {
                Entity           frog         = mLandedFrogs.Frogs[i];
                Landed           landed       = mLandedFrogs.Landed[i];
                FrogControlState controlState = mLandedFrogs.ControlState[i];
                if (controlState.InputDirection.Y >= 0f)
                {
                    if (controlState.JumpSignal)
                    {
                        float newJumpPercentage = landed.RelativeJumpPower + (mTime.DeltaTime / mJumpData.JumpPrepareTime);
                        landed.RelativeJumpPower = MathExtensions.Clamp01(newJumpPercentage);
                    }
                    else if (landed.RelativeJumpPower != 0f)
                    {
                        Facing  facing           = mLandedFrogs.Facing[i]; //For rare cases, should I fetch this from the registry instead?
                        Vector2 blessedDirection = BestBlessedDirection(controlState.InputDirection, facing.CurrentFacing);
                        Vector2 jumpVelocity     = (landed.RelativeJumpPower * mJumpData.JumpSpeed) * blessedDirection;
                        registry.SetComponent(frog, new Velocity(jumpVelocity));
                        mJumpingFrogs.Add(frog);
                    }
                }
                else
                {
                    landed.RelativeJumpPower = 0f;
                }
                registry.SetComponent(frog, landed);
            }
            foreach (Entity frog in mJumpingFrogs)
            {
                registry.RemoveComponent <Landed>(frog);
            }
            mJumpingFrogs.Clear();
        }