Beispiel #1
0
        /// <summary>
        /// Constructor for the Gamestate class
        /// </summary>
        /// <param name="a_gameStateManager">The manager for the gamestate</param>
        /// <param name="a_windowRes">the resolution for the screen</param>
        public GameState(GameStateManager a_gameStateManager, Rectangle a_windowRes)
        {
            m_platformList = new List<Platform>();
            m_particleList = new List<Particle>();

            //Set Resoultion
            m_windowRes = a_windowRes;

            //World
            m_world = new World(new Vector2(0, 0));

            //Gravity
            m_gravity = new Gravity(m_world, new Vector2(0, 1), 7.0f);

            m_gameStateManager = a_gameStateManager;
            m_game = m_gameStateManager.m_game;
            m_camera = new Camera(m_game.GraphicsDevice);

            m_playerSpawnLocation = new Vector2(0, 0);

            //Particle stuff
            m_particleSpawnPosition = new Vector2();
        }
Beispiel #2
0
        /// <summary>
        /// Updating players behaviours
        /// </summary>
        /// <param name="a_gravity">reference to main gravity source</param>  
        /// <param name="a_gameTime"reference to main gameTime></param> 
        public void Update(GameTime a_gameTime, Gravity a_gravity)
        {
            m_collisionBody.Position = m_body.Position + ConvertUnits.ToSimUnits(new Vector2((float)-Math.Sin(a_gravity.angle), (float)Math.Cos(a_gravity.angle)) * (m_size.Y / 2 + 5f));
         
            Vector2 tempRot = new Vector2(-(float)Math.Sin(m_body.Rotation), (float)Math.Cos(m_body.Rotation));

            m_cameraFocus.m_body.Position = m_body.Position - (tempRot/1.5f) + (m_body.LinearVelocity * 0.3f);

            Controls(a_gravity);
        }
Beispiel #3
0
        /// <summary>
        /// Move activates and applies a switch that alters direction depending on the input key
        /// </summary>
        /// <param name="a_gravity">reference to main gravity</param> 
        /// <param name="a_key">key input alters direction of movement</param>     
        //private void Move(Gravity a_gravity, Keys a_key)
        //{
        //    if (Keyboard.GetState().IsKeyDown(a_key))
        //    {
        //        Vector2 directionChange = new Vector2();

        //        switch (a_key)
        //        {
        //            case Keys.A:
        //                directionChange = new Vector2(-m_speed, 0);
        //                break;
        //            case Keys.D:
        //                directionChange = new Vector2(m_speed, 0);
        //                break;
        //            case Keys.W:
        //                directionChange = new Vector2(0, -m_speed);
        //                break;
        //            case Keys.S:
        //                directionChange = new Vector2(0, m_speed);
        //                break;
        //            case Keys.Space:
        //                directionChange = new Vector2(-a_gravity.direction.X, -a_gravity.direction.Y) * 200;
        //                break;
        //        }

        //        //Algorithm - Andrew G
        //        Vector2 gravNorm = new Vector2(-a_gravity.direction.Y, a_gravity.direction.X);
        //        gravNorm.Normalize();

        //        float force = Math.Abs( Vector2.Dot(gravNorm, directionChange));

        //        m_body.ApplyForce(directionChange, m_body.Position);
        //    }
        //}

        /// <summary>
        /// Collection of if statements detecting input keys.
        /// As well as applying rotation to the player based on gravities angle
        /// </summary>
        /// <param name="a_gravity">reference to main gravity</param> 
        private void Controls(Gravity a_gravity)
        {

#if PSM
			GamePadState inputState = GamePad.GetState(PlayerIndex.One);
			
			Vector2 lStickInput = inputState.ThumbSticks.Left;
			lStickInput.Normalize();
				
            bool aDown = lStickInput.X < -0.1 ? true : false;
            bool dDown = lStickInput.X >  0.1 ? true : false;
            bool wDown = lStickInput.Y < -0.1 ? true : false;
            bool sDown = lStickInput.Y >  0.1 ? true : false;
			
			if (m_canJump)
            {
                if (inputState.Buttons.A == ButtonState.Pressed)
                {
                    m_body.ApplyForce(-a_gravity.direction * 170, m_body.Position);
                    m_canJump = false;
                }
            }
#else
            bool aDown = Keyboard.GetState().IsKeyDown(Keys.A);
            bool dDown = Keyboard.GetState().IsKeyDown(Keys.D);
            bool wDown = Keyboard.GetState().IsKeyDown(Keys.W);
            bool sDown = Keyboard.GetState().IsKeyDown(Keys.S);

            if (m_canJump)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    m_body.ApplyForce(-a_gravity.direction * 170, m_body.Position);
                    m_canJump = false;
                }
            }
#endif	
            float invSqrt2 = (float)(1.0f / Math.Sqrt(2));

            Vector2 keyForce = new Vector2(0, 0);

            if (aDown) // moving left
            {
                if (wDown)
                {
                    keyForce = new Vector2(-invSqrt2, -invSqrt2);
                }
                else if (sDown)
                {
                    keyForce = new Vector2(-invSqrt2, invSqrt2);
                }
                else if (dDown)
                {

                }
                else
                {
                    keyForce = new Vector2(-1, 0);
                }
            }
            else if (dDown) // moving right
            {
                if (wDown)
                {
                    keyForce = new Vector2(invSqrt2, -invSqrt2);
                }
                else if (sDown)
                {
                    keyForce = new Vector2(invSqrt2, invSqrt2);
                }
                else if (aDown)
                {

                }
                else
                {
                    keyForce = new Vector2(1, 0);
                }
            }
            else if (wDown)
            {
                if (aDown)
                {
                    keyForce = new Vector2(-invSqrt2, -invSqrt2);
                }
                else if (dDown)
                {
                    keyForce = new Vector2(invSqrt2, -invSqrt2);
                }
                else if (sDown)
                {

                }
                else
                {
                    keyForce = new Vector2(0, -1);
                }
            }
            else if (sDown)
            {
                keyForce = new Vector2(0, 1);
            }


            Vector2 gravNorm = new Vector2(-a_gravity.direction.Y, a_gravity.direction.X);
            gravNorm.Normalize();

            float force = Vector2.Dot(gravNorm, keyForce);

            m_body.ApplyForce(gravNorm * force * 5, m_body.Position);


            if (m_canJump)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    m_body.ApplyForce(-a_gravity.direction * 170, m_body.Position);
                    m_canJump = false;
                }
            }

            m_cameraFocus.m_body.Rotation = a_gravity.angle;
        }