I want to make a Platform object solid from every side so that the Player could not pass through it. I think the most simple idea is to use a "previous position" variable. Especially with the Intersects() method (I like it)!
If Player intersects, then move to last position. But nothing happens. Most likely I couldn't figure out how to implement proper "previous position".
Here's what I have in class Player:
public void Collision(Sprite obj)
{
Vector2 previousPosition = this.Position;
if (this.Bounds.Intersects(obj.Bounds))
{
this.Position = previousPosition;
}
}
Player and Platform inherit Sprite class which has this property:
public Rectangle Bounds
{
get
{
return new Rectangle((int)Position.X, (int)Position.Y,
Texture.Width, Texture.Height);
}
}
Another idea I tried was to use a bool isSolid but I didn't know how to work the logic. I've searched and tried things around the net(including stackoverflow) for maybe 4-5 hours. This is supposed to be so simple, yet I can't understand it!