Preface: I understand that this question probably has an answer somewhere on the internet but I couldn't find a way to formulate it such that google gave me an answer.
Context: I'm working on a small project that involves objects moving around in 2D space. Each of those objects has a position, which is contained in a Vector2D object (has an x coordinate, y coordinate and a few other bits of logic related to positions).
Right now whenever I want to perform any sort of math on these objects (such as, for example, moving one around) , I have to separate out my calculations by X and Y axes which is a massive pain.
On to the question: Is there some way to implement an operator (such as '+' or '*') between classes so don't have to write the separate logic for each separate variable? And if so, what does that look like?
Example: I want to move object A 4 units to the right and 4 down.
Current situation:
this.ObjectA.x += 4;
This.objectA.y += 4;
Ideal situation: this.ObjectA += new Vector2D(4,4);