I have do a collision with my map the collision work but when my
player have a collision I stop the movement of the player and he don’t
walk because I don’t know how stop the player for one direction
its my code collision under the player and the map
public bool IsCollisionTile(Rectangle player) { foreach(Rectangle rect in this._collisionObject) { if (rect.Intersects(player)) { return true; } } return false; }
Its the code for the player don’t move is in the Game1 class
if (mapLoader.IsCollisionTile(player.getDestinationRect()))
{
player.setCantWalk(true);
}
Its the function update and setCantWalk in the class Player.cs
private bool _cantWalk;
public void Update()
{
this._destinationRectangle.X = (int)_position.X;
this._destinationRectangle.Y = (int)_position.Y;
this._destinationRectangle.Width = _texture.Width;
this._destinationRectangle.Height = _texture.Height;
if(Keyboard.GetState().IsKeyDown(Keys.Up))
{
if (_cantWalk == false)
{
_position.Y--;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
if (_cantWalk == false)
{
_position.Y++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
if (_cantWalk == false)
{
_position.X++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
if (_cantWalk == false)
{
_position.X--;
}
}
}
public void setCantWalk(bool walk)
{
_cantWalk = walk;
}
Thinks to help me