completing a level

Sorry if this obvious to everybody else, but it isn’t to me.

I have looked through a whole bunch of sample code for apps that have levels and how they determine when the level is complete, but most are based on scores. In my game I want the level to be complete when the ball touches the goal area. I tried something like

function levelComplete()
if ball.x > ? and ball.x < ? and ball.y > ? and ball.y < ? then
and then I put something here like redRect:rotate(90)
end

But that didn’t work. Then I saw another way to do it would be to use a function from another sample I saw where it got the distance from the ball to the goal and if it was less than whatever you set it to, something would happen

I understand that this is most likely my fault, It would just be great if I knew what had to be fixed :slight_smile:
PS- I didn’t actually put ?, I just dont have the #s off the top of my head.

Thanks :slight_smile: [import]uid: 7116 topic_id: 5675 reply_id: 305675[/import]

Hello!

Do you use an eventlistener to check for levelComplete() ? [import]uid: 10657 topic_id: 5675 reply_id: 19453[/import]

I just tried adding one, but I am not sure I did it right.

function levelComplete(event)
if ball.x > 0 and ball.x < 1000 and ball.y > 0 and ball.y < 1000 then
redRect:rotate(90)
end
Runtime:addEventListener(“enterFrame”,levelComplete)

Still doesnt work anyway,
thanks [import]uid: 7116 topic_id: 5675 reply_id: 19468[/import]

Ah… try adding another end after the one you already got [import]uid: 10657 topic_id: 5675 reply_id: 19469[/import]

ah! well that fixes the syntax error, but redRect isn’t rotating. In the end I want to have something else happen besides making the red rectangle rotate, but I thought I would use this as an example. And I made the values big enough and the ball is on the screen within those values so… [import]uid: 7116 topic_id: 5675 reply_id: 19471[/import]

Doesn’t look like you need it, but this function would be pretty ideal for detecting when the player hits the end game area:
http://developer.anscamobile.com/code/flashs-hittestobject-emulated-using-contentbounds [import]uid: 12108 topic_id: 5675 reply_id: 19552[/import]

that looks great! thanks :slight_smile: [import]uid: 7116 topic_id: 5675 reply_id: 19586[/import]