public void CheckWithEachOther(Sprite sprite1, List<Sprite> sprites, int deltaTime) { foreach (Sprite sprite2 in sprites) { if (sprite1 == sprite2) continue; Vector2 dst1 = sprite1.Position + new Vector2(sprite1.Width / 2, sprite1.Height / 2) + sprite1.Velocity * deltaTime; Vector2 dst2 = sprite2.Position + new Vector2(sprite2.Width / 2, sprite2.Height / 2) + sprite2.Velocity * deltaTime; Vector2 dstBetween = dst1 - dst2; if (Math.Abs(dstBetween.Y) <= sprite1.Height / 2 + sprite2.Height / 2 && Math.Abs(dstBetween.X) <= sprite1.Width / 2 + sprite2.Width / 2) { sprite2.Collide(); sprite1.Velocity = Vector2.Normalize(dstBetween) * sprite1.Velocity.Length(); Game1.soundPlayer.PlaySoundEffect("collideins"); } } }
public void CheckWithScreenBounds(Sprite sprite) { Vector2 dst = sprite.Position + sprite.Velocity; if (sprite.Velocity.X < 0 && dst.X <= 0) { sprite.CollisionV += new Vector2(1, 0); Game1.soundPlayer.PlaySoundEffect("collideins"); } if (sprite.Velocity.X > 0 && dst.X + sprite.Texture.Width > ScreenWidth) { sprite.CollisionV += new Vector2(-1, 0); Game1.soundPlayer.PlaySoundEffect("collideins"); } if (sprite.Velocity.Y < 0 && dst.Y <= 0) { sprite.CollisionV += new Vector2(0, 1); Game1.soundPlayer.PlaySoundEffect("collideins"); } if (sprite.Velocity.Y > 0 && dst.Y + sprite.Texture.Height > ScreenHeight) { sprite.CollisionV += new Vector2(0, -1); } }
public SpriteController(Sprite sprite) { m_sprite = sprite; }