2 problems need help

I’m trying to create my first game and its almost done, just need final touch.
First i would like it to play sound of ball bouncing when it hits floor or walls of my game screen what function to use to do this?
And second i have 2 options for this and would like to do just one of them: to add +1 to score if 2 balls collide or second idea is to count down time and at end of it to write high score and give option to restart game. [import]uid: 189039 topic_id: 32498 reply_id: 332498[/import]

These are some very broad questions and it’s hard to answer them specifically without knowing more about your app.

  1. play sound when a ball hits… You need to enable collision detection. You typically give each object a name and you can when the collision is detected see if the ball hit the floor and then play your sound. Keep in mind that Android sounds lag, so you will never have it precise.

2a. in that same collision detection if ball1 hits ball 2 then simply have a variable called score and do:

score = score + 1  

2b. look up timer.performWithDelay. Lets say you want the round to last 30 seconds:

 levelTime = 30  
 timer.performWithDelay(1000, updateCountDown, 30)  

will cause the function named updateCountDown to be executed 30 times, once every 1000 milliseconds which is 1 second. In that function you can update your time display:

function updateCountDown()  
 levelTime = levelTime - 1  
 timeDisplay.text = levelTime -- assumes you've done a display.newText() and saved it to a variable named timeDisplay  
 if levelTime \<= 0 then  
 -- do your game over code here  
 end  
end  

or something similar. [import]uid: 19626 topic_id: 32498 reply_id: 129248[/import]

What is code for collision detection, like i have given my objects names floor, ceiling, rightWall, leftWall, ball, ball2, ball3? [import]uid: 189039 topic_id: 32498 reply_id: 129273[/import]

Too much for a forum post. Goggle Corona SDK collisions, tons of tutorials and references. [import]uid: 19626 topic_id: 32498 reply_id: 129277[/import]

These are some very broad questions and it’s hard to answer them specifically without knowing more about your app.

  1. play sound when a ball hits… You need to enable collision detection. You typically give each object a name and you can when the collision is detected see if the ball hit the floor and then play your sound. Keep in mind that Android sounds lag, so you will never have it precise.

2a. in that same collision detection if ball1 hits ball 2 then simply have a variable called score and do:

score = score + 1  

2b. look up timer.performWithDelay. Lets say you want the round to last 30 seconds:

 levelTime = 30  
 timer.performWithDelay(1000, updateCountDown, 30)  

will cause the function named updateCountDown to be executed 30 times, once every 1000 milliseconds which is 1 second. In that function you can update your time display:

function updateCountDown()  
 levelTime = levelTime - 1  
 timeDisplay.text = levelTime -- assumes you've done a display.newText() and saved it to a variable named timeDisplay  
 if levelTime \<= 0 then  
 -- do your game over code here  
 end  
end  

or something similar. [import]uid: 19626 topic_id: 32498 reply_id: 129248[/import]

What is code for collision detection, like i have given my objects names floor, ceiling, rightWall, leftWall, ball, ball2, ball3? [import]uid: 189039 topic_id: 32498 reply_id: 129273[/import]

Too much for a forum post. Goggle Corona SDK collisions, tons of tutorials and references. [import]uid: 19626 topic_id: 32498 reply_id: 129277[/import]

This tutorial explains collision detection: http://corona.techority.com/2011/06/19/corona-for-newbies-part-4-physics/

Peach :slight_smile:

[import]uid: 52491 topic_id: 32498 reply_id: 129413[/import]

This tutorial explains collision detection: http://corona.techority.com/2011/06/19/corona-for-newbies-part-4-physics/

Peach :slight_smile:

[import]uid: 52491 topic_id: 32498 reply_id: 129413[/import]