Can I have a collision answer?

I want for my game to be like bloonsTD in that once a bullet hits the zombie it does a bit of damage and after certain amounts of damage it disappears. Can someone show me the coding to have collisions do something like that?

Hey David!

It seems like you are asking a lot of rudimentary questions at once. I like your enthusiasm, but I would suggest that you take a moment to get acquainted with the basics first.

Corona has a fantastic set of tutorials that you could take a look at. First, here’s some general Lua tips with Corona in mind: https://docs.coronalabs.com/tutorial/. Then here are a few simple Corona projects you could take a look at: https://docs.coronalabs.com/guide/programming/index.html.

You can also find simple sample projects, along with their source code, by opening Corona simulator and opening the help tab, then navigate to sample projects. For instance, there’s an entire section for physics sample projects, such as CollisionDetection and CollisionFilters that might provide you with the answers that you seek here.

Finally, Corona Docs is a great resource for most questions like these. You can find extensive examples on topics like collision detection there, just type “corona sdk collision detection” to Google and you’ll get https://docs.coronalabs.com/guide/physics/collisionDetection/index.html.

If we’d copy the approach from the docs, you’d 1) create a display object, 2) give it a value like, “object.currentHP = 5” and then 3) you’d give it a collision listener, but instead of printing the object’s name, you’d always deduct 1 HP from it. Then you’d have a simple conditional statement that checks if the object has more 0 HP left. If it doesn’t, you remove it.

You are just starting to learn how to code, so it’s best to learn it by yourself instead of having someone write some code that sort of works, but that you’d need to rewrite later on anyway. Happy coding!

I second the above advice.

After getting a fundamental understanding of Lua + Corona + Game coding in general, you might consider downloading:

I forgot one:

https://forums.coronalabs.com/topic/74704-template-portfolio-release/

While not a tower defense mechanic, this answer has some parts of what you want.

https://forums.coronalabs.com/topic/72342-make-transition-react-to-collsion-contact/

https://www.youtube.com/watch?v=llV2NdQh9Ls