   OO pong clone
  hello,I am going to try and make a pong clone. I would like to do it object oriented, and i'd like to know if I'm on the right track. This is how I would define the classes.class balls{ private: int x,y,xveloc,yveloc, type; public: balls* nextball; balls(); void checkcollision(); void move(); }ball;class paddles{    private:    int x,width;    public:    paddles();    void moveright();    void moveleft();    friend class balls;    }paddle;class blocks{   private:   int type;   bool active;   public:   void remove();   friend class balls;   };   the ball.move() needs acces to the coordinates of the paddles and blocks and has to be able to call block.remove().will it work like this or am I missing something?   
  You should create a baseclass like Entity and derive the other classes from it.Just call your classes: Ball, Paddle and BlockYou define the object by creating a class.There just can be many instances of those classes.The instances (like all variables) should start with a lowercase letter. The classes shouldn't.Your Entity baseclass should have abstract functions like:virtual bool check_collision(const Entity& entity) = 0;virtual void handle_collision(const Entity& entity) = 0;virtual void set_position(int x, int y);(Make sure the gamelogic uses this funtion correctly for each type of entity)If you decide to use a rectangle even for the ball you could even put all the code in the baseclass.You entity management code can have a list of all Entities then and check each of them against the others.Personally I like to put run_frameBegin(), run_frameIdle() and run_frameEnd() in all the Entities. Those could be called for each entity and like that the ball could move itself.The gamelogic wouldn't need to regard the ball as a special case with a move method that needs to be called.   ;  *falling flat on my back*I think I'm going to have to look in to this after my exams, seems a bit more complex than what I'm capable of right now.   ;  No need to do that ... probably.I just thought that would be good advice since you mentioned you wanted an object oriented approach.What api would you be using? Probably if you don't want to add many twists later you can do it the way you planned.Btw. what are the links between the ball instances for?Guess you weren't going to write an entity manager and can't access them any other way?In that case you should probably add such a pointer for the blocks as well.   ;  I was going to use the pointer to have a variable amount of balls in the game. for the blocks I won't need this because I'm working with a 2D array containing all the blocks, and those that don't show during the game will have active=false;I was going to try OpenGL, but not sure yet. All I've done so far is SDL.;Quote:Original post by twoaterisnI was going to use the pointer to have a variable amount of balls in the game.Don't do that. It's a Bad Thing (tm) to directly hard-code a linked list into your classes like you're doing. I strongly suggest you take out that pointer and simply use a std::vector of balls.I am also curious why you named your classes in the plural. It would make more sense IMHO if it were, for example, paddle rather than paddles.   ;  Or, if you're going to be adding/taking away balls very often, use an std::list. Lists are faster at adding or removing instances, but you don't have random access to the instances. This shouldn't be a problem for balls in a pong game, seeing as you'll probably just be looping through them and drawing them, and looping through them to do collision. At no point is random access necessary.Both SDL and OpenGL are fine for a pong game.   ;  thanks a lot guys :)   