Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public LevelOneScreen()
        {
            map = new Map();
            player = new Player();

            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Move the object's position based on the value of 'vector'.
        /// Object will be blocked by any walls
        /// </summary>
        /// <param name="map">Map the object is moving on</param>
        /// <returns>Set of flags indicating the directions the object hit a wall</returns>
        protected virtual Direction Move(Map map)
        {
            Direction retVal = Direction.None;
            Vector2 movement = vector;

            if (movement.X > 0.0f)
            {
                //We're moving to the right, create a bounding box in the area we're moving through.
                Vector2 collpos = new Vector2(position.X + size.X, position.Y);
                Vector2 collsize = new Vector2(movement.X, size.Y);
                float newX;

                //Check the area we want to move through against the map.
                if (map.Collide(collpos, collsize, Direction.Right, out newX))
                    retVal |= Direction.Right;
                // Update the object's position based on how far we could move.
                position.X = newX - size.X;
            }
            else if (movement.X < 0.0f)
            {
                // We're moving to the left, create a bounding box in the area we're moving through.
                Vector2 collPos = new Vector2(position.X + movement.X, position.Y);
                Vector2 collSize = new Vector2(-movement.X, size.Y);
                float newX;

                // Check the area we want to move through against the map.
                if (map.Collide(collPos, collSize, Direction.Left, out newX))
                    retVal |= Direction.Left;

                // Update the object's x position based on how far we could move.
                position.X = newX;
            }

            if (movement.Y > 0.0f)
            {
                //We're moving down, create a bounding box in the area we're moving through.
                Vector2 collPos = new Vector2(position.X, position.Y + size.Y);
                Vector2 collSize = new Vector2(size.X, movement.Y);
                float newY;

                if (map.Collide(collPos, collSize, Direction.Down, out newY))
                    retVal |= Direction.Down;

                //Update the object's y position based on how far we could move
                position.Y = newY - size.Y;
            }
            else if (movement.Y < 0.0f)
            {
                // We're moving up, create a bounding box in the area we're moving through
                Vector2 collPos = new Vector2(position.X, position.Y + movement.Y);
                Vector2 collSize = new Vector2(size.X, -movement.Y);
                float newY;

                // Check the area we want to move through against the map
                if (map.Collide(collPos, collSize, Direction.Up, out newY))
                    retVal |= Direction.Up;

                //Update the object's y position based on how far we could move.
                position.Y = newY;
            }

            // Return the set of flags indicating which directions we hit.
            return retVal;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Update the object's position and velocity
 /// </summary>
 /// <param name="map">Map the object is on</param>
 public virtual void Update(Map map, GamePadState gamePadState, KeyboardState keyBoardState)
 {
     return;
 }
Ejemplo n.º 4
0
        private Vector2 size = new Vector2(1.0f, 1.0f); //Size of the object

        #endregion Fields

        #region Methods

        public virtual void Draw(SpriteBatch batch, Map map)
        {
            map.DrawOnMap(batch, texture.texture, position);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Move the player around the given map based on the state of the game pad.
        /// </summary>
        /// <param name="map">Map to move the player</param>
        public override void Update(Map map, GamePadState gamePadState, KeyboardState keyboardState)
        {
            //Move the player and detect any wall collisions.
            Direction hitdirn = base.Move(map);

            // If we hit a direction horizontally set the vector's x component to 0
            if ((hitdirn & Direction.Left) != 0 || (hitdirn & Direction.Right) != 0)
                vector.X = 0f;

            // If we hit a direction vertically set the vector's y component to 0
            if ((hitdirn & Direction.Up) != 0 || (hitdirn & Direction.Down) != 0)
                vector.Y = 0f;

            // Check if the player is pushing left or right
            if (gamePadState.ThumbSticks.Left.X > 0.5f || keyboardState.IsKeyDown(Keys.D))
            {
                // Player is pushing right
                vector.X += PLAYER_ACCEL + PLAYER_DECEL;

                // Prevent X vector from going above the maximum speed.
                if (vector.X > PLAYER_MAX_SPEED)
                    vector.X = PLAYER_MAX_SPEED;
            }
            else if (gamePadState.ThumbSticks.Left.X < -0.5f || keyboardState.IsKeyDown(Keys.A))
            {
                // Player is pushing left
                vector.X -= PLAYER_ACCEL + PLAYER_DECEL;

                // Prevent X vector from going above the maximum speed.
                if (vector.X < -PLAYER_MAX_SPEED)
                    vector.X = -PLAYER_MAX_SPEED;
            }

            if (gamePadState.ThumbSticks.Left.Y > 0.5f || keyboardState.IsKeyDown(Keys.W))
            {
                vector.Y -= PLAYER_ACCEL + PLAYER_DECEL;

                // Prevent Y vector from going above the maximum speed.
                if (vector.Y < -PLAYER_MAX_SPEED)
                    vector.Y = -PLAYER_MAX_SPEED;
            }
            else if (gamePadState.ThumbSticks.Left.Y < -0.5f || keyboardState.IsKeyDown(Keys.S))
            {
                vector.Y += PLAYER_ACCEL + PLAYER_DECEL;

                // Prevent Y vector from going above the maximum speed.
                if (vector.Y > PLAYER_MAX_SPEED)
                    vector.Y = PLAYER_MAX_SPEED;
            }

            // Tend the x vector towards zero so we stop when the player isn't pushing on the joystick
            vector.X = Global.TendToZero(vector.X, PLAYER_DECEL);
            vector.Y = Global.TendToZero(vector.Y, PLAYER_DECEL);

            // Update the position of the map so it centers on the player.
            map.setViewPos(position);

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                scale += 0.1f;
                if (!visible)
                    visible = true;
            }

            if (keyboardState.IsKeyDown(Keys.Down))
            {
                scale -= 0.1f;
                if (scale <= 0.0f)
                {
                    scale = 0.1f;
                    visible = false;
                }
            }
        }
Ejemplo n.º 6
0
 public void DrawLight(SpriteBatch batch, Map map)
 {
     if(visible)
         map.DrawOnMap(batch, light, position, scale);
 }