Sign in to follow this  
ukdeveloper

Problem with setting SDL_Rect up

Recommended Posts

Me again, I've got another problem (getting beyond a joke, I haven't even finished one game in SDL yet):
struct pong_ball
{
       
       vector2f *position;
       
       vector2f *direction;
       
       float speed;
       
       pong_ball()
       {
                  position=new vector2f(WINDOW_WIDTH/2,WINDOW_HEIGHT/2);
                  
                  direction=new vector2f(1.0,1.0);
                 
                  speed=0.5f;
       }
       
};

pong_ball g_ball;

void ball_draw()
{
     
     SDL_Rect ballrect;
     
     ballrect.x=g_ball.position.x;
     
     ballrect.y=g_ball.position.y;
     
     SDL_BlitSurface(ball,NULL,GameWindow,&ballrect);
     
}




On compile, it says: 53 C:\Documents and Settings\FINALPONG\main.cpp `x' has not been declared 53 C:\Documents and Settings\FINALPONG\main.cpp request for member of non-aggregate type before ';' token 55 C:\Documents and Settings\FINALPONG\main.cpp `y' has not been declared 55 C:\Documents and Settings\FINALPONG\main.cpp request for member of non-aggregate type before ';' token I've tried

position.x=new vector2f(WINDOW_WIDTH/2);
position.y=new vector2f(WINDOW_HEIGHT/2);


but it didn't like that either (even more errors). Any ideas? I'm stumped, never tried to do this before so I don't know a way round it. Thanks, ukdeveloper.

Share this post


Link to post
Share on other sites
I don't intend to be rude, but maybe you should walk a little and re-read a few tutorials on pointers, re-read the book on C++(at least the basics like classes and operator overloading etc) and then come back to this. Like maybe give it a week.

I know you are dying to complete a game but patience is bitter, the fruits are sweet.

Share this post


Link to post
Share on other sites
Quote:
Original post by CRACK123
I don't intend to be rude, but maybe you should walk a little and re-read a few tutorials on pointers, re-read the book on C++(at least the basics like classes and operator overloading etc) and then come back to this. Like maybe give it a week.

I know you are dying to complete a game but patience is bitter, the fruits are sweet.


I know, I appreciate what you're saying, but I've done work on pointers before, and classes. It's the first time I've used them with regards to graphics though. If this was an ordinary text-based, non-game-whatsoever program there wouldn't be any problem, I don't think.

Or maybe I'm just not made for game programming, who knows.

Share this post


Link to post
Share on other sites
Quote:
Original post by ukdeveloper
Or maybe I'm just not made for game programming, who knows.

No dude, almost everyone has to work on the concept of pointer and object oriented code when they are new to programming. You've made the mistake, correct it, learn from it and continue on. Then the next time you write a program you won't make that mastake again, you'll make bigger, better mistakes [grin].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this