Example #1
0
 private static void DrawPlayerObjects(SpriteBatch spriteBatch, ObjectPositionRepository objectPositionRepository)
 {
     foreach (var item in objectPositionRepository.GetPlayerPositions())
     {
         spriteBatch.Draw(item.Texture, item.DestinationRectangle, item.SourceRectangle, item.Color, item.Rotation, item.Origin, item.Effects, item.LayerDepth);
     }
 }
Example #2
0
        private static void UpdatePlayerPositions(ObjectPositionRepository objectPositionRepository, IControllerInput controllerInput)
        {
            foreach (var player in objectPositionRepository.GetPlayerPositions())
            {
                if (controllerInput.MoveLeft())
                {
                    player.Effects = SpriteEffects.FlipHorizontally;

                    Rectangle newPosition = player.DestinationRectangle;
                    newPosition.X -= MOVEMENTINTERVAL;

                    if (!CollidedWithSolidObject(objectPositionRepository, newPosition))
                    {
                        player.DestinationRectangle = newPosition;
                    }
                }

                if (controllerInput.MoveRight())
                {
                    player.Effects = SpriteEffects.None;

                    Rectangle newPosition = player.DestinationRectangle;
                    newPosition.X += MOVEMENTINTERVAL;

                    if (!CollidedWithSolidObject(objectPositionRepository, newPosition))
                    {
                        player.DestinationRectangle = newPosition;
                    }
                }
            }
        }
Example #3
0
        private static void If_Hostile_Touch_Then_Lose_Player_Life(ObjectPositionRepository objectPositionRepository)
        {
            var players  = objectPositionRepository.GetPlayerPositions();
            var hostiles = objectPositionRepository.GetHostilePositions();

            var hostileRectangles = hostiles.Select(x => x.DestinationRectangle);
            var playersHit        = new List <IPlayer>();

            foreach (var player in players)
            {
                foreach (var hostile in hostileRectangles)
                {
                    if (player.DestinationRectangle.Intersects(hostile))
                    {
                        player.PlayerLives -= 1;
                        //TODO Rename 'position', these are more than just the positions
                        objectPositionRepository.UpdatePlayerPosition(player);
                        break;
                    }
                }
            }
        }