public Ball(Texture2D image, Vector2 position, Color color, Vector2 speed, float scale) : base(position, color, image, scale) { this.Speed = speed; Score = 0; IsGrowing = false; Hitbox = new CircleCollider(Texture.Width * Scale / 2, Position + new Vector2(Texture.Width * Scale / 2, Texture.Height * Scale / 2)); }
public bool Intersects(CircleCollider other) { //step1: calculate the distance between the two positions //step2: calculate the sum of the radii //if the sum is greater than or equal to the distance between the centers //the objects collide, return true //intersection when, distance between centers is smaller than their Radii added together //find the distance between the two balls float distance = Vector2.Distance(Center, other.Center); if (Radius + other.Radius >= distance) { return(true); } return(false); }
public void Update(GameTime time, Viewport port, MouseState ms) { IsGrowing = false; Position += Speed * time.ElapsedGameTime.Milliseconds; // HitBox.X = (int)this.position.X; //HitBox.Y = (int)this.position.Y; // = new CircleCollider(center position of object, width of the texture to act as the radius) Hitbox = new CircleCollider(Texture.Width * Scale / 2, Position + new Vector2(Texture.Width * Scale / 2, Texture.Height * Scale / 2)); if (Hitbox.ContainsPoint(ms.X, ms.Y)) { Grow(); } if (Position.X < 0) { Speed.X = Math.Abs(Speed.X); } else if (Position.X + Texture.Width * Scale > port.Width) { Speed.X = -Math.Abs(Speed.X); } if (Position.Y < 0) { Speed.Y = Math.Abs(Speed.Y); } else if (Position.Y + Texture.Height * Scale > port.Height) { Speed.Y = -Math.Abs(Speed.Y); } if (IsGrowing) { Tint = Color.Red; } else { Tint = Color.White; } }