Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post Posted: April 19th, 2017, 4:47 am 
 

Joined: April 7th, 2017, 12:17 am
Posts: 7
Hey,
so just starting out and have gone through lesson 12 or so and stopped to try and make a version of pong with what i have learned so far.

I have made a ball class and initialize at the beginning of the file and can draw the file with ball.draw(gfx); bounce it off the walls and paddles ect..

my problem is I can't seem to figure out how to destroy the ball object. I mean I can just stop drawing it but x & y keep updating and I can't seen to create another ball at the original settings.


any ideas?

Thanks for your time


Top 
 Profile  
Reply with quote  
 Post Posted: April 19th, 2017, 5:37 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2762
Location: Oklahoma, United States
1)Keep a static constexpr copy of the starting position of the ball in the ball.h file. When you need to reset the ball position, make ball.x and ball.y equal to Ball::xStart and Ball::yStart.

2)Make a reset function in the Ball class, and when you need to reset the position, you call the ball.Reset() function. In that function, you can assign x = xStart and y = yStart in that function.

3)In the Game class when you want to reset the ball position, you can assign a new ball to the old ball, ball = Ball(Ball::xStart, Ball::yStart );

Hope this gives you some ideas. If you want other things to reset, you would have to also make starting values for those as well and reset them. The last option has a drawback though, if you keep track of number of balls ( lives ) in the ball class, it will be reset to the default starting value. If you go with this option, keep the number of lives outside of the ball class, maybe in the Game class.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: April 20th, 2017, 2:21 am 
 

Joined: April 7th, 2017, 12:17 am
Posts: 7
Thanks albinopapa,
been playing with it and think I got a ball.reset() function working.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: