public bool CheckCollision(PhysicalObject other) { Rectangle myrectangle = new Rectangle(Convert.ToInt32(X), Convert.ToInt32(Y), Convert.ToInt32(Width), Convert.ToInt32(Height)); Rectangle otherrectangle = new Rectangle(Convert.ToInt32(other.X), Convert.ToInt32(other.Y), Convert.ToInt32(other.Width), Convert.ToInt32(other.Height)); return(myrectangle.Intersects(otherrectangle)); }
public void CheckTiles() { foreach (PhysicalObject t in GameElements.tiles) { if (speed.Y >= 0) { if (speed.Y > 0 && Y + t.Height / 2 < t.Y) { PhysicalObject temp = new PhysicalObject(texture, X, Y + speed.Y, speed.X, speed.Y); if (temp.CheckCollision(t)) { speed.Y = 0f; vector.Y += t.Y - Y - Height; if (this is Players) { (this as Players).Timespressed = 0; } } } } } }