Skip to main content
deleted 3 characters in body
Source Link
momboco
  • 1.7k
  • 14
  • 12

All of your calculations must be implemented independently of time, the frameTime is the correct form to do this. There are different forms to calculate this elapsed time, but you don't worry about this now. With the frameTime you calculates the desired next position of the ball and then you need to calculate collisions and adjust the position if it's necessary.

About the code:

1.- Decide a convention to the variable names and follow it.

"Time" has the first letter is uppercase unlike buffX

in c++ usually the first letter of variables is lowercase

2.- Do you think that the function CalculateMove needs to be a template?

I don't think that the type of the parameters will be different to float in the game. If it don't needed, don't use it.

3.- For the cast conversions is better use static_cast( variable ) form.

Because it's more clear and it can be searched easily.

4.- In c++ the class names usually begins with uppercase.

5.- The constructor has a lot of parameters.

It's better declare a structure with these parameters and pass it by const reference to the constructor. In addition, the constructor of the structure can have the default parameters.

Like:

struct SpriteParams
{
      float          m_rotation;
      float          m_angle;

      SpriteParams()
          : m_rotation( 0.f )
          , m_angle( 0.f )
      {}
 };

 // The mySprite constructor
 MySprite::MySprite( const SpriteParams& params );

6.- Are you sure that mySprite must inherit from Sprite?

If this class is modelling a paddle, the class must be a paddle and contains a graphics representation ( the sprite )

class Paddle
{
     public:
         void update();

     private:
         sf::Sprite  m_sprite;
};

All of your calculations must be implemented independently of time, the frameTime is the correct form to do this. There are different forms to calculate this elapsed time, but you don't worry about this now. With the frameTime you calculates the desired next position of the ball and then you need to calculate collisions and adjust the position if it's necessary.

About the code:

1.- Decide a convention to the variable names and follow it.

"Time" has the first letter is uppercase unlike buffX

in c++ usually the first letter of variables is lowercase

2.- Do you think that the function CalculateMove needs to be a template?

I don't think that the type of the parameters will be different to float in the game. If it don't needed, don't use it.

3.- For the cast conversions is better use static_cast( variable ) form.

Because it's more clear and it can be searched easily.

4.- In c++ the class names usually begins with uppercase.

5.- The constructor has a lot of parameters.

It's better declare a structure with these parameters and pass it by const reference to the constructor. In addition, the constructor of the structure can have the default parameters.

Like:

struct SpriteParams
{
      float          m_rotation;
      float          m_angle;

      SpriteParams()
          : m_rotation( 0.f )
          , m_angle( 0.f )
      {}
 };

 // The mySprite constructor
 MySprite::MySprite( const SpriteParams& params );

6.- Are you sure that mySprite must inherit from Sprite?

If this class is modelling a paddle, the class must be a paddle and contains a graphics representation ( the sprite )

class Paddle
{
     public:
         void update();

     private:
         sf::Sprite  m_sprite;
};

All of your calculations must be implemented independently of time, the frameTime is the correct form to do this. There are different forms to calculate this elapsed time, but you don't worry about this now. With the frameTime you calculates the desired next position of the ball and then you need to calculate collisions and adjust the position if it's necessary.

About the code:

1.- Decide a convention to the variable names and follow it.

"Time" has the first letter uppercase unlike buffX

in c++ usually the first letter of variables is lowercase

2.- Do you think that the function CalculateMove needs to be a template?

I don't think that the type of the parameters will be different to float in the game. If it don't needed, don't use it.

3.- For the cast conversions is better use static_cast( variable ) form.

Because it's more clear and it can be searched easily.

4.- In c++ the class names usually begins with uppercase.

5.- The constructor has a lot of parameters.

It's better declare a structure with these parameters and pass it by const reference to the constructor. In addition, the constructor of the structure can have the default parameters.

Like:

struct SpriteParams
{
      float          m_rotation;
      float          m_angle;

      SpriteParams()
          : m_rotation( 0.f )
          , m_angle( 0.f )
      {}
 };

 // The mySprite constructor
 MySprite::MySprite( const SpriteParams& params );

6.- Are you sure that mySprite must inherit from Sprite?

If this class is modelling a paddle, the class must be a paddle and contains a graphics representation ( the sprite )

class Paddle
{
     public:
         void update();

     private:
         sf::Sprite  m_sprite;
};
Source Link
momboco
  • 1.7k
  • 14
  • 12

All of your calculations must be implemented independently of time, the frameTime is the correct form to do this. There are different forms to calculate this elapsed time, but you don't worry about this now. With the frameTime you calculates the desired next position of the ball and then you need to calculate collisions and adjust the position if it's necessary.

About the code:

1.- Decide a convention to the variable names and follow it.

"Time" has the first letter is uppercase unlike buffX

in c++ usually the first letter of variables is lowercase

2.- Do you think that the function CalculateMove needs to be a template?

I don't think that the type of the parameters will be different to float in the game. If it don't needed, don't use it.

3.- For the cast conversions is better use static_cast( variable ) form.

Because it's more clear and it can be searched easily.

4.- In c++ the class names usually begins with uppercase.

5.- The constructor has a lot of parameters.

It's better declare a structure with these parameters and pass it by const reference to the constructor. In addition, the constructor of the structure can have the default parameters.

Like:

struct SpriteParams
{
      float          m_rotation;
      float          m_angle;

      SpriteParams()
          : m_rotation( 0.f )
          , m_angle( 0.f )
      {}
 };

 // The mySprite constructor
 MySprite::MySprite( const SpriteParams& params );

6.- Are you sure that mySprite must inherit from Sprite?

If this class is modelling a paddle, the class must be a paddle and contains a graphics representation ( the sprite )

class Paddle
{
     public:
         void update();

     private:
         sf::Sprite  m_sprite;
};