예제 #1
0
파일: Level.cs 프로젝트: jordanell/Blocker
        /// <summary>
        /// Returns a movement for a moveable block based on origin and direction.
        /// </summary>
        /// <param name="origin">The origin of the movement.</param>
        /// <param name="direction">The direction of the movement.</param>
        /// <returns></returns>
        private Movement GetBlockMovement(Vector2 origin, Direction direction)
        {
            // Get the destination of the movement
            Vector2 destination = GetDestination(origin, direction);

            // Create the movement if destination is not origin
            if (destination.X != -1 && destination != origin)
            {
                Movement movement = new Movement(game,
                    new Rectangle(((int)origin.X * blockWidth), (hudBuffer + ((int)origin.Y * blockHeight)), blockWidth, blockHeight),
                    new Rectangle(((int)destination.X * blockWidth), (hudBuffer + ((int)destination.Y * blockHeight)), blockWidth, blockHeight));
                return movement;
            }

            // Return null if movement is bad
            return null;
        }
예제 #2
0
파일: Level.cs 프로젝트: jordanell/Blocker
        /// <summary>
        /// Given a direction, this method applies a movement to the player if possible.
        /// </summary>
        /// <param name="direction">The direction to move the player</param>
        private void ProcessPlayerMove(Direction direction)
        {
            // Where the player started and can move to
            Vector2 origin = new Vector2(
                player.Position.X / blockWidth, (player.Position.Y / blockHeight) - 2);
            Vector2 destination = GetDestination(origin, direction);

            // Only move if the destination is not the origin and they player has fuel
            if (destination.X != -1 && destination != origin && HUD.Fuel > 0)
            {
                // Decrease the fuel
                HUD.DecreaseFuel();

                // Move the player
                Movement movement = new Movement(game,
                    new Rectangle(((int)origin.X * blockWidth), (hudBuffer + ((int)origin.Y * blockHeight)), blockWidth, blockHeight),
                    new Rectangle(((int)destination.X * blockWidth), (hudBuffer + ((int)destination.Y * blockHeight)), blockWidth, blockHeight));
                player.Move(movement);

                // Update the level state and play sound
                state = LevelState.Moving;
                SoundMixer.Instance(game).PlayMove(false);
            }
        }
예제 #3
0
파일: Level.cs 프로젝트: jordanell/Blocker
 /// <summary>
 /// Applies a movement to a moveable block.
 /// </summary>
 /// <param name="target">The moveable block to be moved.</param>
 /// <param name="move">The movement.</param>
 /// <param name="origin">The origin.</param>
 /// <param name="color">The color of the block.</param>
 private void ApplyPush(MoveableBlock target, Movement move, Vector2 origin, Color color)
 {
     ((MoveableBlock)target).Move(move);
     if(color == Color.Red)
         HUD.DecreaseRedMatter();
     else if (color == Color.Blue)
         HUD.DecreaseBlueMatter();
     map[(int)origin.Y, (int)origin.X] = null;
     Vector2 dest = GridIndexOf(new Vector2(move.End.X, move.End.Y));
     map[(int)dest.Y, (int)dest.X] = target;
     GenerateLightning(move.Direction, new Vector2(move.Start.X, move.Start.Y), color);
     SoundMixer.Instance(game).PlayShoot(false);
 }
예제 #4
0
파일: Player.cs 프로젝트: jordanell/Blocker
        /// <summary>
        /// Allows the player to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // Update movement if moving
            if (State == PlayerState.Moving)
            {
                movement.Update(gameTime);

                // Check collisions with matter
                for (int y = 0; y < level.Map.GetLength(0); y++)
                {
                    for (int x = 0; x < level.Map.GetLength(1); x++)
                    {
                        if (level.Map[y, x] != null && level.Map[y, x].GetType() == typeof(Matter))
                        {
                            // Add matter when colidding
                            if (movement.Position.Intersects(level.Map[y, x].Position))
                                level.AddMatterAt(x, y);
                        }
                    }
                }

                // Check if movement is complete
                if (movement.Complete)
                {
                    State = PlayerState.Idle;
                    movement = null;
                }
            }

            // Update idle animation
            else if(State == PlayerState.Idle)
                idle.Update(gameTime);

            base.Update(gameTime);
        }
예제 #5
0
파일: Player.cs 프로젝트: jordanell/Blocker
 /// <summary>
 /// Apply a movement to the player.
 /// </summary>
 /// <param name="movement"></param>
 public void Move(Movement movement)
 {
     this.movement = movement;
     Position = movement.End;
     State = PlayerState.Moving;
 }
예제 #6
0
 /// <summary>
 /// Move a block based on a provided movement
 /// </summary>
 /// <param name="movement">A movement which will be applied to the block</param>
 public void Move(Movement movement)
 {
     this.movement = movement;
     Position = movement.End;
     state = MoveableBlockState.Moving;
 }
예제 #7
0
        /// <summary>
        /// Allows the MoveableBlock to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            //Update a moving block
            if (state == MoveableBlockState.Moving)
            {
                movement.Update(gameTime);

                // Check if movement is complete
                if (movement.Complete)
                {
                    state = MoveableBlockState.Idle;
                    movement = null;
                }
            }
        }