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; } } } }
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); } }
public static void Draw(SpriteBatch spriteBatch, ObjectPositionRepository objectPositionRepository) { spriteBatch.Begin(); DrawSolidObjects(spriteBatch, objectPositionRepository); DrawHostileObjects(spriteBatch, objectPositionRepository); DrawPlayerObjects(spriteBatch, objectPositionRepository); spriteBatch.End(); }
private static bool CollidedWithSolidObject(ObjectPositionRepository objectPositionRepository, Rectangle toBePosition) { var solidObjectRectangles = objectPositionRepository.GetSolidPositions().Select(x => x.DestinationRectangle); foreach (var solidObject in solidObjectRectangles) { if (toBePosition.Intersects(solidObject)) { return(true); } } return(false); }
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; } } } }
public static void UpdateObjectPositions(ObjectPositionRepository objectPositionRepository, IControllerInput controllerInput) { UpdatePlayerPositions(objectPositionRepository, controllerInput); }
public static void CheckGameRules(ObjectPositionRepository objectPositionRepository) { If_Hostile_Touch_Then_Lose_Player_Life(objectPositionRepository); //etc... }