1
General / Re: Is this good beginner code?
« on: July 20, 2019, 06:19:17 pm »
Why did you use extern on speed? Doesn't look like you're using it anywhere else...
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Also, I would highly encourage you to learn vector algebra. It's one of the most intuitive fields of math and can make a lot of geometric relations really simple to model.
In your example, instead of separate X and Y coordinates, you might have a position and direction vector, plus a scalar (float) for the speed.sf::Vector2f position = ...;
sf::Vector2f direction = ...;
float speed = ...
The velocity would be the speed multiplied by the direction. The next position would simply be the current position, plus the velocity vector, scaled by the passed time:sf::Vector2f velocity = speed * direction;
sf::Time passedTime = ...;
sf::Vector2f nextPosition = position + velocity * passedTime.asSeconds();
To get started, maybe look for an introductory course on vectors on the Internet. Regarding API, you can use SFML for the basic types and operations and my library Thor for advanced vector operations.
I don't suppose it matters which dimension you put first; it depends on which way it will be used. Who says which dimension is whatI'm sorry, could you please explain what you mean by first?
If y was first (y2-y1)/(x2-x1), I would presume that the gradient would be multiplied with m_BulletDistanceY instead.