//I dont like this get move commit move model, but frankly my code base is a bit nasty so, Ill do that for now and tidy it if I get chance. public void DoMove(Map terrain) { if (!terrainCollision(nextLocation, terrain)) { location = nextLocation; } }
private bool terrainCollision(Vector2 nextLocation, Map terrain) { Matrix playerMat = Matrix.CreateTranslation(nextLocation.X, nextLocation.Y, 0); Matrix terrainMat = Matrix.CreateTranslation((terrain.getDisplayRectangle().X * -1), (terrain.getDisplayRectangle().Y * -1), 0) * Matrix.CreateTranslation(terrain.getDisplayRectangle().X, terrain.getDisplayRectangle().Y, 0); Vector2 collisionPoint = Helpers.TexturesCollide(playerColors, playerMat, terrainColors, terrainMat); if (collisionPoint.X != -1) { return true; } return false; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); device = graphics.GraphicsDevice; officeTexture = Content.Load<Texture2D>("OfficeTemplate"); playerTexture = Content.Load<Texture2D>("You"); NPCTexture = Content.Load<Texture2D>("NPC"); font = Content.Load<SpriteFont>("Georgia"); menuTexture = CreateRectangle(400, 400); screenWidth = device.PresentationParameters.BackBufferWidth; screenHeight = device.PresentationParameters.BackBufferHeight; gameOverTexture = CreateRectangle(screenWidth, screenHeight); alertTexture = CreateRectangle(screenWidth / 2, screenHeight / 2); playerObject = new Player(playerTexture, officeTexture); level = new Map(officeTexture, screenWidth, screenHeight, playerObject.getLocation()); menu = new GameMenu(); gameEvents = new RandomGameEvents(playerObject); }