I have 3 classes with inheritance (GameObj <- Circle <- Puck) shown below. In my Circle i have a method called "colliding" - it takes two Circles as parameters and returns a boolean whether or not the two circles are intersecting. My problem is i need to feed it one instance of Puck and one instance of Paddle. I havnt made Paddle class yet but two Pucks will do for now. I dont know how to pass two pucks into the method
i can't say for example...
boolean intersect = colliding(this);
because it takes two parameters...
and it will get more complicated when i have two paddles and one puck
any help please??
abstract class GameObj
{
protected Game1 main;
protected Texture2D texture;
protected String spriteLoc;
protected Vector2 position;
protected Rectangle rect;
public GameObj(Game1 m, Vector2 pos, Texture2D t)
{
main = m;
position = pos;
texture = t;
}
public virtual Rectangle getRectangle()
{
rect = new Rectangle(
(int)position.X,
(int)position.Y,
rect.Width,
rect.Height);
return rect;
}
public virtual Vector2 getPosition()
{
Vector2 midPoint;
midPoint.X = position.X + texture.Width / 2;
midPoint.Y = position.Y + texture.Height / 2;
return midPoint;
}
public virtual void loadGraphicsContent(ContentManager content)
{
texture = content.Load<Texture2D>(spriteLoc);
}
public virtual void draw()
{
main.spriteBatch.Draw(texture, position, Color.White);
}
public virtual void draw(Rectangle rect)
{
main.spriteBatch.Draw(texture, rect, Color.White);
}
}
abstract class Circle : GameObj
{
protected Vector2 origin;
protected float radius;
public Circle(Game1 m, Vector2 pos, Texture2D t ) : base(m, pos, t)
{
radius = rect.Width;
}
public Vector2 getOrigin()
{
origin = new Vector2(rect.Width / 2, rect.Height / 2) + position;
return origin;
}
public float getRadius()
{
radius = rect.Width/2;
return radius;
}
public bool colliding(Circle c1, Circle c2)
{
float xd = c1.position.X - c2.position.X;
float yd = c1.position.Y - c2.position.Y;
float sumRadius = c1.radius + c2.radius;
float sqrRadius = sumRadius * sumRadius;
float distSqr = (xd * xd) + (yd * yd);
if (distSqr <= sqrRadius)
{
return true;
}
return false;
}
}
class Puck : Circle
{
protected float speed;
protected Vector2 direction;
public Puck(Game1 m, Texture2D t, Vector2 pos, float s) : base(m, pos, t)
{
speed = s;
direction = new Vector2(speed, speed);
rect = new Rectangle(0,0,50,50);
}
public void update()
{
position += direction;
}
}

New Topic/Question
Reply




MultiQuote




|