Ball movement question

Hi!
This is my first forum post in here. I just bought the indie-program and I’m very excited to start developing games. I’m a HTML/PHP/ASP-developer from scratch, now been playing around with objective-c for half a year and managed to publish four apps. And on my search for cocos2d sample code I found Corona SDK which seems very promising.

Oh well, enough about that. I have an idea for a brick breaker kinda game (without bricks) and for that I’ve tried to tweak this sample code:

http://mobile.tutsplus.com/tutorials/corona/corona-sdk_brick-breaker/

I want the ball to start out from the paddle, but in a specific angle, eg. 45° degrees. And when user moves the paddle to catch the ball, the ball should get attached to the paddle and the paddle will bounce back of the impact (like a jumping mat), then shoot the ball in the specific 45° angle again. The ball should also be affected by gravity.

Does anyone know any good ball samples? Or have any idea how I should tackle this problem?

Best regards,
joelwe [import]uid: 54640 topic_id: 9366 reply_id: 309366[/import]

http://developer.anscamobile.com/code/break-out-game [import]uid: 12482 topic_id: 9366 reply_id: 34253[/import]

Thank you for your link, hgvyas123. I couldn’t find any good code for ball movement there though.

Ok, so I’ve worked out some code. I now have two paddles which has 100x between them. The ball start out in the left paddle and bounces up in a curve, then come down with the purpose of hitting right paddle (paddle2). But when it lands it dies instead of bouncing back in the opposite direction.

Any idea to accomplish this?

function bounce(e)  
  
 if((ball.width) \<= (paddle.width)) then  
 xSpeed = 0  
 ySpeed = 0  
 ball:applyForce( 40, -130, ball.x, ball.y )  
 elseif((ball.width) \<= (paddle2.width)) then  
 xSpeed = 0  
 ySpeed = 0  
 ball:applyForce( -40, -130, ball.x, ball.y )  
 end  
  
 end  
  

Best regards,
joelwe [import]uid: 54640 topic_id: 9366 reply_id: 34271[/import]