public void Move(Vector2 position, DrawController drawController) { if (CheckDirection(drawController, position)) { this.position += position; } }
public void Move(Vector2 position, DrawController drawController) { foreach (var gameElement in drawController.Map) { if (gameElement != null && gameElement.Position() == this.position + position) { if (gameElement.Texture == Constants.WallTexture) { return; } if (gameElement.Texture == Constants.BoxTexture) { var box = gameElement as IDynamic; var boxPosition = (box as IGameElement).Position(); box.Move(position, drawController); if ((box as IGameElement).Position() == boxPosition) { return; } } } } this.position += position; CheckDirection(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { graphics.PreferredBackBufferWidth = Constants.WindowWidth; graphics.PreferredBackBufferHeight = Constants.WindowHeight; graphics.ApplyChanges(); drawController = new DrawController(); base.Initialize(); string[] path = { "Content", "Levels", "Level_1.txt" }; drawController.CreateMap(Path.Combine(path)); }
public bool CheckDirection(DrawController drawController, Vector2 position) { foreach (var gameElement in drawController.Map) { if (gameElement != null && gameElement.Position() == this.position + position) { if (gameElement.Texture == Constants.BoxPlaceTexture) { boxInPlace = true; } if (gameElement.Texture == Constants.WallTexture || gameElement.Texture == Constants.BoxTexture) { return(false); } } } return(true); }