2
\$\begingroup\$

I'm creating a shooter, it's still very early, but i'm implementing some polygon hitboxes.

So far i have created a polygon class, and i'm looking into how i can hook it onto my player.

I'm trying to stay away from having a Tick() function in my polygon class, and I would rather not update the position every tick (it would clutter up my tick functions). At the same time I would really like to have the positions in there somehow (it has a drawing function, and i will be using it for hit detection)

How would i go about implementing this polygon object into my entities?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

This seems like a good place to use Composition.

Give the Entity your Polygon class as a property and update it whenever the entity moves.

public class Entity {
    public Polygon Hitbox { get; private set; }

    public void Move() {
        // stuff to move player
        this.Hitbox.X = this.Position.X;
        this.Hitbox.Width = ...
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ ofcourse! i just need to add a move method to my player! that would solve my problem of it cluttering my tick method, thanks! \$\endgroup\$ Oct 23, 2012 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .