I am new to using Corona and I’ve been creating a simple game to test out both my own and the software’s abilities. So far, I’m loving the program, but I’m afraid I’m stuck. I have this soccer ball and a platform at the top left and I want to know how can I make that platform trigger a “Win” or “Congratulations” message when the ball lands on it. What I’m thinking of is kind of like the popular game Bubble Ball: when the ball reaches the flag, you’ve won the level. I am using this sample as a base: http://www.fantomgl.com/files/JuggleSoccerBall.zip (download)
I’m not sure how to post an image here, but it’s the same thing as the sample code above but with a small platform on the top left; almost to the middle left. The objective is to tap the ball until you can get it unto the platform and “win” the level.
Thank you in advance,
technologygeek01
P.S. Excuse me for sounding like a noob, but I’ve seen the community here help so many other people and thought to myself, “Why not?” [import]uid: 57808 topic_id: 9733 reply_id: 309733[/import]
You could do this a few different ways. The easiest is probably to give the ball/end platform a collision listener; on collision with the other you’d call the endlevel (or whatever you’re calling it) function.
I hope that helps; you can find out more about Collision detection in the Sample Code section of the website.
Basically when the ball makes contact with the platform, you want to know and then use a function to show your message. (Which I assume you know how to do if you’ve gotten this far?)
The example I linked to will print the names of the objects colliding but it can do anything a normal function can; remove an object, spawn something, play a sprite, etc.
I think I got it to detect the collision, but I don’t know how to display the message… The link did help a lot, though. I’m so sorry If I’m being a bother. I’m just so eager to learn this! [import]uid: 57808 topic_id: 9733 reply_id: 35518[/import]
did you put the print function inside the collision?
[lua]-- example
local onGoal = function (self, event)
if event.phase == “began” then
– do something here
– ex: create your winning message here
– print to test if the collision is working, check terminal
print(“Collision is working”)
end
end
[import]uid: 12455 topic_id: 9733 reply_id: 35519[/import]
local onGoal = function (self, event)
if event.phase == “began” then
– goal .name can be created on your goal object
– just add this to your goal object
– goal.name = “goal”
if event.other.name == “goal” then
– this will remove the ball
self:removeSelf()
– update the score, for now check the terminal for result
score = score + 1
print("the score is now: "…score)
end
end
end[/lua]
hope that gives you an idea [import]uid: 12455 topic_id: 9733 reply_id: 35522[/import]
I want to display a “You win” image. When the ball touches the goal the terminal says something like, “Soccerball: collision began with goal,” so I guess that means the collision is working… [import]uid: 57808 topic_id: 9733 reply_id: 35526[/import]
[lua]local youwin = display.newImage “youwin.png” – Obviously this is your image
youwin.x = 150 – change as needed
youwin.y = 150 – change as needed[/lua]
See? Just like adding an image in the normal way; just do it next to your print line. [import]uid: 52491 topic_id: 9733 reply_id: 35528[/import]
So, say that there are different colored balls with different score, how would I attach that score to the object? [import]uid: 25216 topic_id: 9733 reply_id: 35529[/import]
Oh… I figured that it would look something like that! Thanks for your help! I really appreciate it. [import]uid: 25216 topic_id: 9733 reply_id: 35536[/import]
Thanks again, I just have one more question, can I turn simple text
[lua]local score = display.newText( “0”, 460, 10, “font”, 75 )[/lua]
into score? I keep getting stuck up at this part. [import]uid: 25216 topic_id: 9733 reply_id: 35550[/import]