I am new to C++ development and I am trying to create a more flexible projectile system.
In my current system I apply a equation to move the point down the bullet path.
class Bullet{
public:
float x;
float y;
float speed;
float angle;
void Update(){
x=(speed*cos(angle)) + x;
y=(speed*sin(angle)) + y;
};
}
This works fine for moving a bullet on an angle, however I would like to generate much more complex paths, without over complicating the bullet class.
My idea was to pass a function to the bullet class that would be used to move the object but I have not found any way to do this.
Example of what I want to do:
class Bullet{
public:
function dostuff();
float x;
float y;
float angle;
void Update(){
dostuff(x,y,angle,speed);
};
};
class Enemy{
public:
float x;
float y;
float speed;
float angle;
void shoot(){
Bullet bullet;
auto movangle = [](float x, float y, float angle,float speed)
{
x=(speed*cos(angle)) + x;
y=(speed*sin(angle)) + y;
};
bullet.dostuff = movangle;
bullet.Update();
};
};
If anyone knows of any ways to implement a system like this, or ideas on alternatives that could produce similar results It would be appreciated as I am somewhat stumped.